and I thought I wasn't going to do any rsync coding for a while ...
authorAndrew Tridgell <tridge@samba.org>
Wed, 28 Oct 1998 03:28:30 +0000 (03:28 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 28 Oct 1998 03:28:30 +0000 (03:28 +0000)
Jason Andrade convinced me to add ftpd style logging of transfers,
enabled with a "transfer logging" option in rsyncd.conf

you can customise the format in log.c

loadparm.c
log.c
main.c
receiver.c
rsync.h
rsyncd.conf.yo
sender.c
socket.c

index aba7d30..aeb2980 100644 (file)
@@ -120,6 +120,7 @@ typedef struct
        BOOL read_only;
        BOOL list;
        BOOL use_chroot;
        BOOL read_only;
        BOOL list;
        BOOL use_chroot;
+       BOOL transfer_logging;
        char *uid;
        char *gid;
        char *hosts_allow;
        char *uid;
        char *gid;
        char *hosts_allow;
@@ -140,6 +141,7 @@ static service sDefault =
        True,    /* read only */
        True,    /* list */
        True,    /* use chroot */
        True,    /* read only */
        True,    /* list */
        True,    /* use chroot */
+       False,   /* transfer logging */
        "nobody",/* uid */
        "nobody",/* gid */
        NULL,    /* hosts allow */
        "nobody",/* uid */
        "nobody",/* gid */
        NULL,    /* hosts allow */
@@ -252,6 +254,7 @@ static struct parm_struct parm_table[] =
   {"secrets file",     P_STRING,  P_LOCAL,  &sDefault.secrets_file,NULL,   0},
   {"exclude",          P_STRING,  P_LOCAL,  &sDefault.exclude,     NULL,   0},
   {"exclude from",     P_STRING,  P_LOCAL,  &sDefault.exclude_from,NULL,   0},
   {"secrets file",     P_STRING,  P_LOCAL,  &sDefault.secrets_file,NULL,   0},
   {"exclude",          P_STRING,  P_LOCAL,  &sDefault.exclude,     NULL,   0},
   {"exclude from",     P_STRING,  P_LOCAL,  &sDefault.exclude_from,NULL,   0},
+  {"transfer logging", P_BOOL,    P_LOCAL,  &sDefault.transfer_logging,NULL,0},
   {NULL,               P_BOOL,    P_NONE,   NULL,                  NULL,   0}
 };
 
   {NULL,               P_BOOL,    P_NONE,   NULL,                  NULL,   0}
 };
 
@@ -314,6 +317,7 @@ FN_LOCAL_STRING(lp_path, path)
 FN_LOCAL_BOOL(lp_read_only, read_only)
 FN_LOCAL_BOOL(lp_list, list)
 FN_LOCAL_BOOL(lp_use_chroot, use_chroot)
 FN_LOCAL_BOOL(lp_read_only, read_only)
 FN_LOCAL_BOOL(lp_list, list)
 FN_LOCAL_BOOL(lp_use_chroot, use_chroot)
+FN_LOCAL_BOOL(lp_transfer_logging, transfer_logging)
 FN_LOCAL_STRING(lp_uid, uid)
 FN_LOCAL_STRING(lp_gid, gid)
 FN_LOCAL_STRING(lp_hosts_allow, hosts_allow)
 FN_LOCAL_STRING(lp_uid, uid)
 FN_LOCAL_STRING(lp_gid, gid)
 FN_LOCAL_STRING(lp_hosts_allow, hosts_allow)
diff --git a/log.c b/log.c
index 18db19a..a586793 100644 (file)
--- a/log.c
+++ b/log.c
@@ -119,6 +119,12 @@ void rprintf(int fd, const char *format, ...)
 
        buf[len] = 0;
 
 
        buf[len] = 0;
 
