Imported Upstream version 3.2.0
[debian/amanda] / server-src / dumper.c
index 1e008601cf65cfa5fc137bc1baa6741087f29ccf..996c9ddf46c947b87a606b9d87d3e4880f7678f6 100644 (file)
@@ -23,7 +23,7 @@
  * Authors: the Amanda Development Team.  Its members are listed in a
  * file named AUTHORS, in the root directory of this distribution.
  */
-/* $Id: dumper.c,v 1.170 2006/03/22 15:10:52 martinea Exp $
+/* $Id: dumper.c,v 1.190 2006/08/30 19:53:57 martinea Exp $
  *
  * requests remote amandad processes to dump filesystems
  */
 #include "protocol.h"
 #include "security.h"
 #include "stream.h"
-#include "token.h"
-#include "version.h"
 #include "fileheader.h"
 #include "amfeatures.h"
 #include "server_util.h"
 #include "util.h"
+#include "timestamp.h"
+#include "amxml.h"
+
+#define dumper_debug(i,x) do {         \
+       if ((i) <= debug_dumper) {      \
+           dbprintf(x);                \
+       }                               \
+} while (0)
 
 #ifndef SEEK_SET
 #define SEEK_SET 0
@@ -67,11 +73,21 @@ struct databuf {
     pid_t encryptpid;          /* valid if fd is pipe to encrypt */
 };
 
+typedef struct filter_s {
+    int             fd;
+    char           *name;
+    char           *buffer;
+    gint64          first;           /* first byte used */
+    gint64          size;            /* number of byte use in the buffer */
+    gint64          allocated_size ; /* allocated size of the buffer     */
+    event_handle_t *event;
+} filter_t;
+
 static char *handle = NULL;
 
 static char *errstr = NULL;
-static long dumpbytes;
-static long dumpsize, headersize, origsize;
+static off_t dumpbytes;
+static off_t dumpsize, headersize, origsize;
 
 static comp_t srvcompress = COMP_NONE;
 char *srvcompprog = NULL;
@@ -82,19 +98,30 @@ char *srv_encrypt = NULL;
 char *clnt_encrypt = NULL;
 char *srv_decrypt_opt = NULL;
 char *clnt_decrypt_opt = NULL;
+static kencrypt_type dumper_kencrypt;
 
 static FILE *errf = NULL;
 static char *hostname = NULL;
 am_feature_t *their_features = NULL;
 static char *diskname = NULL;
-static char *device = NULL;
+static char *qdiskname = NULL, *b64disk;
+static char *device = NULL, *b64device;
 static char *options = NULL;
 static char *progname = NULL;
+static char *amandad_path=NULL;
+static char *client_username=NULL;
+static char *client_port=NULL;
+static char *ssh_keys=NULL;
+static char *auth=NULL;
+static data_path_t data_path=DATA_PATH_AMANDA;
+static char *dataport_list = NULL;
 static int level;
 static char *dumpdate = NULL;
-static char *datestamp;
-static int conf_dtimeout;
+static char *dumper_timestamp = NULL;
+static time_t conf_dtimeout;
 static int indexfderror;
+static int set_datafd;
+static char *dle_str = NULL;
 
 static dumpfile_t file;
 
@@ -109,44 +136,55 @@ static struct {
 #define        INDEXFD 2
     { "INDEX", NULL },
 };
-#define        NSTREAMS        (sizeof(streams) / sizeof(streams[0]))
+#define        NSTREAMS        (int)(sizeof(streams) / sizeof(streams[0]))
 
 static am_feature_t *our_features = NULL;
 static char *our_feature_string = NULL;
 
+/* buffer to keep partial line from the MESG stream */
+static struct {
+    char *buf;         /* buffer holding msg data */
+    size_t size;       /* size of alloced buffer */
+} msg = { NULL, 0 };
+
+
 /* local functions */
-int main P((int, char **));
-static int do_dump P((struct databuf *));
-static void check_options P((char *));
-static void finish_tapeheader P((dumpfile_t *));
-static int write_tapeheader P((int, dumpfile_t *));
-static void databuf_init P((struct databuf *, int));
-static int databuf_write P((struct databuf *, const void *, int));
-static int databuf_flush P((struct databuf *));
-static void process_dumpeof P((void));
-static void process_dumpline P((const char *));
-static void add_msg_data P((const char *, size_t));
-static void parse_info_line P((char *));
-static void log_msgout P((logtype_t));
-
-static int runcompress P((int, pid_t *, comp_t));
-static int runencrypt P((int, pid_t *,  encrypt_t));
-
-static void sendbackup_response P((void *, pkt_t *, security_handle_t *));
-static int startup_dump P((const char *, const char *, const char *, int,
-                          const char *, const char *, const char *));
-static void stop_dump P((void));
-
-static void read_indexfd P((void *, void *, ssize_t));
-static void read_datafd P((void *, void *, ssize_t));
-static void read_mesgfd P((void *, void *, ssize_t));
-static void timeout P((int));
-static void timeout_callback P((void *));
+int            main(int, char **);
+static int     do_dump(struct databuf *);
+static void    check_options(char *);
+static void     xml_check_options(char *optionstr);
+static void    finish_tapeheader(dumpfile_t *);
+static ssize_t write_tapeheader(int, dumpfile_t *);
+static void    databuf_init(struct databuf *, int);
+static int     databuf_write(struct databuf *, const void *, size_t);
+static int     databuf_flush(struct databuf *);
+static void    process_dumpeof(void);
+static void    process_dumpline(const char *);
+static void    add_msg_data(const char *, size_t);
+static void    parse_info_line(char *);
+static void    log_msgout(logtype_t);
+static char *  dumper_get_security_conf (char *, void *);
+
+static int     runcompress(int, pid_t *, comp_t, char *);
+static int     runencrypt(int, pid_t *,  encrypt_t);
+
+static void    sendbackup_response(void *, pkt_t *, security_handle_t *);
+static int     startup_dump(const char *, const char *, const char *, int,
+                       const char *, const char *, const char *,
+                       const char *, const char *, const char *,
+                       const char *, const char *);
+static void    stop_dump(void);
+
+static void    read_indexfd(void *, void *, ssize_t);
+static void    read_datafd(void *, void *, ssize_t);
+static void    read_mesgfd(void *, void *, ssize_t);
+static void    timeout(time_t);
+static void    timeout_callback(void *);
 
 static void
-check_options(options)
-    char *options;
-{      
+check_options(
+    char *options)
+{
   char *compmode = NULL;
   char *compend  = NULL;
   char *encryptmode = NULL;
@@ -155,14 +193,14 @@ check_options(options)
   char *decryptend = NULL;
 
     /* parse the compression option */
-  if (strstr(options, "srvcomp-best;") != NULL) 
+    if (strstr(options, "srvcomp-best;") != NULL) 
       srvcompress = COMP_BEST;
     else if (strstr(options, "srvcomp-fast;") != NULL)
       srvcompress = COMP_FAST;
     else if ((compmode = strstr(options, "srvcomp-cust=")) != NULL) {
        compend = strchr(compmode, ';');
        if (compend ) {
-           srvcompress = COMP_SERV_CUST;
+           srvcompress = COMP_SERVER_CUST;
            *compend = '\0';
            srvcompprog = stralloc(compmode + strlen("srvcomp-cust="));
            *compend = ';';
@@ -217,99 +255,155 @@ check_options(options)
        *decryptend = ';';
       }
     }
+
+    if (strstr(options, "kencrypt;") != NULL) {
+       dumper_kencrypt = KENCRYPT_WILL_DO;
+    } else {
+       dumper_kencrypt = KENCRYPT_NONE;
+    }
+}
+
+
+static void
+xml_check_options(
+    char *optionstr)
+{
+    char *o, *oo;
+    char *errmsg = NULL;
+    dle_t *dle;
+
+    o = oo = vstralloc("<dle>", strchr(optionstr,'<'), "</dle>", NULL);
+
+    dle = amxml_parse_node_CHAR(o, &errmsg);
+    if (dle == NULL) {
+       error("amxml_parse_node_CHAR failed: %s\n", errmsg);
+    }
+
+    if (dle->compress == COMP_SERVER_FAST) {
+       srvcompress = COMP_FAST;
+    } else if (dle->compress == COMP_SERVER_BEST) {
+       srvcompress = COMP_BEST;
+    } else if (dle->compress == COMP_SERVER_CUST) {
+       srvcompress = COMP_SERVER_CUST;
+       srvcompprog = g_strdup(dle->compprog);
+    } else if (dle->compress == COMP_CUST) {
+       srvcompress = COMP_CUST;
+       clntcompprog = g_strdup(dle->compprog);
+    } else {
+       srvcompress = COMP_NONE;
+    }
+
+    if (dle->encrypt == ENCRYPT_CUST) {
+       srvencrypt = ENCRYPT_CUST;
+       clnt_encrypt = g_strdup(dle->clnt_encrypt);
+       clnt_decrypt_opt = g_strdup(dle->clnt_decrypt_opt);
+    } else if (dle->encrypt == ENCRYPT_SERV_CUST) {
+       srvencrypt = ENCRYPT_SERV_CUST;
+       srv_encrypt = g_strdup(dle->srv_encrypt);
+       srv_decrypt_opt = g_strdup(dle->srv_decrypt_opt);
+    } else {
+       srvencrypt = ENCRYPT_NONE;
+    }
+    free_dle(dle);
+    amfree(o);
 }
 
 
 int
-main(main_argc, main_argv)
-    int main_argc;
-    char **main_argv;
+main(
+    int                argc,
+    char **    argv)
 {
     static struct databuf db;
-    struct cmdargs cmdargs;
-    cmd_t cmd;
+    struct cmdargs *cmdargs = NULL;
     int outfd = -1;
-    int taper_port, rc;
-    unsigned long malloc_hist_1, malloc_size_1;
-    unsigned long malloc_hist_2, malloc_size_2;
-    char *conffile;
+    int rc;
+    in_port_t header_port;
     char *q = NULL;
     int a;
+    int res;
+    config_overrides_t *cfg_ovr = NULL;
+    char *cfg_opt = NULL;
+    int dumper_setuid;
+
+    /*
+     * Configure program for internationalization:
+     *   1) Only set the message locale for now.
+     *   2) Set textdomain for all amanda related programs to "amanda"
+     *      We don't want to be forced to support dozens of message catalogs.
+     */  
+    setlocale(LC_MESSAGES, "C");
+    textdomain("amanda"); 
+
+    /* drop root privileges */
+    dumper_setuid = set_root_privs(0);
 
     safe_fd(-1, 0);
 
     set_pname("dumper");
 
+    dbopen(DBG_SUBDIR_SERVER);
+
     /* Don't die when child closes pipe */
     signal(SIGPIPE, SIG_IGN);
 
-    malloc_size_1 = malloc_inuse(&malloc_hist_1);
+    add_amanda_log_handler(amanda_log_stderr);
+    add_amanda_log_handler(amanda_log_trace_log);
 
-    erroutput_type = (ERR_AMANDALOG|ERR_INTERACTIVE);
-    set_logerror(logerror);
+    cfg_ovr = extract_commandline_config_overrides(&argc, &argv);
+    if (argc > 1)
+       cfg_opt = argv[1];
+    set_config_overrides(cfg_ovr);
+    config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt);
 
-    if (main_argc > 1) {
-       config_name = stralloc(main_argv[1]);
-       config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
-    } else {
-       char my_cwd[STR_SIZE];
+    if (!dumper_setuid) {
+       error(_("dumper must be run setuid root"));
+    }
 
-       if (getcwd(my_cwd, sizeof(my_cwd)) == NULL) {
-           error("cannot determine current working directory");
-       }
-       config_dir = stralloc2(my_cwd, "/");
-       if ((config_name = strrchr(my_cwd, '/')) != NULL) {
-           config_name = stralloc(config_name + 1);
-       }
+    if (config_errors(NULL) >= CFGERR_ERRORS) {
+       g_critical(_("errors processing config file"));
     }
 
-    safe_cd();
+    safe_cd(); /* do this *after* config_init() */
 
-    our_features = am_init_feature_set();
-    our_feature_string = am_feature_to_string(our_features);
+    check_running_as(RUNNING_AS_ROOT | RUNNING_AS_UID_ONLY);
 
-    conffile = stralloc2(config_dir, CONFFILE_NAME);
-    if(read_conffile(conffile)) {
-       error("errors processing config file \"%s\"", conffile);
-    }
-    amfree(conffile);
+    dbrename(get_config_name(), DBG_SUBDIR_SERVER);
 
-    /*
-     * Make our effective uid nonprivlidged, but keep our real uid as root
-     * in case we need to get back (to bind privlidged ports, etc).
-     */
-    if(geteuid() == 0) {
-       uid_t ruid = getuid();
-       setuid(0);
-       seteuid(ruid);
-       setgid(getgid());
-    }
-#if defined BSD_SECURITY && !defined SSH_SECURITY
-    else error("must be run setuid root to communicate correctly");
-#endif
+    our_features = am_init_feature_set();
+    our_feature_string = am_feature_to_string(our_features);
 
-    fprintf(stderr,
-           "%s: pid %ld executable %s version %s\n",
+    log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid());
+    g_fprintf(stderr,
+           _("%s: pid %ld executable %s version %s\n"),
            get_pname(), (long) getpid(),
-           main_argv[0], version());
+           argv[0], VERSION);
     fflush(stderr);
 
     /* now, make sure we are a valid user */
 
-    if (getpwuid(getuid()) == NULL)
-       error("can't get login name for my uid %ld", (long)getuid());
-
     signal(SIGPIPE, SIG_IGN);
 
-    datestamp = construct_datestamp(NULL);
-    conf_dtimeout = getconf_int(CNF_DTIMEOUT);
+    conf_dtimeout = (time_t)getconf_int(CNF_DTIMEOUT);
 
     protocol_init();
 
     do {
-       cmd = getcmd(&cmdargs);
+       if (cmdargs)
+           free_cmdargs(cmdargs);
+       cmdargs = getcmd();
+
+       amfree(errstr);
+       switch(cmdargs->cmd) {
+       case START:
+           if(cmdargs->argc <  2)
+               error(_("error [dumper START: not enough args: timestamp]"));
+           dumper_timestamp = newstralloc(dumper_timestamp, cmdargs->argv[1]);
+           break;
+
+       case ABORT:
+           break;
 
-       switch(cmd) {
        case QUIT:
            break;
 
@@ -325,81 +419,161 @@ main(main_argc, main_argv)
             *   level
             *   dumpdate
             *   progname
+            *   amandad_path
+            *   client_username
+            *   client_port
+            *   ssh_keys
+            *   security_driver
+            *   data_path
+            *   dataport_list
             *   options
             */
-           cmdargs.argc++;                     /* true count of args */
-           a = 2;
+           a = 1; /* skip "PORT-DUMP" */
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: handle]"));
+               /*NOTREACHED*/
            }
-           handle = newstralloc(handle, cmdargs.argv[a++]);
+           handle = newstralloc(handle, cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: port]"));
+               /*NOTREACHED*/
            }
-           taper_port = atoi(cmdargs.argv[a++]);
+           header_port = (in_port_t)atoi(cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: hostname]"));
+               /*NOTREACHED*/
            }
