Subject: path for syslog instead of xferlog

From: Andreas Sindermann <[email-masked]>
Date: Thu, 12 Mar 1998 00:29:29 +0100 (MET)

Hello,

the following patch allows to save transfer messages via syslog
instead of putting them into xferlog. On the command line you can
switch it on with '-X' (no xferlog, like '-A' for no ftpaccess file),
in the ftpaccess file you can switch it on with 'log syslog'.

It's a quite simple patch. It sends the same message (including the
timestamp) to syslog as it would save it into xferlog.

Have fun!

Andreas

PS: Apply the patch from within the wu-ftpd-2.4.2-beta-16 directory as
it also patches the ftpd and ftpaccess manpages.

-- snip --

*** doc/ftpaccess.5.ori	Thu Mar 12 00:20:57 1998
--- doc/ftpaccess.5	Thu Mar 12 00:06:22 1998
***************
*** 216,221 ****
--- 216,225 ----
  of any of the two keywords "inbound" and "outbound", and will
  respectively cause transfers to be logged for files sent to the
  server and sent from the server.
+ .TP 0.5i
+ .B log syslog
+ Redirects the logging messages for incoming and outgoing transfers
+ to syslog. Without this option the messages are written to xferlog.
  .SH Miscellaneous Capabilities
  .TP 0.5i
  .B alias <string> <dir>
*** doc/ftpd.8.ori	Thu Mar 12 00:20:43 1998
--- doc/ftpd.8	Wed Mar 11 23:15:28 1998
***************
*** 45,52 ****
  .BR \-i
  ] [
  .BR \-o
! ]
  .BR \-u umask
  ]
  .SH DESCRIPTION
  .I Ftpd
--- 45,54 ----
  .BR \-i
  ] [
  .BR \-o
! ] [
  .BR \-u umask
+ ] [
+ .BR \-X
  ]
  .SH DESCRIPTION
  .I Ftpd
***************
*** 132,138 ****
  The 
  .B \-o option is overridden by the use of the
  .IR ftpaccess (5)
! file.
  .PP
  If the
  .B \-u
--- 134,147 ----
  The 
  .B \-o option is overridden by the use of the
  .IR ftpaccess (5)
! file. If the
! .B \-X
! option is specified, the output created by the
! .B \-i
! and
! .B \-o
! options is not saved in the xferlog file but saved via syslog
! so you can collect output from several hosts on one central loghost.
  .PP
  If the
  .B \-u
*** src/access.c.ori	Thu Mar 12 00:20:30 1998
--- src/access.c	Wed Mar 11 23:58:30 1998
***************
*** 341,346 ****
--- 341,347 ----
        log_outbound_xfers,
        mangleopts,
        log_commands,
+       syslogmsg,
        lgi_failure_threshold;
  
      struct aclmember *entry = NULL;
***************
*** 355,360 ****
--- 356,362 ----
      log_incoming_xfers = 0;
      log_outbound_xfers = 0;
      log_commands = 0;
+     syslogmsg = 0;
  
      memset((void *)&class[0], 0, sizeof(class));
   
***************
*** 427,432 ****
--- 429,436 ----
              if (set)
                  log_outbound_xfers = outbound;
          }
+         if (!strcasecmp(ARG0, "syslog"))
+             syslogmsg = 1;
      }
  }
  
*** src/ftpd.c.ori	Wed Mar 11 14:15:32 1998
--- src/ftpd.c	Wed Mar 11 17:54:04 1998
***************
*** 240,245 ****
--- 240,249 ----
  int logging = 0;
  int log_commands = 0;
  
+ /* messages usually should be logged to xferlog, but in some cases it makes
+    sense to send them to syslog */
+ int syslogmsg = 0;
+ 
  #ifdef SECUREOSF
  #define SecureWare
  #include <prot.h>
***************
*** 452,458 ****
          envp++;
      LastArgv = envp[-1] + strlen(envp[-1]);
  
!     while ((c = getopt(argc, argv, ":aAvdlLiot:T:u:")) != -1) {
          switch (c) {
  
          case 'a':
--- 456,462 ----
          envp++;
      LastArgv = envp[-1] + strlen(envp[-1]);
  
!     while ((c = getopt(argc, argv, ":aAvdlLiot:T:u:X")) != -1) {
          switch (c) {
  
          case 'a':
***************
*** 512,517 ****
--- 516,525 ----
                  break;
              }
  
+         case 'X':
+             syslogmsg = 1;
+             break;
+ 
          case ':':
              syslog(LOG_ERR, "option -%c requires an argument", optopt);
              break;
***************
*** 1530,1537 ****
          }
      }
  
!     /* if logging is enabled, open logfile before chroot or set group ID */
!     if (log_outbound_xfers || log_incoming_xfers) {
          xferlog = open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0660);
          if (xferlog < 0) {
              syslog(LOG_ERR, "cannot open logfile %s: %s", logfile,
--- 1538,1546 ----
          }
      }
  
!     /* if logging is enabled, open logfile before chroot or set group ID,
!        but only if messages shouldn't be sent to syslog */ 
!     if (log_outbound_xfers || log_incoming_xfers && !syslogmsg) {
          xferlog = open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0660);
          if (xferlog < 0) {
              syslog(LOG_ERR, "cannot open logfile %s: %s", logfile,
***************
*** 1983,1989 ****
                  authenticated ? authuser : "*"
              );
  #endif /* stupid_sprintf */
!         write(xferlog, msg, strlen(msg));
      }
      data = -1;
      pdata = -1;
--- 1992,2001 ----
                  authenticated ? authuser : "*"
              );
  #endif /* stupid_sprintf */
!         if (!syslogmsg)
!             write(xferlog, msg, strlen(msg));
!         else
!             syslog(LOG_INFO, msg);
      }
      data = -1;
      pdata = -1;
***************
*** 2227,2233 ****
                  authenticated ? authuser : "*"
              );
  #endif /* STUPID_SPRINTF */
!         write(xferlog, msg, strlen(msg));
      }
      data = -1;
      pdata = -1;
--- 2239,2248 ----
                  authenticated ? authuser : "*"
              );
  #endif /* STUPID_SPRINTF */
!         if (!syslogmsg)
!             write(xferlog, msg, strlen(msg));
!         else
!             syslog(LOG_INFO, msg);
      }
      data = -1;
      pdata = -1;