1 --- utmpx.c.orig 2004-07-13 13:02:37.000000000 -0700
2 +++ utmpx.c 2004-08-05 15:25:10.000000000 -0700
19 +static void _utmp_compat(const struct utmpx *);
20 +#endif /* UTMP_COMPAT */
22 __warn_references(getlastlogx,
23 "warning: reference to compatibility getlastlogx(); include <utmpx.h> for correct reference")
24 __warn_references(lastlogxname,
26 static int readonly = 0;
27 static struct utmpx ut;
28 static char utfile[MAXPATHLEN] = _PATH_UTMPX;
29 -static char llfile[MAXPATHLEN] = _PATH_LASTLOGX;
31 static struct utmpx *utmp_update(const struct utmpx *);
36 u = memcpy(&ut, &temp, sizeof(ut));
39 +#endif /* UTMP_COMPAT */
42 if (lockf(fileno(fp), F_ULOCK, (off_t)0) == -1)
43 @@ -308,185 +316,50 @@
48 - * The following are extensions and not part of the X/Open spec.
51 -updwtmpx(const char *file, const struct utmpx *utx)
56 - _DIAGASSERT(file != NULL);
57 - _DIAGASSERT(utx != NULL);
59 - fd = open(file, O_WRONLY|O_APPEND|O_SHLOCK);
62 - if ((fd = open(file, O_CREAT|O_WRONLY|O_EXLOCK, 0644)) == -1)
64 - (void)memset(&ut, 0, sizeof(ut));
65 - ut.ut_type = SIGNATURE;
66 - (void)memcpy(ut.ut_user, vers, sizeof(vers));
67 - if (write(fd, &ut, sizeof(ut)) == -1)
71 +_utmp_compat(const struct utmpx *ux)
75 + struct ttyent *ttyp;
77 + switch (ux->ut_type) {
83 + logout(ux->ut_line);
88 - if (write(fd, utx, sizeof(*utx)) == -1)
90 - if (close(fd) == -1)
95 - saved_errno = errno;
97 - errno = saved_errno;
103 -utmpxname(const char *fname)
107 - _DIAGASSERT(fname != NULL);
109 - len = strlen(fname);
111 - if (len >= sizeof(utfile))
114 - /* must end in x! */
115 - if (fname[len - 1] != 'x')
118 - (void)strlcpy(utfile, fname, sizeof(utfile));
125 -getutmp(const struct utmpx *ux, struct utmp *u)
128 - _DIAGASSERT(ux != NULL);
129 - _DIAGASSERT(u != NULL);
131 - (void)memcpy(u->ut_name, ux->ut_name, sizeof(u->ut_name));
132 - (void)memcpy(u->ut_line, ux->ut_line, sizeof(u->ut_line));
133 - (void)memcpy(u->ut_host, ux->ut_host, sizeof(u->ut_host));
134 - u->ut_time = ux->ut_tv.tv_sec;
138 -getutmpx(const struct utmp *u, struct utmpx *ux)
141 - _DIAGASSERT(ux != NULL);
142 - _DIAGASSERT(u != NULL);
144 - (void)memcpy(ux->ut_name, u->ut_name, sizeof(u->ut_name));
145 - (void)memcpy(ux->ut_line, u->ut_line, sizeof(u->ut_line));
146 - (void)memcpy(ux->ut_host, u->ut_host, sizeof(u->ut_host));
147 - ux->ut_tv.tv_sec = u->ut_time;
148 - ux->ut_tv.tv_usec = 0;
149 - (void)memset(&ux->ut_ss, 0, sizeof(ux->ut_ss));
151 - ux->ut_type = USER_PROCESS;
152 - ux->ut_session = 0;
153 - ux->ut_exit.e_termination = 0;
154 - ux->ut_exit.e_exit = 0;
158 -lastlogxname(const char *fname)
162 - _DIAGASSERT(fname != NULL);
164 - len = strlen(fname);
166 - if (len >= sizeof(llfile))
169 - /* must end in x! */
170 - if (fname[len - 1] != 'x')
173 - (void)strlcpy(llfile, fname, sizeof(llfile));
178 -getlastlogx(uid_t uid, struct lastlogx *ll)
181 - return __getlastlogx13(_PATH_LASTLOGX, uid, ll);
185 -__getlastlogx13(const char *fname, uid_t uid, struct lastlogx *ll)
190 - _DIAGASSERT(fname != NULL);
191 - _DIAGASSERT(ll != NULL);
193 - db = dbopen(fname, O_RDONLY|O_SHLOCK, 0, DB_HASH, NULL);
199 - key.size = sizeof(uid);
201 - if ((db->get)(db, &key, &data, 0) != 0)
204 - if (data.size != sizeof(*ll)) {
207 + /* do equivalent of ttyslot(), but using ux->ut_slot */
211 + if ((ttyp = getttyent()) == NULL) {
215 + if (!strcmp(ttyp->ty_name, ux->ut_line)) {
223 - if ((ll = malloc(sizeof(*ll))) == NULL)
226 - (void)memcpy(ll, data.data, sizeof(*ll));
236 -updlastlogx(const char *fname, uid_t uid, struct lastlogx *ll)
242 - _DIAGASSERT(fname != NULL);
243 - _DIAGASSERT(ll != NULL);
245 - db = dbopen(fname, O_RDWR|O_CREAT|O_EXLOCK, 0, DB_HASH, NULL);
251 - key.size = sizeof(uid);
253 - data.size = sizeof(*ll);
254 - if ((db->put)(db, &key, &data, 0) != 0)
259 + /* now write utmp */
260 + (void)memset(&u, 0, sizeof(u));
261 + strncpy(u.ut_line, ux->ut_line, UT_LINESIZE);
262 + strncpy(u.ut_name, ux->ut_user, UT_NAMESIZE);
263 + strncpy(u.ut_host, ux->ut_host, UT_HOSTSIZE);
264 + u.ut_time = ux->ut_tv.tv_sec;
265 + if ((fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
266 + (void)lseek(fd, (off_t)(slot * sizeof(struct utmp)), L_SET);
267 + (void)write(fd, &u, sizeof(struct utmp));
271 +#endif /* UTMP_COMPAT */