xref: /csrg-svn/lib/libutil/logout.c (revision 39179)
135457Sbostic /*
235457Sbostic  * Copyright (c) 1988 The Regents of the University of California.
335457Sbostic  * All rights reserved.
435457Sbostic  *
535457Sbostic  * Redistribution and use in source and binary forms are permitted
635457Sbostic  * provided that the above copyright notice and this paragraph are
735457Sbostic  * duplicated in all such forms and that any documentation,
835457Sbostic  * advertising materials, and other materials related to such
935457Sbostic  * distribution and use acknowledge that the software was developed
1035457Sbostic  * by the University of California, Berkeley.  The name of the
1135457Sbostic  * University may not be used to endorse or promote products derived
1235457Sbostic  * from this software without specific prior written permission.
1335457Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1435457Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1535457Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1635457Sbostic  */
1735457Sbostic 
1835457Sbostic #if defined(LIBC_SCCS) && !defined(lint)
19*39179Sbostic static char sccsid[] = "@(#)logout.c	5.4 (Berkeley) 09/19/89";
2035457Sbostic #endif /* LIBC_SCCS and not lint */
2135457Sbostic 
2235457Sbostic #include <sys/types.h>
2335457Sbostic #include <sys/file.h>
2435457Sbostic #include <sys/time.h>
2535457Sbostic #include <utmp.h>
2635457Sbostic 
27*39179Sbostic typedef struct utmp UTMP;
2836826Sbostic 
2935457Sbostic logout(line)
3035457Sbostic 	register char *line;
3135457Sbostic {
32*39179Sbostic 	register int fd;
33*39179Sbostic 	UTMP ut;
3435457Sbostic 	int rval;
35*39179Sbostic 	off_t lseek();
3635457Sbostic 	time_t time();
3735457Sbostic 
38*39179Sbostic 	if ((fd = open(_PATH_UTMP, O_RDWR)) < 0)
3935457Sbostic 		return(0);
4036826Sbostic 	rval = 0;
41*39179Sbostic 	while (read(fd, (char *)&ut, sizeof(UTMP)) == sizeof(UTMP)) {
42*39179Sbostic 		if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE))
4335457Sbostic 			continue;
44*39179Sbostic 		bzero(ut.ut_name, UT_NAMESIZE);
45*39179Sbostic 		bzero(ut.ut_host, UT_HOSTSIZE);
4635457Sbostic 		(void)time(&ut.ut_time);
47*39179Sbostic 		(void)lseek(fd, -(long)sizeof(UTMP), L_INCR);
48*39179Sbostic 		(void)write(fd, (char *)&ut, sizeof(UTMP));
4936826Sbostic 		rval = 1;
5035457Sbostic 	}
51*39179Sbostic 	(void)close(fd);
5235457Sbostic 	return(rval);
5335457Sbostic }
54