compat_utmpx.c revision 1.2.8.2 1 1.2.8.2 christos /* $NetBSD: compat_utmpx.c,v 1.2.8.2 2008/11/08 21:45:38 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.2 christos __RCSID("$NetBSD: compat_utmpx.c,v 1.2.8.2 2008/11/08 21:45:38 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.2 christos timeval_to_timeval50(&ut->ut_tv, (void *)&ut->ut_tv);
72 1.2.8.2 christos return (void *)ut;
73 1.2.8.2 christos }
74 1.2.8.2 christos
75 1.2.8.2 christos static void
76 1.2.8.2 christos utmpx50_to_utmpx(const struct utmpx50 *ut50, struct utmpx *ut)
77 1.2.8.2 christos {
78 1.2.8.2 christos (void)memcpy(ut, ut50, sizeof(*ut));
79 1.2.8.2 christos timeval50_to_timeval(&ut50->ut_tv, &ut->ut_tv);
80 1.2.8.2 christos }
81 1.2.8.2 christos
82 1.2.8.2 christos static void
83 1.2.8.2 christos utmpx_to_utmpx50(const struct utmpx *ut, struct utmpx50 *ut50)
84 1.2.8.2 christos {
85 1.2.8.2 christos (void)memcpy(ut50, ut, sizeof(*ut50));
86 1.2.8.2 christos timeval_to_timeval50(&ut->ut_tv, &ut50->ut_tv);
87 1.2.8.2 christos }
88 1.2.8.2 christos
89 1.2.8.2 christos static void
90 1.2.8.2 christos lastlogx50_to_lastlogx(const struct lastlogx50 *ll50, struct lastlogx *ll)
91 1.2.8.2 christos {
92 1.2.8.2 christos (void)memcpy(ll->ll_line, ll50->ll_line, sizeof(ll->ll_line));
93 1.2.8.2 christos (void)memcpy(ll->ll_host, ll50->ll_host, sizeof(ll->ll_host));
94 1.2.8.2 christos (void)memcpy(&ll->ll_ss, &ll50->ll_ss, sizeof(&ll->ll_ss));
95 1.2.8.2 christos timeval50_to_timeval(&ll50->ll_tv, &ll->ll_tv);
96 1.2.8.2 christos }
97 1.2.8.2 christos
98 1.2.8.2 christos static void
99 1.2.8.2 christos lastlogx_to_lastlogx50(const struct lastlogx *ll, struct lastlogx50 *ll50)
100 1.2.8.2 christos {
101 1.2.8.2 christos (void)memcpy(ll50->ll_line, ll->ll_line, sizeof(ll50->ll_line));
102 1.2.8.2 christos (void)memcpy(ll50->ll_host, ll->ll_host, sizeof(ll50->ll_host));
103 1.2.8.2 christos (void)memcpy(&ll50->ll_ss, &ll->ll_ss, sizeof(&ll50->ll_ss));
104 1.2.8.2 christos timeval_to_timeval50(&ll->ll_tv, &ll50->ll_tv);
105 1.2.8.2 christos }
106 1.2.8.2 christos
107 1.2.8.2 christos struct utmpx50 *
108 1.2.8.2 christos getutxent(void)
109 1.2.8.2 christos {
110 1.2.8.2 christos return cvt(__getutxent50());
111 1.2.8.2 christos }
112 1.2.8.2 christos
113 1.2.8.2 christos struct utmpx50 *
114 1.2.8.2 christos getutxid(const struct utmpx50 *ut50)
115 1.2.8.2 christos {
116 1.2.8.2 christos struct utmpx ut;
117 1.2.8.2 christos utmpx50_to_utmpx(ut50, &ut);
118 1.2.8.2 christos return cvt(__getutxid50(&ut));
119 1.2.8.2 christos }
120 1.2.8.2 christos
121 1.2.8.2 christos struct utmpx50 *
122 1.2.8.2 christos getutxline(const struct utmpx50 *ut50)
123 1.2.8.2 christos {
124 1.2.8.2 christos struct utmpx ut;
125 1.2.8.2 christos utmpx50_to_utmpx(ut50, &ut);
126 1.2.8.2 christos return cvt(__getutxline50(&ut));
127 1.2.8.2 christos }
128 1.2.8.2 christos
129 1.2.8.2 christos struct utmpx50 *
130 1.2.8.2 christos pututxline(const struct utmpx50 *ut50)
131 1.2.8.2 christos {
132 1.2.8.2 christos struct utmpx ut;
133 1.2.8.2 christos utmpx50_to_utmpx(ut50, &ut);
134 1.2.8.2 christos return cvt(__pututxline50(&ut));
135 1.2.8.2 christos }
136 1.2.8.2 christos
137 1.2.8.2 christos int
138 1.2.8.2 christos updwtmpx(const char *fname, const struct utmpx50 *ut50)
139 1.2.8.2 christos {
140 1.2.8.2 christos struct utmpx ut;
141 1.2.8.2 christos utmpx50_to_utmpx(ut50, &ut);
142 1.2.8.2 christos return __updwtmpx50(fname, &ut);
143 1.2.8.2 christos }
144 1.2.8.2 christos
145 1.2.8.2 christos struct lastlogx50 *
146 1.2.8.2 christos __getlastlogx13(const char *fname, uid_t uid, struct lastlogx50 *ll50)
147 1.2.8.2 christos {
148 1.2.8.2 christos struct lastlogx ll;
149 1.2.8.2 christos if (__getlastlogx50(fname, uid, &ll) == NULL)
150 1.2.8.2 christos return NULL;
151 1.2.8.2 christos lastlogx_to_lastlogx50(&ll, ll50);
152 1.2.8.2 christos return ll50;
153 1.2.8.2 christos }
154 1.2.8.2 christos
155 1.2.8.2 christos static char llfile[MAXPATHLEN] = _PATH_LASTLOGX;
156 1.2.8.2 christos
157 1.2.8.2 christos int
158 1.2.8.2 christos lastlogxname(const char *fname)
159 1.2.8.2 christos {
160 1.2.8.2 christos size_t len;
161 1.2.8.2 christos
162 1.2.8.2 christos _DIAGASSERT(fname != NULL);
163 1.2.8.2 christos
164 1.2.8.2 christos len = strlen(fname);
165 1.2.8.2 christos
166 1.2.8.2 christos if (len >= sizeof(llfile))
167 1.2.8.2 christos return 0;
168 1.2.8.2 christos
169 1.2.8.2 christos /* must end in x! */
170 1.2.8.2 christos if (fname[len - 1] != 'x')
171 1.2.8.2 christos return 0;
172 1.2.8.2 christos
173 1.2.8.2 christos (void)strlcpy(llfile, fname, sizeof(llfile));
174 1.2.8.2 christos return 1;
175 1.2.8.2 christos }
176 1.2.8.2 christos
177 1.2.8.2 christos struct lastlogx50 *
178 1.2.8.2 christos getlastlogx(uid_t uid, struct lastlogx50 *ll)
179 1.2.8.2 christos {
180 1.2.8.2 christos
181 1.2.8.2 christos return __getlastlogx13(llfile, uid, ll);
182 1.2.8.2 christos }
183 1.2.8.2 christos
184 1.2.8.2 christos int
185 1.2.8.2 christos updlastlogx(const char *fname, uid_t uid, struct lastlogx50 *ll50)
186 1.2.8.2 christos {
187 1.2.8.2 christos struct lastlogx ll;
188 1.2.8.2 christos lastlogx50_to_lastlogx(ll50, &ll);
189 1.2.8.2 christos return __updlastlogx50(fname, uid, &ll);
190 1.2.8.2 christos }
191 1.2.8.2 christos
192 1.2.8.2 christos void
193 1.2.8.2 christos getutmp(const struct utmpx50 *utx50, struct utmp *ut)
194 1.2.8.2 christos {
195 1.2.8.2 christos struct utmpx utx;
196 1.2.8.2 christos utmpx50_to_utmpx(utx50, &utx);
197 1.2.8.2 christos __getutmp50(&utx, ut);
198 1.2.8.2 christos }
199 1.2.8.2 christos
200 1.2.8.2 christos void
201 1.2.8.2 christos getutmpx(const struct utmp *ut, struct utmpx50 *utx50)
202 1.2.8.2 christos {
203 1.2.8.2 christos struct utmpx utx;
204 1.2.8.2 christos __getutmpx50(ut, &utx);
205 1.2.8.2 christos utmpx_to_utmpx50(&utx, utx50);
206 1.2.8.2 christos }
207