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