From 11a5a3c704fd75325450ddae3fb2cb01f19b7111 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 28 Oct 1998 03:28:30 +0000 Subject: [PATCH] and I thought I wasn't going to do any rsync coding for a while ... 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 | 4 ++++ log.c | 39 +++++++++++++++++++++++++++++++++++++++ main.c | 2 +- receiver.c | 15 ++++++++++----- rsync.h | 1 + rsyncd.conf.yo | 5 +++++ sender.c | 13 +++++++++---- socket.c | 13 +++++++++++-- 8 files changed, 80 insertions(+), 12 deletions(-) diff --git a/loadparm.c b/loadparm.c index aba7d30e..aeb29804 100644 --- a/loadparm.c +++ b/loadparm.c @@ -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 18db19a0..a5867932 100644 --- 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 94e358fb..146f1e53 100644 --- 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); diff --git a/receiver.c b/receiver.c index 204933ff..794ef6e5 100644 --- a/receiver.c +++ b/receiver.c @@ -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 982eb225..dc2988a3 100644 --- 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" diff --git a/rsyncd.conf.yo b/rsyncd.conf.yo index 3725fd5f..7df37c87 100644 --- a/rsyncd.conf.yo +++ b/rsyncd.conf.yo @@ -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 diff --git a/sender.c b/sender.c index 91fcc21f..d2beb4dc 100644 --- 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); diff --git a/socket.c b/socket.c index 6551df43..15d991b4 100644 --- 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); -- 2.34.1