Imported Upstream version 2.5.1p1
[debian/amanda] / client-src / sendbackup-dump.c
index f0a3af5f366937d9e4b247d17effd14ecae4aace..a568fc8b372e2feb359681b74bc10f01542438e3 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
  * file named AUTHORS, in the root directory of this distribution.
  */
 /* 
- * $Id: sendbackup-dump.c,v 1.65.2.5.4.2.2.9 2003/02/05 02:11:26 martinea Exp $
+ * $Id: sendbackup-dump.c,v 1.90.2.1 2006/09/23 19:19:47 martinea Exp $
  *
  * send backup data using BSD dump
  */
 
+#include "amanda.h"
 #include "sendbackup.h"
-#include "clock.h"
 #include "getfsent.h"
+#include "clock.h"
 #include "version.h"
 
-#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
-
 #define LEAF_AND_DIRS "sed -e \'\ns/^leaf[ \t]*[0-9]*[ \t]*\\.//\nt\n/^dir[ \t]/ {\ns/^dir[ \t]*[0-9]*[ \t]*\\.//\ns%$%/%\nt\n}\nd\n\'"
 
-static regex_t re_table[] = {
+static amregex_t re_table[] = {
   /* the various encodings of dump size */
   /* this should also match BSDI pre-3.0's buggy dump program, that
      produced doubled DUMP: DUMP: messages */
@@ -56,7 +51,6 @@ static regex_t re_table[] = {
             1024),
   AM_SIZE_RE("DUMP: [0-9][0-9]* blocks \\([0-9][0-9]*KB\\) on [0-9][0-9]* volume",
             512),
-
   AM_SIZE_RE("DUMP: [0-9][0-9]* blocks \\([0-9][0-9]*\\.[0-9][0-9]*MB\\) on [0-9][0-9]* volume",
             512),
   AM_SIZE_RE("DUMP: [0-9][0-9]* blocks", 512),
@@ -91,24 +85,25 @@ static regex_t re_table[] = {
 
   /* any blank or non-strange DUMP: lines are marked as normal */
   AM_NORMAL_RE("^ *DUMP:"),
-  AM_NORMAL_RE("^dump:"),                              /* OSF/1 */
-  AM_NORMAL_RE("^vdump:"),                             /* OSF/1 */
-  AM_NORMAL_RE("^ *vxdump:"),                          /* HPUX10 */
-  AM_NORMAL_RE("^ *vxfs *vxdump:"),                    /* Solaris */
-  AM_NORMAL_RE("^xfsdump:"),                           /* IRIX xfs */
-  AM_NORMAL_RE("^ *VXDUMP:"),                          /* Sinix */
-  AM_NORMAL_RE("^ *UFSDUMP:"),                         /* Sinix */
+  AM_NORMAL_RE("^dump:"),                                      /* OSF/1 */
+  AM_NORMAL_RE("^vdump:"),                                     /* OSF/1 */
+  AM_NORMAL_RE("^ *vxdump:"),                                  /* HPUX10 */
+  AM_NORMAL_RE("^ *vxfs *vxdump:"),                            /* Solaris */
+  AM_NORMAL_RE("^Dumping .* to stdout"),                       /* Sol vxdump */
+  AM_NORMAL_RE("^xfsdump:"),                                   /* IRIX xfs */
+  AM_NORMAL_RE("^ *VXDUMP:"),                                  /* Sinix */
+  AM_NORMAL_RE("^ *UFSDUMP:"),                                 /* Sinix */
 
 #ifdef VDUMP   /* this is for OSF/1 3.2's vdump for advfs */
-  AM_NORMAL_RE("^The -s option is ignored"),           /* OSF/1 */
-  AM_NORMAL_RE("^path"),                               /* OSF/1 */
-  AM_NORMAL_RE("^dev/fset"),                           /* OSF/1 */
-  AM_NORMAL_RE("^type"),                               /* OSF/1 */
-  AM_NORMAL_RE("^advfs id"),                           /* OSF/1 */
+  AM_NORMAL_RE("^The -s option is ignored"),                   /* OSF/1 */
+  AM_NORMAL_RE("^path"),                                       /* OSF/1 */
+  AM_NORMAL_RE("^dev/fset"),                                   /* OSF/1 */
+  AM_NORMAL_RE("^type"),                                       /* OSF/1 */
+  AM_NORMAL_RE("^advfs id"),                                   /* OSF/1 */
   AM_NORMAL_RE("^[A-Z][a-z][a-z] [A-Z][a-z][a-z] .[0-9] [0-9]"), /* OSF/1 */
 #endif
 
-  AM_NORMAL_RE("^backup:"),                            /* AIX */
+  AM_NORMAL_RE("^backup:"),                                    /* AIX */
   AM_NORMAL_RE("^        Use the umount command to unmount the filesystem"),
 
   AM_NORMAL_RE("^[ \t]*$"),
@@ -117,29 +112,66 @@ static regex_t re_table[] = {
   AM_STRANGE_RE(NULL)
 };
 
-static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, indexf)
-    char *host;
-    char *disk, *amdevice;
-    int level, dataf, mesgf, indexf;
-    char *dumpdate;
+static void start_backup(char *host, char *disk, char *amdevice, int level,
+               char *dumpdate, int dataf, int mesgf, int indexf);
+static void end_backup(int status);
+
+/*
+ *  doing similar to $ dump | compression | encryption
+ */
+
+static void
+start_backup(
+    char *     host,
+    char *     disk,
+    char *     amdevice,
+    int                level,
+    char *     dumpdate,
+    int                dataf,
+    int                mesgf,
+    int                indexf)
 {
-    int dumpin, dumpout;
+    int dumpin, dumpout, compout;
     char *dumpkeys = NULL;
     char *device = NULL;
     char *fstype = NULL;
     char *cmd = NULL;
+    char *cmdX = NULL;
     char *indexcmd = NULL;
     char level_str[NUM_STR_SIZE];
+    char *compopt  = NULL;
+    char *encryptopt = skip_argument;
+    char *qdisk;
+    char *config;
+
+    (void)dumpdate;    /* Quiet unused parameter warning */
+
+    snprintf(level_str, SIZEOF(level_str), "%d", level);
 
-    ap_snprintf(level_str, sizeof(level_str), "%d", level);
+    qdisk = quote_string(disk);
+    dbprintf(("%s: start: %s:%s lev %d\n",
+             get_pname(), host, qdisk, level));
 
     fprintf(stderr, "%s: start [%s:%s level %d]\n",
-           get_pname(), host, disk, level);
+           get_pname(), host, qdisk, level);
+    amfree(qdisk);
+
+    /*  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 */
 
-    NAUGHTY_BITS;
 
     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) {
@@ -149,7 +181,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("-dump"), (long)comppid, COMPRESS_PATH));
@@ -157,8 +189,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;
     }
 
