1*35457Sbostic /* 2*35457Sbostic * Copyright (c) 1988 The Regents of the University of California. 3*35457Sbostic * All rights reserved. 4*35457Sbostic * 5*35457Sbostic * Redistribution and use in source and binary forms are permitted 6*35457Sbostic * provided that the above copyright notice and this paragraph are 7*35457Sbostic * duplicated in all such forms and that any documentation, 8*35457Sbostic * advertising materials, and other materials related to such 9*35457Sbostic * distribution and use acknowledge that the software was developed 10*35457Sbostic * by the University of California, Berkeley. The name of the 11*35457Sbostic * University may not be used to endorse or promote products derived 12*35457Sbostic * from this software without specific prior written permission. 13*35457Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*35457Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*35457Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*35457Sbostic */ 17*35457Sbostic 18*35457Sbostic #if defined(LIBC_SCCS) && !defined(lint) 19*35457Sbostic static char sccsid[] = "@(#)logout.c 5.1 (Berkeley) 08/31/88"; 20*35457Sbostic #endif /* LIBC_SCCS and not lint */ 21*35457Sbostic 22*35457Sbostic #include <sys/types.h> 23*35457Sbostic #include <sys/file.h> 24*35457Sbostic #include <sys/time.h> 25*35457Sbostic #include <utmp.h> 26*35457Sbostic #include <stdio.h> 27*35457Sbostic 28*35457Sbostic #define UTMPFILE "/etc/utmp" 29*35457Sbostic 30*35457Sbostic logout(line) 31*35457Sbostic register char *line; 32*35457Sbostic { 33*35457Sbostic register FILE *fp; 34*35457Sbostic struct utmp ut; 35*35457Sbostic int rval; 36*35457Sbostic time_t time(); 37*35457Sbostic 38*35457Sbostic if (!(fp = fopen(UTMPFILE, "r+"))) 39*35457Sbostic return(0); 40*35457Sbostic rval = 1; 41*35457Sbostic while (fread((char *)&ut, sizeof(struct utmp), 1, fp) == 1) { 42*35457Sbostic if (!ut.ut_name[0] || 43*35457Sbostic strncmp(ut.ut_line, line, sizeof(ut.ut_line))) 44*35457Sbostic continue; 45*35457Sbostic bzero(ut.ut_name, sizeof(ut.ut_name)); 46*35457Sbostic bzero(ut.ut_host, sizeof(ut.ut_host)); 47*35457Sbostic (void)time(&ut.ut_time); 48*35457Sbostic (void)fseek(fp, (long)-sizeof(struct utmp), L_INCR); 49*35457Sbostic (void)fwrite((char *)&ut, sizeof(struct utmp), 1, fp); 50*35457Sbostic (void)fseek(fp, (long)0, L_INCR); 51*35457Sbostic rval = 0; 52*35457Sbostic } 53*35457Sbostic (void)fclose(fp); 54*35457Sbostic return(rval); 55*35457Sbostic } 56