Imported Upstream version 2.5.0
[debian/amanda] / client-src / sendbackup-gnutar.c
index 666796e2bcc4eff097783acc607fba8579128ffb..f3c74fc6cb07d2b33b66c5777beb21115fa38836 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
- * Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 1991-1999 University of Maryland at College Park
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -24,7 +24,7 @@
  * file named AUTHORS, in the root directory of this distribution.
  */
 /* 
- * $Id: sendbackup-gnutar.c,v 1.56.2.15.4.4.2.11.2.2 2005/06/23 08:46:07 weichinger Exp $
+ * $Id: sendbackup-gnutar.c,v 1.92 2005/12/09 03:22:52 paddy_s Exp $
  *
  * send backup data using GNU tar
  */
 #include "findpass.h"
 #endif
 
-#ifdef KRB4_SECURITY
-#include "sendbackup-krb4.h"
-#else                                  /* I'd tell you what this does */
-#define NAUGHTY_BITS                   /* but then I'd have to kill you */
-#endif
-
-
 static regex_t re_table[] = {
   /* tar prints the size in bytes */
   AM_SIZE_RE("^ *Total bytes written: [0-9][0-9]*", 1),
-
   AM_NORMAL_RE("^Elapsed time:"),
   AM_NORMAL_RE("^Throughput"),
 
@@ -125,6 +117,8 @@ static regex_t re_table[] = {
   AM_STRANGE_RE(NULL)
 };
 
+extern char *efile;
+
 int cur_level;
 char *cur_disk;
 time_t cur_dumptime;
@@ -132,14 +126,16 @@ time_t cur_dumptime;
 #ifdef GNUTAR_LISTED_INCREMENTAL_DIR
 static char *incrname = NULL;
 #endif
-
+/*
+ *  doing similar to $ gtar | compression | encryption 
+ */
 static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, indexf)
     char *host;
     char *disk, *amdevice;
     int level, dataf, mesgf, indexf;
     char *dumpdate;
 {
-    int dumpin, dumpout;
+    int dumpin, dumpout, compout;
     char *cmd = NULL;
     char *indexcmd = NULL;
     char *dirname = NULL;
@@ -149,17 +145,28 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
     amandates_t *amdates;
     time_t prev_dumptime;
     char *error_pn = NULL;
+    char *compopt  = NULL;
+    char *encryptopt = skip_argument;
 
     error_pn = stralloc2(get_pname(), "-smbclient");
 
+
     fprintf(stderr, "%s: start [%s:%s level %d]\n",
            get_pname(), host, disk, level);
-
-    NAUGHTY_BITS;
-
+     /*  apply client-side encryption here */
+     if ( options->encrypt == ENCRYPT_CUST ) {
+      encpid = pipespawn(options->clnt_encrypt, STDIN_PIPE,
+                       &compout, &dataf, &mesgf, 
+                       options->clnt_encrypt, encryptopt, NULL);
+      dbprintf(("%s: pid %ld: %s\n",
+                 debug_prefix_time("-gnutar"), (long)encpid, options->clnt_encrypt));
+    } else {
+       compout = dataf;
+       encpid = -1;
+    } 
+     /*  now do the client-side compression */
     if(options->compress == COMPR_FAST || options->compress == COMPR_BEST) {
-       char *compopt = skip_argument;
-
+          compopt = skip_argument;
 #if defined(COMPRESS_BEST_OPT) && defined(COMPRESS_FAST_OPT)
        if(options->compress == COMPR_BEST) {
            compopt = COMPRESS_BEST_OPT;
@@ -168,7 +175,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
        }
 #endif
        comppid = pipespawn(COMPRESS_PATH, STDIN_PIPE,
-                           &dumpout, &dataf, &mesgf,
+                           &dumpout, &compout, &mesgf,
                            COMPRESS_PATH, compopt, NULL);
        dbprintf(("%s: pid %ld: %s",
                  debug_prefix_time("-gnutar"), (long)comppid, COMPRESS_PATH));
@@ -176,8 +183,19 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
            dbprintf((" %s", compopt));
        }
        dbprintf(("\n"));
+     } else if (options->compress == COMPR_CUST) {
+        compopt = skip_argument;
+       comppid = pipespawn(options->clntcompprog, STDIN_PIPE,
+                           &dumpout, &compout, &mesgf,
+                           options->clntcompprog, compopt, NULL);
+       dbprintf(("%s: pid %ld: %s",
+                 debug_prefix_time("-gnutar-cust"), (long)comppid, options->clntcompprog));
+       if(compopt != skip_argument) {
+           dbprintf((" %s", compopt));
+       }
+       dbprintf(("\n"));
     } else {
-       dumpout = dataf;
+       dumpout = compout;
        comppid = -1;
     }
 