-           hostname = newstralloc(hostname, cmdargs.argv[a++]);
+           hostname = newstralloc(hostname, cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: features]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: features]"));
+               /*NOTREACHED*/
            }
            am_release_feature_set(their_features);
-           their_features = am_string_to_feature(cmdargs.argv[a++]);
+           their_features = am_string_to_feature(cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: diskname]"));
+               /*NOTREACHED*/
            }
-           diskname = newstralloc(diskname, cmdargs.argv[a++]);
+           diskname = newstralloc(diskname, cmdargs->argv[a++]);
+           if (qdiskname != NULL)
+               amfree(qdiskname);
+           qdiskname = quote_string(diskname);
+           b64disk = amxml_format_tag("disk", diskname);
+
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: device]"));
+               /*NOTREACHED*/
+           }
+           device = newstralloc(device, cmdargs->argv[a++]);
+           b64device = amxml_format_tag("diskdevice", device);
+           if(strcmp(device,"NODEVICE") == 0)
+               amfree(device);
+
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: level]"));
+               /*NOTREACHED*/
+           }
+           level = atoi(cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: dumpdate]"));
+               /*NOTREACHED*/
            }
-           device = newstralloc(device, cmdargs.argv[a++]);
-           if(strcmp(device,"NODEVICE") == 0) amfree(device);
+           dumpdate = newstralloc(dumpdate, cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: program]"));
+               /*NOTREACHED*/
            }
-           level = atoi(cmdargs.argv[a++]);
+           progname = newstralloc(progname, cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: amandad_path]"));
+               /*NOTREACHED*/
            }
-           dumpdate = newstralloc(dumpdate, cmdargs.argv[a++]);
+           amandad_path = newstralloc(amandad_path, cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: client_username]"));
            }
-           progname = newstralloc(progname, cmdargs.argv[a++]);
+           client_username = newstralloc(client_username, cmdargs->argv[a++]);
 
-           if(a >= cmdargs.argc) {
-               error("error [dumper PORT-DUMP: not enough args: handle]");
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: client_port]"));
            }
-           options = newstralloc(options, cmdargs.argv[a++]);
+           client_port = newstralloc(client_port, cmdargs->argv[a++]);
 
-           if(a != cmdargs.argc) {
-               error("error [dumper PORT-DUMP: too many args: %d != %d]",
-                     cmdargs.argc, a);
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: ssh_keys]"));
            }
+           ssh_keys = newstralloc(ssh_keys, cmdargs->argv[a++]);
 
-           /* connect outf to taper port */
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: auth]"));
+           }
+           auth = newstralloc(auth, cmdargs->argv[a++]);
+
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: data_path]"));
+           }
+           data_path = data_path_from_string(cmdargs->argv[a++]);
+
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: dataport_list]"));
+           }
+           dataport_list = newstralloc(dataport_list, cmdargs->argv[a++]);
+
+           if(a >= cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: not enough args: options]"));
+           }
+           options = newstralloc(options, cmdargs->argv[a++]);
 
-           outfd = stream_client("localhost", taper_port,
-                                 STREAM_BUFSIZE, -1, NULL, 0);
+           if(a != cmdargs->argc) {
+               error(_("error [dumper PORT-DUMP: too many args: %d != %d]"),
+                     cmdargs->argc, a);
+               /*NOTREACHED*/
+           }
+
+           /* Double-check that 'localhost' resolves properly */
+           if ((res = resolve_hostname("localhost", 0, NULL, NULL) != 0)) {
+               errstr = newvstrallocf(errstr,
+                                    _("could not resolve localhost: %s"),
+                                    gai_strerror(res));
+               q = quote_string(errstr);
+               putresult(FAILED, "%s %s\n", handle, q);
+               log_add(L_FAIL, "%s %s %s %d [%s]", hostname, qdiskname,
+                       dumper_timestamp, level, errstr);
+               amfree(q);
+               break;
+           }
+
+           /* connect outf to chunker/taper port */
+
+           g_debug(_("Sending header to localhost:%d\n"), header_port);
+           outfd = stream_client("localhost", header_port,
+                                 STREAM_BUFSIZE, 0, NULL, 0);
            if (outfd == -1) {
-               q = squotef("[taper port open: %s]", strerror(errno));
+               
+               errstr = newvstrallocf(errstr, _("port open: %s"),
+                                     strerror(errno));
+               q = quote_string(errstr);
                putresult(FAILED, "%s %s\n", handle, q);
+               log_add(L_FAIL, "%s %s %s %d [%s]", hostname, qdiskname,
+                       dumper_timestamp, level, errstr);
                amfree(q);
                break;
            }
            databuf_init(&db, outfd);
 
-           check_options(options);
+           if (am_has_feature(their_features, fe_req_xml))
+               xml_check_options(options); /* note: modifies globals */
+           else
+               check_options(options); /* note: modifies globals */
 
            rc = startup_dump(hostname,
                              diskname,
@@ -407,28 +581,42 @@ main(main_argc, main_argv)
                              level,
                              dumpdate,
                              progname,
+                             amandad_path,
+                             client_username,
+                             client_port,
+                             ssh_keys,
+                             auth,
                              options);
            if (rc != 0) {
-               q = squote(errstr);
+               q = quote_string(errstr);
                putresult(rc == 2? FAILED : TRYAGAIN, "%s %s\n",
                    handle, q);
                if (rc == 2)
-                   log_add(L_FAIL, "%s %s %s %d [%s]", hostname, diskname,
-                       datestamp, level, errstr);
+                   log_add(L_FAIL, "%s %s %s %d [%s]", hostname, qdiskname,
+                       dumper_timestamp, level, errstr);
                amfree(q);
            } else {
-               if (do_dump(&db)) {
-               }
+               do_dump(&db);
+               /* try to clean up any defunct processes, since Amanda doesn't
+                  wait() for them explicitly */
+               while(waitpid(-1, NULL, WNOHANG)> 0);
            }
+
+           amfree(amandad_path);
+           amfree(client_username);
+           amfree(client_port);
+           amfree(device);
+           amfree(b64device);
+           amfree(qdiskname);
+           amfree(b64disk);
+
            break;
 
        default:
-           if(cmdargs.argc >= 1) {
-               q = squote(cmdargs.argv[1]);
-           } else if(cmdargs.argc >= 0) {
-               q = squote(cmdargs.argv[0]);
+           if(cmdargs->argc >= 1) {
+               q = quote_string(cmdargs->argv[0]);
            } else {
-               q = stralloc("(no input?)");
+               q = stralloc(_("(no input?)"));
            }
            putresult(BAD_COMMAND, "%s\n", q);
            amfree(q);
@@ -437,12 +625,18 @@ main(main_argc, main_argv)
 
        if (outfd != -1)
            aclose(outfd);
-    } while(cmd != QUIT);
+    } while(cmdargs->cmd != QUIT);
+    free_cmdargs(cmdargs);
+
+    log_add(L_INFO, "pid-done %ld", (long)getpid());
 
+    am_release_feature_set(our_features);
+    amfree(our_feature_string);
     amfree(errstr);
-    amfree(datestamp);
+    amfree(dumper_timestamp);
     amfree(handle);
     amfree(hostname);
+    amfree(qdiskname);
     amfree(diskname);
     amfree(device);
     amfree(dumpdate);
@@ -454,15 +648,9 @@ main(main_argc, main_argv)
     amfree(srv_decrypt_opt);
     amfree(clnt_decrypt_opt);
     amfree(options);
-    amfree(config_dir);
-    amfree(config_name);
-
-    malloc_size_2 = malloc_inuse(&malloc_hist_2);
 
-    if (malloc_size_1 != malloc_size_2)
-       malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
-
-    exit(0);
+    dbclose();
+    return (0); /* exit */
 }
 
 
@@ -470,9 +658,9 @@ main(main_argc, main_argv)
  * Initialize a databuf.  Takes a writeable file descriptor.
  */
 static void
