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