1 diff -ur proftpd-1.2.0rc2.orig/src/log.c proftpd-1.2.0rc2/src/log.c
2 --- proftpd-1.2.0rc2.orig/src/log.c Wed Jul 26 13:03:17 2000
3 +++ proftpd-1.2.0rc2/src/log.c Sun Aug 20 01:07:51 2000
5 int log_wtmp(char *line, char *name, char *host, p_in_addr_t *ip)
12 -#if defined(SVR4) || defined(__SVR4)
13 -#if !(defined(LINUX) || defined(__hpux) || defined (_AIX))
14 - /* This "auxilliary" utmp doesn't exist under linux. */
19 - if(fdx < 0 && (fdx = open(WTMPX_FILE, O_WRONLY | O_APPEND, 0)) < 0) {
20 - log_pri(LOG_WARNING,"wtmpx %s: %s",WTMPX_FILE,strerror(errno));
24 - /* Unfortunately, utmp string fields are terminated by '\0' if they are
25 - * shorter than the size of the field, but if they are exactly the size of
26 - * the field they don't have to be terminated at all. Frankly, this sucks.
27 - * Insane if you ask me. Unless there's massive uproar, I prefer to err on
28 - * the side of caution and always null-terminate our strings.
30 - if(fstat(fdx,&buf) == 0) {
31 - memset(&utx,0,sizeof(utx));
32 - sstrncpy(utx.ut_user,name,sizeof(utx.ut_user));
33 - sstrncpy(utx.ut_id,"ftp",sizeof(utx.ut_user));
34 - sstrncpy(utx.ut_line,line,sizeof(utx.ut_line));
35 - sstrncpy(utx.ut_host,host,sizeof(utx.ut_host));
36 - utx.ut_syslen = strlen(utx.ut_host)+1;
37 - utx.ut_pid = getpid();
38 - time(&utx.ut_tv.tv_sec);
40 - utx.ut_type = USER_PROCESS;
42 - utx.ut_type = DEAD_PROCESS;
43 - utx.ut_exit.e_termination = 0;
44 - utx.ut_exit.e_exit = 0;
45 - if(write(fdx,(char*)&utx,sizeof(utx)) != sizeof(utx))
46 - ftruncate(fdx, buf.st_size);
48 - log_debug(DEBUG0,"%s fstat(): %s",WTMPX_FILE,strerror(errno));
51 + if (fdx >= 0 || access(_PATH_WTMP"x", F_OK) == 0) {
54 + if(fdx < 0 && (fdx = open(_PATH_WTMP"x", O_WRONLY | O_APPEND, 0)) < 0) {
55 + log_pri(LOG_WARNING,"wtmpx %s: %s",_PATH_WTMP"x",strerror(errno));
59 + /* Unfortunately, utmp string fields are terminated by '\0' if they are
60 + * shorter than the size of the field, but if they are exactly the size of
61 + * the field they don't have to be terminated at all. Frankly, this sucks.
62 + * Insane if you ask me. Unless there's massive uproar, I prefer to err on
63 + * the side of caution and always null-terminate our strings.
65 + if(fstat(fdx,&buf) == 0) {
66 + memset(&utx,0,sizeof(utx));
68 + sstrncpy(utx.ut_user,name,sizeof(utx.ut_user));
69 + sstrncpy(utx.ut_id,"ftp",sizeof(utx.ut_id));
70 + sstrncpy(utx.ut_line,line,sizeof(utx.ut_line));
72 + sstrncpy(utx.ut_host,host,sizeof(utx.ut_host));
74 + utx.ut_syslen = strlen(utx.ut_host)+1;
75 + utx.ut_exit.e_termination = 0;
76 + utx.ut_exit.e_exit = 0;
79 + utx.ut_pid = getpid();
80 + time(&utx.ut_tv.tv_sec);
82 + utx.ut_type = USER_PROCESS;
84 + utx.ut_type = DEAD_PROCESS;
86 + memcpy(&utx.ut_addr,ip,sizeof(utx.ut_addr));
87 + if(write(fdx,(char*)&utx,sizeof(utx)) != sizeof(utx))
88 + ftruncate(fdx, buf.st_size);
90 + log_debug(DEBUG0,"%s fstat(): %s",_PATH_WTMP"x",strerror(errno));
96 - if(fd < 0 && (fd = open(WTMP_FILE,O_WRONLY|O_APPEND,0)) < 0) {
97 - log_pri(LOG_WARNING,"wtmp %s: %s",WTMP_FILE,strerror(errno));
100 + if(fd < 0 && (fd = open(WTMP_FILE,O_WRONLY|O_APPEND,0)) < 0) {
101 + log_pri(LOG_WARNING,"wtmp %s: %s",WTMP_FILE,strerror(errno));
105 - if(fstat(fd,&buf) == 0) {
106 - memset(&ut,0,sizeof(ut));
107 + if(fstat(fd,&buf) == 0) {
108 + memset(&ut,0,sizeof(ut));
109 #ifdef HAVE_UTMAXTYPE
112 - memcpy(&ut.ut_addr,ip,sizeof(ut.ut_addr));
114 + memcpy(&ut.ut_addr,ip,sizeof(ut.ut_addr));
116 - sstrncpy(ut.ut_id,"ftp",sizeof(ut.ut_id));
117 - ut.ut_exit.e_termination = 0;
118 - ut.ut_exit.e_exit = 0;
119 + sstrncpy(ut.ut_id,"ftp",sizeof(ut.ut_id));
120 + ut.ut_exit.e_termination = 0;
121 + ut.ut_exit.e_exit = 0;
123 - sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
125 - sstrncpy(ut.ut_user,name,sizeof(ut.ut_user));
126 - ut.ut_pid = getpid();
128 - ut.ut_type = USER_PROCESS;
130 - ut.ut_type = DEAD_PROCESS;
131 + sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
133 + sstrncpy(ut.ut_user,name,sizeof(ut.ut_user));
134 + ut.ut_pid = getpid();
136 + ut.ut_type = USER_PROCESS;
138 + ut.ut_type = DEAD_PROCESS;
139 #else /* !HAVE_UTMAXTYPE */
140 - sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
142 - sstrncpy(ut.ut_name,name,sizeof(ut.ut_name));
143 + sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
145 + sstrncpy(ut.ut_name,name,sizeof(ut.ut_name));
146 #endif /* HAVE_UTMAXTYPE */
148 #ifdef HAVE_UT_UT_HOST
150 - sstrncpy(ut.ut_host,host,sizeof(ut.ut_host));
152 + sstrncpy(ut.ut_host,host,sizeof(ut.ut_host));
153 #endif /* HAVE_UT_UT_HOST */
156 - if(write(fd,(char*)&ut,sizeof(ut)) != sizeof(ut))
157 - ftruncate(fd,buf.st_size);
159 - log_debug(DEBUG0,"%s fstat(): %s",WTMP_FILE,strerror(errno));
162 + if(write(fd,(char*)&ut,sizeof(ut)) != sizeof(ut))
163 + ftruncate(fd,buf.st_size);
165 + log_debug(DEBUG0,"%s fstat(): %s",WTMP_FILE,strerror(errno));