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 aba7d30ec08195723a8aca414b96781f91cd5940..aeb2980403803c3b80b57f2da6732a28113c5898 100644 (file)
@@ -120,6 +120,7 @@ typedef struct
        BOOL read_only;
        BOOL list;
        BOOL use_chroot;
+       BOOL transfer_logging;
        char *uid;
        char *gid;
        char *hosts_allow;
@@ -140,6 +141,7 @@ static service sDefault =
        True,    /* read only */
        True,    /* list */
        True,    /* use chroot */
+       False,   /* transfer logging */
        "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},
+  {"transfer logging", P_BOOL,    P_LOCAL,  &sDefault.transfer_logging,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_transfer_logging, transfer_logging)
 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 18db19a0539a44bac293c5d4f3b66a134b0831ce..a586793228fc896c18797ccb950836be3f973b36 100644 (file)
--- a/log.c
+++ b/log.c
@@ -119,6 +119,12 @@ void rprintf(int fd, const char *format, ...)
 
        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;
@@ -178,3 +184,36 @@ void rflush(int fd)
        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 94e358fb589b78d594820c8c82f086333ad59f69..146f1e53e39f6e27febf33396d82fc2731c0a3cf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -36,7 +36,7 @@ static void report(int f)
        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);
index 204933ff21d80dbac37288b721755e0d0b57589a..794ef6e5867429f71a40c5da0e24a7453d483d10 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;
-       
+       extern int module_id;
+
        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) {
-                       if (!am_server && verbose)
-                               rprintf(FINFO,"%s\n",fname);
+                       if (!am_server) {
+                               log_transfer(file, fname);
+                       }
                        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);
 
-               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);
diff --git a/rsync.h b/rsync.h
index 982eb225ae588fe7cfc66aa35f71b388882f93eb..dc2988a3a88524e7d7c26b9816d7f80d516d879e 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -59,6 +59,7 @@
 #define MPLEX_BASE 7
 #define FERROR 1
 #define FINFO 2
+#define FLOG 3
 
 #include "config.h"
 
index 3725fd5f87e0393a329b7a3ca61edf453dbe9974..7df37c878358b0b49253af09eab12ce19b529d36 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. 
 
+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
index 91fcc21f8cf58ccd496edfae24be0eb0caf81f9d..d2beb4dc6c6e6280f0ff9421290d27e98c2f86f4 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));
+               clean_fname(fname);
          
                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;
                }
@@ -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);
+
+               log_send(file);
          
                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 (!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);
          
index 6551df434e7dee208320b7a3ad9434d8401b2c37..15d991b4d4a4a4e66bb016e94a789d3998a62b18 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];
+       static int initialised;
+
+       if (initialised) return addr_buf;
+
+       initialised = 1;
 
        if (getpeername(fd, &sa, &length)) {
                exit_cleanup(1);
        }
-
+       
        strlcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr), sizeof(addr_buf)-1);
-
        return addr_buf;
 }
 
@@ -343,6 +347,11 @@ char *client_name(int fd)
        struct hostent *hp;
        char **p;
        char *def = "UNKNOWN";
+       static int initialised;
+
+       if (initialised) return name_buf;
+
+       initialised = 1;
 
        strcpy(name_buf,def);