135673Sbostic /* 235673Sbostic * Copyright (c) 1988 The Regents of the University of California. 335673Sbostic * All rights reserved. 435673Sbostic * 535673Sbostic * Redistribution and use in source and binary forms are permitted 635673Sbostic * provided that the above copyright notice and this paragraph are 735673Sbostic * duplicated in all such forms and that any documentation, 835673Sbostic * advertising materials, and other materials related to such 935673Sbostic * distribution and use acknowledge that the software was developed 1035673Sbostic * by the University of California, Berkeley. The name of the 1135673Sbostic * University may not be used to endorse or promote products derived 1235673Sbostic * from this software without specific prior written permission. 1335673Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1435673Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1536773Srick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1635673Sbostic * 1735673Sbostic */ 1835673Sbostic 1935673Sbostic #ifndef lint 20*37274Sbostic static char sccsid[] = "@(#)logwtmp.c 5.5 (Berkeley) 04/02/89"; 2135673Sbostic #endif /* not lint */ 2235673Sbostic 2335673Sbostic #include <sys/types.h> 2435673Sbostic #include <sys/file.h> 2535673Sbostic #include <sys/time.h> 2635673Sbostic #include <sys/stat.h> 2735673Sbostic #include <utmp.h> 2835673Sbostic 2936304Skarels static int fd = -1; 3035674Sbostic 3136304Skarels /* 3236304Skarels * Modified version of logwtmp that holds wtmp file open 3336304Skarels * after first call, for use with ftp (which may chroot 3436304Skarels * after login, but before logout). 3536304Skarels */ 3635673Sbostic logwtmp(line, name, host) 3735673Sbostic char *line, *name, *host; 3835673Sbostic { 3935673Sbostic struct utmp ut; 4035673Sbostic struct stat buf; 4135673Sbostic time_t time(); 4235673Sbostic char *strncpy(); 4335673Sbostic 44*37274Sbostic if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) 4535673Sbostic return; 4636304Skarels if (fstat(fd, &buf) == 0) { 4735673Sbostic (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line)); 4835673Sbostic (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name)); 4935673Sbostic (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host)); 5035673Sbostic (void)time(&ut.ut_time); 5135673Sbostic if (write(fd, (char *)&ut, sizeof(struct utmp)) != 5235673Sbostic sizeof(struct utmp)) 5335673Sbostic (void)ftruncate(fd, buf.st_size); 5435673Sbostic } 5535673Sbostic } 56