logwtmp.c revision 202209
11592Srgrimes/* 21592Srgrimes * Copyright (c) 1988, 1993 31592Srgrimes * The Regents of the University of California. All rights reserved. 41592Srgrimes * 51592Srgrimes * Redistribution and use in source and binary forms, with or without 61592Srgrimes * modification, are permitted provided that the following conditions 71592Srgrimes * are met: 81592Srgrimes * 1. Redistributions of source code must retain the above copyright 91592Srgrimes * notice, this list of conditions and the following disclaimer. 101592Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111592Srgrimes * notice, this list of conditions and the following disclaimer in the 121592Srgrimes * documentation and/or other materials provided with the distribution. 131592Srgrimes * 3. All advertising materials mentioning features or use of this software 141592Srgrimes * must display the following acknowledgement: 151592Srgrimes * This product includes software developed by the University of 161592Srgrimes * California, Berkeley and its contributors. 171592Srgrimes * 4. Neither the name of the University nor the names of its contributors 181592Srgrimes * may be used to endorse or promote products derived from this software 191592Srgrimes * without specific prior written permission. 201592Srgrimes * 211592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241592Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311592Srgrimes * SUCH DAMAGE. 321592Srgrimes */ 331592Srgrimes 341592Srgrimes#ifndef lint 3531329Scharnier#if 0 361592Srgrimesstatic char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; 3731329Scharnier#endif 381592Srgrimes#endif /* not lint */ 391592Srgrimes 40137859Syar#include <sys/cdefs.h> 41137859Syar__FBSDID("$FreeBSD: head/libexec/ftpd/logwtmp.c 202209 2010-01-13 18:28:41Z ed $"); 42137859Syar 431592Srgrimes#include <sys/types.h> 441592Srgrimes#include <sys/stat.h> 4516433Sache#include <netinet/in.h> 4616433Sache#include <arpa/inet.h> 4756668Sshin#include <sys/socket.h> 481592Srgrimes 49202209Sed#include <libutil.h> 501592Srgrimes#include <stdio.h> 511592Srgrimes#include <string.h> 52202209Sed#include <unistd.h> 53202209Sed#include <utmpx.h> 541592Srgrimes#include "extern.h" 551592Srgrimes 561592Srgrimesvoid 57202209Sedftpd_logwtmp(char *id, char *user, struct sockaddr *addr) 581592Srgrimes{ 59202209Sed struct utmpx ut; 601592Srgrimes 61202209Sed memset(&ut, 0, sizeof(ut)); 6216433Sache 63202209Sed if (*user != '\0') { 64202209Sed /* Log in. */ 65202209Sed ut.ut_type = USER_PROCESS; 66202209Sed (void)strncpy(ut.ut_user, user, sizeof(ut.ut_user)); 67202209Sed if (addr != NULL) 68202209Sed realhostname_sa(ut.ut_host, sizeof(ut.ut_host), 69202209Sed addr, addr->sa_len); 70202209Sed } else { 71202209Sed /* Log out. */ 72202209Sed ut.ut_type = DEAD_PROCESS; 731592Srgrimes } 74202209Sed 75202209Sed ut.ut_pid = getpid(); 76202209Sed gettimeofday(&ut.ut_tv, NULL); 77202209Sed (void)strncpy(ut.ut_id, id, sizeof(ut.ut_id)); 78202209Sed 79202209Sed pututxline(&ut); 801592Srgrimes} 81