1 /* $NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 __RCSID("$NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $");
35 #endif /* LIBC_SCCS and not lint */
37 #include "namespace.h"
38 #include <sys/types.h>
39 #include <sys/param.h>
41 #define __LIBC12_SOURCE__
45 #include <compat/sys/time.h>
47 #include <compat/include/utmpx.h>
49 __warn_references(getutxent
,
50 "warning: reference to compatibility getutxent(); include <utmpx.h> for correct reference")
51 __warn_references(getutxid
,
52 "warning: reference to compatibility getutxid(); include <utmpx.h> for correct reference")
53 __warn_references(getutxline
,
54 "warning: reference to compatibility getutxline(); include <utmpx.h> for correct reference")
55 __warn_references(pututxline
,
56 "warning: reference to compatibility pututxline(); include <utmpx.h> for correct reference")
57 __warn_references(updwtmpx
,
58 "warning: reference to compatibility updwtmpx(); include <utmpx.h> for correct reference")
59 __warn_references(getlastlogx
,
60 "warning: reference to compatibility getlastlogx(); include <utmpx.h> for correct reference")
61 __warn_references(updlastlogx
,
62 "warning: reference to compatibility updlastlogx(); include <utmpx.h> for correct reference")
63 __warn_references(getutmp
,
64 "warning: reference to compatibility getutmp(); include <utmpx.h> for correct reference")
65 __warn_references(getutmpx
,
66 "warning: reference to compatibility getutmpx(); include <utmpx.h> for correct reference")
68 static struct utmpx50
*
73 timeval_to_timeval50(&ut
->ut_tv
, (void *)&ut
->ut_tv
);
78 lastlogx50_to_lastlogx(const struct lastlogx50
*ll50
, struct lastlogx
*ll
)
80 (void)memcpy(ll
->ll_line
, ll50
->ll_line
, sizeof(ll
->ll_line
));
81 (void)memcpy(ll
->ll_host
, ll50
->ll_host
, sizeof(ll
->ll_host
));
82 (void)memcpy(&ll
->ll_ss
, &ll50
->ll_ss
, sizeof(&ll
->ll_ss
));
83 timeval50_to_timeval(&ll50
->ll_tv
, &ll
->ll_tv
);
87 lastlogx_to_lastlogx50(const struct lastlogx
*ll
, struct lastlogx50
*ll50
)
89 (void)memcpy(ll50
->ll_line
, ll
->ll_line
, sizeof(ll50
->ll_line
));
90 (void)memcpy(ll50
->ll_host
, ll
->ll_host
, sizeof(ll50
->ll_host
));
91 (void)memcpy(&ll50
->ll_ss
, &ll
->ll_ss
, sizeof(&ll50
->ll_ss
));
92 timeval_to_timeval50(&ll
->ll_tv
, &ll50
->ll_tv
);
98 return cvt(__getutxent50());
102 getutxid(const struct utmpx50
*ut50
)
105 utmpx50_to_utmpx(ut50
, &ut
);
106 return cvt(__getutxid50(&ut
));
110 getutxline(const struct utmpx50
*ut50
)
113 utmpx50_to_utmpx(ut50
, &ut
);
114 return cvt(__getutxline50(&ut
));
118 pututxline(const struct utmpx50
*ut50
)
121 utmpx50_to_utmpx(ut50
, &ut
);
122 return cvt(__pututxline50(&ut
));
126 updwtmpx(const char *fname
, const struct utmpx50
*ut50
)
129 utmpx50_to_utmpx(ut50
, &ut
);
130 return __updwtmpx50(fname
, &ut
);
134 __getlastlogx13(const char *fname
, uid_t uid
, struct lastlogx50
*ll50
)
137 if (__getlastlogx50(fname
, uid
, &ll
) == NULL
)
139 lastlogx_to_lastlogx50(&ll
, ll50
);
143 static char llfile
[MAXPATHLEN
] = _PATH_LASTLOGX
;
146 lastlogxname(const char *fname
)
150 _DIAGASSERT(fname
!= NULL
);
154 if (len
>= sizeof(llfile
))
158 if (fname
[len
- 1] != 'x')
161 (void)strlcpy(llfile
, fname
, sizeof(llfile
));
166 getlastlogx(uid_t uid
, struct lastlogx50
*ll
)
169 return __getlastlogx13(llfile
, uid
, ll
);
173 updlastlogx(const char *fname
, uid_t uid
, struct lastlogx50
*ll50
)
176 lastlogx50_to_lastlogx(ll50
, &ll
);
177 return __updlastlogx50(fname
, uid
, &ll
);
181 getutmp(const struct utmpx50
*utx50
, struct utmp
*ut
)
184 utmpx50_to_utmpx(utx50
, &utx
);
185 __getutmp50(&utx
, ut
);
189 getutmpx(const struct utmp
*ut
, struct utmpx50
*utx50
)
192 __getutmpx50(ut
, &utx
);
193 utmpx_to_utmpx50(&utx
, utx50
);