]> git.pld-linux.org Git - packages/proftpd.git/blob - proftpd-wtmp.patch
- kinda "fixed" now
[packages/proftpd.git] / proftpd-wtmp.patch
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
4 @@ -530,93 +530,96 @@
5  int log_wtmp(char *line, char *name, char *host, p_in_addr_t *ip)
6  {
7    struct stat buf;
8 -  struct utmp ut;
9    int res = 0;
10 -  static int fd = -1;
11 -
12 -#if defined(SVR4) || defined(__SVR4)
13 -#if !(defined(LINUX) || defined(__hpux) || defined (_AIX))
14 -  /* This "auxilliary" utmp doesn't exist under linux. */
15 -  struct utmpx utx;
16    static int fdx = -1;
17 +  static int fd = -1;
18  
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));
21 -    return -1;
22 -  }
23 -
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.
29 -   */
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);
39 -    if(*name)
40 -      utx.ut_type = USER_PROCESS;
41 -    else
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);
47 -  } else {
48 -    log_debug(DEBUG0,"%s fstat(): %s",WTMPX_FILE,strerror(errno));
49 -    res = -1;
50 -  }
51 +  if (fdx >= 0 || access(_PATH_WTMP"x", F_OK) == 0) {
52 +    struct utmpx utx;
53  
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));
56 +      return -1;
57 +    }
58 +
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.
64 +     */
65 +    if(fstat(fdx,&buf) == 0) {
66 +      memset(&utx,0,sizeof(utx));
67 +      if(name && *name)
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));
71 +      if(host && *host)
72 +        sstrncpy(utx.ut_host,host,sizeof(utx.ut_host));
73 +#ifndef LINUX
74 +      utx.ut_syslen = strlen(utx.ut_host)+1;
75 +      utx.ut_exit.e_termination = 0;
76 +      utx.ut_exit.e_exit = 0;
77  #endif
78 -#endif /* SVR4 */
79 +      utx.ut_pid = getpid();
80 +      time(&utx.ut_tv.tv_sec);
81 +      if(name && *name)
82 +        utx.ut_type = USER_PROCESS;
83 +      else
84 +        utx.ut_type = DEAD_PROCESS;
85 +      if(ip)
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);
89 +    } else {
90 +      log_debug(DEBUG0,"%s fstat(): %s",_PATH_WTMP"x",strerror(errno));
91 +      res = -1;
92 +    }
93 +  } else {
94 +    struct utmp ut;
95  
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));
98 -    return -1;
99 -  }
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));
102 +      return -1;
103 +    }
104   
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
110  #ifdef LINUX
111 -    if(ip)
112 -      memcpy(&ut.ut_addr,ip,sizeof(ut.ut_addr));
113 +      if(ip)
114 +        memcpy(&ut.ut_addr,ip,sizeof(ut.ut_addr));
115  #else
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;
122  #endif
123 -    sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
124 -    if(name && *name)
125 -      sstrncpy(ut.ut_user,name,sizeof(ut.ut_user));
126 -    ut.ut_pid = getpid();
127 -    if(name && *name)
128 -      ut.ut_type = USER_PROCESS;
129 -    else
130 -      ut.ut_type = DEAD_PROCESS;
131 +      sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
132 +      if(name && *name)
133 +        sstrncpy(ut.ut_user,name,sizeof(ut.ut_user));
134 +      ut.ut_pid = getpid();
135 +      if(name && *name)
136 +        ut.ut_type = USER_PROCESS;
137 +      else
138 +        ut.ut_type = DEAD_PROCESS;
139  #else  /* !HAVE_UTMAXTYPE */
140 -    sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
141 -    if(name && *name)
142 -      sstrncpy(ut.ut_name,name,sizeof(ut.ut_name));
143 +      sstrncpy(ut.ut_line,line,sizeof(ut.ut_line));
144 +      if(name && *name)
145 +        sstrncpy(ut.ut_name,name,sizeof(ut.ut_name));
146  #endif /* HAVE_UTMAXTYPE */
147  
148  #ifdef HAVE_UT_UT_HOST
149 -    if(host && *host)
150 -      sstrncpy(ut.ut_host,host,sizeof(ut.ut_host));
151 +      if(host && *host)
152 +        sstrncpy(ut.ut_host,host,sizeof(ut.ut_host));
153  #endif /* HAVE_UT_UT_HOST */
154  
155 -    time(&ut.ut_time);
156 -    if(write(fd,(char*)&ut,sizeof(ut)) != sizeof(ut))
157 -      ftruncate(fd,buf.st_size);
158 -  } else {
159 -    log_debug(DEBUG0,"%s fstat(): %s",WTMP_FILE,strerror(errno));
160 -    res = -1;
161 +      time(&ut.ut_time);
162 +      if(write(fd,(char*)&ut,sizeof(ut)) != sizeof(ut))
163 +        ftruncate(fd,buf.st_size);
164 +    } else {
165 +      log_debug(DEBUG0,"%s fstat(): %s",WTMP_FILE,strerror(errno));
166 +      res = -1;
167 +    }
168    }
169  
170    return res;
This page took 0.06371 seconds and 4 git commands to generate.