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 15*36773Srick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1635673Sbostic * 1735673Sbostic */ 1835673Sbostic 1935673Sbostic #ifndef lint 20*36773Srick static char sccsid[] = "@(#)logwtmp.c 5.4 (Berkeley) 02/14/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 2935673Sbostic #define WTMPFILE "/usr/adm/wtmp" 3035673Sbostic 3136304Skarels static int fd = -1; 3235674Sbostic 3336304Skarels /* 3436304Skarels * Modified version of logwtmp that holds wtmp file open 3536304Skarels * after first call, for use with ftp (which may chroot 3636304Skarels * after login, but before logout). 3736304Skarels */ 3835673Sbostic logwtmp(line, name, host) 3935673Sbostic char *line, *name, *host; 4035673Sbostic { 4135673Sbostic struct utmp ut; 4235673Sbostic struct stat buf; 4335673Sbostic time_t time(); 4435673Sbostic char *strncpy(); 4535673Sbostic 4636304Skarels if (fd < 0 && (fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0) 4735673Sbostic return; 4836304Skarels if (fstat(fd, &buf) == 0) { 4935673Sbostic (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line)); 5035673Sbostic (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name)); 5135673Sbostic (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host)); 5235673Sbostic (void)time(&ut.ut_time); 5335673Sbostic if (write(fd, (char *)&ut, sizeof(struct utmp)) != 5435673Sbostic sizeof(struct utmp)) 5535673Sbostic (void)ftruncate(fd, buf.st_size); 5635673Sbostic } 5735673Sbostic } 58