135673Sbostic /* 235673Sbostic * Copyright (c) 1988 The Regents of the University of California. 335673Sbostic * All rights reserved. 435673Sbostic * 542667Sbostic * %sccs.include.redist.c% 635673Sbostic * 735673Sbostic */ 835673Sbostic 935673Sbostic #ifndef lint 10*54527Sandrew static char sccsid[] = "@(#)logwtmp.c 5.8 (Berkeley) 06/27/92"; 1135673Sbostic #endif /* not lint */ 1235673Sbostic 1335673Sbostic #include <sys/types.h> 1435673Sbostic #include <sys/time.h> 1535673Sbostic #include <sys/stat.h> 16*54527Sandrew 1746669Sbostic #include <fcntl.h> 1835673Sbostic #include <utmp.h> 1946669Sbostic #include <unistd.h> 20*54527Sandrew #include <stdio.h> 2146669Sbostic #include <string.h> 22*54527Sandrew #include "extern.h" 2335673Sbostic 2436304Skarels static int fd = -1; 2535674Sbostic 2636304Skarels /* 2736304Skarels * Modified version of logwtmp that holds wtmp file open 2836304Skarels * after first call, for use with ftp (which may chroot 2936304Skarels * after login, but before logout). 3036304Skarels */ 31*54527Sandrew void 3235673Sbostic logwtmp(line, name, host) 3335673Sbostic char *line, *name, *host; 3435673Sbostic { 3535673Sbostic struct utmp ut; 3635673Sbostic struct stat buf; 3735673Sbostic 3837274Sbostic if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) 3935673Sbostic return; 4036304Skarels if (fstat(fd, &buf) == 0) { 4135673Sbostic (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line)); 4235673Sbostic (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name)); 4335673Sbostic (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host)); 4435673Sbostic (void)time(&ut.ut_time); 4535673Sbostic if (write(fd, (char *)&ut, sizeof(struct utmp)) != 4635673Sbostic sizeof(struct utmp)) 4735673Sbostic (void)ftruncate(fd, buf.st_size); 4835673Sbostic } 4935673Sbostic } 50