@@ -171,8 +214,15 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
 
 #if defined(USE_RUNDUMP) || !defined(DUMP)
     cmd = vstralloc(libexecdir, "/", "rundump", versionsuffix(), NULL);
+    cmdX = cmd;
+    if (g_options->config)
+       config = g_options->config;
+    else
+       config = "NOCONFIG";
 #else
     cmd = stralloc(DUMP);
+    cmdX = skip_argument;
+    config = skip_argument;
 #endif
 
 #ifndef AIX_BACKUP                                     /* { */
@@ -186,6 +236,12 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
     {
         char *progname = cmd = newvstralloc(cmd, libexecdir, "/", "rundump",
                                            versionsuffix(), NULL);
+       cmdX = cmd;
+       if (g_options->config)
+           config = g_options->config;
+       else
+           config = "NOCONFIG";
+
        program->backup_name  = XFSDUMP;
        program->restore_name = XFSRESTORE;
 
@@ -197,13 +253,14 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
                             " | sed",
                             " -e", " \'s/^/\\//\'",
                             NULL);
-       write_tapeheader();
+       info_tapeheader();
 
        start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
 
        dumpkeys = stralloc(level_str);
        dumppid = pipespawn(progname, STDIN_PIPE,
                            &dumpin, &dumpout, &mesgf,
+                           cmdX, config,
                            "xfsdump",
                            options->no_record ? "-J" : skip_argument,
                            "-F",
@@ -224,8 +281,15 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
 #ifdef USE_RUNDUMP
         char *progname = cmd = newvstralloc(cmd, libexecdir, "/", "rundump",
                                            versionsuffix(), NULL);
+       cmdX = cmd;
+       if (g_options->config)
+           config = g_options->config;
+       else
+           config = "NOCONFIG";
 #else
        char *progname = cmd = newvstralloc(cmd, VXDUMP, NULL);
+       cmdX = skip_argument;
+       config = skip_argument;
 #endif
        program->backup_name  = VXDUMP;
        program->restore_name = VXRESTORE;
@@ -242,12 +306,13 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
                             " | ",
                             LEAF_AND_DIRS,
                             NULL);
