]> git.pld-linux.org Git - packages/proftpd.git/blobdiff - proftpd-wtmp.patch
- updated to 1.3.5b
[packages/proftpd.git] / proftpd-wtmp.patch
index 219e751188cd1a37c8523f63e53779e9d3408ac3..fb84cbd7496c6efc72c47335826d6474e88fce35 100644 (file)
---- proftpd-1.3.0.orig/src/log.c       2005-11-14 17:33:06.000000000 +0100
-+++ proftpd-1.3.0/src/log.c    2007-02-21 00:31:27.000000000 +0100
-@@ -54,31 +54,13 @@
- int log_wtmp(char *line, const char *name, const char *host,
-     pr_netaddr_t *ip) {
--  struct stat buf;
+diff -ruNp proftpd-1.3.5.orig/src/wtmp.c proftpd-1.3.5/src/wtmp.c
+--- proftpd-1.3.5.orig/src/wtmp.c      2013-12-09 20:16:15.000000000 +0100
++++ proftpd-1.3.5/src/wtmp.c   2015-04-03 11:47:21.710554599 +0200
+@@ -136,11 +136,33 @@ int log_wtmp(const char *line, const cha
    struct utmp ut;
-   int res = 0;
--  static int fd = -1;
-+  static int washere = 0;
--#if ((defined(SVR4) || defined(__SVR4)) || \
--    (defined(__NetBSD__) && defined(HAVE_UTMPX_H))) && \
--    !(defined(LINUX) || defined(__hpux) || defined (_AIX))
--  /* This "auxilliary" utmp doesn't exist under linux. */
--#ifdef __sparcv9
--  struct futmpx utx;
--  time_t t;
--#else
--  struct utmpx utx;
--#endif
--  static int fdx = -1;
--
--#if !defined(WTMPX_FILE) && defined(_PATH_WTMPX)
--# define WTMPX_FILE _PATH_WTMPX
--#endif
--
--  if (fdx < 0 &&
--      (fdx = open(WTMPX_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
--    pr_log_pri(PR_LOG_WARNING, "wtmpx %s: %s", WTMPX_FILE, strerror(errno));
--    return -1;
-+  if (!washere) {
-+    utmpname(_PATH_WTMP);
-+    washere = 1;
-   }
+   static int fd = -1;
  
-   /* Unfortunately, utmp string fields are terminated by '\0' if they are
-@@ -87,52 +69,7 @@
-    * Insane if you ask me.  Unless there's massive uproar, I prefer to err on
-    * the side of caution and always null-terminate our strings.
-    */
--  if (fstat(fdx, &buf) == 0) {
--    memset(&utx, 0, sizeof(utx));
--
--    sstrncpy(utx.ut_user, name, sizeof(utx.ut_user));
--    sstrncpy(utx.ut_id, "ftp", sizeof(utx.ut_user));
--    sstrncpy(utx.ut_line, line, sizeof(utx.ut_line));
--    sstrncpy(utx.ut_host, host, sizeof(utx.ut_host));
--    utx.ut_pid = getpid();
--#if defined(__NetBSD__) && defined(HAVE_UTMPX_H)
--    memcpy(&utx.ut_ss, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_ss));
--    gettimeofday(&utx.ut_tv, NULL);
--#else /* SVR4 */
--    utx.ut_syslen = strlen(utx.ut_host)+1;
--#  ifdef __sparcv9
--    time(&t);
--    utx.ut_tv.tv_sec = (time32_t)t;
--#  else
--    time(&utx.ut_tv.tv_sec);
--#  endif
--#endif /* SVR4 */
--
--    if (*name)
--      utx.ut_type = USER_PROCESS;
--    else
--      utx.ut_type = DEAD_PROCESS;
--#ifdef HAVE_UT_UT_EXIT
--    utx.ut_exit.e_termination = 0;
--    utx.ut_exit.e_exit = 0;
--#endif /* HAVE_UT_UT_EXIT */
--    if (write(fdx, (char *)&utx, sizeof(utx)) != sizeof(utx))
--      ftruncate(fdx, buf.st_size);
--
--  } else {
--    pr_log_debug(DEBUG0, "%s fstat(): %s", WTMPX_FILE, strerror(errno));
--    res = -1;
--  }
--
--#else /* Non-SVR4 systems */
--
--  if (fd < 0 &&
++#if defined(HAVE_UTMPX_H)
++#if !defined(WTMPX_FILE) && defined(_PATH_WTMPX)
++# define WTMPX_FILE _PATH_WTMPX
++#endif
++  static char *wtmp_file = NULL;
++  if (wtmp_file == NULL) {
++    if (access(WTMPX_FILE"x", F_OK) == 0)
++      wtmp_file = WTMPX_FILE"x";
++    else if (access(WTMPX_FILE, F_OK) == 0)
++      wtmp_file = WTMPX_FILE;
++    else if (access(WTMP_FILE"x", F_OK) == 0)
++      wtmp_file = WTMP_FILE"x";
++    else if (access(WTMP_FILE, F_OK) == 0)
++      wtmp_file = WTMP_FILE;
++    else {
++      pr_log_pri(PR_LOG_WARNING, "cannot find "WTMPX_FILE);
++      return -1;
++    }
++  }
++#else
++  static char *wtmp_file = WTMP_FILE;
++#endif
+   if (fd < 0 &&
 -      (fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
--    pr_log_pri(PR_LOG_WARNING, "wtmp %s: %s", WTMP_FILE, strerror(errno));
--    return -1;
--  }
--  if (fstat(fd, &buf) == 0) {
-     memset(&ut, 0, sizeof(ut));
- #ifdef HAVE_UTMAXTYPE
- # ifdef LINUX
-@@ -169,15 +106,12 @@
- #endif /* HAVE_UT_UT_HOST */
-     time(&ut.ut_time);
--    if (write(fd, (char *)&ut, sizeof(ut)) != sizeof(ut))
--      ftruncate(fd, buf.st_size);
--
--  } else {
--    pr_log_debug(DEBUG0, "%s fstat(): %s",WTMP_FILE,strerror(errno));
--    res = -1;
--  }
--#endif /* SVR4 */
++      (fd = open(wtmp_file, O_WRONLY|O_APPEND, 0)) < 0) {
+     int xerrno = errno;
  
-+  setutent();
-+  while ((getutent())) ;
-+  pututline(&ut);
-+  if (!washere)
-+    endutent();
-   return res;
- }
+-    pr_log_pri(PR_LOG_WARNING, "failed to open wtmp %s: %s", WTMP_FILE,
++    pr_log_pri(PR_LOG_WARNING, "failed to open wtmp %s: %s", wtmp_file,
+       strerror(xerrno));
  
+     errno = xerrno;
This page took 0.080894 seconds and 4 git commands to generate.