1331722Seadler/*
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.
13262136Sbrueffer * 3. Neither the name of the University nor the names of its contributors
141592Srgrimes *    may be used to endorse or promote products derived from this software
151592Srgrimes *    without specific prior written permission.
161592Srgrimes *
171592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201592Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271592Srgrimes * SUCH DAMAGE.
281592Srgrimes */
291592Srgrimes
301592Srgrimes#ifndef lint
3131329Scharnier#if 0
321592Srgrimesstatic char sccsid[] = "@(#)logwtmp.c	8.1 (Berkeley) 6/4/93";
3331329Scharnier#endif
341592Srgrimes#endif /* not lint */
351592Srgrimes
36137859Syar#include <sys/cdefs.h>
37137859Syar__FBSDID("$FreeBSD$");
38137859Syar
391592Srgrimes#include <sys/types.h>
401592Srgrimes#include <sys/stat.h>
4116433Sache#include <netinet/in.h>
4216433Sache#include <arpa/inet.h>
4356668Sshin#include <sys/socket.h>
441592Srgrimes
45202209Sed#include <libutil.h>
461592Srgrimes#include <stdio.h>
471592Srgrimes#include <string.h>
48202209Sed#include <unistd.h>
49202209Sed#include <utmpx.h>
501592Srgrimes#include "extern.h"
511592Srgrimes
521592Srgrimesvoid
53202209Sedftpd_logwtmp(char *id, char *user, struct sockaddr *addr)
541592Srgrimes{
55202209Sed	struct utmpx ut;
561592Srgrimes
57202209Sed	memset(&ut, 0, sizeof(ut));
5816433Sache
59202604Sed	if (user != NULL) {
60202209Sed		/* Log in. */
61202209Sed		ut.ut_type = USER_PROCESS;
62202209Sed		(void)strncpy(ut.ut_user, user, sizeof(ut.ut_user));
63202209Sed		if (addr != NULL)
64202209Sed			realhostname_sa(ut.ut_host, sizeof(ut.ut_host),
65202209Sed			    addr, addr->sa_len);
66202209Sed	} else {
67202209Sed		/* Log out. */
68202209Sed		ut.ut_type = DEAD_PROCESS;
691592Srgrimes	}
70202209Sed
71202209Sed	ut.ut_pid = getpid();
72202209Sed	gettimeofday(&ut.ut_tv, NULL);
73202209Sed	(void)strncpy(ut.ut_id, id, sizeof(ut.ut_id));
74203698Sed	(void)strncpy(ut.ut_line, "ftpd", sizeof(ut.ut_line));
75202209Sed
76202209Sed	pututxline(&ut);
771592Srgrimes}
78