Imported Upstream version 2.5.2p1
[debian/amanda] / client-src / client_util.c
index 71ce4b4c6443c8152d97fb176b4b10bdfb4b6db4..bba8b184b5b5103cae0958dd9f6656b7eeef565b 100644 (file)
  */
 
 #include "amanda.h"
+#include "conffile.h"
 #include "client_util.h"
 #include "getfsent.h"
 #include "util.h"
+#include "pipespawn.h"
 
 #define MAXMAXDUMPS 16
 
@@ -153,7 +155,7 @@ build_name(
        afilename = newvstralloc(afilename, dbgdir, filename, NULL);
        quoted = quote_string(afilename);
        dbprintf(("%s: Cannot create %s (%s)\n",
-                       debug_prefix(NULL), quoted, strerror(errno)));
+                       debug_prefix_time(NULL), quoted, strerror(errno)));
        if(verbose) {
            printf("ERROR [cannot create %s (%s)]\n",
                        quoted, strerror(errno));
@@ -218,7 +220,7 @@ add_include(
     if (strncmp(ainc, "./", 2) != 0) {
         quoted = quote_string(ainc);
         dbprintf(("%s: include must start with './' (%s)\n",
-                 debug_prefix(NULL), quoted));
+                 debug_prefix_time(NULL), quoted));
        if(verbose) {
            printf("ERROR [include must start with './' (%s)]\n", quoted);
        }
@@ -246,7 +248,7 @@ add_include(
            if((d = opendir(device)) == NULL) {
                quoted = quote_string(device);
                dbprintf(("%s: Can't open disk %s\n",
-                     debug_prefix(NULL), quoted));
+                     debug_prefix_time(NULL), quoted));
                if(verbose) {
                    printf("ERROR [Can't open disk %s]\n", quoted);
                }
@@ -328,7 +330,7 @@ build_exclude(
                    else {
                        quoted = quote_string(exclname);
                        dbprintf(("%s: Can't open exclude file %s (%s)\n",
-                                 debug_prefix(NULL),
+                                 debug_prefix_time(NULL),
                                  quoted, strerror(errno)));
                        if(verbose && (options->exclude_optional == 0 ||
                                       errno != ENOENT)) {
@@ -345,7 +347,7 @@ build_exclude(
        else {
            quoted = quote_string(filename);
            dbprintf(("%s: Can't create exclude file %s (%s)\n",
-                     debug_prefix(NULL),
+                     debug_prefix_time(NULL),
                      quoted, strerror(errno)));
            if(verbose) {
                printf("ERROR [Can't create exclude file %s (%s)]\n",
@@ -411,7 +413,7 @@ build_include(
                    else {
                        quoted = quote_string(inclname);
                        dbprintf(("%s: Can't open include file %s (%s)\n",
-                                 debug_prefix(NULL), quoted, strerror(errno)));
+                                 debug_prefix_time(NULL), quoted, strerror(errno)));
                        if(verbose && (options->include_optional == 0 ||
                                       errno != ENOENT)) {
                            printf("ERROR [Can't open include file %s (%s)]\n",
@@ -427,7 +429,7 @@ build_include(
        else {
            quoted = quote_string(filename);
            dbprintf(("%s: Can't create include file %s (%s)\n",
-                     debug_prefix(NULL), quoted, strerror(errno)));
+                     debug_prefix_time(NULL), quoted, strerror(errno)));
            if(verbose) {
                printf("ERROR [Can't create include file %s (%s)]\n",
                        quoted, strerror(errno));
@@ -438,7 +440,7 @@ build_include(
        
     if(nb_exp == 0) {
        quoted = quote_string(disk);
-       dbprintf(("%s: No include for %s\n", debug_prefix(NULL), quoted));
+       dbprintf(("%s: No include for %s\n", debug_prefix_time(NULL), quoted));
        if(verbose && options->include_optional == 0) {
            printf("ERROR [No include for %s]\n", quoted);
        }
@@ -454,7 +456,7 @@ init_options(
     option_t *options)
 {
     options->str = NULL;
-    options->compress = NO_COMPR;
+    options->compress = COMP_NONE;
     options->srvcompprog = NULL;
     options->clntcompprog = NULL;
     options->encrypt = ENCRYPT_NONE;
@@ -504,7 +506,7 @@ parse_options(
            if(options->auth != NULL) {
                quoted = quote_string(tok + 5);
                dbprintf(("%s: multiple auth option %s\n",
-                         debug_prefix(NULL), quoted));
+                         debug_prefix_time(NULL), quoted));
                if(verbose) {
                    printf("ERROR [multiple auth option %s]\n", quoted);
                }
@@ -516,7 +518,7 @@ parse_options(
           && BSTRNCMP(tok, "bsd-auth") == 0) {
            if(options->auth != NULL) {
                dbprintf(("%s: multiple auth option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple auth option]\n");
                }
@@ -527,7 +529,7 @@ parse_options(
           && BSTRNCMP(tok, "krb4-auth") == 0) {
            if(options->auth != NULL) {
                dbprintf(("%s: multiple auth option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple auth option]\n");
                }
@@ -535,72 +537,72 @@ parse_options(
            options->auth = stralloc("krb4");
        }
        else if(BSTRNCMP(tok, "compress-fast") == 0) {
-           if(options->compress != NO_COMPR) {
+           if(options->compress != COMP_NONE) {
                dbprintf(("%s: multiple compress option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple compress option]\n");
                }
            }
-           options->compress = COMPR_FAST;
+           options->compress = COMP_FAST;
        }
        else if(BSTRNCMP(tok, "compress-best") == 0) {
-           if(options->compress != NO_COMPR) {
+           if(options->compress != COMP_NONE) {
                dbprintf(("%s: multiple compress option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple compress option]\n");
                }
            }
-           options->compress = COMPR_BEST;
+           options->compress = COMP_BEST;
        }
        else if(BSTRNCMP(tok, "srvcomp-fast") == 0) {
-           if(options->compress != NO_COMPR) {
+           if(options->compress != COMP_NONE) {
                dbprintf(("%s: multiple compress option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple compress option]\n");
                }
            }
-           options->compress = COMPR_SERVER_FAST;
+           options->compress = COMP_SERVER_FAST;
        }
        else if(BSTRNCMP(tok, "srvcomp-best") == 0) {
-           if(options->compress != NO_COMPR) {
+           if(options->compress != COMP_NONE) {
                dbprintf(("%s: multiple compress option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple compress option]\n");
                }
            }
-           options->compress = COMPR_SERVER_BEST;
+           options->compress = COMP_SERVER_BEST;
        }
        else if(BSTRNCMP(tok, "srvcomp-cust=") == 0) {
-           if(options->compress != NO_COMPR) {
+           if(options->compress != COMP_NONE) {
                dbprintf(("%s: multiple compress option\n", 
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple compress option]\n");
                }
            }
            options->srvcompprog = stralloc(tok + SIZEOF("srvcomp-cust=") -1);
-           options->compress = COMPR_SERVER_CUST;
+           options->compress = COMP_SERVER_CUST;
        }
        else if(BSTRNCMP(tok, "comp-cust=") == 0) {
-           if(options->compress != NO_COMPR) {
+           if(options->compress != COMP_NONE) {
                dbprintf(("%s: multiple compress option\n", 
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple compress option]\n");
                }
            }
            options->clntcompprog = stralloc(tok + SIZEOF("comp-cust=") -1);
-           options->compress = COMPR_CUST;
+           options->compress = COMP_CUST;
            /* parse encryption options */
        } 
        else if(BSTRNCMP(tok, "encrypt-serv-cust=") == 0) {
            if(options->encrypt != ENCRYPT_NONE) {
                dbprintf(("%s: multiple encrypt option\n", 
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple encrypt option]\n");
                }
@@ -611,7 +613,7 @@ parse_options(
        else if(BSTRNCMP(tok, "encrypt-cust=") == 0) {
            if(options->encrypt != ENCRYPT_NONE) {
                dbprintf(("%s: multiple encrypt option\n", 
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple encrypt option]\n");
                }
@@ -628,7 +630,7 @@ parse_options(
        else if(BSTRNCMP(tok, "no-record") == 0) {
            if(options->no_record != 0) {
                dbprintf(("%s: multiple no-record option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple no-record option]\n");
                }
@@ -638,7 +640,7 @@ parse_options(
        else if(BSTRNCMP(tok, "index") == 0) {
            if(options->createindex != 0) {
                dbprintf(("%s: multiple index option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple index option]\n");
                }
@@ -648,7 +650,7 @@ parse_options(
        else if(BSTRNCMP(tok, "exclude-optional") == 0) {
            if(options->exclude_optional != 0) {
                dbprintf(("%s: multiple exclude-optional option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple exclude-optional option]\n");
                }
@@ -658,7 +660,7 @@ parse_options(
        else if(strcmp(tok, "include-optional") == 0) {
            if(options->include_optional != 0) {
                dbprintf(("%s: multiple include-optional option\n",
-                         debug_prefix(NULL)));
+                         debug_prefix_time(NULL)));
                if(verbose) {
                    printf("ERROR [multiple include-optional option]\n");
                }
@@ -688,7 +690,7 @@ parse_options(
        else if(strcmp(tok,"|") != 0) {
            quoted = quote_string(tok);
            dbprintf(("%s: unknown option %s\n",
-                       debug_prefix(NULL), quoted));
+                       debug_prefix_time(NULL), quoted));
            if(verbose) {
                printf("ERROR [unknown option: %s]\n", quoted);
            }
@@ -699,3 +701,162 @@ parse_options(
     amfree(p);
     return options;
 }
+
+void
+output_tool_property(
+    FILE     *tool,
+    option_t *options)
+{
+    sle_t *sle;
+    char *q;
+
+    if (!is_empty_sl(options->exclude_file)) {
+       for(sle = options->exclude_file->first ; sle != NULL; sle=sle->next) {
+           q = quote_string(sle->name);
+           fprintf(tool, "EXCLUDE-FILE %s\n", q);
+           amfree(q);
+       }
+    }
+
+    if (!is_empty_sl(options->exclude_list)) {
+       for(sle = options->exclude_list->first ; sle != NULL; sle=sle->next) {
+           q = quote_string(sle->name);
+           fprintf(tool, "EXCLUDE-LIST %s\n", q);
+           amfree(q);
+       }
+    }
+
+    if (!is_empty_sl(options->include_file)) {
+       for(sle = options->include_file->first ; sle != NULL; sle=sle->next) {
+           q = quote_string(sle->name);
+           fprintf(tool, "INCLUDE-FILE %s\n", q);
+           amfree(q);
+       }
+    }
+
+    if (!is_empty_sl(options->include_list)) {
+       for(sle = options->include_list->first ; sle != NULL; sle=sle->next) {
+           q = quote_string(sle->name);
+           fprintf(tool, "INCLUDE-LIST %s\n", q);
+           amfree(q);
+       }
+    }
+
+    if (!is_empty_sl(options->exclude_file) ||
+       !is_empty_sl(options->exclude_list)) {
+       if (options->exclude_optional)
+           fprintf(tool, "EXCLUDE-OPTIONAL YES\n");
+       else
+           fprintf(tool, "EXCLUDE-OPTIONAL NO\n");
+    }
+
+    if (!is_empty_sl(options->include_file) ||
+       !is_empty_sl(options->include_list)) {
+       if (options->include_optional)
+           fprintf(tool, "INCLUDE-OPTIONAL YES\n");
+       else
+           fprintf(tool, "INCLUDE-OPTIONAL NO\n");
+    }
+}
+
+backup_support_option_t *
+backup_support_option(
+    char       *program,
+    g_option_t *g_options,
+    char       *disk,
+    char       *amdevice)
+{
+    pid_t   supportpid;
+    int     supportin, supportout, supporterr;
+    char   *cmd;
+    char  **argvchild;
+    int     i;
+    FILE   *streamout;
+    char   *line;
+    backup_support_option_t *bsu;
+
+    cmd = vstralloc(DUMPER_DIR, "/", program, NULL);
+    argvchild = malloc(5 * SIZEOF(char *));
+    i = 0;
+    argvchild[i++] = program;
+    argvchild[i++] = "support";
+    if (g_options->config) {
+       argvchild[i++] = "--config";
+       argvchild[i++] = g_options->config;
+    }
+    if (g_options->hostname) {
+       argvchild[i++] = "--host";
+       argvchild[i++] = g_options->hostname;
+    }
+    if (disk) {
+       argvchild[i++] = "--disk";
+       argvchild[i++] = disk;
+    }
+    if (amdevice) {
+       argvchild[i++] = "--device";
+       argvchild[i++] = amdevice;
+    }
+    argvchild[i++] = NULL;
+
+    supporterr = fileno(stderr);
+    supportpid = pipespawnv(cmd, STDIN_PIPE|STDOUT_PIPE, &supportin,
+                           &supportout, &supporterr, argvchild);
+
+    aclose(supportin);
+
+    bsu = malloc(SIZEOF(*bsu));
+    memset(bsu, '\0', SIZEOF(*bsu));
+    streamout = fdopen(supportout, "r");
+    while((line = agets(streamout)) != NULL) {
+       dbprintf(("support line: %s\n", line));
+       if (strncmp(line,"CONFIG ", 7) == 0) {
+           if (strcmp(line+7, "YES") == 0)
+               bsu->config = 1;
+       } else if (strncmp(line,"HOST ", 5) == 0) {
+           if (strcmp(line+5, "YES") == 0)
+           bsu->host = 1;
+       } else if (strncmp(line,"DISK ", 5) == 0) {
+           if (strcmp(line+5, "YES") == 0)
+               bsu->host = 1;
+       } else if (strncmp(line,"INDEX-LINE ", 11) == 0) {
+           if (strcmp(line+11, "YES") == 0)
+               bsu->index_line = 1;
+       } else if (strncmp(line,"INDEX-XML ", 10) == 0) {
+           if (strcmp(line+10, "YES") == 0)
+               bsu->index_xml = 1;
+       } else if (strncmp(line,"MESSAGE-LINE ", 13) == 0) {
+           if (strcmp(line+13, "YES") == 0)
+               bsu->message_line = 1;
+       } else if (strncmp(line,"MESSAGE-XML ", 12) == 0) {
+           if (strcmp(line+12, "YES") == 0)
+               bsu->message_xml = 1;
+       } else if (strncmp(line,"RECORD ", 7) == 0) {
+           if (strcmp(line+7, "YES") == 0)
+               bsu->record = 1;
+       } else if (strncmp(line,"INCLUDE-FILE ", 13) == 0) {
+           if (strcmp(line+13, "YES") == 0)
+               bsu->include_file = 1;
+       } else if (strncmp(line,"INCLUDE-LIST ", 13) == 0) {
+           if (strcmp(line+13, "YES") == 0)
+               bsu->include_list = 1;
+       } else if (strncmp(line,"EXCLUDE-FILE ", 13) == 0) {
+           if (strcmp(line+13, "YES") == 0)
+               bsu->exclude_file = 1;
+       } else if (strncmp(line,"EXCLUDE-LIST ", 13) == 0) {
+           if (strcmp(line+13, "YES") == 0)
+               bsu->exclude_list = 1;
+       } else if (strncmp(line,"COLLECTION ", 11) == 0) {
+           if (strcmp(line+11, "YES") == 0)
+               bsu->collection = 1;
+       } else if (strncmp(line,"MAX-LEVEL ", 10) == 0) {
+           bsu->max_level  = atoi(line+10);
+       } else {
+           dbprintf(("Invalid support line: %s\n", line));
+       }
+       amfree(line);
+    }
+    aclose(supportout);
+
+    return NULL;
+}
+