Commit | Line | Data |
---|---|---|
224c7076 | 1 | /* |
1f2f436a | 2 | * Copyright (c) 2005, 2009 Apple Inc. All rights reserved. |
224c7076 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights | |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.0 (the 'License'). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License." | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
34e8f829 | 24 | #include <pthread.h> |
1f2f436a A |
25 | #include <stdio.h> |
26 | #include <stdlib.h> | |
27 | #include <string.h> | |
28 | #include <sys/param.h> | |
224c7076 A |
29 | |
30 | #ifdef UTMP_COMPAT | |
31 | #define UTMP_COMPAT_UTMP0 0x01 | |
32 | #define UTMP_COMPAT_UTMP1 0x02 | |
33 | #define UTMP_COMPAT_WTMP 0x04 | |
34 | #define UTMP_COMPAT_LASTLOG 0x08 | |
35 | #endif /* UTMP_COMPAT */ | |
36 | ||
37 | #define LASTLOG_FACILITY "com.apple.system.lastlog" | |
38 | #define UTMPX_FACILITY "com.apple.system.utmpx" | |
39 | ||
1f2f436a A |
40 | #define UTMPX_LOCK(x) if (__is_threaded) pthread_mutex_lock(&(x)->utmpx_mutex) |
41 | #define UTMPX_UNLOCK(x) if (__is_threaded) pthread_mutex_unlock(&(x)->utmpx_mutex) | |
42 | #define UTMPX_MAGIC 8 | |
43 | #define __UTX_MAGIC__ { 'u', 't', 'x', 0, 'v', 1, 0, 0 } | |
44 | ||
45 | #define TEST_UTMPX_T(x,y) { \ | |
46 | if (!(y)) \ | |
47 | LIBC_ABORT("%s: NULL utmpx_t", (x)); \ | |
48 | if (memcmp((y)->magic, __utx_magic__, UTMPX_MAGIC) != 0) \ | |
49 | LIBC_ABORT("%s: magic mismatch", (x)); \ | |
50 | } | |
34e8f829 | 51 | |
34e8f829 | 52 | extern int __is_threaded; |
1f2f436a A |
53 | |
54 | struct _utmpx { | |
55 | char magic[UTMPX_MAGIC]; | |
56 | struct utmpx ut; | |
57 | pthread_mutex_t utmpx_mutex; | |
58 | char *utfile; | |
59 | FILE *fp; | |
60 | unsigned int utfile_system :1; /* are we using _PATH_UTMPX? */ | |
61 | unsigned int readonly :1; | |
62 | }; | |
63 | extern struct _utmpx __utx__; /* the default struct _utmpx */ | |
64 | extern const char __utx_magic__[]; /* size of UTMPX_MAGIC */ | |
224c7076 A |
65 | |
66 | #ifdef __LP64__ | |
67 | #define __need_struct_timeval32 | |
68 | #include <_structs.h> | |
69 | ||
70 | /* | |
71 | * these structures assume natural alignment so they are the same size | |
72 | * and layout as their 32-bit counterpart | |
73 | */ | |
74 | #ifdef UTMP_COMPAT | |
75 | struct lastlog32 { | |
76 | __int32_t ll_time; | |
77 | char ll_line[UT_LINESIZE]; | |
78 | char ll_host[UT_HOSTSIZE]; | |
79 | }; | |
80 | ||
81 | struct utmp32 { | |
82 | char ut_line[UT_LINESIZE]; | |
83 | char ut_name[UT_NAMESIZE]; | |
84 | char ut_host[UT_HOSTSIZE]; | |
85 | __int32_t ut_time; | |
86 | }; | |
87 | #endif /* UTMP_COMPAT */ | |
88 | ||
89 | struct utmpx32 { | |
90 | char ut_user[_UTX_USERSIZE]; /* login name */ | |
91 | char ut_id[_UTX_IDSIZE]; /* id */ | |
92 | char ut_line[_UTX_LINESIZE]; /* tty name */ | |
93 | pid_t ut_pid; /* process id creating the entry */ | |
94 | short ut_type; /* type of this entry */ | |
95 | struct timeval32 ut_tv; /* time entry was created */ | |
96 | char ut_host[_UTX_HOSTSIZE]; /* host name */ | |
97 | __uint32_t ut_pad[16]; /* reserved for future use */ | |
98 | }; | |
99 | #endif /* __LP64__ */ | |
100 | ||
1f2f436a A |
101 | void __endutxent(struct _utmpx *); |
102 | struct utmpx *__getutxent(struct _utmpx *); | |
103 | void __setutxent(struct _utmpx *); | |
104 | struct utmpx *__pututxline(struct _utmpx *, const struct utmpx *); | |
105 | int __utmpxname(struct _utmpx *, const char *); | |
224c7076 A |
106 | #ifdef __LP64__ |
107 | void _utmpx32_64(const struct utmpx32 *, struct utmpx *); | |
108 | void _utmpx64_32(const struct utmpx *, struct utmpx32 *); | |
109 | #endif /* __LP64__ */ | |
110 | void _utmpx_asl(const struct utmpx *); | |
111 | const struct utmpx *_utmpx_working_copy(const struct utmpx *, struct utmpx *, int); | |
112 | ||
113 | #ifdef UTMP_COMPAT | |
114 | #ifdef __LP64__ | |
115 | void _getutmp32(const struct utmpx *, struct utmp32 *); | |
116 | int _utmp_compat(const struct utmpx *, struct utmp32 *); | |
117 | void _write_lastlog(const struct utmp32 *, const struct utmpx *); | |
118 | void _write_utmp(const struct utmp32 *, int); | |
119 | #else /* __LP64__ */ | |
120 | int _utmp_compat(const struct utmpx *, struct utmp *); | |
121 | void _write_lastlog(const struct utmp *, const struct utmpx *); | |
122 | void _write_utmp(const struct utmp *, int); | |
123 | #endif /* __LP64__ */ | |
124 | void _write_utmp_compat(const struct utmpx *); | |
125 | #ifdef __LP64__ | |
126 | void _write_wtmp(const struct utmp32 *); | |
127 | #else /* __LP64__ */ | |
128 | void _write_wtmp(const struct utmp *); | |
129 | #endif /* __LP64__ */ | |
130 | #endif /* UTMP_COMPAT */ |