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