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