]> git.pld-linux.org Git - packages/proftpd.git/blob - proftpd-wtmp.patch
- rel 4
[packages/proftpd.git] / proftpd-wtmp.patch
1 --- proftpd-1.3.1-wtmp/acconfig.h       2002-12-15 20:05:09.000000000 +0200
2 +++ proftpd-1.3.1/acconfig.h    2008-01-09 00:43:47.043739566 +0200
3 @@ -70,7 +70,7 @@
4  #undef HAVE_UT_UT_HOST
5  
6  /* Define if your struct utmp uses ut_user and not ut_name */
7 -#undef HAVE_UTMAXTYPE
8 +#undef HAVE_UT_UT_USER
9  
10  #define PF_ARGV_NONE           0
11  #define PF_ARGV_NEW            1
12 --- proftpd-1.3.1-wtmp/config.h.in      2008-01-09 00:43:32.506904225 +0200
13 +++ proftpd-1.3.1/config.h.in   2008-01-09 00:43:47.043739566 +0200
14 @@ -122,7 +122,7 @@
15  #undef HAVE_UT_UT_HOST
16  
17  /* Define if your struct utmp uses ut_user and not ut_name */
18 -#undef HAVE_UTMAXTYPE
19 +#undef HAVE_UT_UT_USER
20  
21  #define PF_ARGV_NONE           0
22  #define PF_ARGV_NEW            1
23 --- proftpd-1.3.1-wtmp/configure.in     2007-05-22 23:54:09.000000000 +0300
24 +++ proftpd-1.3.1/configure.in  2008-01-09 00:43:47.043739566 +0200
25 @@ -1063,7 +1063,7 @@
26  AC_CHECK_HEADERS(sys/stat.h errno.h sys/socket.h sys/termios.h sys/termio.h)
27  AC_CHECK_HEADERS(sys/statvfs.h sys/un.h sys/vfs.h sys/select.h)
28  AC_CHECK_HEADERS(dirent.h ndir.h sys/ndir.h sys/dir.h vmsdir.h)
29 -AC_CHECK_HEADERS(ucontext.h utime.h utmpx.h)
30 +AC_CHECK_HEADERS(ucontext.h utime.h)
31  AC_CHECK_HEADERS(regex.h)
32  AC_CHECK_HEADER(syslog.h,have_syslog_h="yes",)
33  AC_CHECK_HEADERS(curses.h ncurses.h)
34 @@ -1143,10 +1143,10 @@
35  
36  if test $have_utmp; then
37    AC_CACHE_CHECK(whether your struct utmp has ut_user,
38 -               pr_cv_header_utmaxtype,
39 +               pr_cv_header_ut_user,
40         AC_EGREP_HEADER([ *ut_user.*;],utmp.h,
41 -                       pr_cv_header_utmaxtype="yes",
42 -                       pr_cv_header_utmaxtype="no"))
43 +                       pr_cv_header_ut_user="yes",
44 +                       pr_cv_header_ut_user="no"))
45    AC_CACHE_CHECK(whether your struct utmp has ut_host,
46                 pr_cv_header_ut_host,
47         AC_EGREP_HEADER([ *ut_host.*;],utmp.h,
48 @@ -1157,8 +1157,8 @@
49         AC_EGREP_HEADER([ *ut_exit.*;],utmp.h,
50                         pr_cv_header_ut_exit="yes",
51                         pr_cv_header_ut_exit="no"))
52 -  if test "$pr_cv_header_utmaxtype" = "yes"; then
53 -    AC_DEFINE(HAVE_UTMAXTYPE, 1, [If struct utmp has ut_user.])
54 +  if test "$pr_cv_header_ut_user" = "yes"; then
55 +    AC_DEFINE(HAVE_UT_UT_USER, 1, [If struct utmp has ut_user.])
56    fi
57    if test "$pr_cv_header_ut_host" = "yes"; then
58      AC_DEFINE(HAVE_UT_UT_HOST, 1, [If struct utmp has ut_host.])
59 @@ -1168,6 +1168,28 @@
60    fi
61  fi
62  
63 +dnl See what type of utmp exists
64 +AC_CHECK_HEADERS(utmpx.h, have_utmpx=1, have_utmpx=0)
65 +
66 +if test $have_utmpx; then
67 +  AC_CACHE_CHECK(whether your struct utmpx has ut_exit,
68 +               pr_cv_header_utx_exit,
69 +       AC_EGREP_HEADER([ *ut_exit.*;],utmpx.h,
70 +                       pr_cv_header_utx_exit="yes",
71 +                       pr_cv_header_utx_exit="no"))
72 +  AC_CACHE_CHECK(whether your struct utmpx has ut_syslen,
73 +               pr_cv_header_utx_syslen,
74 +       AC_EGREP_HEADER([ *ut_syslen.*;],utmpx.h,
75 +                       pr_cv_header_utx_syslen="yes",
76 +                       pr_cv_header_utx_syslen="no"))
77 +  if test "$pr_cv_header_utx_exit" = "yes"; then
78 +    AC_DEFINE(HAVE_UTX_UT_EXIT, 1, [If struct utmpx has ut_exit.])
79 +  fi
80 +  if test "$pr_cv_header_utx_syslen" = "yes"; then
81 +    AC_DEFINE(HAVE_UTX_UT_SYSLEN, 1, [If struct utmpx has ut_syslen.])
82 +  fi
83 +fi
84 +
85  dnl See if various LOG_ macros are defined
86  if test "$have_syslog_h" = "yes"; then
87    AC_DEFINE(HAVE_SYSLOG_H)
88 --- proftpd-1.3.1-wtmp/src/log.c        2007-09-11 03:49:44.000000000 +0300
89 +++ proftpd-1.3.1/src/log.c     2008-01-09 00:43:47.043739566 +0200
90 @@ -59,119 +59,124 @@
91    int res = 0;
92    static int fd = -1;
93  
94 -#if ((defined(SVR4) || defined(__SVR4)) || \
95 -    (defined(__NetBSD__) && defined(HAVE_UTMPX_H))) && \
96 -    !(defined(LINUX) || defined(__hpux) || defined (_AIX))
97 -  /* This "auxilliary" utmp doesn't exist under linux. */
98 -#if defined(__sparcv9) && !defined(__NetBSD__)
99 -  struct futmpx utx;
100 -  time_t t;
101 -#else
102 -  struct utmpx utx;
103 -#endif
104 +#if defined(HAVE_UTMPX_H)
105 +  char *wtmpx_file = NULL;
106    static int fdx = -1;
107  
108  #if !defined(WTMPX_FILE) && defined(_PATH_WTMPX)
109  # define WTMPX_FILE _PATH_WTMPX
110  #endif
111 +  if (access(WTMPX_FILE, F_OK) == 0)
112 +    wtmpx_file = strdup(WTMPX_FILE);
113 +  else if (access(WTMPX_FILE"x", F_OK) == 0)
114 +    wtmpx_file = strdup(WTMPX_FILE"x");
115  
116 -  if (fdx < 0 &&
117 -      (fdx = open(WTMPX_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
118 -    pr_log_pri(PR_LOG_WARNING, "wtmpx %s: %s", WTMPX_FILE, strerror(errno));
119 -    return -1;
120 -  }
121 +  if (fdx >= 0 || wtmpx_file != NULL)
122 +  {
123 +#if defined(__sparcv9) && !defined(__NetBSD__)
124 +    struct futmpx utx;
125 +#else
126 +    struct utmpx utx;
127 +    time_t t;
128 +#endif
129  
130 -  /* Unfortunately, utmp string fields are terminated by '\0' if they are
131 -   * shorter than the size of the field, but if they are exactly the size of
132 -   * the field they don't have to be terminated at all.  Frankly, this sucks.
133 -   * Insane if you ask me.  Unless there's massive uproar, I prefer to err on
134 -   * the side of caution and always null-terminate our strings.
135 -   */
136 -  if (fstat(fdx, &buf) == 0) {
137 -    memset(&utx, 0, sizeof(utx));
138 +    if (fdx < 0 && (fdx = open(wtmpx_file, O_WRONLY|O_APPEND, 0)) < 0) {
139 +      pr_log_pri(PR_LOG_WARNING, "wtmpx %s: %s", wtmpx_file, strerror(errno));
140 +      return -1;
141 +    }
142  
143 -    sstrncpy(utx.ut_user, name, sizeof(utx.ut_user));
144 -    sstrncpy(utx.ut_id, "ftp", sizeof(utx.ut_user));
145 -    sstrncpy(utx.ut_line, line, sizeof(utx.ut_line));
146 -    sstrncpy(utx.ut_host, host, sizeof(utx.ut_host));
147 -    utx.ut_pid = getpid();
148 -#if defined(__NetBSD__) && defined(HAVE_UTMPX_H)
149 -    memcpy(&utx.ut_ss, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_ss));
150 -    gettimeofday(&utx.ut_tv, NULL);
151 -#else /* SVR4 */
152 -    utx.ut_syslen = strlen(utx.ut_host)+1;
153 -#  ifdef __sparcv9
154 -    time(&t);
155 -    utx.ut_tv.tv_sec = (time32_t)t;
156 -#  else
157 -    time(&utx.ut_tv.tv_sec);
158 -#  endif
159 -#endif /* SVR4 */
160 +    /* Unfortunately, utmp string fields are terminated by '\0' if they are
161 +     * shorter than the size of the field, but if they are exactly the size of
162 +     * the field they don't have to be terminated at all.  Frankly, this sucks.
163 +     * Insane if you ask me.  Unless there's massive uproar, I prefer to err on
164 +     * the side of caution and always null-terminate our strings.
165 +     */
166 +    if (fstat(fdx, &buf) == 0) {
167 +      memset(&utx, 0, sizeof(utx));
168  
169 -    if (*name)
170 -      utx.ut_type = USER_PROCESS;
171 -    else
172 -      utx.ut_type = DEAD_PROCESS;
173 -#ifdef HAVE_UT_UT_EXIT
174 -    utx.ut_exit.e_termination = 0;
175 -    utx.ut_exit.e_exit = 0;
176 +      if (name && *name) {
177 +        sstrncpy(utx.ut_user, name, sizeof(utx.ut_user));
178 +        utx.ut_type = USER_PROCESS;
179 +      } else {
180 +        utx.ut_type = DEAD_PROCESS;
181 +      }
182 +      utx.ut_pid = getpid();
183 +      sstrncpy(utx.ut_line, line, sizeof(utx.ut_line));
184 +      sstrncpy(utx.ut_id, "ftp", sizeof(utx.ut_user));
185 +      if (host && *host)
186 +        sstrncpy(utx.ut_host, host, sizeof(utx.ut_host));
187 +#ifdef HAVE_UTX_UT_EXIT
188 +      utx.ut_exit.e_termination = 0;
189 +      utx.ut_exit.e_exit = 0;
190  #endif /* HAVE_UT_UT_EXIT */
191 -    if (write(fdx, (char *)&utx, sizeof(utx)) != sizeof(utx))
192 -      (void) ftruncate(fdx, buf.st_size);
193  
194 -  } else {
195 -    pr_log_debug(DEBUG0, "%s fstat(): %s", WTMPX_FILE, strerror(errno));
196 -    res = -1;
197 -  }
198 +#ifdef HAVE_UTX_UT_SYSLEN
199 +      utx.ut_syslen = strlen(utx.ut_host)+1;
200 +#endif
201 +#if defined(__NetBSD__)
202 +      memcpy(&utx.ut_ss, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_ss));
203 +      gettimeofday(&utx.ut_tv, NULL);
204 +#else
205 +      time(&t);
206 +      utx.ut_tv.tv_sec = t;
207 +#endif
208  
209 -#else /* Non-SVR4 systems */
210 +      if (ip)
211 +#ifndef PR_USE_IPV6
212 +        memcpy(&utx.ut_addr, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_addr));
213 +#else
214 +        memcpy(&utx.ut_addr_v6, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_addr_v6));
215 +#endif /* !PR_USE_IPV6 */
216  
217 -  if (fd < 0 &&
218 -      (fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
219 +      if (write(fdx, (char *)&utx, sizeof(utx)) != sizeof(utx))
220 +        (void )ftruncate(fdx, buf.st_size);
221 +    } else {
222 +      pr_log_debug(DEBUG0, "%s fstat(): %s", wtmpx_file, strerror(errno));
223 +      res = -1;
224 +    }
225 +
226 +    free(wtmpx_file);
227 +    return res;
228 +  }
229 +#else /* HAVE_UTMPX_H */
230 +  if (fd < 0 && (fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
231      pr_log_pri(PR_LOG_WARNING, "wtmp %s: %s", WTMP_FILE, strerror(errno));
232      return -1;
233    }
234  
235    if (fstat(fd, &buf) == 0) {
236      memset(&ut, 0, sizeof(ut));
237 -#ifdef HAVE_UTMAXTYPE
238 -# ifdef LINUX
239 -    if (ip)
240 -#  ifndef PR_USE_IPV6
241 -      memcpy(&ut.ut_addr, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr));
242 -#  else
243 -      memcpy(&ut.ut_addr_v6, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr_v6));
244 -#  endif /* !PR_USE_IPV6 */
245 -# else
246 -    sstrncpy(ut.ut_id, "ftp", sizeof(ut.ut_id));
247 -#  ifdef HAVE_UT_UT_EXIT
248 -    ut.ut_exit.e_termination = 0;
249 -    ut.ut_exit.e_exit = 0;
250 -#  endif /* !HAVE_UT_UT_EXIT */
251 -# endif /* !LINUX */
252 -    sstrncpy(ut.ut_line, line, sizeof(ut.ut_line));
253 -    if (name && *name)
254 +    if (name && *name) {
255 +#ifdef HAVE_UT_UT_USER
256        sstrncpy(ut.ut_user, name, sizeof(ut.ut_user));
257 -    ut.ut_pid = getpid();
258 -    if (name && *name)
259 +#else
260 +      sstrncpy(ut.ut_name, name, sizeof(ut.ut_name));
261 +#endif
262        ut.ut_type = USER_PROCESS;
263 -    else
264 +    } else {
265        ut.ut_type = DEAD_PROCESS;
266 -#else  /* !HAVE_UTMAXTYPE */
267 +    }
268 +    ut.ut_pid = getpid();
269      sstrncpy(ut.ut_line, line, sizeof(ut.ut_line));
270 -    if (name && *name)
271 -      sstrncpy(ut.ut_name, name, sizeof(ut.ut_name));
272 -#endif /* HAVE_UTMAXTYPE */
273 -
274 +    sstrncpy(ut.ut_id, "ftp", sizeof(ut.ut_id));
275  #ifdef HAVE_UT_UT_HOST
276      if (host && *host)
277        sstrncpy(ut.ut_host, host, sizeof(ut.ut_host));
278  #endif /* HAVE_UT_UT_HOST */
279 -
280 +#ifdef HAVE_UT_UT_EXIT
281 +    ut.ut_exit.e_termination = 0;
282 +    ut.ut_exit.e_exit = 0;
283 +#endif /* !HAVE_UT_UT_EXIT */
284      time(&ut.ut_time);
285 +    if (ip)
286 +#ifndef PR_USE_IPV6
287 +      memcpy(&ut.ut_addr, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr));
288 +#else
289 +      memcpy(&ut.ut_addr_v6, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr_v6));
290 +#endif /* !PR_USE_IPV6 */
291 +
292      if (write(fd, (char *)&ut, sizeof(ut)) != sizeof(ut))
293        ftruncate(fd, buf.st_size);
294 -
295    } else {
296      pr_log_debug(DEBUG0, "%s fstat(): %s",WTMP_FILE,strerror(errno));
297      res = -1;
This page took 0.04458 seconds and 3 git commands to generate.