xref: /csrg-svn/lib/libutil/logout.c (revision 54586)
135457Sbostic /*
235457Sbostic  * Copyright (c) 1988 The Regents of the University of California.
335457Sbostic  * All rights reserved.
435457Sbostic  *
542662Sbostic  * %sccs.include.redist.c%
635457Sbostic  */
735457Sbostic 
835457Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*54586Sbostic static char sccsid[] = "@(#)logout.c	5.6 (Berkeley) 07/01/92";
1035457Sbostic #endif /* LIBC_SCCS and not lint */
1135457Sbostic 
1235457Sbostic #include <sys/types.h>
1335457Sbostic #include <sys/time.h>
14*54586Sbostic 
15*54586Sbostic #include <fcntl.h>
1635457Sbostic #include <utmp.h>
17*54586Sbostic #include <unistd.h>
18*54586Sbostic #include <stdlib.h>
19*54586Sbostic #include <string.h>
2035457Sbostic 
2139179Sbostic typedef struct utmp UTMP;
2236826Sbostic 
23*54586Sbostic int
2435457Sbostic logout(line)
2535457Sbostic 	register char *line;
2635457Sbostic {
2739179Sbostic 	register int fd;
2839179Sbostic 	UTMP ut;
2935457Sbostic 	int rval;
3035457Sbostic 
31*54586Sbostic 	if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
3235457Sbostic 		return(0);
3336826Sbostic 	rval = 0;
34*54586Sbostic 	while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) {
3539179Sbostic 		if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE))
3635457Sbostic 			continue;
3739179Sbostic 		bzero(ut.ut_name, UT_NAMESIZE);
3839179Sbostic 		bzero(ut.ut_host, UT_HOSTSIZE);
3935457Sbostic 		(void)time(&ut.ut_time);
40*54586Sbostic 		(void)lseek(fd, -(off_t)sizeof(UTMP), L_INCR);
41*54586Sbostic 		(void)write(fd, &ut, sizeof(UTMP));
4236826Sbostic 		rval = 1;
4335457Sbostic 	}
4439179Sbostic 	(void)close(fd);
4535457Sbostic 	return(rval);
4635457Sbostic }
47