]> git.pld-linux.org Git - packages/proftpd.git/blob - proftpd-wtmp.patch
- rel 2
[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 diff -burNp proftpd-1.3.2.orig/configure.in proftpd-1.3.2-dud/configure.in
24 --- proftpd-1.3.2.orig/configure.in     2008-11-19 04:51:38.000000000 +0100
25 +++ proftpd-1.3.2-dud/configure.in      2009-02-09 12:03:19.465085522 +0100
26 @@ -1131,7 +1131,7 @@ AC_CHECK_HEADERS(netinet/tcp.h arpa/inet
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(ucred.h 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 @@ -1211,10 +1211,10 @@ AC_CHECK_HEADERS(utmp.h, have_utmp=1, ha
36  
37  if test $have_utmp; then
38    AC_CACHE_CHECK(whether 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 struct utmp has ut_host,
47                 pr_cv_header_ut_host,
48         AC_EGREP_HEADER([ *ut_host.*;],utmp.h,
49 @@ -1225,7 +1225,7 @@ if test $have_utmp; then
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 +  if test "$pr_cv_header_ut_user" = "yes"; then
55      AC_DEFINE(HAVE_UTMAXTYPE, 1, [If struct utmp has ut_user.])
56    fi
57    if test "$pr_cv_header_ut_host" = "yes"; then
58 @@ -1236,6 +1236,28 @@ if test $have_utmp; then
59    fi
60  fi
61  
62 +dnl See what type of utmp exists
63 +AC_CHECK_HEADERS(utmpx.h, have_utmpx=1, have_utmpx=0)
64 +
65 +if test $have_utmpx; then
66 +  AC_CACHE_CHECK(whether your struct utmpx has ut_exit,
67 +               pr_cv_header_utx_exit,
68 +       AC_EGREP_HEADER([ *ut_exit.*;],utmpx.h,
69 +                         pr_cv_header_utx_exit="yes",
70 +                         pr_cv_header_utx_exit="no"))
71 +  AC_CACHE_CHECK(whether your struct utmpx has ut_syslen,
72 +               pr_cv_header_utx_syslen,
73 +       AC_EGREP_HEADER([ *ut_syslen.*;],utmpx.h,
74 +                         pr_cv_header_utx_syslen="yes",
75 +                         pr_cv_header_utx_syslen="no"))
76 +  if test "$pr_cv_header_utx_exit" = "yes"; then
77 +    AC_DEFINE(HAVE_UTX_UT_EXIT, 1, [If struct utmpx has ut_exit.])
78 +  fi
79 +  if test "$pr_cv_header_utx_syslen" = "yes"; then
80 +    AC_DEFINE(HAVE_UTX_UT_SYSLEN, 1, [If struct utmpx has ut_syslen.])
81 +  fi
82 +fi
83 +
84  dnl See if various LOG_ macros are defined
85  if test "$have_syslog_h" = "yes"; then
86    AC_DEFINE(HAVE_SYSLOG_H)
87 diff -burNp proftpd-1.3.2.orig/src/log.c proftpd-1.3.2-dud/src/log.c
88 --- proftpd-1.3.2.orig/src/log.c        2008-12-17 00:43:55.000000000 +0100
89 +++ proftpd-1.3.2-dud/src/log.c 2009-02-09 14:24:34.271689801 +0100
90 @@ -58,26 +58,29 @@ int log_wtmp(char *line, const char *nam
91    struct utmp ut;
92    int res = 0;
93    static int fd = -1;
94 +#if defined(HAVE_UTMPX_H)
95 +  char *wtmpx_file = NULL;
96 +  static int fdx = -1;
97 +
98 +#if !defined(WTMPX_FILE) && defined(_PATH_WTMPX)
99 +# define WTMPX_FILE _PATH_WTMPX
100 +#endif
101 +  if (access(WTMPX_FILE, F_OK) == 0)
102 +         wtmpx_file = strdup(WTMPX_FILE);
103 +  else if (access(WTMPX_FILE"x", F_OK) == 0)
104 +         wtmpx_file = strdup(WTMPX_FILE"x");
105  
106 -#if ((defined(SVR4) || defined(__SVR4)) || \
107 -    (defined(__NetBSD__) && defined(HAVE_UTMPX_H))) && \
108 -    !(defined(LINUX) || defined(__hpux) || defined (_AIX))
109 -  /* This "auxilliary" utmp doesn't exist under linux. */
110 +  if (fdx >= 0 || wtmpx_file != NULL)
111 +  {
112  #if defined(__sparcv9) && !defined(__NetBSD__)
113    struct futmpx utx;
114 -  time_t t;
115  #else
116    struct utmpx utx;
117 -#endif
118 -  static int fdx = -1;
119 -
120 -#if !defined(WTMPX_FILE) && defined(_PATH_WTMPX)
121 -# define WTMPX_FILE _PATH_WTMPX
122 +         time_t t;
123  #endif
124  
125 -  if (fdx < 0 &&
126 -      (fdx = open(WTMPX_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
127 -    pr_log_pri(PR_LOG_WARNING, "wtmpx %s: %s", WTMPX_FILE, strerror(errno));
128 +  if (fdx < 0 && (fdx = open(wtmpx_file, O_WRONLY|O_APPEND, 0)) < 0) {
129 +      pr_log_pri(PR_LOG_WARNING, "wtmpx %s: %s", wtmpx_file, strerror(errno));
130      return -1;
131    }
132  
133 @@ -87,95 +90,95 @@ int log_wtmp(char *line, const char *nam
134     * Insane if you ask me.  Unless there's massive uproar, I prefer to err on
135     * the side of caution and always null-terminate our strings.
136     */
137 +
138    if (fstat(fdx, &buf) == 0) {
139      memset(&utx, 0, sizeof(utx));
140 -
141 +      if (name && *name) {
142      sstrncpy(utx.ut_user, name, sizeof(utx.ut_user));
143 -    sstrncpy(utx.ut_id, "ftp", sizeof(utx.ut_user));
144 -    sstrncpy(utx.ut_line, line, sizeof(utx.ut_line));
145 -    sstrncpy(utx.ut_host, host, sizeof(utx.ut_host));
146 -    utx.ut_pid = session.pid ? session.pid : getpid();
147 -#if defined(__NetBSD__) && defined(HAVE_UTMPX_H)
148 -    memcpy(&utx.ut_ss, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_ss));
149 -    gettimeofday(&utx.ut_tv, NULL);
150 -#else /* SVR4 */
151 -    utx.ut_syslen = strlen(utx.ut_host)+1;
152 -#  ifdef __sparcv9
153 -    time(&t);
154 -    utx.ut_tv.tv_sec = (time32_t)t;
155 -#  else
156 -    time(&utx.ut_tv.tv_sec);
157 -#  endif
158 -#endif /* SVR4 */
159 -
160 -    if (*name)
161        utx.ut_type = USER_PROCESS;
162 -    else
163 +      } else {
164        utx.ut_type = DEAD_PROCESS;
165 -#ifdef HAVE_UT_UT_EXIT
166 +      }
167 +      utx.ut_pid = getpid();
168 +      sstrncpy(utx.ut_line, line, sizeof(utx.ut_line));
169 +      sstrncpy(utx.ut_id, "ftp", sizeof(utx.ut_user));
170 +      if (host && *host)
171 +        sstrncpy(utx.ut_host, host, sizeof(utx.ut_host));
172 +#ifdef HAVE_UTX_UT_EXIT
173      utx.ut_exit.e_termination = 0;
174      utx.ut_exit.e_exit = 0;
175  #endif /* HAVE_UT_UT_EXIT */
176 +#ifdef HAVE_UTX_UT_SYSLEN
177 +      utx.ut_syslen = strlen(utx.ut_host)+1;
178 +#endif
179 +#if defined(__NetBSD__)
180 +      memcpy(&utx.ut_ss, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_ss));
181 +      gettimeofday(&utx.ut_tv, NULL);
182 +#else
183 +      time(&t);
184 +      utx.ut_tv.tv_sec = t;
185 +#endif
186 +      if (ip)
187 +#ifndef PR_USE_IPV6
188 +        memcpy(&utx.ut_addr, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_addr));
189 +#else
190 +        memcpy(&utx.ut_addr_v6, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_addr_v6));
191 +#endif /* !PR_USE_IPV6 */
192      if (write(fdx, (char *)&utx, sizeof(utx)) != sizeof(utx))
193 -      (void) ftruncate(fdx, buf.st_size);
194 -
195 +        (void )ftruncate(fdx, buf.st_size);
196    } else {
197 -    pr_log_debug(DEBUG0, "%s fstat(): %s", WTMPX_FILE, strerror(errno));
198 +      pr_log_debug(DEBUG0, "%s fstat(): %s", wtmpx_file, strerror(errno));
199      res = -1;
200    }
201 -
202 -#else /* Non-SVR4 systems */
203 -
204 -  if (fd < 0 &&
205 -      (fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
206 +    free(wtmpx_file);
207 +    return res;
208 +  }
209 +#else /* HAVE_UTMPX_H */
210 +  if (fd < 0 && (fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
211      pr_log_pri(PR_LOG_WARNING, "wtmp %s: %s", WTMP_FILE, strerror(errno));
212      return -1;
213    }
214  
215    if (fstat(fd, &buf) == 0) {
216      memset(&ut, 0, sizeof(ut));
217 -#ifdef HAVE_UTMAXTYPE
218 -# ifdef LINUX
219 -    if (ip)
220 -#  ifndef PR_USE_IPV6
221 -      memcpy(&ut.ut_addr, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr));
222 -#  else
223 -      memcpy(&ut.ut_addr_v6, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr_v6));
224 -#  endif /* !PR_USE_IPV6 */
225 -# else
226 -    sstrncpy(ut.ut_id, "ftp", sizeof(ut.ut_id));
227 -#  ifdef HAVE_UT_UT_EXIT
228 -    ut.ut_exit.e_termination = 0;
229 -    ut.ut_exit.e_exit = 0;
230 -#  endif /* !HAVE_UT_UT_EXIT */
231 -# endif /* !LINUX */
232 -    sstrncpy(ut.ut_line, line, sizeof(ut.ut_line));
233 -    if (name && *name)
234 +    if (name && *name) {
235 +#ifdef HAVE_UT_UT_USER
236        sstrncpy(ut.ut_user, name, sizeof(ut.ut_user));
237 -    ut.ut_pid = session.pid ? session.pid : getpid();
238 -    if (name && *name)
239 +#else
240 +           sstrncpy(ut.ut_name, name, sizeof(ut.ut_name));
241 +#endif
242        ut.ut_type = USER_PROCESS;
243 -    else
244 +    } else {
245        ut.ut_type = DEAD_PROCESS;
246 -#else  /* !HAVE_UTMAXTYPE */
247 +    }
248 +    ut.ut_pid = session.pid ? session.pid : getpid();
249      sstrncpy(ut.ut_line, line, sizeof(ut.ut_line));
250 -    if (name && *name)
251 -      sstrncpy(ut.ut_name, name, sizeof(ut.ut_name));
252 -#endif /* HAVE_UTMAXTYPE */
253 +    sstrncpy(ut.ut_id, "ftp", sizeof(ut.ut_id));
254  
255  #ifdef HAVE_UT_UT_HOST
256      if (host && *host)
257        sstrncpy(ut.ut_host, host, sizeof(ut.ut_host));
258  #endif /* HAVE_UT_UT_HOST */
259  
260 +#ifdef HAVE_UT_UT_EXIT
261 +    ut.ut_exit.e_termination = 0;
262 +    ut.ut_exit.e_exit = 0;
263 +#endif /* !HAVE_UT_UT_EXIT */
264 +
265      ut.ut_time = time(NULL);
266 +    if (ip)
267 +#ifndef PR_USE_IPV6
268 +      memcpy(&ut.ut_addr, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr));
269 +#else
270 +      memcpy(&ut.ut_addr_v6, pr_netaddr_get_inaddr(ip), sizeof(ut.ut_addr_v6));
271 +#endif /* !PR_USE_IPV6 */
272 +
273      if (write(fd, (char *)&ut, sizeof(ut)) != sizeof(ut)) {
274        if (ftruncate(fd, buf.st_size) < 0) {
275          pr_log_debug(DEBUG0, "error truncating '%s': %s", WTMP_FILE,
276            strerror(errno));
277        }
278      }
279 -
280    } else {
281      pr_log_debug(DEBUG0, "%s fstat(): %s", WTMP_FILE, strerror(errno));
282      res = -1;
This page took 0.116748 seconds and 3 git commands to generate.