+       if (fd == FLOG) {
+               if (am_daemon) logit(LOG_INFO, buf);
+               depth--;
+               return;
+       }
+
        if (am_daemon) {
                int priority = LOG_INFO;
                if (fd == FERROR) priority = LOG_WARNING;
        if (am_daemon) {
                int priority = LOG_INFO;
                if (fd == FERROR) priority = LOG_WARNING;
@@ -178,3 +184,36 @@ void rflush(int fd)
        fflush(f);
 }
 
        fflush(f);
 }
 
+
+/* log the outgoing transfer of a file */
+void log_send(struct file_struct *file)
+{
+       extern int module_id;
+       if (lp_transfer_logging(module_id)) {
+               rprintf(FLOG,"Sending %s [%s] %.0f %s\n",
+                       client_name(0), client_addr(0),
+                       (double)file->length, f_name(file));
+       }
+}
+
+/* log the incoming transfer of a file */
+void log_recv(struct file_struct *file)
+{
+       extern int module_id;
+       if (lp_transfer_logging(module_id)) {
+               rprintf(FLOG,"Receiving %s [%s] %.0f %s\n",
+                       client_name(0), client_addr(0),
+                       (double)file->length, f_name(file));
+       }
+}
+
+/* log the incoming transfer of a file for interactive use, this
+   will be called at the end where the client was run */
+void log_transfer(struct file_struct *file, char *fname)
+{
+       extern int verbose;
+
+       if (!verbose) return;
+
+       rprintf(FINFO,"%s\n", fname);
+}
diff --git a/main.c b/main.c
index 94e358f..146f1e5 100644 (file)
--- a/main.c
+++ b/main.c
@@ -36,7 +36,7 @@ static void report(int f)
        extern int do_stats;
 
        if (am_daemon) {
        extern int do_stats;
 
        if (am_daemon) {
-               syslog(LOG_INFO,"wrote %.0f bytes  read %.0f bytes  total size %.0f\n",
+               rprintf(FLOG,"wrote %.0f bytes  read %.0f bytes  total size %.0f\n",
                       (double)stats.total_written,
                       (double)stats.total_read,
                       (double)stats.total_size);
                       (double)stats.total_written,
                       (double)stats.total_read,
                       (double)stats.total_size);
index 204933f..794ef6e 100644 (file)
@@ -292,7 +292,8 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
        struct file_struct *file;
        int phase=0;
        int recv_ok;
        struct file_struct *file;
        int phase=0;
        int recv_ok;
-       
+       extern int module_id;
+
        if (verbose > 2) {
                rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
        }
        if (verbose > 2) {
                rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
        }
@@ -333,8 +334,9 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
                        fname = local_name;
 
                if (dry_run) {
                        fname = local_name;
 
                if (dry_run) {
-                       if (!am_server && verbose)
-                               rprintf(FINFO,"%s\n",fname);
+                       if (!am_server) {
+                               log_transfer(file, fname);
+                       }
                        continue;
                }
 
                        continue;
                }
 
@@ -413,8 +415,11 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
       
                cleanup_set(fnametmp, fname, file, buf, fd1, fd2);
 
       
                cleanup_set(fnametmp, fname, file, buf, fd1, fd2);
 
-               if (!am_server && verbose)
-                       rprintf(FINFO,"%s\n",fname);
+               if (!am_server) {
+                       log_transfer(file, fname);
+               }
+
+               log_recv(file);
                
                /* recv file data */
                recv_ok = receive_data(f_in,buf,fd2,fname,file->length);
                
                /* recv file data */
                recv_ok = receive_data(f_in,buf,fd2,fname,file->length);
diff --git a/rsync.h b/rsync.h
index 982eb22..dc2988a 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -59,6 +59,7 @@
 #define MPLEX_BASE 7
 #define FERROR 1
 #define FINFO 2
 #define MPLEX_BASE 7
 #define FERROR 1
 #define FINFO 2
+#define FLOG 3
 
 #include "config.h"
 
 
 #include "config.h"
 
index 3725fd5..7df37c8 100644 (file)
@@ -107,6 +107,11 @@ ftp, kern, lpr, mail, news, security, syslog, user, uucp, local0,
 local1, local2, local3, local4, local5, local6 and local7. The default
 is daemon. 
 
 local1, local2, local3, local4, local5, local6 and local7. The default
 is daemon. 
 
+dit(bf(transfer file)) The "transfer logging" option enables per-file 
+logging of downloads and uploads in a format somewhat similar to that
+used by ftp daemons. If you want to customise the log formats look at
+log_send, log_recv and log_transfer in log.c
+
 dit(bf(socket options)) This option can provide endless fun for people
 who like to tune their systems to the utmost degree. You can set all
 sorts of socket options which may make transfers faster (or
 dit(bf(socket options)) This option can provide endless fun for people
 who like to tune their systems to the utmost degree. You can set all
 sorts of socket options which may make transfers faster (or
index 91fcc21..d2beb4d 100644 (file)
--- a/sender.c
+++ b/sender.c
@@ -137,13 +137,15 @@ void send_files(struct file_list *flist,int f_out,int f_in)
                        offset = strlen(file->basedir)+1;
                }
                strlcat(fname,f_name(file),MAXPATHLEN-strlen(fname));
                        offset = strlen(file->basedir)+1;
                }
                strlcat(fname,f_name(file),MAXPATHLEN-strlen(fname));
+               clean_fname(fname);
          
                if (verbose > 2) 
                        rprintf(FINFO,"send_files(%d,%s)\n",i,fname);
          
                if (dry_run) {  
          
                if (verbose > 2) 
                        rprintf(FINFO,"send_files(%d,%s)\n",i,fname);
          
                if (dry_run) {  
-                       if (!am_server && verbose)
-                               rprintf(FINFO,"%s\n",fname);
+                       if (!am_server) {
+                               log_transfer(file, fname+offset);
+                       }
                        write_int(f_out,i);
                        continue;
                }
                        write_int(f_out,i);
                        continue;
                }
@@ -182,6 +184,8 @@ void send_files(struct file_list *flist,int f_out,int f_in)
                if (verbose > 2)
                        rprintf(FINFO,"send_files mapped %s of size %d\n",
                                fname,(int)st.st_size);
                if (verbose > 2)
                        rprintf(FINFO,"send_files mapped %s of size %d\n",
                                fname,(int)st.st_size);
+
+               log_send(file);
          
                write_int(f_out,i);
          
          
                write_int(f_out,i);
          
@@ -192,8 +196,9 @@ void send_files(struct file_list *flist,int f_out,int f_in)
                if (verbose > 2)
                        rprintf(FINFO,"calling match_sums %s\n",fname);
          
                if (verbose > 2)
                        rprintf(FINFO,"calling match_sums %s\n",fname);
          
-               if (!am_server && verbose)
-                       rprintf(FINFO,"%s\n",fname+offset);
+               if (!am_server) {
+                       log_transfer(file, fname+offset);
+               }
          
                match_sums(f_out,s,buf,st.st_size);
          
          
                match_sums(f_out,s,buf,st.st_size);
          
index 6551df4..15d991b 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -320,13 +320,17 @@ char *client_addr(int fd)
        struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
        int     length = sizeof(sa);
        static char addr_buf[100];
        struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
        int     length = sizeof(sa);
        static char addr_buf[100];
+       static int initialised;
+
+       if (initialised) return addr_buf;
+
+       initialised = 1;
 
        if (getpeername(fd, &sa, &length)) {
                exit_cleanup(1);
        }
 
        if (getpeername(fd, &sa, &length)) {
                exit_cleanup(1);
        }
-
+       
        strlcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr), sizeof(addr_buf)-1);
        strlcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr), sizeof(addr_buf)-1);
-
        return addr_buf;
 }
 
        return addr_buf;
 }
 
@@ -343,6 +347,11 @@ char *client_name(int fd)
        struct hostent *hp;
        char **p;
        char *def = "UNKNOWN";
        struct hostent *hp;
        char **p;
        char *def = "UNKNOWN";
+       static int initialised;
+
+       if (initialised) return name_buf;
+
+       initialised = 1;
 
        strcpy(name_buf,def);
 
 
        strcpy(name_buf,def);