993209
From ee6af258e8cb1a7fada5e6d3e54429b89f12b158 Mon Sep 17 00:00:00 2001
993209
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
993209
Date: Fri, 15 Jun 2018 12:02:21 +0200
993209
Subject: [PATCH 1/3] Log die() calls to syslog
993209
993209
Pass messages given to die(), die2() and bug() to syslog. Currently this
993209
functionality requires waiting for a short amount of time (1 second is
993209
used) after logging the message and before exiting. This is a workaround
993209
for the following systemd bug:
993209
https://github.com/systemd/systemd/issues/2913
993209
993209
The need for this workaround is the main reason why I decided not to
993209
enable this functionality by default.
993209
993209
Resolves: rhbz#1318198
993209
Resolves: rhbz#1582672
993209
---
993209
 logging.c     | 13 +++++++++----
993209
 logging.h     |  2 ++
993209
 main.c        |  4 ++++
993209
 parseconf.c   |  1 +
993209
 tcpwrap.c     |  3 ---
993209
 tunables.c    |  2 ++
993209
 tunables.h    |  2 ++
993209
 utility.c     | 11 +++++++++++
993209
 vsftpd.conf.5 | 10 ++++++++++
993209
 9 files changed, 41 insertions(+), 7 deletions(-)
993209
993209
diff --git a/logging.c b/logging.c
993209
index c4461f7..9e86808 100644
993209
--- a/logging.c
993209
+++ b/logging.c
993209
@@ -30,10 +30,6 @@ static void vsf_log_do_log_to_file(int fd, struct mystr* p_str);
993209
 void
993209
 vsf_log_init(struct vsf_session* p_sess)
993209
 {
993209
-  if (tunable_syslog_enable || tunable_tcp_wrappers)
993209
-  {
993209
-    vsf_sysutil_openlog(0);
993209
-  }
993209
   if (!tunable_xferlog_enable && !tunable_dual_log_enable)
993209
   {
993209
     return;
993209
@@ -389,3 +385,12 @@ vsf_log_do_log_vsftpd_format(struct vsf_session* p_sess, struct mystr* p_str,
993209
   }
993209
 }
993209
 
993209
+void
993209
+vsf_log_die(const char* p_text)
993209
+{
993209
+  struct mystr log_str = INIT_MYSTR;
993209
+
993209
+  str_append_text(&log_str, "ERROR: ");
993209
+  str_append_text(&log_str, p_text);
993209
+  str_syslog(&log_str, 1);
993209
+}
993209
diff --git a/logging.h b/logging.h
993209
index 1ff57d1..75f06c1 100644
993209
--- a/logging.h
993209
+++ b/logging.h
993209
@@ -91,5 +91,7 @@ void vsf_log_line(struct vsf_session* p_sess, enum EVSFLogEntryType what,
993209
 void vsf_log_failed_line(struct vsf_session* p_sess, enum EVSFLogEntryType what,
993209
                   struct mystr* p_str);
993209
 
993209
+void vsf_log_die(const char* p_text);
993209
+
993209
 #endif /* VSF_LOGGING_H */
993209
 
993209
diff --git a/main.c b/main.c
993209
index f039081..1178d44 100644
993209
--- a/main.c
993209
+++ b/main.c
993209
@@ -120,6 +120,10 @@ main(int argc, const char* argv[])
993209
     }
993209
     vsf_sysutil_free(p_statbuf);
993209
   }
993209
+  if (tunable_log_die || tunable_syslog_enable || tunable_tcp_wrappers)
993209
+  {
993209
+    vsf_sysutil_openlog(0);
993209
+  }
993209
   /* Resolve pasv_address if required */
993209
   if (tunable_pasv_address && tunable_pasv_addr_resolve)
993209
   {
993209
diff --git a/parseconf.c b/parseconf.c
993209
index 47b54f1..aeb401a 100644
993209
--- a/parseconf.c
993209
+++ b/parseconf.c
993209
@@ -112,6 +112,7 @@ parseconf_bool_array[] =
993209
   { "seccomp_sandbox", &tunable_seccomp_sandbox },
993209
   { "allow_writeable_chroot", &tunable_allow_writeable_chroot },
993209
   { "better_stou", &tunable_better_stou },
993209
+  { "log_die", &tunable_log_die },
993209
   { 0, 0 }
993209
 };
993209
 
993209
diff --git a/tcpwrap.c b/tcpwrap.c
993209
index 5bf57d3..132b771 100644
993209
--- a/tcpwrap.c
993209
+++ b/tcpwrap.c
993209
@@ -27,15 +27,12 @@ int
993209
 vsf_tcp_wrapper_ok(int remote_fd)
