Sat Nov 7 20:33:26 2015 UTC ()
Pull up following revision(s) (requested by shm in ticket #1975):
	libexec/ftpd/logwtmp.c: revision 1.26
	libexec/ftpd/logwtmp.c: revision 1.27
Removed unnecessary memset(3) call
--
Clear utmpx struct before writing it to wtmpx files


(snj)
diff -r1.25 -r1.25.24.1 src/libexec/ftpd/logwtmp.c

cvs diff -r1.25 -r1.25.24.1 src/libexec/ftpd/logwtmp.c (expand / switch to unified diff)

--- src/libexec/ftpd/logwtmp.c 2006/09/23 16:03:50 1.25
+++ src/libexec/ftpd/logwtmp.c 2015/11/07 20:33:26 1.25.24.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: logwtmp.c,v 1.25 2006/09/23 16:03:50 xtraeme Exp $ */ 1/* $NetBSD: logwtmp.c,v 1.25.24.1 2015/11/07 20:33:26 snj Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1993 4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 * 30 *
31 */ 31 */
32 32
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35#ifndef lint 35#ifndef lint
36#if 0 36#if 0
37static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; 37static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
38#else 38#else
39__RCSID("$NetBSD: logwtmp.c,v 1.25 2006/09/23 16:03:50 xtraeme Exp $"); 39__RCSID("$NetBSD: logwtmp.c,v 1.25.24.1 2015/11/07 20:33:26 snj Exp $");
40#endif 40#endif
41#endif /* not lint */ 41#endif /* not lint */
42 42
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/time.h> 45#include <sys/time.h>
46#include <sys/stat.h> 46#include <sys/stat.h>
47#include <sys/wait.h> 47#include <sys/wait.h>
48 48
49#include <fcntl.h> 49#include <fcntl.h>
50#include <signal.h> 50#include <signal.h>
51#include <stdio.h> 51#include <stdio.h>
52#include <string.h> 52#include <string.h>
@@ -114,32 +114,31 @@ ftpd_initwtmpx(void) @@ -114,32 +114,31 @@ ftpd_initwtmpx(void)
114 syslog(LOG_ERR, "Cannot open `%s' (%m)", wf); 114 syslog(LOG_ERR, "Cannot open `%s' (%m)", wf);
115} 115}
116 116
117void 117void
118ftpd_logwtmpx(const char *line, const char *name, const char *host, 118ftpd_logwtmpx(const char *line, const char *name, const char *host,
119 struct sockinet *haddr, int status, int utx_type) 119 struct sockinet *haddr, int status, int utx_type)
120{ 120{
121 struct utmpx ut; 121 struct utmpx ut;
122 struct stat buf; 122 struct stat buf;
123  123
124 if (fdx < 0)  124 if (fdx < 0)
125 return; 125 return;
126 if (fstat(fdx, &buf) == 0) { 126 if (fstat(fdx, &buf) == 0) {
 127 (void)memset(&ut, 0, sizeof(ut));
127 (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line)); 128 (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
128 (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name)); 129 (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
129 (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host)); 130 (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
130 if (haddr) 131 if (haddr)
131 (void)memcpy(&ut.ut_ss, &haddr->si_su, haddr->su_len); 132 (void)memcpy(&ut.ut_ss, &haddr->si_su, haddr->su_len);
132 else 
133 (void)memset(&ut.ut_ss, 0, sizeof(ut.ut_ss)); 
134 ut.ut_type = utx_type; 133 ut.ut_type = utx_type;
135 if (WIFEXITED(status)) 134 if (WIFEXITED(status))
136 ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status); 135 ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
137 if (WIFSIGNALED(status)) 136 if (WIFSIGNALED(status))
138 ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status); 137 ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status);
139 (void)gettimeofday(&ut.ut_tv, NULL); 138 (void)gettimeofday(&ut.ut_tv, NULL);
140 if(write(fdx, (char *)&ut, sizeof(struct utmpx)) != 139 if(write(fdx, (char *)&ut, sizeof(struct utmpx)) !=
141 sizeof(struct utmpx)) 140 sizeof(struct utmpx))
142 (void)ftruncate(fdx, buf.st_size); 141 (void)ftruncate(fdx, buf.st_size);
143 } 142 }
144} 143}
145#endif 144#endif