[vhffs-dev] [2169] new pure-ftpd patch, altlog to syslog feature added |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 2169
Author: gradator
Date: 2012-05-02 23:32:49 +0200 (Wed, 02 May 2012)
Log Message:
-----------
new pure-ftpd patch, altlog to syslog feature added
Added Paths:
-----------
trunk/vhffs-patches/pureftpd/pure-ftpd-1.0.35-altlog-syslog.patch
Added: trunk/vhffs-patches/pureftpd/pure-ftpd-1.0.35-altlog-syslog.patch
===================================================================
--- trunk/vhffs-patches/pureftpd/pure-ftpd-1.0.35-altlog-syslog.patch (rev 0)
+++ trunk/vhffs-patches/pureftpd/pure-ftpd-1.0.35-altlog-syslog.patch 2012-05-02 21:32:49 UTC (rev 2169)
@@ -0,0 +1,170 @@
+diff -Nru a/man/pure-ftpd.8.in b/man/pure-ftpd.8.in
+--- a/man/pure-ftpd.8.in 2011-10-31 00:37:10.000000000 +0000
++++ b/man/pure-ftpd.8.in 2012-05-02 21:25:54.404381576 +0000
+@@ -369,6 +369,7 @@
+ .IR pure\-uploadscript .
+ .TP
+ .B \-O format:log file
++.B \-O format:syslog,facility
+ Record all file transfers into a specific log
+ file, in an alternative format. Currently, three formats are supported : CLF,
+ Stats, W3C and xferlog.
+@@ -401,6 +402,17 @@
+ For security purposes, the path must be absolute
+ (eg.
+ \fB/var/log/pureftpd.log\fR, not \fB ../log/pureftpd.log\fR).
++.br
++If you add
++.br
++\fB\-O clf:syslog,local2\fR
++.br
++to your starting options,
++Pure-FTPd will send log, in a format similar to the Apache web server in default
++configuration, to syslog with the local2 facility.
++.I Facility is optional and
++defaults to
++.BR ftp .
+ .TP
+ .B \-p first:last
+ Use only ports in the range \fIfirst\fR to \fIlast\fR
+diff -Nru a/src/altlog.c b/src/altlog.c
+--- a/src/altlog.c 2011-10-30 20:58:07.000000000 +0000
++++ b/src/altlog.c 2012-05-02 21:16:08.688137804 +0000
+@@ -19,30 +19,50 @@
+
+ static int altlog_write(const char *str)
+ {
+- struct flock lock;
+- ssize_t left;
+-
+- if (altlog_fd == -1 || str == NULL ||
+- (left = (ssize_t) strlen(str)) <= (ssize_t) 0) {
+- return -1;
+- }
+- lock.l_whence = SEEK_SET;
+- lock.l_start = (off_t) 0;
+- lock.l_len = (off_t) 0;
+- lock.l_pid = getpid();
+- lock.l_type = F_WRLCK;
+- while (fcntl(altlog_fd, F_SETLKW, &lock) < 0 && errno == EINTR);
+- if (lseek(altlog_fd, (off_t) 0, SEEK_END) < (off_t) 0
++ if( altlog_syslog ) {
++# ifdef SAVE_DESCRIPTORS
++ openlog("pure-ftpd", log_pid, altlog_syslog_facility);
++# else
++ if (syslog_facility != altlog_syslog_facility) {
++ closelog();
++ openlog("pure-ftpd", log_pid, altlog_syslog_facility);
++ }
++# endif
++ syslog(LOG_NOTICE, str);
++# ifdef SAVE_DESCRIPTORS
++ closelog();
++# else
++ if (syslog_facility != altlog_syslog_facility) {
++ closelog();
++ openlog("pure-ftpd", LOG_NDELAY | log_pid, syslog_facility);
++ }
++# endif
++ } else {
++ struct flock lock;
++ ssize_t left;
++
++ if (altlog_fd == -1 || str == NULL ||
++ (left = (ssize_t) strlen(str)) <= (ssize_t) 0) {
++ return -1;
++ }
++ lock.l_whence = SEEK_SET;
++ lock.l_start = (off_t) 0;
++ lock.l_len = (off_t) 0;
++ lock.l_pid = getpid();
++ lock.l_type = F_WRLCK;
++ while (fcntl(altlog_fd, F_SETLKW, &lock) < 0 && errno == EINTR);
++ if (lseek(altlog_fd, (off_t) 0, SEEK_END) < (off_t) 0
+ # ifdef ESPIPE
+- && errno != ESPIPE
++ && errno != ESPIPE
+ # endif
+- ) {
+- return -1;
++ ) {
++ return -1;
++ }
++ (void) safe_write(altlog_fd, str, (size_t) left, -1);
++ lock.l_type = F_UNLCK;
++ while (fcntl(altlog_fd, F_SETLK, &lock) < 0 && errno == EINTR);
+ }
+- (void) safe_write(altlog_fd, str, (size_t) left, -1);
+- lock.l_type = F_UNLCK;
+- while (fcntl(altlog_fd, F_SETLK, &lock) < 0 && errno == EINTR);
+-
++
+ return 0;
+ }
+
+diff -Nru a/src/ftpd.c b/src/ftpd.c
+--- a/src/ftpd.c 2011-12-03 06:42:06.000000000 +0000
++++ b/src/ftpd.c 2012-05-02 21:15:57.656282264 +0000
+@@ -5943,14 +5943,35 @@
+ optarg_copy);
+ }
+ }
+- if (*delpoint != '/') {
++ if (*delpoint == '/') {
++ if ((altlog_filename = strdup(delpoint)) == NULL) {
++ die_mem();
++ }
++ }
++ else if ( strncasecmp(delpoint, "syslog", sizeof "syslog" - 1U) == 0) {
++ char *syslogdelpoint;
++ if ((syslogdelpoint = strchr(delpoint, ALTLOG_SYSLOG_DELIMITER)) != NULL) {
++ int n = 0;
++ *syslogdelpoint++ = 0;
++
++ while (facilitynames[n].c_name &&
++ strcasecmp(facilitynames[n].c_name, syslogdelpoint) != 0) {
++ n++;
++ }
++ if (facilitynames[n].c_name) {
++ altlog_syslog_facility = facilitynames[n].c_val;
++ } else {
++ logfile(LOG_ERR,
++ MSG_CONF_ERR ": " MSG_ILLEGAL_FACILITY ": %s", syslogdelpoint);
++ }
++ }
++ altlog_syslog = 1;
++ }
++ else {
+ die(421, LOG_ERR,
+ MSG_CONF_ERR ": " MSG_SANITY_FILE_FAILURE,
+ delpoint);
+ }
+- if ((altlog_filename = strdup(delpoint)) == NULL) {
+- die_mem();
+- }
+ (void) free(optarg_copy);
+ break;
+ }
+diff -Nru a/src/ftpd_p.h b/src/ftpd_p.h
+--- a/src/ftpd_p.h 2011-09-07 05:02:03.000000000 +0000
++++ b/src/ftpd_p.h 2012-05-02 21:27:28.623047526 +0000
+@@ -207,6 +207,7 @@
+ };
+
+ # define ALTLOG_DELIMITER ':'
++# define ALTLOG_SYSLOG_DELIMITER ','
+ # define ALTLOG_DEFAULT ALTLOG_CLF
+ #endif
+
+diff -Nru a/src/globals.h b/src/globals.h
+--- a/src/globals.h 2011-10-30 22:50:45.000000000 +0000
++++ b/src/globals.h 2012-05-02 21:16:13.740071625 +0000
+@@ -134,6 +134,8 @@
+ #ifdef WITH_ALTLOG
+ GLOBAL0(const char *altlog_filename);
+ GLOBAL0(AltLogFormat altlog_format);
++GLOBAL(signed char altlog_syslog, 0);
++GLOBAL(int altlog_syslog_facility, DEFAULT_FACILITY);
+ GLOBAL(int altlog_fd, -1);
+ #endif
+