logwtmp.c revision 202604
1255767Sdes/*
2224638Sbrooks * Copyright (c) 1988, 1993
376259Sgreen *	The Regents of the University of California.  All rights reserved.
476259Sgreen *
576259Sgreen * Redistribution and use in source and binary forms, with or without
676259Sgreen * modification, are permitted provided that the following conditions
776259Sgreen * are met:
876259Sgreen * 1. Redistributions of source code must retain the above copyright
976259Sgreen *    notice, this list of conditions and the following disclaimer.
1076259Sgreen * 2. Redistributions in binary form must reproduce the above copyright
1176259Sgreen *    notice, this list of conditions and the following disclaimer in the
1276259Sgreen *    documentation and/or other materials provided with the distribution.
1376259Sgreen * 3. All advertising materials mentioning features or use of this software
1476259Sgreen *    must display the following acknowledgement:
1576259Sgreen *	This product includes software developed by the University of
16162852Sdes *	California, Berkeley and its contributors.
17162852Sdes * 4. Neither the name of the University nor the names of its contributors
18162852Sdes *    may be used to endorse or promote products derived from this software
19137015Sdes *    without specific prior written permission.
20137015Sdes *
2192555Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2292555Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23137015Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24137015Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2592555Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2692555Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27157016Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28162852Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29146998Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3092555Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3192555Sdes * SUCH DAMAGE.
3292555Sdes */
33149749Sdes
34149749Sdes#ifndef lint
35162852Sdes#if 0
36157016Sdesstatic char sccsid[] = "@(#)logwtmp.c	8.1 (Berkeley) 6/4/93";
37181111Sdes#endif
38181111Sdes#endif /* not lint */
39255767Sdes
40204917Sdes#include <sys/cdefs.h>
41224638Sbrooks__FBSDID("$FreeBSD: head/libexec/ftpd/logwtmp.c 202604 2010-01-18 23:28:25Z ed $");
4276259Sgreen
4392555Sdes#include <sys/types.h>
44181111Sdes#include <sys/stat.h>
4576259Sgreen#include <netinet/in.h>
4692555Sdes#include <arpa/inet.h>
4792555Sdes#include <sys/socket.h>
4898675Sdes
49137015Sdes#include <libutil.h>
50137015Sdes#include <stdio.h>
5192555Sdes#include <string.h>
52157016Sdes#include <unistd.h>
53157016Sdes#include <utmpx.h>
54157016Sdes#include "extern.h"
55157016Sdes
56157016Sdesvoid
57137015Sdesftpd_logwtmp(char *id, char *user, struct sockaddr *addr)
58157016Sdes{
59157016Sdes	struct utmpx ut;
60157016Sdes
61157016Sdes	memset(&ut, 0, sizeof(ut));
62157016Sdes
63157016Sdes	if (user != NULL) {
64157016Sdes		/* Log in. */
65157016Sdes		ut.ut_type = USER_PROCESS;
66157016Sdes		(void)strncpy(ut.ut_user, user, sizeof(ut.ut_user));
67157016Sdes		if (addr != NULL)
68157016Sdes			realhostname_sa(ut.ut_host, sizeof(ut.ut_host),
69157016Sdes			    addr, addr->sa_len);
70162852Sdes	} else {
71162852Sdes		/* Log out. */
72162852Sdes		ut.ut_type = DEAD_PROCESS;
73162852Sdes	}
74162852Sdes
75162852Sdes	ut.ut_pid = getpid();
76162852Sdes	gettimeofday(&ut.ut_tv, NULL);
77162852Sdes	(void)strncpy(ut.ut_id, id, sizeof(ut.ut_id));
78162852Sdes
79162852Sdes	pututxline(&ut);
80162852Sdes}
81162852Sdes