xref: /csrg-svn/lib/libutil/logout.c (revision 36826)
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*36826Sbostic static char sccsid[] = "@(#)logout.c	5.2 (Berkeley) 02/17/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 #include <stdio.h>
2735457Sbostic 
2835457Sbostic #define	UTMPFILE	"/etc/utmp"
2935457Sbostic 
30*36826Sbostic /* 0 on failure, 1 on success */
31*36826Sbostic 
3235457Sbostic logout(line)
3335457Sbostic 	register char *line;
3435457Sbostic {
3535457Sbostic 	register FILE *fp;
3635457Sbostic 	struct utmp ut;
3735457Sbostic 	int rval;
3835457Sbostic 	time_t time();
3935457Sbostic 
4035457Sbostic 	if (!(fp = fopen(UTMPFILE, "r+")))
4135457Sbostic 		return(0);
42*36826Sbostic 	rval = 0;
4335457Sbostic 	while (fread((char *)&ut, sizeof(struct utmp), 1, fp) == 1) {
4435457Sbostic 		if (!ut.ut_name[0] ||
4535457Sbostic 		    strncmp(ut.ut_line, line, sizeof(ut.ut_line)))
4635457Sbostic 			continue;
4735457Sbostic 		bzero(ut.ut_name, sizeof(ut.ut_name));
4835457Sbostic 		bzero(ut.ut_host, sizeof(ut.ut_host));
4935457Sbostic 		(void)time(&ut.ut_time);
5035457Sbostic 		(void)fseek(fp, (long)-sizeof(struct utmp), L_INCR);
5135457Sbostic 		(void)fwrite((char *)&ut, sizeof(struct utmp), 1, fp);
5235457Sbostic 		(void)fseek(fp, (long)0, L_INCR);
53*36826Sbostic 		rval = 1;
5435457Sbostic 	}
5535457Sbostic 	(void)fclose(fp);
5635457Sbostic 	return(rval);
5735457Sbostic }
58