993209
 {
993209
   struct request_info req;
993209
-  vsf_sysutil_openlog(0);
993209
   request_init(&req, RQ_DAEMON, "vsftpd", RQ_FILE, remote_fd, 0);
993209
   fromhost(&req;;
993209
   if (!hosts_access(&req))
993209
   {
993209
-    vsf_sysutil_closelog();
993209
     return 0;
993209
   }
993209
-  vsf_sysutil_closelog();
993209
   return 1;
993209
 }
993209
 
993209
diff --git a/tunables.c b/tunables.c
993209
index 5ec2bdc..63de8e6 100644
993209
--- a/tunables.c
993209
+++ b/tunables.c
993209
@@ -93,6 +93,7 @@ int tunable_http_enable;
993209
 int tunable_seccomp_sandbox;
993209
 int tunable_allow_writeable_chroot;
993209
 int tunable_better_stou;
993209
+int tunable_log_die;
993209
 
993209
 unsigned int tunable_accept_timeout;
993209
 unsigned int tunable_connect_timeout;
993209
@@ -241,6 +242,7 @@ tunables_load_defaults()
993209
   tunable_seccomp_sandbox = 0;
993209
   tunable_allow_writeable_chroot = 0;
993209
   tunable_better_stou = 0;
993209
+  tunable_log_die = 0;
993209
 
993209
   tunable_accept_timeout = 60;
993209
   tunable_connect_timeout = 60;
993209
diff --git a/tunables.h b/tunables.h
993209
index 85ea1a8..8a4b8b2 100644
993209
--- a/tunables.h
993209
+++ b/tunables.h
993209
@@ -96,6 +96,8 @@ extern int tunable_allow_writeable_chroot;    /* Allow misconfiguration */
993209
 extern int tunable_better_stou;               /* Use better file name generation
993209
                                                * algorithm for the STOU command
993209
 					       */
993209
+extern int tunable_log_die;                   /* Log calls to die(), die2()
993209
+                                               * and bug() */
993209
 
993209
 /* Integer/numeric defines */
993209
 extern unsigned int tunable_accept_timeout;
993209
diff --git a/utility.c b/utility.c
993209
index 5fd714d..75e5bdd 100644
993209
--- a/utility.c
993209
+++ b/utility.c
993209
@@ -9,6 +9,8 @@
993209
 #include "sysutil.h"
993209
 #include "str.h"
993209
 #include "defs.h"
993209
+#include "logging.h"
993209
+#include "tunables.h"
993209
 
993209
 #define DIE_DEBUG
993209
 
993209
@@ -41,11 +43,20 @@ void
993209
 bug(const char* p_text)
993209
 {
993209
   /* Rats. Try and write the reason to the network for diagnostics */
993209
+  if (tunable_log_die)
993209
+  {
993209
+    vsf_log_die(p_text);
993209
+  }
993209
   vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD);
993209
   (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "500 OOPS: ", 10);
993209
   (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text,
993209
                                 vsf_sysutil_strlen(p_text));
993209
   (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "\r\n", 2);
993209
+  if (tunable_log_die)
993209
+  {
993209
+    /* Workaround for https://github.com/systemd/systemd/issues/2913 */
993209
+    vsf_sysutil_sleep(1.0);
993209
+  }
993209
   vsf_sysutil_exit(2);
993209
 }
993209
 
993209
diff --git a/vsftpd.conf.5 b/vsftpd.conf.5
993209
index e9ae474..f246906 100644
993209
--- a/vsftpd.conf.5
993209
+++ b/vsftpd.conf.5
993209
@@ -358,6 +358,16 @@ wanting to e.g. append a file.
993209
 
993209
 Default: YES
993209
 .TP
993209
+.B log_die
993209
+Log an error to syslog when some error condition occurs and vsftpd decides
993209
+to quit. Internally, the error messages given to the functions die(), die2()
993209
+and bug() are passed to syslog. Currently this functionality requires waiting
993209
+for a short amount of time (1 second is used) after logging the message and
993209
+before exiting. This is a workaround for the following systemd bug:
993209
+https://github.com/systemd/systemd/issues/2913
993209
+
993209
+Default: NO
993209
+.TP
993209
 .B log_ftp_protocol
993209
 When enabled, all FTP requests and responses are logged, providing the option
993209
 xferlog_std_format is not enabled. Useful for debugging.
993209
-- 
993209
2.14.4
993209