xref: /original-bsd/lib/libutil/logout.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1988, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)logout.c	8.1 (Berkeley) 06/04/93";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/time.h>
14 
15 #include <fcntl.h>
16 #include <utmp.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 typedef struct utmp UTMP;
22 
23 int
24 logout(line)
25 	register char *line;
26 {
27 	register int fd;
28 	UTMP ut;
29 	int rval;
30 
31 	if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
32 		return(0);
33 	rval = 0;
34 	while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) {
35 		if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE))
36 			continue;
37 		bzero(ut.ut_name, UT_NAMESIZE);
38 		bzero(ut.ut_host, UT_HOSTSIZE);
39 		(void)time(&ut.ut_time);
40 		(void)lseek(fd, -(off_t)sizeof(UTMP), L_INCR);
41 		(void)write(fd, &ut, sizeof(UTMP));
42 		rval = 1;
43 	}
44 	(void)close(fd);
45 	return(rval);
46 }
47