1ea022d16SRodney W. Grimes /* 2ea022d16SRodney W. Grimes * Copyright (c) 1988, 1993 3ea022d16SRodney W. Grimes * The Regents of the University of California. All rights reserved. 4ea022d16SRodney W. Grimes * 5ea022d16SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6ea022d16SRodney W. Grimes * modification, are permitted provided that the following conditions 7ea022d16SRodney W. Grimes * are met: 8ea022d16SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9ea022d16SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10ea022d16SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11ea022d16SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12ea022d16SRodney W. Grimes * documentation and/or other materials provided with the distribution. 13ea022d16SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14ea022d16SRodney W. Grimes * must display the following acknowledgement: 15ea022d16SRodney W. Grimes * This product includes software developed by the University of 16ea022d16SRodney W. Grimes * California, Berkeley and its contributors. 17ea022d16SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18ea022d16SRodney W. Grimes * may be used to endorse or promote products derived from this software 19ea022d16SRodney W. Grimes * without specific prior written permission. 20ea022d16SRodney W. Grimes * 21ea022d16SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22ea022d16SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23ea022d16SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24ea022d16SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25ea022d16SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26ea022d16SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27ea022d16SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28ea022d16SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29ea022d16SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30ea022d16SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31ea022d16SRodney W. Grimes * SUCH DAMAGE. 32ea022d16SRodney W. Grimes */ 33ea022d16SRodney W. Grimes 34ea022d16SRodney W. Grimes #ifndef lint 35e02897faSPhilippe Charnier #if 0 36ea022d16SRodney W. Grimes static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; 37e02897faSPhilippe Charnier #endif 38ea022d16SRodney W. Grimes #endif /* not lint */ 39ea022d16SRodney W. Grimes 400c4b401fSYaroslav Tykhiy #include <sys/cdefs.h> 410c4b401fSYaroslav Tykhiy __FBSDID("$FreeBSD$"); 420c4b401fSYaroslav Tykhiy 43ea022d16SRodney W. Grimes #include <sys/types.h> 44ea022d16SRodney W. Grimes #include <sys/stat.h> 45333468baSAndrey A. Chernov #include <netinet/in.h> 46333468baSAndrey A. Chernov #include <arpa/inet.h> 474dd8b5abSYoshinobu Inoue #include <sys/socket.h> 48ea022d16SRodney W. Grimes 4980643af0SEd Schouten #include <libutil.h> 50ea022d16SRodney W. Grimes #include <stdio.h> 51ea022d16SRodney W. Grimes #include <string.h> 5280643af0SEd Schouten #include <unistd.h> 5380643af0SEd Schouten #include <utmpx.h> 54ea022d16SRodney W. Grimes #include "extern.h" 55ea022d16SRodney W. Grimes 56ea022d16SRodney W. Grimes void 5780643af0SEd Schouten ftpd_logwtmp(char *id, char *user, struct sockaddr *addr) 58ea022d16SRodney W. Grimes { 5980643af0SEd Schouten struct utmpx ut; 60ea022d16SRodney W. Grimes 6180643af0SEd Schouten memset(&ut, 0, sizeof(ut)); 62333468baSAndrey A. Chernov 6380643af0SEd Schouten if (*user != '\0') { 6480643af0SEd Schouten /* Log in. */ 6580643af0SEd Schouten ut.ut_type = USER_PROCESS; 6680643af0SEd Schouten (void)strncpy(ut.ut_user, user, sizeof(ut.ut_user)); 6780643af0SEd Schouten if (addr != NULL) 6880643af0SEd Schouten realhostname_sa(ut.ut_host, sizeof(ut.ut_host), 6980643af0SEd Schouten addr, addr->sa_len); 7080643af0SEd Schouten } else { 7180643af0SEd Schouten /* Log out. */ 7280643af0SEd Schouten ut.ut_type = DEAD_PROCESS; 73ea022d16SRodney W. Grimes } 7480643af0SEd Schouten 7580643af0SEd Schouten ut.ut_pid = getpid(); 7680643af0SEd Schouten gettimeofday(&ut.ut_tv, NULL); 7780643af0SEd Schouten (void)strncpy(ut.ut_id, id, sizeof(ut.ut_id)); 7880643af0SEd Schouten 7980643af0SEd Schouten pututxline(&ut); 80ea022d16SRodney W. Grimes } 81