Fixed some patch fuzz.
[rsync/rsync-patches.git] / ODBC-dblog.diff
index 408894c..574b5a4 100644 (file)
@@ -87,22 +87,32 @@ This patch adds the following options:
     after the session row is inserted (as is done when the session ID is
     automatically generates unique IDs).  Defaults to True.
 
     after the session row is inserted (as is done when the session ID is
     automatically generates unique IDs).  Defaults to True.
 
-
---- orig/Makefile.in   2004-07-04 08:59:17
-+++ Makefile.in        2004-07-03 20:22:18
-@@ -32,7 +32,7 @@ ZLIBOBJ=zlib/deflate.o zlib/infblock.o z
-       zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/trees.o \
-       zlib/zutil.o zlib/adler32.o
+--- orig/Makefile.in   2005-07-07 23:11:07
++++ Makefile.in        2005-05-23 23:31:30
+@@ -31,7 +31,7 @@ LIBOBJ=lib/wildmatch.o lib/compat.o lib/
+ ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
+       zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
  OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
 -      main.o checksum.o match.o syscall.o log.o backup.o
 +      main.o checksum.o match.o syscall.o log.o backup.o @EXTRA_OBJECT@
  OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
        fileio.o batch.o clientname.o
  OBJS3=progress.o pipe.o
  OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
 -      main.o checksum.o match.o syscall.o log.o backup.o
 +      main.o checksum.o match.o syscall.o log.o backup.o @EXTRA_OBJECT@
  OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
        fileio.o batch.o clientname.o
  OBJS3=progress.o pipe.o