@@ -212,7 +230,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
            if(ch == '/' || isspace(ch)) s[-1] = '_';
        }
 
-       ap_snprintf(number, sizeof(number), "%d", level);
+       snprintf(number, sizeof(number), "%d", level);
        incrname = vstralloc(basename, "_", number, ".new", NULL);
        unlink(incrname);
 
@@ -224,7 +242,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
        baselevel = level;
        while (in == NULL) {
            if (--baselevel >= 0) {
-               ap_snprintf(number, sizeof(number), "%d", baselevel);
+               snprintf(number, sizeof(number), "%d", baselevel);
                inputname = newvstralloc(inputname,
                                         basename, "_", number, NULL);
            } else {
@@ -297,7 +315,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
     free_amandates();
 
     gmtm = gmtime(&prev_dumptime);
-    ap_snprintf(dumptimestr, sizeof(dumptimestr),
+    snprintf(dumptimestr, sizeof(dumptimestr),
                "%04d-%02d-%02d %2d:%02d:%02d GMT",
                gmtm->tm_year + 1900, gmtm->tm_mon+1, gmtm->tm_mday,
                gmtm->tm_hour, gmtm->tm_min, gmtm->tm_sec);
@@ -336,18 +354,18 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
 
        parsesharename(amdevice, &share, &subdir);
        if (!share) {
-            amfree(share);
-            amfree(subdir);
-            set_pname(error_pn);
-            amfree(error_pn);
-            error("cannot parse disk entry '%s' for share/subdir", disk);
+           amfree(share);
+           amfree(subdir);
+           set_pname(error_pn);
+           amfree(error_pn);
+           error("cannot parse disk entry '%s' for share/subdir", disk);
        }
        if ((subdir) && (SAMBA_VERSION < 2)) {
-            amfree(share);
-            amfree(subdir);
-            set_pname(error_pn);
-            amfree(error_pn);
-            error("subdirectory specified for share '%s' but samba not v2 or better", disk);
+           amfree(share);
+           amfree(subdir);
+           set_pname(error_pn);
+           amfree(error_pn);
+           error("subdirectory specified for share '%s' but samba not v2 or better", disk);
        }
        if ((user_and_password = findpass(share, &domain)) == NULL) {
            if(domain) {
@@ -406,7 +424,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
 
        program->backup_name = program->restore_name = SAMBA_CLIENT;
        cmd = stralloc(program->backup_name);
-       write_tapeheader();
+       info_tapeheader();
 
        start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
 
@@ -457,8 +475,9 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
        amfree(taropt);
        tarpid = dumppid;
     } else
-#endif                                                                 /* } */
+#endif                 /*end of samba */
     {
+
        int nb_exclude = 0;
        int nb_include = 0;
        char **my_argv;
@@ -477,7 +496,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
        my_argv = alloc(sizeof(char *) * (17 + (nb_exclude*2)+(nb_include*2)));
 
        cmd = vstralloc(libexecdir, "/", "runtar", versionsuffix(), NULL);
-       write_tapeheader();
+       info_tapeheader();
 
        start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
 
@@ -495,7 +514,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
        my_argv[i++] = "--incremental";
        my_argv[i++] = "--newer";
        my_argv[i++] = dumptimestr;
-#endif 
+#endif
 #ifdef ENABLE_GNUTAR_ATIME_PRESERVE
        /* --atime-preserve causes gnutar to call
         * utime() after reading files in order to
@@ -542,6 +561,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
 
     aclose(dumpin);
     aclose(dumpout);
+    aclose(compout);
     aclose(dataf);
     aclose(mesgf);
     if (options->createindex)
@@ -558,8 +578,8 @@ int goterror;
        
            nodotnew = stralloc(incrname);
            nodotnew[strlen(nodotnew)-4] = '\0';
-           if (rename(incrname, nodotnew) != 0) {
-               fprintf(stderr, "%s: warning [renaming %s to %s: %s]\n",
+           if (rename(incrname, nodotnew)) {
+               fprintf(stderr, "%s: warning [renaming %s to %s: %s]\n", 
                        get_pname(), incrname, nodotnew, strerror(errno));
            }
            amfree(nodotnew);
@@ -568,7 +588,7 @@ int goterror;
 #endif
 
         if(!start_amandates(1)) {
-           fprintf(stderr, "%s: warning [opening %s: %s]\n", get_pname(),
+           fprintf(stderr, "%s: warning [opening %s: %s]", get_pname(),
                    AMANDATES_FILE, strerror(errno));
        }
        else {