-databuf_init(db, fd)
-    struct databuf *db;
-    int fd;
+databuf_init(
+    struct databuf *   db,
+    int                        fd)
 {
 
     db->fd = fd;
@@ -489,10 +677,10 @@ databuf_init(db, fd)
  * any boundaries.
  */
 static int
-databuf_write(db, buf, size)
-    struct databuf *db;
-    const void *buf;
-    int size;
+databuf_write(
+    struct databuf *   db,
+    const void *       buf,
+    size_t             size)
 {
     db->buf = (char *)buf;
     db->datain = db->datalimit = db->buf + size;
@@ -504,10 +692,11 @@ databuf_write(db, buf, size)
  * Write out the buffer to chunker.
  */
 static int
-databuf_flush(db)
-    struct databuf *db;
+databuf_flush(
+    struct databuf *   db)
 {
-    int written;
+    size_t written;
+    char *m;
 
     /*
      * If there's no data, do nothing.
@@ -519,17 +708,23 @@ databuf_flush(db)
     /*
      * Write out the buffer
      */
-    written = fullwrite(db->fd, db->dataout, db->datain - db->dataout);
+    written = full_write(db->fd, db->dataout,
+                       (size_t)(db->datain - db->dataout));
     if (written > 0) {
        db->dataout += written;
-        dumpbytes += written;
+        dumpbytes += (off_t)written;
     }
-    if (dumpbytes >= 1024) {
-       dumpsize += (dumpbytes / 1024);
-       dumpbytes %= 1024;
+    if (dumpbytes >= (off_t)1024) {
+       dumpsize += (dumpbytes / (off_t)1024);
+       dumpbytes %= (off_t)1024;
     }
-    if (written < 0) {
-       errstr = squotef("data write: %s", strerror(errno));
+    if (written == 0) {
+       int save_errno = errno;
+       m = vstrallocf(_("data write: %s"), strerror(save_errno));
+       amfree(errstr);
+       errstr = quote_string(m);
+       amfree(m);
+       errno = save_errno;
        return -1;
     }
     db->datain = db->dataout = db->buf;
@@ -545,27 +740,27 @@ static int status;
 
 
 static void
-process_dumpeof()
+process_dumpeof(void)
 {
     /* process any partial line in msgbuf? !!! */
     add_msg_data(NULL, 0);
     if(!ISSET(status, GOT_SIZELINE) && dump_result < 2) {
        /* make a note if there isn't already a failure */
-       fprintf(errf,
-               "? %s: strange [missing size line from sendbackup]\n",
+       g_fprintf(errf,
+               _("? %s: strange [missing size line from sendbackup]\n"),
                get_pname());
        if(errstr == NULL) {
-           errstr = stralloc("missing size line from sendbackup");
+           errstr = stralloc(_("missing size line from sendbackup"));
        }
        dump_result = max(dump_result, 2);
     }
 
     if(!ISSET(status, GOT_ENDLINE) && dump_result < 2) {
-       fprintf(errf,
-               "? %s: strange [missing end line from sendbackup]\n",
+       g_fprintf(errf,
+               _("? %s: strange [missing end line from sendbackup]\n"),
                get_pname());
        if(errstr == NULL) {
-           errstr = stralloc("missing end line from sendbackup");
+           errstr = stralloc(_("missing end line from sendbackup"));
        }
        dump_result = max(dump_result, 2);
     }
@@ -577,26 +772,27 @@ process_dumpeof()
  * of any duplicates.
  */
 static void
-parse_info_line(str)
-    char *str;
+parse_info_line(
+    char *str)
 {
     static const struct {
        const char *name;
        char *value;
        size_t len;
     } fields[] = {
-       { "BACKUP", file.program, sizeof(file.program) },
-       { "RECOVER_CMD", file.recover_cmd, sizeof(file.recover_cmd) },
-       { "COMPRESS_SUFFIX", file.comp_suffix, sizeof(file.comp_suffix) },
-       { "SERVER_CUSTOM_COMPRESS", file.srvcompprog, sizeof(file.srvcompprog) },
-       { "CLIENT_CUSTOM_COMPRESS", file.clntcompprog, sizeof(file.clntcompprog) },
-       { "SERVER_ENCRYPT", file.srv_encrypt, sizeof(file.srv_encrypt) },
-       { "CLIENT_ENCRYPT", file.clnt_encrypt, sizeof(file.clnt_encrypt) },
-       { "SERVER_DECRYPT_OPTION", file.srv_decrypt_opt, sizeof(file.srv_decrypt_opt) },
-       { "CLIENT_DECRYPT_OPTION", file.clnt_decrypt_opt, sizeof(file.clnt_decrypt_opt) }
+       { "BACKUP", file.program, SIZEOF(file.program) },
+       { "APPLICATION", file.application, SIZEOF(file.application) },
+       { "RECOVER_CMD", file.recover_cmd, SIZEOF(file.recover_cmd) },
+       { "COMPRESS_SUFFIX", file.comp_suffix, SIZEOF(file.comp_suffix) },
+       { "SERVER_CUSTOM_COMPRESS", file.srvcompprog, SIZEOF(file.srvcompprog) },
+       { "CLIENT_CUSTOM_COMPRESS", file.clntcompprog, SIZEOF(file.clntcompprog) },
+       { "SERVER_ENCRYPT", file.srv_encrypt, SIZEOF(file.srv_encrypt) },
+       { "CLIENT_ENCRYPT", file.clnt_encrypt, SIZEOF(file.clnt_encrypt) },
+       { "SERVER_DECRYPT_OPTION", file.srv_decrypt_opt, SIZEOF(file.srv_decrypt_opt) },
+       { "CLIENT_DECRYPT_OPTION", file.clnt_decrypt_opt, SIZEOF(file.clnt_decrypt_opt) }
     };
     char *name, *value;
-    int i;
+    size_t i;
 
     if (strcmp(str, "end") == 0) {
        SET(status, GOT_INFO_ENDLINE);
@@ -610,7 +806,7 @@ parse_info_line(str)
     if (value == NULL)
        return;
 
-    for (i = 0; i < sizeof(fields) / sizeof(fields[0]); i++) {
+    for (i = 0; i < SIZEOF(fields) / SIZEOF(fields[0]); i++) {
        if (strcmp(name, fields[i].name) == 0) {
            strncpy(fields[i].value, value, fields[i].len - 1);
            fields[i].value[fields[i].len - 1] = '\0';
@@ -620,8 +816,8 @@ parse_info_line(str)
 }
 
 static void
-process_dumpline(str)
-    const char *str;
+process_dumpline(
+    const char *       str)
 {
     char *buf, *tok;
 
@@ -645,18 +841,24 @@ process_dumpline(str)
        if (tok == NULL)
            goto bad_line;
 
-       if (strcmp(tok, "start") == 0)
+       if (strcmp(tok, "start") == 0) {
            break;
+       }
 
        if (strcmp(tok, "size") == 0) {
            tok = strtok(NULL, "");
            if (tok != NULL) {
-               origsize = (long)atof(tok);
+               origsize = OFF_T_ATOI(tok);
                SET(status, GOT_SIZELINE);
            }
            break;
        }
 
+       if (strcmp(tok, "no-op") == 0) {
+           amfree(buf);
+           return;
+       }
+
        if (strcmp(tok, "end") == 0) {
            SET(status, GOT_ENDLINE);
            break;
@@ -672,15 +874,18 @@ process_dumpline(str)
            dump_result = max(dump_result, 2);
 
            tok = strtok(NULL, "");
-           if (tok == NULL || *tok != '[') {
-               errstr = newvstralloc(errstr, "bad remote error: ", str, NULL);
-           } else {
-               char *enderr;
-
-               tok++;  /* skip over '[' */
-               if ((enderr = strchr(tok, ']')) != NULL)
-                   *enderr = '\0';
-               errstr = newstralloc(errstr, tok);
+           if (!errstr) { /* report first error line */
+               if (tok == NULL || *tok != '[') {
+                   errstr = newvstrallocf(errstr, _("bad remote error: %s"),
+                                          str);
+               } else {
+                   char *enderr;
+
+                   tok++;      /* skip over '[' */
+                   if ((enderr = strchr(tok, ']')) != NULL)
+                       *enderr = '\0';
+                   errstr = newstralloc(errstr, tok);
+               }
            }
            break;
        }
@@ -695,24 +900,20 @@ process_dumpline(str)
     default:
 bad_line:
        /* prefix with ?? */
-       fprintf(errf, "??");
+       g_fprintf(errf, "??");
        dump_result = max(dump_result, 1);
        break;
     }
-    fprintf(errf, "%s\n", str);
+    g_fprintf(errf, "%s\n", str);
     amfree(buf);
 }
 
 static void
-add_msg_data(str, len)
-    const char *str;
-    size_t len;
+add_msg_data(
+    const char *       str,
+    size_t             len)
 {
-    static struct {
-       char *buf;      /* buffer holding msg data */
-       size_t size;    /* size of alloced buffer */
-    } msg = { NULL, 0 };
-    char *line, *nl;
+    char *line, *ch;
     size_t buflen;
 
     if (msg.buf != NULL)
@@ -727,9 +928,9 @@ add_msg_data(str, len)
     if (str == NULL) {
        if (buflen == 0)
            return;
-       fprintf(errf,"? %s: error [partial line in msgbuf: %ld bytes]\n",
-           get_pname(), (long)buflen);
-       fprintf(errf,"? %s: error [partial line in msgbuf: \"%s\"]\n",
+       g_fprintf(errf,_("? %s: error [partial line in msgbuf: %zu bytes]\n"),
+           get_pname(), buflen);
+       g_fprintf(errf,_("? %s: error [partial line in msgbuf: \"%s\"]\n"),
            get_pname(), msg.buf);
        msg.buf[0] = '\0';
        return;
@@ -738,18 +939,18 @@ add_msg_data(str, len)
     /*
      * Expand the buffer if it can't hold the new contents.
      */
-    if (buflen + len + 1 > msg.size) {
+    if ((buflen + len + 1) > msg.size) {
        char *newbuf;
        size_t newsize;
 
 /* round up to next y, where y is a power of 2 */
 #define        ROUND(x, y)     (((x) + (y) - 1) & ~((y) - 1))
 
-       newsize = ROUND(buflen + len + 1, 256);
+       newsize = ROUND(buflen + (ssize_t)len + 1, 256);
        newbuf = alloc(newsize);
 
        if (msg.buf != NULL) {
-           strcpy(newbuf, msg.buf);
+           strncpy(newbuf, msg.buf, newsize);
            amfree(msg.buf);
        } else
            newbuf[0] = '\0';
@@ -765,17 +966,17 @@ add_msg_data(str, len)
 
     /*
      * Process all lines in the buffer
+     * scanning line for unqouted newline.
      */
-    for (line = msg.buf;;) {
-       /*
-        * If there's no newline, then we've only got a partial line.
-        * We go back for more.
-        */
-       if ((nl = strchr(line, '\n')) == NULL)
-           break;
-       *nl = '\0';
-       process_dumpline(line);
-       line = nl + 1;
+    for (ch = line = msg.buf; *ch != '\0'; ch++) {
+       if (*ch == '\n') {
+           /*
+            * Found a newline.  Terminate and process line.
+            */
+           *ch = '\0';
+           process_dumpline(line);
+           line = ch + 1;
+       }
     }
 
     /*
@@ -784,7 +985,7 @@ add_msg_data(str, len)
      */
     if (*line != '\0') {
        buflen = strlen(line);
-       memmove(msg.buf, line, buflen + 1);
+       memmove(msg.buf, line, (size_t)buflen + 1);
     } else {
        msg.buf[0] = '\0';
     }
@@ -792,15 +993,19 @@ add_msg_data(str, len)
 
 
 static void
-log_msgout(typ)
-    logtype_t typ;
+log_msgout(
+    logtype_t  typ)
 {
     char *line;
 
     fflush(errf);
-    (void) fseek(errf, 0L, SEEK_SET);
+    if (fseeko(errf, 0L, SEEK_SET) < 0) {
+       dbprintf(_("log_msgout: warning - seek failed: %s\n"), strerror(errno));
+    }
     while ((line = agets(errf)) != NULL) {
-       log_add(typ, "%s", line);
+       if (line[0] != '\0') {
+               log_add(typ, "%s", line);
+       }
        amfree(line);
     }
 
@@ -813,17 +1018,18 @@ log_msgout(typ)
  * Fill in the rest of the tape header
  */
 static void
-finish_tapeheader(file)
-    dumpfile_t *file;
+finish_tapeheader(
+    dumpfile_t *file)
 {
 
     assert(ISSET(status, HEADER_DONE));
 
     file->type = F_DUMPFILE;
-    strncpy(file->datestamp, datestamp, sizeof(file->datestamp) - 1);
-    strncpy(file->name, hostname, sizeof(file->name) - 1);
-    strncpy(file->disk, diskname, sizeof(file->disk) - 1);
+    strncpy(file->datestamp, dumper_timestamp, sizeof(file->datestamp) - 1);
+    strncpy(file->name, hostname, SIZEOF(file->name) - 1);
+    strncpy(file->disk, diskname, SIZEOF(file->disk) - 1);
     file->dumplevel = level;
+    file->blocksize = DISK_BLOCK_BYTES;
 
     /*
      * If we're doing the compression here, we need to override what
@@ -834,29 +1040,32 @@ finish_tapeheader(file)
 #ifndef UNCOMPRESS_OPT
 #define        UNCOMPRESS_OPT  ""
 #endif
-       if (srvcompress == COMP_SERV_CUST) {
-           snprintf(file->uncompress_cmd, sizeof(file->uncompress_cmd),
+       if (srvcompress == COMP_SERVER_CUST) {
+           g_snprintf(file->uncompress_cmd, SIZEOF(file->uncompress_cmd),
                     " %s %s |", srvcompprog, "-d");
-           strcpy(file->comp_suffix, "cust");
-           strncpy(file->srvcompprog, srvcompprog, sizeof(file->srvcompprog));
-           file->srvcompprog[sizeof(file->srvcompprog)-1] = '\0';
+           strncpy(file->comp_suffix, "cust", SIZEOF(file->comp_suffix) - 1);
+           file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
+           strncpy(file->srvcompprog, srvcompprog, SIZEOF(file->srvcompprog) - 1);
+           file->srvcompprog[SIZEOF(file->srvcompprog) - 1] = '\0';
        } else if ( srvcompress == COMP_CUST ) {
-           snprintf(file->uncompress_cmd, sizeof(file->uncompress_cmd),
+           g_snprintf(file->uncompress_cmd, SIZEOF(file->uncompress_cmd),
                     " %s %s |", clntcompprog, "-d");
-           strcpy(file->comp_suffix, "cust");
-           strncpy(file->clntcompprog, clntcompprog, sizeof(file->clntcompprog));
-           file->clntcompprog[sizeof(file->clntcompprog)-1] = '\0';
+           strncpy(file->comp_suffix, "cust", SIZEOF(file->comp_suffix) - 1);
+           file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
+           strncpy(file->clntcompprog, clntcompprog, SIZEOF(file->clntcompprog));
+           file->clntcompprog[SIZEOF(file->clntcompprog) - 1] = '\0';
        } else {
-           snprintf(file->uncompress_cmd, sizeof(file->uncompress_cmd),
+           g_snprintf(file->uncompress_cmd, SIZEOF(file->uncompress_cmd),
                " %s %s |", UNCOMPRESS_PATH, UNCOMPRESS_OPT);
-           strncpy(file->comp_suffix, COMPRESS_SUFFIX,sizeof(file->comp_suffix)-1);
-           file->comp_suffix[sizeof(file->comp_suffix)-1] = '\0';
+           strncpy(file->comp_suffix, COMPRESS_SUFFIX,SIZEOF(file->comp_suffix) - 1);
+           file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
        }
     } else {
        if (file->comp_suffix[0] == '\0') {
            file->compressed = 0;
-           assert(sizeof(file->comp_suffix) >= 2);
-           strcpy(file->comp_suffix, "N");
+           assert(SIZEOF(file->comp_suffix) >= 2);
+           strncpy(file->comp_suffix, "N", SIZEOF(file->comp_suffix) - 1);
+           file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
        } else {
            file->compressed = 1;
        }
@@ -865,56 +1074,85 @@ finish_tapeheader(file)
     if (srvencrypt != ENCRYPT_NONE) {
       file->encrypted= 1;
       if (srvencrypt == ENCRYPT_SERV_CUST) {
-       snprintf(file->decrypt_cmd, sizeof(file->decrypt_cmd),
-                " %s %s |", srv_encrypt, srv_decrypt_opt); 
-       strcpy(file->encrypt_suffix, "enc");
-       strncpy(file->srv_encrypt, srv_encrypt, sizeof(file->srv_encrypt));
-       file->srv_encrypt[sizeof(file->srv_encrypt)-1] = '\0';
-       strncpy(file->srv_decrypt_opt, srv_decrypt_opt, sizeof(file->srv_decrypt_opt));
-       file->srv_decrypt_opt[sizeof(file->srv_decrypt_opt)-1] = '\0';
+       if (srv_decrypt_opt) {
+         g_snprintf(file->decrypt_cmd, SIZEOF(file->decrypt_cmd),
+                  " %s %s |", srv_encrypt, srv_decrypt_opt); 
+         strncpy(file->srv_decrypt_opt, srv_decrypt_opt, SIZEOF(file->srv_decrypt_opt) - 1);
+         file->srv_decrypt_opt[SIZEOF(file->srv_decrypt_opt) - 1] = '\0';
+       } else {
+         g_snprintf(file->decrypt_cmd, SIZEOF(file->decrypt_cmd),
+                  " %s |", srv_encrypt); 
+         file->srv_decrypt_opt[0] = '\0';
+       }
+       strncpy(file->encrypt_suffix, "enc", SIZEOF(file->encrypt_suffix) - 1);
+       file->encrypt_suffix[SIZEOF(file->encrypt_suffix) - 1] = '\0';
+       strncpy(file->srv_encrypt, srv_encrypt, SIZEOF(file->srv_encrypt) - 1);
+       file->srv_encrypt[SIZEOF(file->srv_encrypt) - 1] = '\0';
       } else if ( srvencrypt == ENCRYPT_CUST ) {
-       snprintf(file->decrypt_cmd, sizeof(file->decrypt_cmd),
+       if (clnt_decrypt_opt) {
+         g_snprintf(file->decrypt_cmd, SIZEOF(file->decrypt_cmd),
+                  " %s %s |", clnt_encrypt, clnt_decrypt_opt);
+         strncpy(file->clnt_decrypt_opt, clnt_decrypt_opt,
+                 SIZEOF(file->clnt_decrypt_opt));
+         file->clnt_decrypt_opt[SIZEOF(file->clnt_decrypt_opt) - 1] = '\0';
+       } else {
+         g_snprintf(file->decrypt_cmd, SIZEOF(file->decrypt_cmd),
+                  " %s |", clnt_encrypt);
+         file->clnt_decrypt_opt[0] = '\0';
+       }
+       g_snprintf(file->decrypt_cmd, SIZEOF(file->decrypt_cmd),
                 " %s %s |", clnt_encrypt, clnt_decrypt_opt);
-       strcpy(file->encrypt_suffix, "enc");
-       strncpy(file->clnt_encrypt, clnt_encrypt, sizeof(file->clnt_encrypt));
-       file->clnt_encrypt[sizeof(file->clnt_encrypt)-1] = '\0';
-       strncpy(file->clnt_decrypt_opt, clnt_decrypt_opt, sizeof(file->clnt_decrypt_opt));
-       file->clnt_decrypt_opt[sizeof(file->clnt_decrypt_opt)-1] = '\0';
+       strncpy(file->encrypt_suffix, "enc", SIZEOF(file->encrypt_suffix) - 1);
+       file->encrypt_suffix[SIZEOF(file->encrypt_suffix) - 1] = '\0';
+       strncpy(file->clnt_encrypt, clnt_encrypt, SIZEOF(file->clnt_encrypt) - 1);
+       file->clnt_encrypt[SIZEOF(file->clnt_encrypt) - 1] = '\0';
       }
     } else {
       if (file->encrypt_suffix[0] == '\0') {
        file->encrypted = 0;
-       assert(sizeof(file->encrypt_suffix) >= 2);
-       strcpy(file->encrypt_suffix, "N");
+       assert(SIZEOF(file->encrypt_suffix) >= 2);
+       strncpy(file->encrypt_suffix, "N", SIZEOF(file->encrypt_suffix) - 1);
+       file->encrypt_suffix[SIZEOF(file->encrypt_suffix) - 1] = '\0';
       } else {
        file->encrypted= 1;
       }
     }
+    if (dle_str)
+       file->dle_str = stralloc(dle_str);
+    else
+       file->dle_str = NULL;
 }
 
 /*
  * Send an Amanda dump header to the output file.
  */
-static int
-write_tapeheader(outfd, file)
-    int outfd;
-    dumpfile_t *file;
+static ssize_t
+write_tapeheader(
+    int                outfd,
+    dumpfile_t *file)
 {
-    char buffer[DISK_BLOCK_BYTES];
-    int written;
+    char * buffer;
+    size_t written;
+
+    if (debug_dumper > 1)
+       dump_dumpfile_t(file);
+    buffer = build_header(file, NULL, DISK_BLOCK_BYTES);
+    if (!buffer) /* this shouldn't happen */
+       error(_("header does not fit in %zd bytes"), (size_t)DISK_BLOCK_BYTES);
 
-    build_header(buffer, file, sizeof(buffer));
+    written = full_write(outfd, buffer, DISK_BLOCK_BYTES);
+    amfree(buffer);
+    if(written == DISK_BLOCK_BYTES)
+        return 0;
 
-    written = write(outfd, buffer, sizeof(buffer));
-    if(written == sizeof(buffer)) return 0;
-    if(written < 0) return written;
-    errno = ENOSPC;
     return -1;
 }
 
+int indexout = -1;
+
 static int
-do_dump(db)
-    struct databuf *db;
+do_dump(
+    struct databuf *db)
 {
     char *indexfile_tmp = NULL;
     char *indexfile_real = NULL;
@@ -924,16 +1162,18 @@ do_dump(db)
     times_t runtime;
     double dumptime;   /* Time dump took in secs */
     char *errfname = NULL;
-    int indexout;
     pid_t indexpid = -1;
+    char *m;
 
     startclock();
 
-    dumpbytes = dumpsize = headersize = origsize = dump_result = 0;
+    if (msg.buf) msg.buf[0] = '\0';    /* reset msg buffer */
     status = 0;
+    dump_result = 0;
+    dumpbytes = dumpsize = headersize = origsize = (off_t)0;
     fh_init(&file);
 
-    snprintf(level_str, sizeof(level_str), "%d", level);
+    g_snprintf(level_str, SIZEOF(level_str), "%d", level);
     fn = sanitise_filename(diskname);
     errfname = newvstralloc(errfname,
                            AMANDA_TMPDIR,
@@ -944,10 +1184,8 @@ do_dump(db)
                            NULL);
     amfree(fn);
     if((errf = fopen(errfname, "w+")) == NULL) {
-       errstr = newvstralloc(errstr,
-                             "errfile open \"", errfname, "\": ",
-                             strerror(errno),
-                             NULL);
+       errstr = newvstrallocf(errstr, "errfile open \"%s\": %s",
+                             errfname, strerror(errno));
        amfree(errfname);
        goto failed;
     }
@@ -955,27 +1193,25 @@ do_dump(db)
     amfree(errfname);
 
     if (streams[INDEXFD].fd != NULL) {
-       indexfile_real = getindexfname(hostname, diskname, datestamp, level);
+       indexfile_real = getindexfname(hostname, diskname, dumper_timestamp, level);
        indexfile_tmp = stralloc2(indexfile_real, ".tmp");
 
-       if (mkpdir(indexfile_tmp, 02755, (uid_t)-1, (gid_t)-1) == -1) {
-          errstr = newvstralloc(errstr,
-                                "err create ",
+       if (mkpdir(indexfile_tmp, 0755, (uid_t)-1, (gid_t)-1) == -1) {
+          errstr = newvstrallocf(errstr,
+                                _("err create %s: %s"),
                                 indexfile_tmp,
-                                ": ",
-                                strerror(errno),
-                                NULL);
+                                strerror(errno));
           amfree(indexfile_real);
           amfree(indexfile_tmp);
           goto failed;
        }
        indexout = open(indexfile_tmp, O_WRONLY | O_CREAT | O_TRUNC, 0600);
        if (indexout == -1) {
-           errstr = newvstralloc(errstr, "err open ", indexfile_tmp, ": ",
-               strerror(errno), NULL);
+           errstr = newvstrallocf(errstr, _("err open %s: %s"),
+                       indexfile_tmp, strerror(errno));
            goto failed;
        } else {
-           if (runcompress(indexout, &indexpid, COMP_BEST) < 0) {
+           if (runcompress(indexout, &indexpid, COMP_BEST, "index compress") < 0) {
                aclose(indexout);
                goto failed;
            }
@@ -992,6 +1228,7 @@ do_dump(db)
      * the header, we will start processing data too.
      */
     security_stream_read(streams[MESGFD].fd, read_mesgfd, db);
+    set_datafd = 0;
 
     /*
      * Setup a read timeout
@@ -1004,34 +1241,63 @@ do_dump(db)
      */
     event_loop(0);
 
+    if (!ISSET(status, HEADER_DONE)) {
+       dump_result = max(dump_result, 2);
+       if (!errstr) errstr = stralloc(_("got no header information"));
+    }
+
+    dumpsize -= headersize;            /* don't count the header */
+    if (dumpsize <= (off_t)0 && data_path == DATA_PATH_AMANDA) {
+       dumpsize = (off_t)0;
+       dump_result = max(dump_result, 2);
+       if (!errstr) errstr = stralloc(_("got no data"));
+    }
+
+    if (data_path == DATA_PATH_DIRECTTCP) {
+       dumpsize = origsize;
+    }
+
+    if (!ISSET(status, HEADER_DONE)) {
+       dump_result = max(dump_result, 2);
+       if (!errstr) errstr = stralloc(_("got no header information"));
+    }
+
+    if (dumpsize == 0 && data_path == DATA_PATH_AMANDA) {
+       dump_result = max(dump_result, 2);
+       if (!errstr) errstr = stralloc(_("got no data"));
+    }
+
     if (dump_result > 1)
        goto failed;
 
     runtime = stopclock();
-    dumptime = runtime.r.tv_sec + runtime.r.tv_usec/1000000.0;
-
-    dumpsize -= headersize;            /* don't count the header */
-    if (dumpsize < 0) dumpsize = 0;    /* XXX - maybe this should be fatal? */
+    dumptime = g_timeval_to_double(runtime);
 
     amfree(errstr);
     errstr = alloc(128);
-    snprintf(errstr, 128, "sec %s kb %ld kps %3.1f orig-kb %ld",
-       walltime_str(runtime), dumpsize,
-       dumptime ? dumpsize / dumptime : 0.0, origsize);
-    q = squotef("[%s]", errstr);
-    putresult(DONE, "%s %ld %ld %ld %s\n", handle, origsize, dumpsize,
-             (long)(dumptime+0.5), q);
+    g_snprintf(errstr, 128, _("sec %s kb %lld kps %3.1lf orig-kb %lld"),
+       walltime_str(runtime),
+       (long long)dumpsize,
+       (isnormal(dumptime) ? ((double)dumpsize / (double)dumptime) : 0.0),
+       (long long)origsize);
+    m = vstrallocf("[%s]", errstr);
+    q = quote_string(m);
+    amfree(m);
+    putresult(DONE, _("%s %lld %lld %lu %s\n"), handle,
+               (long long)origsize,
+               (long long)dumpsize,
+               (unsigned long)((double)dumptime+0.5), q);
     amfree(q);
 
     switch(dump_result) {
     case 0:
-       log_add(L_SUCCESS, "%s %s %s %d [%s]", hostname, diskname, datestamp, level, errstr);
+       log_add(L_SUCCESS, "%s %s %s %d [%s]", hostname, qdiskname, dumper_timestamp, level, errstr);
 
        break;
 
     case 1:
        log_start_multiline();
-       log_add(L_STRANGE, "%s %s %d [%s]", hostname, diskname, level, errstr);
+       log_add(L_STRANGE, "%s %s %d [%s]", hostname, qdiskname, level, errstr);
        log_msgout(L_STRANGE);
        log_end_multiline();
 
@@ -1040,14 +1306,17 @@ do_dump(db)
 
     if (errf) afclose(errf);
 
-    aclose(db->fd);
+    if (data_path == DATA_PATH_AMANDA)
+       aclose(db->fd);
+
     if (indexfile_tmp) {
        amwait_t index_status;
 
-       aclose(indexout);
+       /*@i@*/ aclose(indexout);
        waitpid(indexpid,&index_status,0);
+       log_add(L_INFO, "pid-done %ld", (long)indexpid);
        if (rename(indexfile_tmp, indexfile_real) != 0) {
-           log_add(L_WARNING, "could not rename \"%s\" to \"%s\": %s",
+           log_add(L_WARNING, _("could not rename \"%s\" to \"%s\": %s"),
                    indexfile_tmp, indexfile_real, strerror(errno));
        }
        amfree(indexfile_tmp);
@@ -1056,60 +1325,77 @@ do_dump(db)
 
     if(db->compresspid != -1) {
        waitpid(db->compresspid,NULL,0);
+       log_add(L_INFO, "pid-done %ld", (long)db->compresspid);
     }
     if(db->encryptpid != -1) {
        waitpid(db->encryptpid,NULL,0);
+       log_add(L_INFO, "pid-done %ld", (long)db->encryptpid);
     }
 
     amfree(errstr);
+    dumpfile_free_data(&file);
 
     return 1;
 
 failed:
-    q = squotef("[%s]", errstr);
+    m = vstrallocf("[%s]", errstr);
+    q = quote_string(m);
     putresult(FAILED, "%s %s\n", handle, q);
     amfree(q);
+    amfree(m);
 
     aclose(db->fd);
     /* kill all child process */
     if (db->compresspid != -1) {
-       fprintf(stderr,"%s: kill compress command\n",get_pname());
+       g_fprintf(stderr,_("%s: kill compress command\n"),get_pname());
        if (kill(db->compresspid, SIGTERM) < 0) {
-           if (errno != ESRCH)
-               fprintf(stderr,"%s: can't kill compress command: %s\n"
+           if (errno != ESRCH) {
+               g_fprintf(stderr,_("%s: can't kill compress command: %s\n")
                    get_pname(), strerror(errno));
+           } else {
+               log_add(L_INFO, "pid-done %ld", (long)db->compresspid);
+           }
        }
        else {
            waitpid(db->compresspid,NULL,0);
+           log_add(L_INFO, "pid-done %ld", (long)db->compresspid);
        }
     }
 
     if (db->encryptpid != -1) {
-       fprintf(stderr,"%s: kill encrypt command\n",get_pname());
+       g_fprintf(stderr,_("%s: kill encrypt command\n"),get_pname());
        if (kill(db->encryptpid, SIGTERM) < 0) {
-           if (errno != ESRCH)
-               fprintf(stderr,"%s: can't kill encrypt command: %s\n"
+           if (errno != ESRCH) {
+               g_fprintf(stderr,_("%s: can't kill encrypt command: %s\n")
                    get_pname(), strerror(errno));
+           } else {
+               log_add(L_INFO, "pid-done %ld", (long)db->encryptpid);
+           }
        }
        else {
            waitpid(db->encryptpid,NULL,0);
+           log_add(L_INFO, "pid-done %ld", (long)db->encryptpid);
        }
     }
 
     if (indexpid != -1) {
-       fprintf(stderr,"%s: kill index command\n",get_pname());
+       g_fprintf(stderr,_("%s: kill index command\n"),get_pname());
        if (kill(indexpid, SIGTERM) < 0) {
-           if (errno != ESRCH)
-               fprintf(stderr,"%s: can't kill index command: %s\n"
+           if (errno != ESRCH) {
+               g_fprintf(stderr,_("%s: can't kill index command: %s\n")
                    get_pname(),strerror(errno));
+           } else {
+               log_add(L_INFO, "pid-done %ld", (long)indexpid);
+           }
        }
        else {
            waitpid(indexpid,NULL,0);
+           log_add(L_INFO, "pid-done %ld", (long)indexpid);
        }
     }
 
     log_start_multiline();
-    log_add(L_FAIL, "%s %s %s %d [%s]", hostname, diskname, datestamp,
+    log_add(L_FAIL, _("%s %s %s %d [%s]"), hostname, qdiskname, dumper_timestamp,
            level, errstr);
     if (errf) {
        log_msgout(L_FAIL);
@@ -1131,9 +1417,10 @@ failed:
  * Callback for reads on the mesgfd stream
  */
 static void
-read_mesgfd(cookie, buf, size)
-    void *cookie, *buf;
-    ssize_t size;
+read_mesgfd(
+    void *     cookie,
+    void *     buf,
+    ssize_t    size)
 {
     struct databuf *db = cookie;
 
@@ -1141,11 +1428,12 @@ read_mesgfd(cookie, buf, size)
 
     switch (size) {
     case -1:
-       errstr = newstralloc2(errstr, "mesg read: ",
+       errstr = newvstrallocf(errstr, _("mesg read: %s"),
            security_stream_geterror(streams[MESGFD].fd));
        dump_result = 2;
        stop_dump();
        return;
+
     case 0:
        /*
         * EOF.  Just shut down the mesg stream.
@@ -1156,34 +1444,56 @@ read_mesgfd(cookie, buf, size)
        /*
         * If the data fd and index fd has also shut down, then we're done.
         */
-       if (streams[DATAFD].fd == NULL && streams[INDEXFD].fd == NULL)
+       if ((set_datafd == 0 || streams[DATAFD].fd == NULL) && 
+           streams[INDEXFD].fd == NULL)
            stop_dump();
        return;
+
     default:
        assert(buf != NULL);
-       add_msg_data(buf, size);
+       add_msg_data(buf, (size_t)size);
        security_stream_read(streams[MESGFD].fd, read_mesgfd, cookie);
        break;
     }
 
-    /*
-     * Reset the timeout for future reads
-     */
-    timeout(conf_dtimeout);
-
     if (ISSET(status, GOT_INFO_ENDLINE) && !ISSET(status, HEADER_DONE)) {
+       /* Use the first in the dataport_list */
+       in_port_t data_port;
+       char *data_host = dataport_list;
+       char *s= strchr(dataport_list, ':');
+       *s = '\0';
+       s++;
+       data_port = atoi(s);
+
        SET(status, HEADER_DONE);
        /* time to do the header */
        finish_tapeheader(&file);
        if (write_tapeheader(db->fd, &file)) {
-           errstr = newstralloc2(errstr, "write_tapeheader: "
+           errstr = newvstrallocf(errstr, _("write_tapeheader: %s")
                                  strerror(errno));
            dump_result = 2;
            stop_dump();
+           dumpfile_free_data(&file);
            return;
        }
-       dumpsize += DISK_BLOCK_KB;
-       headersize += DISK_BLOCK_KB;
+       dumpfile_free_data(&file);
+       aclose(db->fd);
+       if (data_path == DATA_PATH_AMANDA) {
+           g_debug(_("Sending data to %s:%d\n"), data_host, data_port);
+           db->fd = stream_client(data_host, data_port,
+                                  STREAM_BUFSIZE, 0, NULL, 0);
+           if (db->fd == -1) {
+               errstr = newvstrallocf(errstr,
+                                      _("Can't opendata output stream: %s"),
+                                      strerror(errno));
+               dump_result = 2;
+               stop_dump();
+               return;
+           }
+       }
+
+       dumpsize += (off_t)DISK_BLOCK_KB;
+       headersize += (off_t)DISK_BLOCK_KB;
 
        if (srvencrypt == ENCRYPT_SERV_CUST) {
            if (runencrypt(db->fd, &db->encryptpid, srvencrypt) < 0) {
@@ -1197,23 +1507,30 @@ read_mesgfd(cookie, buf, size)
         * reading the datafd.
         */
        if ((srvcompress != COMP_NONE) && (srvcompress != COMP_CUST)) {
-           if (runcompress(db->fd, &db->compresspid, srvcompress) < 0) {
+           if (runcompress(db->fd, &db->compresspid, srvcompress, "data compress") < 0) {
                dump_result = 2;
                stop_dump();
                return;
            }
        }
        security_stream_read(streams[DATAFD].fd, read_datafd, db);
+       set_datafd = 1;
     }
+
+    /*
+     * Reset the timeout for future reads
+     */
+    timeout(conf_dtimeout);
 }
 
 /*
  * Callback for reads on the datafd stream
  */
 static void
-read_datafd(cookie, buf, size)
-    void *cookie, *buf;
-    ssize_t size;
+read_datafd(
+    void *     cookie,
+    void *     buf,
+    ssize_t    size)
 {
     struct databuf *db = cookie;
 
@@ -1223,18 +1540,14 @@ read_datafd(cookie, buf, size)
      * The read failed.  Error out
      */
     if (size < 0) {
-       errstr = newstralloc2(errstr, "data read: ",
+       errstr = newvstrallocf(errstr, _("data read: %s"),
            security_stream_geterror(streams[DATAFD].fd));
        dump_result = 2;
+       aclose(db->fd);
        stop_dump();
        return;
     }
 
-    /*
-     * Reset the timeout for future reads
-     */
-    timeout(conf_dtimeout);
-
     /* The header had better be written at this point */
     assert(ISSET(status, HEADER_DONE));
 
@@ -1243,11 +1556,12 @@ read_datafd(cookie, buf, size)
      */
     if (size == 0) {
        databuf_flush(db);
-       if (dumpbytes) {
-           dumpsize++;
+       if (dumpbytes != (off_t)0) {
+           dumpsize += (off_t)1;
        }
        security_stream_close(streams[DATAFD].fd);
        streams[DATAFD].fd = NULL;
+       aclose(db->fd);
        /*
         * If the mesg fd and index fd has also shut down, then we're done.
         */
@@ -1261,12 +1575,19 @@ read_datafd(cookie, buf, size)
      * more data.
      */
     assert(buf != NULL);
-    if (databuf_write(db, buf, size) < 0) {
-       errstr = newstralloc2(errstr, "data write: ", strerror(errno));
+    if (databuf_write(db, buf, (size_t)size) < 0) {
+       int save_errno = errno;
+       errstr = newvstrallocf(errstr, _("data write: %s"), strerror(save_errno));
        dump_result = 2;
        stop_dump();
        return;
     }
+
+    /*
+     * Reset the timeout for future reads
+     */
+    timeout(conf_dtimeout);
+
     security_stream_read(streams[DATAFD].fd, read_datafd, cookie);
 }
 
@@ -1274,9 +1595,10 @@ read_datafd(cookie, buf, size)
  * Callback for reads on the index stream
  */
 static void
-read_indexfd(cookie, buf, size)
-    void *cookie, *buf;
-    ssize_t size;
+read_indexfd(
+    void *     cookie,
+    void *     buf,
+    ssize_t    size)
 {
     int fd;
 
@@ -1284,7 +1606,7 @@ read_indexfd(cookie, buf, size)
     fd = *(int *)cookie;
 
     if (size < 0) {
-       errstr = newstralloc2(errstr, "index read: ",
+       errstr = newvstrallocf(errstr, _("index read: %s"),
            security_stream_geterror(streams[INDEXFD].fd));
        dump_result = 2;
        stop_dump();
@@ -1300,8 +1622,10 @@ read_indexfd(cookie, buf, size)
        /*
         * If the mesg fd has also shut down, then we're done.
         */
-       if (streams[DATAFD].fd == NULL && streams[MESGFD].fd == NULL)
+       if ((set_datafd == 0 || streams[DATAFD].fd == NULL) &&
+            streams[MESGFD].fd == NULL)
            stop_dump();
+       aclose(indexout);
        return;
     }
 
@@ -1310,23 +1634,95 @@ read_indexfd(cookie, buf, size)
     /*
      * We ignore error while writing to the index file.
      */
-    if (fullwrite(fd, buf, size) < 0) {
+    if (full_write(fd, buf, (size_t)size) < (size_t)size) {
        /* Ignore error, but schedule another read. */
        if(indexfderror == 0) {
            indexfderror = 1;
-           log_add(L_INFO, "Index corrupted for %s:%s", hostname, diskname);
+           log_add(L_INFO, _("Index corrupted for %s:%s"), hostname, qdiskname);
        }
     }
     security_stream_read(streams[INDEXFD].fd, read_indexfd, cookie);
 }
 
+static void
+handle_filter_stderr(
+    void *cookie)
+{
+    filter_t *filter = cookie;
+    ssize_t   nread;
+    char     *b, *p;
+    gint64    len;
+
+    event_release(filter->event);
+
+    if (filter->buffer == NULL) {
+       /* allocate initial buffer */
+       filter->buffer = g_malloc(2048);
+       filter->first = 0;
+       filter->size = 0;
+       filter->allocated_size = 2048;
+    } else if (filter->first > 0) {
+       if (filter->allocated_size - filter->size - filter->first < 1024) {
+           memmove(filter->buffer, filter->buffer + filter->first,
+                                   filter->size);
+           filter->first = 0;
+       }
+    } else if (filter->allocated_size - filter->size < 1024) {
+       /* double the size of the buffer */
+       filter->allocated_size *= 2;
+       filter->buffer = g_realloc(filter->buffer, filter->allocated_size);
+    }
+
+    nread = read(filter->fd, filter->buffer + filter->first + filter->size,
+                            filter->allocated_size - filter->first - filter->size - 2);
+
+    if (nread != 0) {
+       dump_result = max(dump_result, 2);
+    }
+
+    if (nread <= 0) {
+       aclose(filter->fd);
+       if (filter->size > 0 && filter->buffer[filter->first + filter->size - 1] != '\n') {
+           /* Add a '\n' at end of buffer */
+           filter->buffer[filter->first + filter->size] = '\n';
+           filter->size++;
+       }
+    } else {
+       filter->size += nread;
+    }
+
+    /* process all complete lines */
+    b = filter->buffer + filter->first;
+    filter->buffer[filter->first + filter->size] = '\0';
+    while (b < filter->buffer + filter->first + filter->size &&
+          (p = strchr(b, '\n')) != NULL) {
+       *p = '\0';
+       g_fprintf(errf, _("? %s: %s\n"), filter->name, b);
+       if (errstr == NULL) {
+           errstr = stralloc(b);
+       }
+       len = p - b + 1;
+       filter->first += len;
+       filter->size -= len;
+       b = p + 1;
+    }
+
+    if (nread <= 0) {
+       g_free(filter->buffer);
+       g_free(filter);
+    } else {
+       filter->event = event_register((event_id_t)filter->fd, EV_READFD,
+                                      handle_filter_stderr, filter);
+    }
+}
+
 /*
  * Startup a timeout in the event handler.  If the arg is 0,
  * then remove the timeout.
  */
 static void
-timeout(seconds)
-    int seconds;
+timeout(
+    time_t seconds)
 {
     static event_handle_t *ev_timeout = NULL;
 
@@ -1342,7 +1738,7 @@ timeout(seconds)
      * Now, schedule a new one if 'seconds' is greater than 0
      */
     if (seconds > 0)
-       ev_timeout = event_register(seconds, EV_TIME, timeout_callback, NULL);
+       ev_timeout = event_register((event_id_t)seconds, EV_TIME, timeout_callback, NULL);
 }
 
 /*
@@ -1350,11 +1746,13 @@ timeout(seconds)
  * have a data timeout.
  */
 static void
-timeout_callback(unused)
-    void *unused;
+timeout_callback(
+    void *     unused)
 {
+    (void)unused;      /* Quiet unused parameter warning */
+
     assert(unused == NULL);
-    errstr = newstralloc(errstr, "data timeout");
+    errstr = newstralloc(errstr, _("data timeout"));
     dump_result = 2;
     stop_dump();
 }
@@ -1364,9 +1762,21 @@ timeout_callback(unused)
  * will exit.
  */
 static void
-stop_dump()
+stop_dump(void)
 {
-    int i;
+    int             i;
+    struct cmdargs *cmdargs = NULL;
+
+    /* Check if I have a pending ABORT command */
+    cmdargs = get_pending_cmd();
+    if (cmdargs) {
+       if (cmdargs->cmd != ABORT) {
+           error(_("beurk"));
+       }
+       amfree(errstr);
+       errstr = stralloc(cmdargs->argv[1]);
+       free_cmdargs(cmdargs);
+    }
 
     for (i = 0; i < NSTREAMS; i++) {
        if (streams[i].fd != NULL) {
@@ -1374,6 +1784,7 @@ stop_dump()
            streams[i].fd = NULL;
        }
     }
+    aclose(indexout);
     timeout(0);
 }
 
@@ -1385,51 +1796,93 @@ stop_dump()
  * process.
  */
 static int
-runcompress(outfd, pid, comptype)
-    int outfd;
-    pid_t *pid;
-    comp_t comptype;
+runcompress(
+    int                outfd,
+    pid_t *    pid,
+    comp_t     comptype,
+    char       *name)
 {
     int outpipe[2], rval;
+    int errpipe[2];
+    filter_t *filter;
 
     assert(outfd >= 0);
     assert(pid != NULL);
 
     /* outpipe[0] is pipe's stdin, outpipe[1] is stdout. */
     if (pipe(outpipe) < 0) {
-       errstr = newstralloc2(errstr, "pipe: ", strerror(errno));
+       errstr = newvstrallocf(errstr, _("pipe: %s"), strerror(errno));
+       return (-1);
+    }
+
+    /* errpipe[0] is pipe's output, outpipe[1] is input. */
+    if (pipe(errpipe) < 0) {
+       errstr = newvstrallocf(errstr, _("pipe: %s"), strerror(errno));
        return (-1);
     }
 
     switch (*pid = fork()) {
     case -1:
-       errstr = newstralloc2(errstr, "couldn't fork: ", strerror(errno));
+       errstr = newvstrallocf(errstr, _("couldn't fork: %s"), strerror(errno));
        aclose(outpipe[0]);
        aclose(outpipe[1]);
+       aclose(errpipe[0]);
+       aclose(errpipe[1]);
        return (-1);
     default:
        rval = dup2(outpipe[1], outfd);
        if (rval < 0)
-           errstr = newstralloc2(errstr, "couldn't dup2: ", strerror(errno));
+           errstr = newvstrallocf(errstr, _("couldn't dup2: %s"), strerror(errno));
        aclose(outpipe[1]);
        aclose(outpipe[0]);
+       aclose(errpipe[1]);
+       filter = g_new0(filter_t, 1);
+       filter->fd = errpipe[0];
+       filter->name = name;
+       filter->buffer = NULL;
+       filter->size = 0;
+       filter->allocated_size = 0;
+       filter->event = event_register((event_id_t)filter->fd, EV_READFD,
+                                      handle_filter_stderr, filter);
+g_debug("event register %s %d", name, filter->fd);
        return (rval);
     case 0:
-       if (dup2(outpipe[0], 0) < 0)
-           error("err dup2 in: %s", strerror(errno));
-       if (dup2(outfd, 1) == -1)
-           error("err dup2 out: %s", strerror(errno));
-       safe_fd(-1, 0);
-       if (comptype != COMP_SERV_CUST) {
+       close(outpipe[1]);
+       close(errpipe[0]);
+       if (dup2(outpipe[0], 0) < 0) {
+           error(_("err dup2 in: %s"), strerror(errno));
+           /*NOTREACHED*/
+       }
+       if (dup2(outfd, 1) == -1) {
+           error(_("err dup2 out: %s"), strerror(errno));
+           /*NOTREACHED*/
+       }
+       if (dup2(errpipe[1], 2) == -1) {
+           error(_("err dup2 err: %s"), strerror(errno));
+           /*NOTREACHED*/
+       }
+       if (comptype != COMP_SERVER_CUST) {
+           char *base = stralloc(COMPRESS_PATH);
+           log_add(L_INFO, "%s pid %ld", basename(base), (long)getpid());
+           amfree(base);
+           safe_fd(-1, 0);
+           set_root_privs(-1);
            execlp(COMPRESS_PATH, COMPRESS_PATH, (  comptype == COMP_BEST ?
-               COMPRESS_BEST_OPT : COMPRESS_FAST_OPT), NULL);
-           error("error: couldn't exec %s: %s", COMPRESS_PATH, strerror(errno));
+               COMPRESS_BEST_OPT : COMPRESS_FAST_OPT), (char *)NULL);
+           error(_("error: couldn't exec %s: %s"), COMPRESS_PATH, strerror(errno));
+           /*NOTREACHED*/
        } else if (*srvcompprog) {
+           char *base = stralloc(srvcompprog);
+           log_add(L_INFO, "%s pid %ld", basename(base), (long)getpid());
+           amfree(base);
+           safe_fd(-1, 0);
+           set_root_privs(-1);
            execlp(srvcompprog, srvcompprog, (char *)0);
-           error("error: couldn't exec server custom filter%s.\n", srvcompprog);
+           error(_("error: couldn't exec server custom compression '%s'.\n"), srvcompprog);
+           /*NOTREACHED*/
        }
     }
-    /* NOTREACHED */
+    /*NOTREACHED*/
     return (-1);
 }
 
@@ -1440,47 +1893,83 @@ runcompress(outfd, pid, comptype)
  * process.
  */
 static int
-runencrypt(outfd, pid, encrypttype)
-    int outfd;
-    pid_t *pid;
-    encrypt_t encrypttype;
+runencrypt(
+    int                outfd,
+    pid_t *    pid,
+    encrypt_t  encrypttype)
 {
     int outpipe[2], rval;
+    int errpipe[2];
+    filter_t *filter;
 
     assert(outfd >= 0);
     assert(pid != NULL);
 
     /* outpipe[0] is pipe's stdin, outpipe[1] is stdout. */
     if (pipe(outpipe) < 0) {
-       errstr = newstralloc2(errstr, "pipe: ", strerror(errno));
+       errstr = newvstrallocf(errstr, _("pipe: %s"), strerror(errno));
+       return (-1);
+    }
+
+    /* errpipe[0] is pipe's output, outpipe[1] is input. */
+    if (pipe(errpipe) < 0) {
+       errstr = newvstrallocf(errstr, _("pipe: %s"), strerror(errno));
        return (-1);
     }
 
     switch (*pid = fork()) {
     case -1:
-       errstr = newstralloc2(errstr, "couldn't fork: ", strerror(errno));
+       errstr = newvstrallocf(errstr, _("couldn't fork: %s"), strerror(errno));
        aclose(outpipe[0]);
        aclose(outpipe[1]);
+       aclose(errpipe[0]);
+       aclose(errpipe[1]);
        return (-1);
     default:
        rval = dup2(outpipe[1], outfd);
        if (rval < 0)
-           errstr = newstralloc2(errstr, "couldn't dup2: ", strerror(errno));
+           errstr = newvstrallocf(errstr, _("couldn't dup2: %s"), strerror(errno));
        aclose(outpipe[1]);
        aclose(outpipe[0]);
+       aclose(errpipe[1]);
+       filter = g_new0(filter_t, 1);
+       filter->fd = errpipe[0];
+       filter->name = "encrypt";
+       filter->buffer = NULL;
+       filter->size = 0;
+       filter->allocated_size = 0;
+       filter->event = event_register((event_id_t)filter->fd, EV_READFD,
+                                      handle_filter_stderr, filter);
+g_debug("event register %s %d", "encrypt data", filter->fd);
        return (rval);
-    case 0:
-       if (dup2(outpipe[0], 0) < 0)
-           error("err dup2 in: %s", strerror(errno));
-       if (dup2(outfd, 1) < 0 )
-           error("err dup2 out: %s", strerror(errno));
+    case 0: {
+       char *base;
+       if (dup2(outpipe[0], 0) < 0) {
+           error(_("err dup2 in: %s"), strerror(errno));
+           /*NOTREACHED*/
+       }
+       if (dup2(outfd, 1) < 0 ) {
+           error(_("err dup2 out: %s"), strerror(errno));
+           /*NOTREACHED*/
+       }
+       if (dup2(errpipe[1], 2) == -1) {
+           error(_("err dup2 err: %s"), strerror(errno));
+           /*NOTREACHED*/
+       }
+       close(errpipe[0]);
+       base = stralloc(srv_encrypt);
+       log_add(L_INFO, "%s pid %ld", basename(base), (long)getpid());
+       amfree(base);
        safe_fd(-1, 0);
        if ((encrypttype == ENCRYPT_SERV_CUST) && *srv_encrypt) {
+           set_root_privs(-1);
            execlp(srv_encrypt, srv_encrypt, (char *)0);
-           error("error: couldn't exec server encryption%s.\n", srv_encrypt);
+           error(_("error: couldn't exec server custom encryption '%s'.\n"), srv_encrypt);
+           /*NOTREACHED*/
+       }
        }
     }
-    /* NOTREACHED */
+    /*NOTREACHED*/
     return (-1);
 }
 
@@ -1488,30 +1977,33 @@ runencrypt(outfd, pid, encrypttype)
 /* -------------------- */
 
 static void
-sendbackup_response(datap, pkt, sech)
-    void *datap;
-    pkt_t *pkt;
-    security_handle_t *sech;
+sendbackup_response(
+    void *             datap,
+    pkt_t *            pkt,
+    security_handle_t *        sech)
 {
     int ports[NSTREAMS], *response_error = datap, i;
     char *p;
     char *tok;
-    char *tok_end;
-    char *extra = NULL;
+    char *extra;
 
     assert(response_error != NULL);
     assert(sech != NULL);
 
+    security_close_connection(sech, hostname);
+
     if (pkt == NULL) {
-       errstr = newvstralloc(errstr, "[request failed: ",
-           security_geterror(sech), "]", NULL);
+       errstr = newvstrallocf(errstr, _("[request failed: %s]"),
+           security_geterror(sech));
        *response_error = 1;
        return;
     }
 
+    extra = NULL;
+    memset(ports, 0, SIZEOF(ports));
     if (pkt->type == P_NAK) {
 #if defined(PACKET_DEBUG)
-       fprintf(stderr, "got nak response:\n----\n%s\n----\n\n", pkt->body);
+       g_fprintf(stderr, _("got nak response:\n----\n%s\n----\n\n"), pkt->body);
 #endif
 
        tok = strtok(pkt->body, " ");
@@ -1520,26 +2012,24 @@ sendbackup_response(datap, pkt, sech)
 
        tok = strtok(NULL, "\n");
        if (tok != NULL) {
-           errstr = newvstralloc(errstr, "NAK: ", tok, NULL);
+           errstr = newvstrallocf(errstr, "NAK: %s", tok);
            *response_error = 1;
        } else {
 bad_nak:
-           errstr = newstralloc(errstr, "request NAK");
+           errstr = newvstrallocf(errstr, "request NAK");
            *response_error = 2;
        }
        return;
     }
 
     if (pkt->type != P_REP) {
-       errstr = newvstralloc(errstr, "received strange packet type ",
-           pkt_type2str(pkt->type), ": ", pkt->body, NULL);
+       errstr = newvstrallocf(errstr, _("received strange packet type %s: %s"),
+           pkt_type2str(pkt->type), pkt->body);
        *response_error = 1;
        return;
     }
 
-#if defined(PACKET_DEBUG)
-    fprintf(stderr, "got response:\n----\n%s\n----\n\n", pkt->body);
-#endif
+    dbprintf(_("got response:\n----\n%s\n----\n\n"), pkt->body);
 
     for(i = 0; i < NSTREAMS; i++) {
        ports[i] = -1;
@@ -1557,8 +2047,8 @@ bad_nak:
        if (strcmp(tok, "ERROR") == 0) {
            tok = strtok(NULL, "\n");
            if (tok == NULL)
-               tok = "[bogus error packet]";
-           errstr = newstralloc(errstr, tok);
+               tok = _("[bogus error packet]");
+           errstr = newvstrallocf(errstr, "%s", tok);
            *response_error = 2;
            return;
        }
@@ -1574,22 +2064,17 @@ bad_nak:
            for (i = 0; i < NSTREAMS; i++) {
                tok = strtok(NULL, " ");
                if (tok == NULL || strcmp(tok, streams[i].name) != 0) {
-                   extra = vstralloc("CONNECT token is \"",
-                                     tok ? tok : "(null)",
-                                     "\": expected \"",
-                                     streams[i].name,
-                                     "\"",
-                                     NULL);
+                   extra = vstrallocf(
+                               _("CONNECT token is \"%s\": expected \"%s\""),
+                               tok ? tok : "(null)",
+                               streams[i].name);
                    goto parse_error;
                }
                tok = strtok(NULL, " \n");
                if (tok == NULL || sscanf(tok, "%d", &ports[i]) != 1) {
-                   extra = vstralloc("CONNECT ",
-                                     streams[i].name,
-                                     " token is \"",
-                                     tok ? tok : "(null)",
-                                     "\": expected a port number",
-                                     NULL);
+                   extra = vstrallocf(
+                       _("CONNECT %s token is \"%s\": expected a port number"),
+                       streams[i].name, tok ? tok : "(null)");
                    goto parse_error;
                }
            }
@@ -1602,38 +2087,40 @@ bad_nak:
        if (strcmp(tok, "OPTIONS") == 0) {
            tok = strtok(NULL, "\n");
            if (tok == NULL) {
-               extra = stralloc("OPTIONS token is missing");
+               extra = vstrallocf(_("OPTIONS token is missing"));
                goto parse_error;
            }
-           tok_end = tok + strlen(tok);
 
            while((p = strchr(tok, ';')) != NULL) {
+               char ch;
                *p++ = '\0';
-#define sc "features="
-               if(strncmp(tok, sc, sizeof(sc)-1) == 0) {
-                   tok += sizeof(sc) - 1;
-#undef sc
+               if(strncmp_const_skip(tok, "features=", tok, ch) == 0) {
+                   char *u = strchr(tok, ';');
+                   if (u)
+                      *u = '\0';
                    am_release_feature_set(their_features);
                    if((their_features = am_string_to_feature(tok)) == NULL) {
-                       errstr = newvstralloc(errstr,
-                                             "OPTIONS: bad features value: ",
-                                             tok,
-                                             NULL);
+                       errstr = newvstrallocf(errstr,
+                                             _("OPTIONS: bad features value: %s"),
+                                             tok);
                        goto parse_error;
                    }
+                   if (u)
+                      *u = ';';
                }
                tok = p;
            }
            continue;
        }
 
-       extra = vstralloc("next token is \"",
-                         tok ? tok : "(null)",
-                         "\": expected \"CONNECT\", \"ERROR\" or \"OPTIONS\"",
-                         NULL);
+       extra = vstrallocf(_("next token is \"%s\": expected \"CONNECT\", \"ERROR\" or \"OPTIONS\""),
+                         tok ? tok : "(null)");
        goto parse_error;
     }
 
+    if (dumper_kencrypt == KENCRYPT_WILL_DO)
+       dumper_kencrypt = KENCRYPT_YES;
+
     /*
      * Connect the streams to their remote ports
      */
@@ -1642,9 +2129,10 @@ bad_nak:
            continue;
        streams[i].fd = security_stream_client(sech, ports[i]);
        if (streams[i].fd == NULL) {
-           errstr = newvstralloc(errstr,
-               "[could not connect ", streams[i].name, " stream: ",
-               security_geterror(sech), "]", NULL);
+           errstr = newvstrallocf(errstr,
+               _("[could not connect %s stream: %s]"),
+               streams[i].name,
+               security_geterror(sech));
            goto connect_error;
        }
     }
@@ -1655,20 +2143,11 @@ bad_nak:
     for (i = 0; i < NSTREAMS; i++) {
        if (streams[i].fd == NULL)
            continue;
-#ifdef KRB4_SECURITY
-       /*
-        * XXX krb4 historically never authenticated the index stream!
-        * We need to reproduce this lossage here to preserve compatibility
-        * with old clients.
-        * It is wrong to delve into sech, but we have no choice here.
-        */
-       if (strcasecmp(sech->driver->name, "krb4") != 0 && i == INDEXFD)
-           continue;
-#endif
        if (security_stream_auth(streams[i].fd) < 0) {
-           errstr = newvstralloc(errstr,
-               "[could not authenticate ", streams[i].name, " stream: ",
-               security_stream_geterror(streams[i].fd), "]", NULL);
+           errstr = newvstrallocf(errstr,
+               _("[could not authenticate %s stream: %s]"),
+               streams[i].name, 
+               security_stream_geterror(streams[i].fd));
            goto connect_error;
        }
     }
@@ -1678,7 +2157,7 @@ bad_nak:
      * them, complain.
      */
     if (streams[MESGFD].fd == NULL || streams[DATAFD].fd == NULL) {
-       errstr = newstralloc(errstr, "[couldn't open MESG or INDEX streams]");
+       errstr = newvstrallocf(errstr, _("[couldn't open MESG or INDEX streams]"));
        goto connect_error;
     }
 
@@ -1687,11 +2166,9 @@ bad_nak:
     return;
 
 parse_error:
-    errstr = newvstralloc(errstr,
-                         "[parse of reply message failed: ",
-                         extra ? extra : "(no additional information)",
-                         "]",
-                         NULL);
+    errstr = newvstrallocf(errstr,
+                         _("[parse of reply message failed: %s]"),
+                         extra ? extra : _("(no additional information)"));
     amfree(extra);
     *response_error = 2;
     return;
@@ -1701,21 +2178,74 @@ connect_error:
     *response_error = 1;
 }
 
+static char *
+dumper_get_security_conf(
+    char *     string,
+    void *     arg)
+{
+        (void)arg;     /* Quiet unused parameter warning */
+
+        if(!string || !*string)
+                return(NULL);
+
+        if(strcmp(string, "krb5principal")==0) {
+                return(getconf_str(CNF_KRB5PRINCIPAL));
+        } else if(strcmp(string, "krb5keytab")==0) {
+                return(getconf_str(CNF_KRB5KEYTAB));
+        } else if(strcmp(string, "amandad_path")==0) {
+                return (amandad_path);
+        } else if(strcmp(string, "client_username")==0) {
+                return (client_username);
+        } else if(strcmp(string, "client_port")==0) {
+                return (client_port);
+        } else if(strcmp(string, "ssh_keys")==0) {
+                return (ssh_keys);
+        } else if(strcmp(string, "kencrypt")==0) {
+               if (dumper_kencrypt == KENCRYPT_YES)
+                    return ("yes");
+               else
+                   return (NULL);
+        }
+        return(NULL);
+}
+
 static int
-startup_dump(hostname, disk, device, level, dumpdate, progname, options)
-    const char *hostname, *disk, *device, *dumpdate, *progname, *options;
-    int level;
+startup_dump(
+    const char *hostname,
+    const char *disk,
+    const char *device,
+    int                level,
+    const char *dumpdate,
+    const char *progname,
+    const char *amandad_path,
+    const char *client_username,
+    const char *client_port,
+    const char *ssh_keys,
+    const char *auth,
+    const char *options)
 {
     char level_string[NUM_STR_SIZE];
     char *req = NULL;
-    char *authopt, *endauthopt, authoptbuf[64];
+    char *authopt;
     int response_error;
     const security_driver_t *secdrv;
-    char *dumper_api;
-
-    int has_features = am_has_feature(their_features, fe_req_options_features);
-    int has_hostname = am_has_feature(their_features, fe_req_options_hostname);
-    int has_device   = am_has_feature(their_features, fe_sendbackup_req_device);
+    char *application_api;
+    int has_features;
+    int has_hostname;
+    int has_device;
+    int has_config;
+
+    (void)disk;                        /* Quiet unused parameter warning */
+    (void)amandad_path;                /* Quiet unused parameter warning */
+    (void)client_username;     /* Quiet unused parameter warning */
+    (void)client_port;         /* Quiet unused parameter warning */
+    (void)ssh_keys;            /* Quiet unused parameter warning */
+    (void)auth;                        /* Quiet unused parameter warning */
+
+    has_features = am_has_feature(their_features, fe_req_options_features);
+    has_hostname = am_has_feature(their_features, fe_req_options_hostname);
+    has_config   = am_has_feature(their_features, fe_req_options_config);
+    has_device   = am_has_feature(their_features, fe_sendbackup_req_device);
 
     /*
      * Default to bsd authentication if none specified.  This is gross.
@@ -1723,23 +2253,13 @@ startup_dump(hostname, disk, device, level, dumpdate, progname, options)
      * Options really need to be pre-parsed into some sort of structure
      * much earlier, and then flattened out again before transmission.
      */
-    if ((authopt = strstr(options, "auth=")) == NULL
-       || (endauthopt = strchr(authopt, ';')) == NULL
-       || (sizeof(authoptbuf) - 1 < endauthopt - authopt)) {
-       authopt = "BSD";
-    } else {
-       authopt += strlen("auth=");
-       strncpy(authoptbuf, authopt, endauthopt - authopt);
-       authoptbuf[endauthopt - authopt] = '\0';
-       authopt = authoptbuf;
-    }
 
-    snprintf(level_string, sizeof(level_string), "%d", level);
-    if(strncmp(progname, "DUMP", 4) == 0
-       || strncmp(progname, "GNUTAR", 6) == 0) {
-       dumper_api = "";
+    g_snprintf(level_string, SIZEOF(level_string), "%d", level);
+    if(strcmp(progname, "DUMP") == 0
+       || strcmp(progname, "GNUTAR") == 0) {
+       application_api = "";
     } else {
-       dumper_api = "DUMPER ";
+       application_api = "BACKUP ";
     }
     req = vstralloc("SERVICE sendbackup\n",
                    "OPTIONS ",
@@ -1749,25 +2269,64 @@ startup_dump(hostname, disk, device, level, dumpdate, progname, options)
                    has_hostname ? "hostname=" : "",
                    has_hostname ? hostname : "",
                    has_hostname ? ";" : "",
-                   "\n",
-                   dumper_api, progname,
-                   " ", disk,
-                   " ", device && has_device ? device : "",
-                   " ", level_string,
-                   " ", dumpdate,
-                   " OPTIONS ", options,
-                   /* compat: if auth=krb4, send krb4-auth */
-                   (strcasecmp(authopt, "krb4") ? "" : "krb4-auth"),
+                   has_config   ? "config=" : "",
+                   has_config   ? get_config_name() : "",
+                   has_config   ? ";" : "",
                    "\n",
                    NULL);
 
-    secdrv = security_getdriver(authopt);
+    amfree(dle_str);
+    if (am_has_feature(their_features, fe_req_xml)) {
+       char *p = NULL;
+       char *pclean;
+       vstrextend(&p, "<dle>\n", NULL);
+       if (*application_api != '\0') {
+           vstrextend(&p, "  <program>APPLICATION</program>\n", NULL);
+       } else {
+           vstrextend(&p, "  <program>", progname, "</program>\n", NULL);
+       }
+       vstrextend(&p, "  ", b64disk, "\n", NULL);
+       if (device && has_device) {
+           vstrextend(&p, "  ", b64device, "\n",
+                      NULL);
+       }
+       vstrextend(&p, "  <level>", level_string, "</level>\n", NULL);
+       vstrextend(&p, options+1, "</dle>\n", NULL);
+       pclean = clean_dle_str_for_client(p);
+       vstrextend(&req, pclean, NULL);
+       amfree(pclean);
+       dle_str = p;
+    } else if (*application_api != '\0') {
+       errstr = newvstrallocf(errstr,
+               _("[does not support application-api]"));
+       amfree(req);
+       return 2;
+    } else {
+       authopt = strstr(options, "auth=");
+       if (auth == NULL) {
+           auth = "BSD";
+       }
+       vstrextend(&req,
+                  progname,
+                  " ", qdiskname,
+                  " ", device && has_device ? device : "",
+                  " ", level_string,
+                  " ", dumpdate,
+                  " OPTIONS ", options,
+                  "\n",
+                  NULL);
+    }
+
+    dbprintf(_("send request:\n----\n%s\n----\n\n"), req);
+    secdrv = security_getdriver(auth);
     if (secdrv == NULL) {
-       error("no '%s' security driver available for host '%s'",
-           authopt, hostname);
+       errstr = newvstrallocf(errstr,
+               _("[could not find security driver '%s']"), auth);
+       amfree(req);
+       return 2;
     }
 
-    protocol_sendreq(hostname, secdrv, generic_get_security_conf, req,
+    protocol_sendreq(hostname, secdrv, dumper_get_security_conf, req,
        STARTUP_TIMEOUT, sendbackup_response, &response_error);
 
     amfree(req);