compat_utmpx.c revision 1.3 1 1.3 christos /* $NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.3 christos * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by Christos Zoulas.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos *
19 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
30 1.1 christos */
31 1.1 christos #include <sys/cdefs.h>
32 1.1 christos
33 1.1 christos #if defined(LIBC_SCCS) && !defined(lint)
34 1.3 christos __RCSID("$NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $");
35 1.1 christos #endif /* LIBC_SCCS and not lint */
36 1.1 christos
37 1.1 christos #include "namespace.h"
38 1.1 christos #include <sys/types.h>
39 1.1 christos #include <sys/param.h>
40 1.1 christos
41 1.3 christos #define __LIBC12_SOURCE__
42 1.1 christos #include <assert.h>
43 1.3 christos #include <sys/time.h>
44 1.1 christos #include <string.h>
45 1.3 christos #include <compat/sys/time.h>
46 1.1 christos #include <utmpx.h>
47 1.1 christos #include <compat/include/utmpx.h>
48 1.1 christos
49 1.3 christos __warn_references(getutxent,
50 1.3 christos "warning: reference to compatibility getutxent(); include <utmpx.h> for correct reference")
51 1.3 christos __warn_references(getutxid,
52 1.3 christos "warning: reference to compatibility getutxid(); include <utmpx.h> for correct reference")
53 1.3 christos __warn_references(getutxline,
54 1.3 christos "warning: reference to compatibility getutxline(); include <utmpx.h> for correct reference")
55 1.3 christos __warn_references(pututxline,
56 1.3 christos "warning: reference to compatibility pututxline(); include <utmpx.h> for correct reference")
57 1.3 christos __warn_references(updwtmpx,
58 1.3 christos "warning: reference to compatibility updwtmpx(); include <utmpx.h> for correct reference")
59 1.1 christos __warn_references(getlastlogx,
60 1.1 christos "warning: reference to compatibility getlastlogx(); include <utmpx.h> for correct reference")
61 1.3 christos __warn_references(updlastlogx,
62 1.3 christos "warning: reference to compatibility updlastlogx(); include <utmpx.h> for correct reference")
63 1.3 christos __warn_references(getutmp,
64 1.3 christos "warning: reference to compatibility getutmp(); include <utmpx.h> for correct reference")
65 1.3 christos __warn_references(getutmpx,
66 1.3 christos "warning: reference to compatibility getutmpx(); include <utmpx.h> for correct reference")
67 1.3 christos
68 1.3 christos static struct utmpx50 *
69 1.3 christos cvt(struct utmpx *ut)
70 1.3 christos {
71 1.3 christos if (ut == NULL)
72 1.3 christos return NULL;
73 1.3 christos timeval_to_timeval50(&ut->ut_tv, (void *)&ut->ut_tv);
74 1.3 christos return (void *)ut;
75 1.3 christos }
76 1.3 christos
77 1.3 christos static void
78 1.3 christos lastlogx50_to_lastlogx(const struct lastlogx50 *ll50, struct lastlogx *ll)
79 1.3 christos {
80 1.3 christos (void)memcpy(ll->ll_line, ll50->ll_line, sizeof(ll->ll_line));
81 1.3 christos (void)memcpy(ll->ll_host, ll50->ll_host, sizeof(ll->ll_host));
82 1.3 christos (void)memcpy(&ll->ll_ss, &ll50->ll_ss, sizeof(&ll->ll_ss));
83 1.3 christos timeval50_to_timeval(&ll50->ll_tv, &ll->ll_tv);
84 1.3 christos }
85 1.3 christos
86 1.3 christos static void
87 1.3 christos lastlogx_to_lastlogx50(const struct lastlogx *ll, struct lastlogx50 *ll50)
88 1.3 christos {
89 1.3 christos (void)memcpy(ll50->ll_line, ll->ll_line, sizeof(ll50->ll_line));
90 1.3 christos (void)memcpy(ll50->ll_host, ll->ll_host, sizeof(ll50->ll_host));
91 1.3 christos (void)memcpy(&ll50->ll_ss, &ll->ll_ss, sizeof(&ll50->ll_ss));
92 1.3 christos timeval_to_timeval50(&ll->ll_tv, &ll50->ll_tv);
93 1.3 christos }
94 1.3 christos
95 1.3 christos struct utmpx50 *
96 1.3 christos getutxent(void)
97 1.3 christos {
98 1.3 christos return cvt(__getutxent50());
99 1.3 christos }
100 1.3 christos
101 1.3 christos struct utmpx50 *
102 1.3 christos getutxid(const struct utmpx50 *ut50)
103 1.3 christos {
104 1.3 christos struct utmpx ut;
105 1.3 christos utmpx50_to_utmpx(ut50, &ut);
106 1.3 christos return cvt(__getutxid50(&ut));
107 1.3 christos }
108 1.3 christos
109 1.3 christos struct utmpx50 *
110 1.3 christos getutxline(const struct utmpx50 *ut50)
111 1.3 christos {
112 1.3 christos struct utmpx ut;
113 1.3 christos utmpx50_to_utmpx(ut50, &ut);
114 1.3 christos return cvt(__getutxline50(&ut));
115 1.3 christos }
116 1.3 christos
117 1.3 christos struct utmpx50 *
118 1.3 christos pututxline(const struct utmpx50 *ut50)
119 1.3 christos {
120 1.3 christos struct utmpx ut;
121 1.3 christos utmpx50_to_utmpx(ut50, &ut);
122 1.3 christos return cvt(__pututxline50(&ut));
123 1.3 christos }
124 1.3 christos
125 1.3 christos int
126 1.3 christos updwtmpx(const char *fname, const struct utmpx50 *ut50)
127 1.3 christos {
128 1.3 christos struct utmpx ut;
129 1.3 christos utmpx50_to_utmpx(ut50, &ut);
130 1.3 christos return __updwtmpx50(fname, &ut);
131 1.3 christos }
132 1.3 christos
133 1.3 christos struct lastlogx50 *
134 1.3 christos __getlastlogx13(const char *fname, uid_t uid, struct lastlogx50 *ll50)
135 1.3 christos {
136 1.3 christos struct lastlogx ll;
137 1.3 christos if (__getlastlogx50(fname, uid, &ll) == NULL)
138 1.3 christos return NULL;
139 1.3 christos lastlogx_to_lastlogx50(&ll, ll50);
140 1.3 christos return ll50;
141 1.3 christos }
142 1.1 christos
143 1.1 christos static char llfile[MAXPATHLEN] = _PATH_LASTLOGX;
144 1.1 christos
145 1.1 christos int
146 1.1 christos lastlogxname(const char *fname)
147 1.1 christos {
148 1.1 christos size_t len;
149 1.1 christos
150 1.1 christos _DIAGASSERT(fname != NULL);
151 1.1 christos
152 1.1 christos len = strlen(fname);
153 1.1 christos
154 1.1 christos if (len >= sizeof(llfile))
155 1.1 christos return 0;
156 1.1 christos
157 1.1 christos /* must end in x! */
158 1.1 christos if (fname[len - 1] != 'x')
159 1.1 christos return 0;
160 1.1 christos
161 1.1 christos (void)strlcpy(llfile, fname, sizeof(llfile));
162 1.1 christos return 1;
163 1.1 christos }
164 1.1 christos
165 1.3 christos struct lastlogx50 *
166 1.3 christos getlastlogx(uid_t uid, struct lastlogx50 *ll)
167 1.1 christos {
168 1.1 christos
169 1.1 christos return __getlastlogx13(llfile, uid, ll);
170 1.1 christos }
171 1.3 christos
172 1.3 christos int
173 1.3 christos updlastlogx(const char *fname, uid_t uid, struct lastlogx50 *ll50)
174 1.3 christos {
175 1.3 christos struct lastlogx ll;
176 1.3 christos lastlogx50_to_lastlogx(ll50, &ll);
177 1.3 christos return __updlastlogx50(fname, uid, &ll);
178 1.3 christos }
179 1.3 christos
180 1.3 christos void
181 1.3 christos getutmp(const struct utmpx50 *utx50, struct utmp *ut)
182 1.3 christos {
183 1.3 christos struct utmpx utx;
184 1.3 christos utmpx50_to_utmpx(utx50, &utx);
185 1.3 christos __getutmp50(&utx, ut);
186 1.3 christos }
187 1.3 christos
188 1.3 christos void
189 1.3 christos getutmpx(const struct utmp *ut, struct utmpx50 *utx50)
190 1.3 christos {
191 1.3 christos struct utmpx utx;
192 1.3 christos __getutmpx50(ut, &utx);
193 1.3 christos utmpx_to_utmpx50(&utx, utx50);
194 1.3 christos }
195