-       write_tapeheader();
+       info_tapeheader();
 
        start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
 
        dumppid = pipespawn(progname, STDIN_PIPE,
                            &dumpin, &dumpout, &mesgf, 
+                           cmdX, config,
                            "vxdump",
                            dumpkeys,
                            "1048576",
@@ -267,6 +332,11 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
     {
         char *progname = cmd = newvstralloc(cmd, libexecdir, "/", "rundump",
                                            versionsuffix(), NULL);
+       cmdX = cmd;
+       if (g_options->config)
+           config = g_options->config;
+       else
+           config = "NOCONFIG";
        device = newstralloc(device, amname_to_dirname(amdevice));
        program->backup_name  = VDUMP;
        program->restore_name = VRESTORE;
@@ -283,12 +353,13 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
                             " | ",
                             "sed -e \'\n/^\\./ {\ns/^\\.//\ns/, [0-9]*$//\ns/^\\.//\ns/ @-> .*$//\nt\n}\nd\n\'",
                             NULL);
-       write_tapeheader();
+       info_tapeheader();
 
        start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
 
        dumppid = pipespawn(cmd, STDIN_PIPE,
                            &dumpin, &dumpout, &mesgf, 
+                           cmdX, config,
                            "vdump",
                            dumpkeys,
                            "60",
@@ -320,12 +391,13 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
                             " | ",
                             LEAF_AND_DIRS,
                             NULL);
-       write_tapeheader();
+       info_tapeheader();
 
        start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
 
        dumppid = pipespawn(cmd, STDIN_PIPE,
                            &dumpin, &dumpout, &mesgf, 
+                           cmdX, config,
                            "dump",
                            dumpkeys,
                            "1048576",
@@ -351,12 +423,13 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
                         " | ",
                         LEAF_AND_DIRS,
                         NULL);
-    write_tapeheader();
+    info_tapeheader();
 
     start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
 
     dumppid = pipespawn(cmd, STDIN_PIPE,
                        &dumpin, &dumpout, &mesgf, 
+                       cmdX, config,
                        "backup",
                        dumpkeys,
                        "-",
@@ -365,6 +438,7 @@ static void start_backup(host, disk, amdevice, level, dumpdate, dataf, mesgf, in
 #endif                                                 /* } */
 
     amfree(dumpkeys);
+    amfree(fstype);
     amfree(device);
     amfree(cmd);
     amfree(indexcmd);
@@ -373,15 +447,19 @@ 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)
        aclose(indexf);
 }
 
-static void end_backup(status)
-int status;
+static void
+end_backup(
+    int                status)
 {
+    (void)status;      /* Quiet unused parameter warning */
+
     /* don't need to do anything for dump */
 }