]>
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 | ||
6465356a A |
40 | #define UTMPX_LOCK(x) pthread_mutex_lock(&(x)->utmpx_mutex) |
41 | #define UTMPX_UNLOCK(x) pthread_mutex_unlock(&(x)->utmpx_mutex) | |
1f2f436a A |
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 | |
1f2f436a A |
52 | struct _utmpx { |
53 | char magic[UTMPX_MAGIC]; | |
54 | struct utmpx ut; | |
55 | pthread_mutex_t utmpx_mutex; | |
56 | char *utfile; | |
57 | FILE *fp; | |
58 | unsigned int utfile_system :1; /* are we using _PATH_UTMPX? */ | |
59 | unsigned int readonly :1; | |
60 | }; | |
1f2f436a | 61 | extern const char __utx_magic__[]; /* size of UTMPX_MAGIC */ |
224c7076 A |
62 | |
63 | #ifdef __LP64__ | |
23e20b00 A |
64 | #include <sys/_types.h> |
65 | #include <sys/_types/_timeval32.h> | |
224c7076 A |
66 | |
67 | /* | |
68 | * these structures assume natural alignment so they are the same size | |
69 | * and layout as their 32-bit counterpart | |
70 | */ | |
71 | #ifdef UTMP_COMPAT | |
72 | struct lastlog32 { | |
73 | __int32_t ll_time; | |
74 | char ll_line[UT_LINESIZE]; | |
75 | char ll_host[UT_HOSTSIZE]; | |
76 | }; | |
77 | ||
78 | struct utmp32 { | |
79 | char ut_line[UT_LINESIZE]; | |
80 | char ut_name[UT_NAMESIZE]; | |
81 | char ut_host[UT_HOSTSIZE]; | |
82 | __int32_t ut_time; | |
83 | }; | |
84 | #endif /* UTMP_COMPAT */ | |
85 | ||
86 | struct utmpx32 { | |
87 | char ut_user[_UTX_USERSIZE]; /* login name */ | |
88 | char ut_id[_UTX_IDSIZE]; /* id */ | |
89 | char ut_line[_UTX_LINESIZE]; /* tty name */ | |
90 | pid_t ut_pid; /* process id creating the entry */ | |
91 | short ut_type; /* type of this entry */ | |
92 | struct timeval32 ut_tv; /* time entry was created */ | |
93 | char ut_host[_UTX_HOSTSIZE]; /* host name */ | |
94 | __uint32_t ut_pad[16]; /* reserved for future use */ | |
95 | }; | |
96 | #endif /* __LP64__ */ | |
97 | ||
6465356a A |
98 | struct _utmpx *__default_utx(void); |
99 | ||
1f2f436a A |
100 | void __endutxent(struct _utmpx *); |
101 | struct utmpx *__getutxent(struct _utmpx *); | |
102 | void __setutxent(struct _utmpx *); | |
103 | struct utmpx *__pututxline(struct _utmpx *, const struct utmpx *); | |
104 | int __utmpxname(struct _utmpx *, const char *); | |
224c7076 A |
105 | #ifdef __LP64__ |
106 | void _utmpx32_64(const struct utmpx32 *, struct utmpx *); | |
107 | void _utmpx64_32(const struct utmpx *, struct utmpx32 *); | |
108 | #endif /* __LP64__ */ | |
109 | void _utmpx_asl(const struct utmpx *); | |
110 | const struct utmpx *_utmpx_working_copy(const struct utmpx *, struct utmpx *, int); | |
111 | ||
112 | #ifdef UTMP_COMPAT | |
113 | #ifdef __LP64__ | |
114 | void _getutmp32(const struct utmpx *, struct utmp32 *); | |
115 | int _utmp_compat(const struct utmpx *, struct utmp32 *); | |
116 | void _write_lastlog(const struct utmp32 *, const struct utmpx *); | |
117 | void _write_utmp(const struct utmp32 *, int); | |
118 | #else /* __LP64__ */ | |
119 | int _utmp_compat(const struct utmpx *, struct utmp *); | |
120 | void _write_lastlog(const struct utmp *, const struct utmpx *); | |
121 | void _write_utmp(const struct utmp *, int); | |
122 | #endif /* __LP64__ */ | |
123 | void _write_utmp_compat(const struct utmpx *); | |
124 | #ifdef __LP64__ | |
125 | void _write_wtmp(const struct utmp32 *); | |
126 | #else /* __LP64__ */ | |
127 | void _write_wtmp(const struct utmp *); | |
128 | #endif /* __LP64__ */ | |
129 | #endif /* UTMP_COMPAT */ |