---- orig/cleanup.c     2004-07-02 18:11:26
-+++ cleanup.c  2004-07-03 20:22:18
-@@ -141,8 +141,12 @@ void _exit_cleanup(int code, const char 
-                       code = RERR_VANISHED;
+--- orig/cleanup.c     2005-03-05 18:58:38
++++ cleanup.c  2005-05-23 23:28:28
+@@ -39,6 +39,10 @@ void close_all(void)
+       int ret;
+       STRUCT_STAT st;
++#ifdef HAVE_LIBODBC
++      db_log_close();
++#endif
++
+       max_fd = sysconf(_SC_OPEN_MAX) - 1;
+       for (fd = max_fd; fd >= 0; fd--) {
+               if ((ret = do_fstat(fd, &st)) == 0) {
+@@ -144,8 +148,12 @@ void _exit_cleanup(int code, const char 
+                       code = RERR_PARTIAL;
        }
  
 -      if (code)
        }
  
 -      if (code)
@@ -115,19 +125,19 @@ This patch adds the following options:
  
        if (verbose > 2) {
                rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): about to call exit(%d)\n",
  
        if (verbose > 2) {
                rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): about to call exit(%d)\n",
---- orig/clientserver.c        2004-07-15 02:21:10
-+++ clientserver.c     2004-07-03 20:22:18
-@@ -316,6 +316,9 @@ static int rsync_module(int f_in, int f_
-       exclude_path_prefix = NULL;
+--- orig/clientserver.c        2005-08-17 06:45:07
++++ clientserver.c     2005-05-23 23:29:31
+@@ -348,6 +348,9 @@ static int rsync_module(int f_in, int f_
+                  XFLG_ANCHORED2ABS | XFLG_OLD_PREFIXES);
  
        log_init();
 +#ifdef HAVE_LIBODBC
 +      db_log_open();
 +#endif
  
  
        log_init();
 +#ifdef HAVE_LIBODBC
 +      db_log_open();
 +#endif
  
-       if (use_chroot) {
-               /*
-@@ -434,6 +437,9 @@ static int rsync_module(int f_in, int f_
+ #ifdef HAVE_PUTENV
+       s = lp_prexfer_exec(i);
+@@ -524,6 +527,9 @@ static int rsync_module(int f_in, int f_
                        rprintf(FLOG, "rsync %s %s from %s@%s (%s)\n",
                                am_sender ? "on" : "to",
                                request, auth_user, host, addr);
                        rprintf(FLOG, "rsync %s %s from %s@%s (%s)\n",
                                am_sender ? "on" : "to",
                                request, auth_user, host, addr);
@@ -137,9 +147,9 @@ This patch adds the following options:
                } else {
                        rprintf(FLOG, "rsync %s %s from %s (%s)\n",
                                am_sender ? "on" : "to",
                } else {
                        rprintf(FLOG, "rsync %s %s from %s (%s)\n",
                                am_sender ? "on" : "to",
---- orig/configure.in  2004-04-30 18:04:07
-+++ configure.in       2004-07-03 20:22:18
-@@ -94,6 +94,8 @@ AC_ARG_WITH(rsync-path,
+--- orig/configure.in  2005-07-29 02:47:19
++++ configure.in       2005-05-23 23:32:21
+@@ -92,6 +92,8 @@ AC_ARG_WITH(rsync-path,
        [  --with-rsync-path=PATH  set default --rsync-path to PATH (default: rsync)],
        [ RSYNC_PATH="$with_rsync_path" ],
        [ RSYNC_PATH="rsync" ])
        [  --with-rsync-path=PATH  set default --rsync-path to PATH (default: rsync)],
        [ RSYNC_PATH="$with_rsync_path" ],
        [ RSYNC_PATH="rsync" ])
@@ -148,7 +158,7 @@ This patch adds the following options:
  
  AC_DEFINE_UNQUOTED(RSYNC_PATH, "$RSYNC_PATH", [location of rsync on remote machine])
  
  
  AC_DEFINE_UNQUOTED(RSYNC_PATH, "$RSYNC_PATH", [location of rsync on remote machine])
  
-@@ -465,6 +467,14 @@ then
+@@ -547,6 +549,14 @@ then
      AC_CHECK_LIB(popt, poptGetContext, , [with_included_popt=yes])
  fi
  
      AC_CHECK_LIB(popt, poptGetContext, , [with_included_popt=yes])
  fi
  
@@ -163,8 +173,8 @@ This patch adds the following options:
  AC_MSG_CHECKING([whether to use included libpopt])
  if test x"$with_included_popt" = x"yes"
  then
  AC_MSG_CHECKING([whether to use included libpopt])
  if test x"$with_included_popt" = x"yes"
  then
---- orig/dblog-tables-mysql.sql        2004-07-02 21:35:58
-+++ dblog-tables-mysql.sql     2004-07-02 21:35:58
+--- orig/dblog-tables-mysql.sql        2005-05-23 23:28:40
++++ dblog-tables-mysql.sql     2005-05-23 23:28:40
 @@ -0,0 +1,43 @@
 +drop table transfer;
 +drop table exit;
 @@ -0,0 +1,43 @@
 +drop table transfer;
 +drop table exit;
@@ -185,7 +195,6 @@ This patch adds the following options:
 +      id                      int auto_increment NOT NULL,
 +      session_id              int NOT NULL,
 +      date                    timestamp NOT NULL,
 +      id                      int auto_increment NOT NULL,
 +      session_id              int NOT NULL,
 +      date                    timestamp NOT NULL,
-+      file_path               varchar(255) NOT NULL,
 +      file_name               varchar(255) NOT NULL,
 +      file_size               bigint NOT NULL,
 +      bytes_transferred       bigint NOT NULL,
 +      file_name               varchar(255) NOT NULL,
 +      file_size               bigint NOT NULL,
 +      bytes_transferred       bigint NOT NULL,
@@ -206,11 +215,12 @@ This patch adds the following options:
 +      error_code              int NOT NULL,
 +      error_file              varchar(64) NOT NULL,
 +      error_line              int NOT NULL,
 +      error_code              int NOT NULL,
 +      error_file              varchar(64) NOT NULL,
 +      error_line              int NOT NULL,
++      process_id              int NOT NULL,
 +      Primary Key (id),
 +      foreign key (session_id) references session (id)
 +);
 +      Primary Key (id),
 +      foreign key (session_id) references session (id)
 +);
---- orig/dblog-tables-postgresql.sql   2004-07-02 21:35:58
-+++ dblog-tables-postgresql.sql        2004-07-02 21:35:58
+--- orig/dblog-tables-postgresql.sql   2005-05-23 23:28:48
++++ dblog-tables-postgresql.sql        2005-05-23 23:28:48
 @@ -0,0 +1,45 @@
 +drop table transfer;
 +drop table exit;
 @@ -0,0 +1,45 @@
 +drop table transfer;
 +drop table exit;
@@ -233,7 +243,6 @@ This patch adds the following options:
 +      "id"                    serial NOT NULL,
 +      "session_id"            int NOT NULL,
 +      "date"                  timestamp NOT NULL default now(),
 +      "id"                    serial NOT NULL,
 +      "session_id"            int NOT NULL,
 +      "date"                  timestamp NOT NULL default now(),
-+      "file_path"             varchar(512) NOT NULL,
 +      "file_name"             varchar(512) NOT NULL,
 +      "file_size"             bigint NOT NULL,
 +      "bytes_transferred"     bigint NOT NULL,
 +      "file_name"             varchar(512) NOT NULL,
 +      "file_size"             bigint NOT NULL,
 +      "bytes_transferred"     bigint NOT NULL,
@@ -254,12 +263,13 @@ This patch adds the following options:
 +      "error_code"            int NOT NULL,
 +      "error_file"            varchar(64) NOT NULL,
 +      "error_line"            int NOT NULL,
 +      "error_code"            int NOT NULL,
 +      "error_file"            varchar(64) NOT NULL,
 +      "error_line"            int NOT NULL,
++      "process_id"            int NOT NULL,
 +      Primary Key (id),
 +      foreign key (session_id) references session (id)
 +);
 +      Primary Key (id),
 +      foreign key (session_id) references session (id)
 +);
---- orig/dblog.c       2004-07-02 21:35:58
-+++ dblog.c    2004-07-02 21:35:58
-@@ -0,0 +1,352 @@
+--- orig/dblog.c       2005-05-24 07:12:54
++++ dblog.c    2005-05-24 07:12:54
+@@ -0,0 +1,360 @@
 +/*
 + *  ODBC Database logging functions
 + *
 +/*
 + *  ODBC Database logging functions
 + *
@@ -545,17 +555,25 @@ This patch adds the following options:
 +void db_log_transfer(struct file_struct *file,struct stats *initial_stats,char *operation)
 +{
 +      extern struct stats stats;
 +void db_log_transfer(struct file_struct *file,struct stats *initial_stats,char *operation)
 +{
 +      extern struct stats stats;
-+      char strSqlStatement[1024];
-+      char strFilePath[255];
-+      char strFileName[255];
++      char strSqlStatement[2048];
++      char strFileName[MAXPATHLEN];
++      char *strFileNamePtr;
 +      char strFileSize[255];
 +      int64 intBytesTransferred;
 +      int64 intCheckSumBytes;
 +
 +      if (lp_database_logging(module_id)) {
 +              if (db_handle != NULL) {
 +      char strFileSize[255];
 +      int64 intBytesTransferred;
 +      int64 intCheckSumBytes;
 +
 +      if (lp_database_logging(module_id)) {
 +              if (db_handle != NULL) {
-+                      snprintf(strFileName,sizeof(strFileName), "%s",f_name(file));
-+                      snprintf(strFilePath, sizeof(strFilePath), "%s", file->basedir?file->basedir:"");
++                      strFileNamePtr = safe_fname(f_name(file));
++                      if (am_sender && file->dir.root) {
++                              pathjoin(strFileName, sizeof strFileName,
++                                       file->dir.root, strFileNamePtr);
++                              strFileNamePtr = strFileName;
++                      }
++                      clean_fname(strFileNamePtr, 0);
++                      if (*strFileNamePtr == '/')
++                              strFileNamePtr++;
++
 +                      snprintf(strFileSize,sizeof(strFileSize),"%.0f", (double)file->length);
 +                      if (am_sender) {
 +                              intBytesTransferred = stats.total_written - initial_stats->total_written;
 +                      snprintf(strFileSize,sizeof(strFileSize),"%.0f", (double)file->length);
 +                      if (am_sender) {
 +                              intBytesTransferred = stats.total_written - initial_stats->total_written;
@@ -569,7 +587,7 @@ This patch adds the following options:
 +                              intCheckSumBytes = stats.total_read - initial_stats->total_read;
 +                      }
 +
 +                              intCheckSumBytes = stats.total_read - initial_stats->total_read;
 +                      }
 +
-+                      snprintf(strSqlStatement,sizeof(strSqlStatement),"INSERT INTO %s (session_id,date,file_path, file_name, file_size, bytes_transferred, checksum_bytes_transferred, operation) VALUES ('%ld','%s','%s','%s','%s','%Ld','%Ld','%s');",lp_transfer_table_name(module_id),session_id,timestring(time(NULL)),sanitizeSql(strFilePath),sanitizeSql(strFileName),strFileSize,intBytesTransferred,intCheckSumBytes,operation);
++                      snprintf(strSqlStatement,sizeof(strSqlStatement),"INSERT INTO %s (session_id,date, file_name, file_size, bytes_transferred, checksum_bytes_transferred, operation) VALUES ('%ld','%s','%s','%s','%Ld','%Ld','%s');",lp_transfer_table_name(module_id),session_id,timestring(time(NULL)),sanitizeSql(strFileNamePtr),strFileSize,intBytesTransferred,intCheckSumBytes,operation);
 +                      result = SQLExecDirect(sql_statement_handle,strSqlStatement,SQL_NTS);
 +                      if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
 +                              SQLGetDiagRec(SQL_HANDLE_DBC, db_handle,1, sql_status,&V_OD_err,V_OD_msg,100,&V_OD_mlen);
 +                      result = SQLExecDirect(sql_statement_handle,strSqlStatement,SQL_NTS);
 +                      if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
 +                              SQLGetDiagRec(SQL_HANDLE_DBC, db_handle,1, sql_status,&V_OD_err,V_OD_msg,100,&V_OD_mlen);
@@ -599,7 +617,7 @@ This patch adds the following options:
 +                      } else {
 +                              error_text = "";
 +                      }
 +                      } else {
 +                              error_text = "";
 +                      }
-+                      snprintf(strSqlStatement,sizeof(strSqlStatement),"INSERT INTO %s (session_id, date, total_bytes_written,total_bytes_read,total_size,error_text,error_code,error_file,error_line) VALUES ('%ld','%s','%Ld','%Ld','%Ld','%s','%d','%s','%d');",lp_exit_table_name(module_id),session_id,timestring(time(NULL)),stats.total_written,stats.total_read,stats.total_size,error_text,code,file,line);
++                      snprintf(strSqlStatement,sizeof(strSqlStatement),"INSERT INTO %s (session_id, date, total_bytes_written,total_bytes_read,total_size,error_text,error_code,error_file,error_line,process_id) VALUES ('%ld','%s','%Ld','%Ld','%Ld','%s','%d','%s','%d','%d');",lp_exit_table_name(module_id),session_id,timestring(time(NULL)),stats.total_written,stats.total_read,stats.total_size,error_text,code,file,line,getpid());
 +
 +                      result = SQLExecDirect(sql_statement_handle,strSqlStatement,SQL_NTS);
 +
 +
 +                      result = SQLExecDirect(sql_statement_handle,strSqlStatement,SQL_NTS);
 +
@@ -612,9 +630,9 @@ This patch adds the following options:
 +              rprintf(FERROR,"Error at db_log_exit: Not connected to database!\n");
 +      }
 +}
 +              rprintf(FERROR,"Error at db_log_exit: Not connected to database!\n");
 +      }
 +}
---- orig/loadparm.c    2004-05-21 08:43:10
-+++ loadparm.c 2004-07-03 20:22:18
-@@ -123,6 +123,17 @@ typedef struct
+--- orig/loadparm.c    2005-07-28 17:25:13
++++ loadparm.c 2005-05-23 23:29:42
+@@ -124,6 +124,17 @@ typedef struct
        BOOL list;
        BOOL use_chroot;
        BOOL transfer_logging;
        BOOL list;
        BOOL use_chroot;
        BOOL transfer_logging;
@@ -632,7 +650,7 @@ This patch adds the following options:
        BOOL ignore_errors;
        char *uid;
        char *gid;
        BOOL ignore_errors;
        char *uid;
        char *gid;
-@@ -156,6 +167,17 @@ static service sDefault =
+@@ -161,6 +172,17 @@ static service sDefault =
        True,    /* list */
        True,    /* use chroot */
        False,   /* transfer logging */
        True,    /* list */
        True,    /* use chroot */
        False,   /* transfer logging */
@@ -648,9 +666,9 @@ This patch adds the following options:
 +      NULL,    /* custom unique id select*/
 +      True,    /* get custom id before insert */
        False,   /* ignore errors */
 +      NULL,    /* custom unique id select*/
 +      True,    /* get custom id before insert */
        False,   /* ignore errors */
-       "nobody",/* uid */
-@@ -295,6 +317,17 @@ static struct parm_struct parm_table[] =
+       NOBODY_USER,/* uid */
+       NOBODY_GROUP,/* gid */
+@@ -298,6 +320,17 @@ static struct parm_struct parm_table[] =
    {"include",          P_STRING,  P_LOCAL,  &sDefault.include,     NULL,   0},
    {"include from",     P_STRING,  P_LOCAL,  &sDefault.include_from,NULL,   0},
    {"transfer logging", P_BOOL,    P_LOCAL,  &sDefault.transfer_logging,NULL,0},
    {"include",          P_STRING,  P_LOCAL,  &sDefault.include,     NULL,   0},
    {"include from",     P_STRING,  P_LOCAL,  &sDefault.include_from,NULL,   0},
    {"transfer logging", P_BOOL,    P_LOCAL,  &sDefault.transfer_logging,NULL,0},
@@ -668,7 +686,7 @@ This patch adds the following options:
    {"ignore errors",    P_BOOL,    P_LOCAL,  &sDefault.ignore_errors,NULL,0},
    {"log format",       P_STRING,  P_LOCAL,  &sDefault.log_format,  NULL,   0},
    {"refuse options",   P_STRING,  P_LOCAL,  &sDefault.refuse_options,NULL, 0},
    {"ignore errors",    P_BOOL,    P_LOCAL,  &sDefault.ignore_errors,NULL,0},
    {"log format",       P_STRING,  P_LOCAL,  &sDefault.log_format,  NULL,   0},
    {"refuse options",   P_STRING,  P_LOCAL,  &sDefault.refuse_options,NULL, 0},
-@@ -363,6 +396,17 @@ FN_LOCAL_BOOL(lp_write_only, write_only)
+@@ -370,6 +403,17 @@ FN_LOCAL_BOOL(lp_write_only, write_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_BOOL(lp_list, list)
  FN_LOCAL_BOOL(lp_use_chroot, use_chroot)
  FN_LOCAL_BOOL(lp_transfer_logging, transfer_logging)
@@ -686,9 +704,9 @@ This patch adds the following options:
  FN_LOCAL_BOOL(lp_ignore_errors, ignore_errors)
  FN_LOCAL_BOOL(lp_ignore_nonreadable, ignore_nonreadable)
  FN_LOCAL_STRING(lp_uid, uid)
  FN_LOCAL_BOOL(lp_ignore_errors, ignore_errors)
  FN_LOCAL_BOOL(lp_ignore_nonreadable, ignore_nonreadable)
  FN_LOCAL_STRING(lp_uid, uid)
---- orig/log.c 2004-06-09 15:34:38
-+++ log.c      2004-07-03 20:22:18
-@@ -75,7 +75,7 @@ struct {
+--- orig/log.c 2005-06-10 21:33:28
++++ log.c      2005-05-23 23:29:54
+@@ -84,7 +84,7 @@ struct {
  /*
   * Map from rsync error code to name, or return NULL.
   */
  /*
   * Map from rsync error code to name, or return NULL.
   */
@@ -697,9 +715,9 @@ This patch adds the following options:
  {
        int i;
        for (i = 0; rerr_names[i].name; i++) {
  {
        int i;
        for (i = 0; rerr_names[i].name; i++) {
---- orig/main.c        2004-07-15 17:02:03
-+++ main.c     2004-07-03 20:22:18
-@@ -134,6 +134,9 @@ static void report(int f)
+--- orig/main.c        2005-07-27 23:31:12
++++ main.c     2005-05-23 23:30:01
+@@ -139,6 +139,9 @@ static void handle_stats(int f)
  
        if (am_daemon) {
                log_exit(0, __FILE__, __LINE__);
  
        if (am_daemon) {
                log_exit(0, __FILE__, __LINE__);
@@ -709,25 +727,24 @@ This patch adds the following options:
                if (f == -1 || !am_sender)
                        return;
        }
                if (f == -1 || !am_sender)
                        return;
        }
---- orig/receiver.c    2004-07-14 17:12:06
-+++ receiver.c 2004-07-03 20:22:18
-@@ -460,7 +460,9 @@ int recv_files(int f_in, struct file_lis
-               recv_ok = receive_data(f_in,mapbuf,fd2,fname,file->length);
+--- orig/receiver.c    2005-08-17 06:45:08
++++ receiver.c 2005-05-23 23:30:07
+@@ -668,6 +668,9 @@ int recv_files(int f_in, struct file_lis
  
  
-               log_recv(file, &initial_stats);
--
+               if (!log_before_transfer)
+                       log_item(file, &initial_stats, iflags, NULL);
 +#ifdef HAVE_LIBODBC
 +              db_log_transfer(file, &initial_stats, "receive");
 +#endif
 +#ifdef HAVE_LIBODBC
 +              db_log_transfer(file, &initial_stats, "receive");
 +#endif
-               if (mapbuf)
-                       unmap_file(mapbuf);
                if (fd1 != -1)
                if (fd1 != -1)
---- orig/sender.c      2004-07-15 02:21:11
-+++ sender.c   2004-07-15 02:37:48
-@@ -229,6 +229,9 @@ void send_files(struct file_list *flist,
+                       close(fd1);
+--- orig/sender.c      2005-07-28 01:46:25
++++ sender.c   2005-05-23 23:30:15
+@@ -356,6 +356,9 @@ void send_files(struct file_list *flist,
  
  
-               match_sums(f_out, s, mbuf, st.st_size);
-               log_send(file, &initial_stats);
+               if (!log_before_transfer)
+                       log_item(file, &initial_stats, iflags, NULL);
 +#ifdef HAVE_LIBODBC
 +              db_log_transfer(file, &initial_stats,"send");
 +#endif
 +#ifdef HAVE_LIBODBC
 +              db_log_transfer(file, &initial_stats,"send");
 +#endif