logwtmp.c revision 79968
179968Sobrien/*	$NetBSD: logwtmp.c,v 1.16 2001/02/04 22:04:12 christos Exp $	*/
279968Sobrien
379968Sobrien/*
479968Sobrien * Copyright (c) 1988, 1993
579968Sobrien *	The Regents of the University of California.  All rights reserved.
679968Sobrien *
779968Sobrien * Redistribution and use in source and binary forms, with or without
879968Sobrien * modification, are permitted provided that the following conditions
979968Sobrien * are met:
1079968Sobrien * 1. Redistributions of source code must retain the above copyright
1179968Sobrien *    notice, this list of conditions and the following disclaimer.
1279968Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1379968Sobrien *    notice, this list of conditions and the following disclaimer in the
1479968Sobrien *    documentation and/or other materials provided with the distribution.
1579968Sobrien * 3. All advertising materials mentioning features or use of this software
1679968Sobrien *    must display the following acknowledgement:
1779968Sobrien *	This product includes software developed by the University of
1879968Sobrien *	California, Berkeley and its contributors.
1979968Sobrien * 4. Neither the name of the University nor the names of its contributors
2079968Sobrien *    may be used to endorse or promote products derived from this software
2179968Sobrien *    without specific prior written permission.
2279968Sobrien *
2379968Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2479968Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2579968Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2679968Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2779968Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2879968Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2979968Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3079968Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3179968Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3279968Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3379968Sobrien * SUCH DAMAGE.
3479968Sobrien *
3579968Sobrien */
3679968Sobrien
3779968Sobrien#include "lukemftpd.h"
3879968Sobrien
3979968Sobrien#include "extern.h"
4079968Sobrien
4179968Sobrienstatic int fd = -1;
4279968Sobrien
4379968Sobrien/*
4479968Sobrien * Modified version of logwtmp that holds wtmp file open
4579968Sobrien * after first call, for use with ftp (which may chroot
4679968Sobrien * after login, but before logout).
4779968Sobrien */
4879968Sobrienvoid
4979968Sobrienlogwtmp(const char *line, const char *name, const char *host)
5079968Sobrien{
5179968Sobrien	struct utmp ut;
5279968Sobrien	struct stat buf;
5379968Sobrien
5479968Sobrien	if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
5579968Sobrien		return;
5679968Sobrien	if (fstat(fd, &buf) == 0) {
5779968Sobrien		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
5879968Sobrien		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
5979968Sobrien		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
6079968Sobrien		(void)time(&ut.ut_time);
6179968Sobrien		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
6279968Sobrien		    sizeof(struct utmp))
6379968Sobrien			(void)ftruncate(fd, buf.st_size);
6479968Sobrien	}
6579968Sobrien}
66