When using daemon mode over a remote shell program and not running as root,
authorDavid Dykstra <dwd@samba.org>
Fri, 30 Aug 2002 23:27:26 +0000 (23:27 +0000)
committerDavid Dykstra <dwd@samba.org>
Fri, 30 Aug 2002 23:27:26 +0000 (23:27 +0000)
default the config file to just "rsyncd.conf" in the current directory
instead of /etc/rsyncd.conf.  Also, fix problems with logging messages when
running daemon mode over a remote shell program: it was pretty much doing
the opposite of what it should have, sending early error messages to the
log and later messages to the client.  Switched it around so the very early
error messages go to the client and the later ones go to the log.

clientserver.c
loadparm.c
log.c
options.c
params.c
rsync.h
rsync.yo
rsyncd.conf.yo

index 3f1f583954b79ebc43f0ca243d64bcf0a7c91452..d158a2ff18be6fc19914d12430cabdca11c94e49 100644 (file)
@@ -502,6 +502,8 @@ int start_daemon(int f_in, int f_out)
                exit_cleanup(RERR_SYNTAX);
        }
 
+       log_init();
+
        if (!am_server) {
                set_socket_options(f_in, "SO_KEEPALIVE");
                set_socket_options(f_in, lp_socket_options());
index d559b1175f45b6650f35b91807a656482e22e72d..20326621c66a319e3dfaba70b7c73931c09d1b4a 100644 (file)
@@ -748,6 +748,9 @@ False on failure.
 ***************************************************************************/
 BOOL lp_load(char *pszFname, int globals_only)
 {
+       extern int am_server;
+       extern int am_daemon;
+       extern int am_root;
        pstring n2;
        BOOL bRetval;
  
@@ -757,7 +760,12 @@ BOOL lp_load(char *pszFname, int globals_only)
   
        init_globals();
 
-       pstrcpy(n2,pszFname);
+       if (pszFname)
+           pstrcpy(n2,pszFname);
+       else if (am_server && am_daemon && !am_root)
+           pstrcpy(n2,RSYNCD_USERCONF);
+       else
+           pstrcpy(n2,RSYNCD_SYSCONF);
 
        /* We get sections first, so have to start 'behind' to make up */
        iServiceIndex = -1;
diff --git a/log.c b/log.c
index ab8644ed0b2130346c75502ad71fffcf0359b3de..ade21ebd702b947f252b25f7e9fee05f8e5f013d 100644 (file)
--- a/log.c
+++ b/log.c
@@ -27,6 +27,7 @@
   */
 #include "rsync.h"
 
+static int log_initialised;
 static char *logfname;
 static FILE *logfile;
 static int log_error_fd = -1;
@@ -146,12 +147,11 @@ static void logit(int priority, char *buf)
 
 void log_init(void)
 {
-       static int initialised;
        int options = LOG_PID;
        time_t t;
 
-       if (initialised) return;
-       initialised = 1;
+       if (log_initialised) return;
+       log_initialised = 1;
 
        /* this looks pointless, but it is needed in order for the
           C library on some systems to fetch the timezone info
@@ -238,16 +238,20 @@ void rwrite(enum logcode code, char *buf, int len)
                return;
        }
 
-       /* If that fails, try to pass it to the other end.
-        *
-        * io_multiplex_write can fail if we do not have a multiplexed
-        * connection at the moment, in which case we fall through and
-        * log locally instead. */
-       if (am_server && io_multiplex_write(code, buf, len)) {
+       /* next, if we are a server but not in daemon mode, and multiplexing
+        *  is enabled, pass it to the other side.  */
+       if (am_server && !am_daemon && io_multiplex_write(code, buf, len)) {
                return;
        }
 
-       if (am_daemon) {
+       /* otherwise, if in daemon mode and either we are not a server
+        *  (that is, we are not running --daemon over a remote shell) or
+        *  the log has already been initialised, log the message on this
+        *  side because we don't want the client to see most errors for
+        *  security reasons.  We do want early messages when running daemon
+        *  mode over a remote shell to go to the remote side; those will
+        *  fall through to the next case. */
+       if (am_daemon && (!am_server || log_initialised)) {
                static int depth;
                int priority = LOG_INFO;
                if (code == FERROR) priority = LOG_WARNING;
index 06b442c805dce76ce5050188a94b53553990f6d0..310e8a08ab641caedd7ac3e66fc0bc5221b1c3a7 100644 (file)
--- a/options.c
+++ b/options.c
@@ -108,7 +108,7 @@ int suffix_specified = 0;
 char *backup_suffix = BACKUP_SUFFIX;
 char *tmpdir = NULL;
 char *compare_dest = NULL;
-char *config_file = RSYNCD_CONF;
+char *config_file = NULL;
 char *shell_cmd = NULL;
 char *log_format = NULL;
 char *password_file = NULL;
index 323d20baac41c9537aabf91a93028428dba909da..816381187d724e3c6df2d370684ad976769ba701 100644 (file)
--- a/params.c
+++ b/params.c
@@ -491,8 +491,8 @@ static FILE *OpenConfFile( char *FileName )
   OpenedFile = fopen( FileName, "r" );
   if( NULL == OpenedFile )
     {
-    rprintf(FERROR,"%s Unable to open configuration file \"%s\":\n\t%s\n",
-           func, FileName, strerror(errno));
+    rprintf(FERROR,"rsync: unable to open configuration file \"%s\": %s\n",
+           FileName, strerror(errno));
     }
 
   return( OpenedFile );
diff --git a/rsync.h b/rsync.h
index 4ea7e0ba39b4eda5d764f13f24bc90f0e1d1db0a..9bb30d176ebdf14cf3d6bba140beab867fcc7e6c 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -26,7 +26,8 @@
 #define RSYNC_RSH_ENV "RSYNC_RSH"
 
 #define RSYNC_NAME "rsync"
-#define RSYNCD_CONF "/etc/rsyncd.conf"
+#define RSYNCD_SYSCONF "/etc/rsyncd.conf"
+#define RSYNCD_USERCONF "rsyncd.conf"
 
 #define DEFAULT_LOCK_FILE "/var/run/rsyncd.lock"
 #define URL_PREFIX "rsync://"
index e0d131b2754161a4b4367e129df748832d078ff1..06c9f87dade2f03c9d295e8ac7309596d3fa26cf 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -212,9 +212,12 @@ used to check against the rsyncd.conf on the remote host.
 
 manpagesection(RUNNING AN RSYNC SERVER)
 
-An rsync server is configured using a config file which by default is
-called /etc/rsyncd.conf. Please see the rsyncd.conf(5) man page for more
-information. 
+An rsync server is configured using a config file.  Please see the 
+rsyncd.conf(5) man page for more information.  By default the configuration
+file is called /etc/rsyncd.conf, unless rsync is running over a remote
+shell program and is not running as root; in that case, the default name
+is rsyncd.conf in the current directory on the remote computer 
+(typically $HOME).
 
 manpagesection(RUNNING AN RSYNC SERVER OVER A REMOTE SHELL PROGRAM)
 
@@ -234,7 +237,7 @@ quote(rsync --server --daemon .)
 
 NOTE: rsync's argument parsing expects the trailing ".", so make sure
 that it's there.  If you want to use a rsyncd.conf(5)-style
-configuration file other than /etc/rsyncd.conf, you can added a
+configuration file other than the default, you can added a
 --config-file option to the em(command):
 
 quote(rsync --server --daemon --config-file=em(file) .)
@@ -727,7 +730,7 @@ bf(rsync://host/module/) syntax.
 If standard input is a socket then rsync will assume that it is being
 run via inetd, otherwise it will detach from the current terminal and
 become a background daemon.  The daemon will read the config file
-(/etc/rsyncd.conf) on each connect made by a client and respond to
+(rsyncd.conf) on each connect made by a client and respond to
 requests accordingly.  See the rsyncd.conf(5) man page for more
 details.
 
@@ -747,8 +750,10 @@ address (or hostname) to bind to. This makes virtual hosting possible
 in conjunction with the --config option.
 
 dit(bf(--config=FILE)) This specifies an alternate config file than
-the default /etc/rsyncd.conf. This is only relevant when --daemon is
-specified. 
+the default.  This is only relevant when --daemon is specified. 
+The default is /etc/rsyncd.conf unless the daemon is running over
+a remote shell program and the remote user is not root; in that case
+the default is rsyncd.conf in the current directory (typically $HOME).
 
 dit(bf(--port=PORT)) This specifies an alternate TCP port number to use
 rather than the default port 873.
@@ -1093,7 +1098,7 @@ enddit()
 
 manpagefiles()
 
-/etc/rsyncd.conf
+/etc/rsyncd.conf or rsyncd.conf
 
 manpageseealso()
 
index bfccfe7b2154a5b5acea73cc3d763d02e2360240..697534a3ad0bd7661dae10b91a78bf50ebe4f8c4 100644 (file)
@@ -68,7 +68,7 @@ your system.  You will then need to send inetd a HUP signal to tell it to
 reread its config file.
 
 Note that you should not send the rsync server a HUP signal to force
-it to reread the tt(/etc/rsyncd.conf). The file is re-read on each client
+it to reread the tt(rsyncd.conf) file. The file is re-read on each client
 connection. 
 
 manpagesection(GLOBAL OPTIONS)
@@ -127,7 +127,7 @@ of available modules. The default is no comment.
 
 dit(bf(path)) The "path" option specifies the directory in the servers
 filesystem to make available in this module.  You must specify this option
-for each module in tt(/etc/rsyncd.conf).
+for each module in tt(rsyncd.conf).
 
 dit(bf(use chroot)) If "use chroot" is true, the rsync server will chroot
 to the "path" before starting the file transfer with the client.  This has
@@ -438,7 +438,7 @@ susan:herpass
 
 manpagefiles()
 
-/etc/rsyncd.conf
+/etc/rsyncd.conf or rsyncd.conf
 
 manpageseealso()