Add "syslog tag" to rsync daemon config.
authorWayne Davison <wayned@samba.org>
Sat, 29 Apr 2017 18:07:39 +0000 (11:07 -0700)
committerWayne Davison <wayned@samba.org>
Sat, 29 Apr 2017 20:49:14 +0000 (13:49 -0700)
loadparm.c
log.c
rsyncd.conf.yo

index 6d75b4dd58264df657886eb1ba1d81d35a384f21..21703efe99e943344f415baea4786cb8dace9c2f 100644 (file)
@@ -129,6 +129,7 @@ typedef struct {
        char *prexfer_exec;
        char *refuse_options;
        char *secrets_file;
+       char *syslog_tag;
        char *temp_dir;
        char *uid;
 /* NOTE: update this macro if the last char* variable changes! */
@@ -205,6 +206,7 @@ static const all_vars Defaults = {
  /* prexfer_exec; */           NULL,
  /* refuse_options; */         NULL,
  /* secrets_file; */           NULL,
+ /* syslog_tag; */             "rsyncd",
  /* temp_dir; */               NULL,
  /* uid; */                    NULL,
 
@@ -357,6 +359,7 @@ static struct parm_struct parm_table[] =
  {"secrets file",      P_STRING, P_LOCAL, &Vars.l.secrets_file,        NULL,0},
  {"strict modes",      P_BOOL,   P_LOCAL, &Vars.l.strict_modes,        NULL,0},
  {"syslog facility",   P_ENUM,   P_LOCAL, &Vars.l.syslog_facility,     enum_facilities,0},
+ {"syslog tag",        P_STRING, P_LOCAL, &Vars.l.syslog_tag,          NULL,0},
  {"temp dir",          P_PATH,   P_LOCAL, &Vars.l.temp_dir,            NULL,0},
  {"timeout",           P_INTEGER,P_LOCAL, &Vars.l.timeout,             NULL,0},
  {"transfer logging",  P_BOOL,   P_LOCAL, &Vars.l.transfer_logging,    NULL,0},
@@ -474,6 +477,7 @@ FN_LOCAL_STRING(lp_postxfer_exec, postxfer_exec)
 FN_LOCAL_STRING(lp_prexfer_exec, prexfer_exec)
 FN_LOCAL_STRING(lp_refuse_options, refuse_options)
 FN_LOCAL_STRING(lp_secrets_file, secrets_file)
+FN_LOCAL_STRING(lp_syslog_tag, syslog_tag)
 FN_LOCAL_STRING(lp_temp_dir, temp_dir)
 FN_LOCAL_STRING(lp_uid, uid)
 
diff --git a/log.c b/log.c
index f7da1e5ecab8ac203a911badd53f6d4edb2a111d..b145ee1d893904835cd3c9276ec7c9c6fbaf13f3 100644 (file)
--- a/log.c
+++ b/log.c
@@ -134,21 +134,16 @@ static void logit(int priority, const char *buf)
 
 static void syslog_init()
 {
-       static int been_here = 0;
        int options = LOG_PID;
 
-       if (been_here)
-               return;
-       been_here = 1;
-
 #ifdef LOG_NDELAY
        options |= LOG_NDELAY;
 #endif
 
 #ifdef LOG_DAEMON
-       openlog("rsyncd", options, lp_syslog_facility(module_id));
+       openlog(lp_syslog_tag(module_id), options, lp_syslog_facility(module_id));
 #else
-       openlog("rsyncd", options);
+       openlog(lp_syslog_tag(module_id), options);
 #endif
 
 #ifndef LOG_NDELAY
@@ -168,14 +163,16 @@ static void logfile_open(void)
                rsyserr(FERROR, fopen_errno,
                        "failed to open log-file %s", logfile_name);
                rprintf(FINFO, "Ignoring \"log file\" setting.\n");
+               logfile_name = "";
        }
 }
 
 void log_init(int restart)
 {
        if (log_initialised) {
-               if (!restart)
+               if (!restart) /* Note: a restart only happens with am_daemon */
                        return;
+               assert(logfile_name); /* all am_daemon procs got at least an empty string */
                if (strcmp(logfile_name, lp_log_file(module_id)) != 0) {
                        if (logfile_fp) {
                                fclose(logfile_fp);
@@ -185,7 +182,8 @@ void log_init(int restart)
                        logfile_name = NULL;
                } else if (*logfile_name)
                        return; /* unchanged, non-empty "log file" names */
-               else if (lp_syslog_facility(-1) != lp_syslog_facility(module_id))
+               else if (lp_syslog_facility(-1) != lp_syslog_facility(module_id)
+                     || strcmp(lp_syslog_tag(-1), lp_syslog_tag(module_id)) != 0)
                        closelog();
                else
                        return; /* unchanged syslog settings */
@@ -207,6 +205,7 @@ void log_init(int restart)
                syslog_init();
 }
 
+/* Note that this close & reopen idiom intentionally ignores syslog logging. */
 void logfile_close(void)
 {
        if (logfile_fp) {
index 64156ae3bba64f8181b187346c79498ac42b0630..b6fc2b58f96f285e6cd0618fb25ebc378a1f1963 100644 (file)
@@ -316,6 +316,17 @@ is daemon.  This setting has no effect if the "log file" setting is a
 non-empty string (either set in the per-modules settings, or inherited
 from the global settings).
 
+dit(bf(syslog tag)) This parameter allows you to specify the syslog
+tag to use when logging messages from the rsync daemon. The default is
+"rsyncd".  This setting has no effect if the "log file" setting is a
+non-empty string (either set in the per-modules settings, or inherited
+from the global settings).
+
+For example, if you wanted each authenticated user's name to be
+included in the syslog tag, you could do something like this:
+
+verb(    syslog tag = rsyncd.%RSYNC_USER_NAME%)
+
 dit(bf(max verbosity)) This parameter allows you to control
 the maximum amount of verbose information that you'll allow the daemon to
 generate (since the information goes into the log file). The default is 1,