2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
26 /* $Id: dumper.c,v 1.190 2006/08/30 19:53:57 martinea Exp $
28 * requests remote amandad processes to dump filesystems
42 #include "fileheader.h"
43 #include "amfeatures.h"
44 #include "server_util.h"
46 #include "timestamp.h"
49 #define dumper_debug(i,x) do { \
50 if ((i) <= debug_dumper) { \
63 #define CONNECT_TIMEOUT 5*60
65 #define STARTUP_TIMEOUT 60
68 int fd; /* file to flush to */
70 char *datain; /* data buffer markers */
73 pid_t compresspid; /* valid if fd is pipe to compress */
74 pid_t encryptpid; /* valid if fd is pipe to encrypt */
77 static char *handle = NULL;
79 static char *errstr = NULL;
80 static off_t dumpbytes;
81 static off_t dumpsize, headersize, origsize;
83 static comp_t srvcompress = COMP_NONE;
84 char *srvcompprog = NULL;
85 char *clntcompprog = NULL;
87 static encrypt_t srvencrypt = ENCRYPT_NONE;
88 char *srv_encrypt = NULL;
89 char *clnt_encrypt = NULL;
90 char *srv_decrypt_opt = NULL;
91 char *clnt_decrypt_opt = NULL;
92 static kencrypt_type dumper_kencrypt;
94 static FILE *errf = NULL;
95 static char *hostname = NULL;
96 am_feature_t *their_features = NULL;
97 static char *diskname = NULL;
98 static char *qdiskname = NULL, *b64disk;
99 static char *device = NULL, *b64device;
100 static char *options = NULL;
101 static char *progname = NULL;
102 static char *amandad_path=NULL;
103 static char *client_username=NULL;
104 static char *ssh_keys=NULL;
105 static char *auth=NULL;
107 static char *dumpdate = NULL;
108 static char *dumper_timestamp = NULL;
109 static time_t conf_dtimeout;
110 static int indexfderror;
111 static int set_datafd;
112 static char *dle_str = NULL;
114 static dumpfile_t file;
118 security_stream_t *fd;
127 #define NSTREAMS (int)(sizeof(streams) / sizeof(streams[0]))
129 static am_feature_t *our_features = NULL;
130 static char *our_feature_string = NULL;
132 /* buffer to keep partial line from the MESG stream */
134 char *buf; /* buffer holding msg data */
135 size_t size; /* size of alloced buffer */
139 /* local functions */
140 int main(int, char **);
141 static int do_dump(struct databuf *);
142 static void check_options(char *);
143 static void xml_check_options(char *optionstr);
144 static void finish_tapeheader(dumpfile_t *);
145 static ssize_t write_tapeheader(int, dumpfile_t *);
146 static void databuf_init(struct databuf *, int);
147 static int databuf_write(struct databuf *, const void *, size_t);
148 static int databuf_flush(struct databuf *);
149 static void process_dumpeof(void);
150 static void process_dumpline(const char *);
151 static void add_msg_data(const char *, size_t);
152 static void parse_info_line(char *);
153 static void log_msgout(logtype_t);
154 static char * dumper_get_security_conf (char *, void *);
156 static int runcompress(int, pid_t *, comp_t);
157 static int runencrypt(int, pid_t *, encrypt_t);
159 static void sendbackup_response(void *, pkt_t *, security_handle_t *);
160 static int startup_dump(const char *, const char *, const char *, int,
161 const char *, const char *, const char *,
162 const char *, const char *, const char *,
164 static void stop_dump(void);
166 static void read_indexfd(void *, void *, ssize_t);
167 static void read_datafd(void *, void *, ssize_t);
168 static void read_mesgfd(void *, void *, ssize_t);
169 static void timeout(time_t);
170 static void timeout_callback(void *);
176 char *compmode = NULL;
177 char *compend = NULL;
178 char *encryptmode = NULL;
179 char *encryptend = NULL;
180 char *decryptmode = NULL;
181 char *decryptend = NULL;
183 /* parse the compression option */
184 if (strstr(options, "srvcomp-best;") != NULL)
185 srvcompress = COMP_BEST;
186 else if (strstr(options, "srvcomp-fast;") != NULL)
187 srvcompress = COMP_FAST;
188 else if ((compmode = strstr(options, "srvcomp-cust=")) != NULL) {
189 compend = strchr(compmode, ';');
191 srvcompress = COMP_SERVER_CUST;
193 srvcompprog = stralloc(compmode + strlen("srvcomp-cust="));
196 } else if ((compmode = strstr(options, "comp-cust=")) != NULL) {
197 compend = strchr(compmode, ';');
199 srvcompress = COMP_CUST;
201 clntcompprog = stralloc(compmode + strlen("comp-cust="));
206 srvcompress = COMP_NONE;
210 /* now parse the encryption option */
211 if ((encryptmode = strstr(options, "encrypt-serv-cust=")) != NULL) {
212 encryptend = strchr(encryptmode, ';');
214 srvencrypt = ENCRYPT_SERV_CUST;
216 srv_encrypt = stralloc(encryptmode + strlen("encrypt-serv-cust="));
219 } else if ((encryptmode = strstr(options, "encrypt-cust=")) != NULL) {
220 encryptend = strchr(encryptmode, ';');
222 srvencrypt = ENCRYPT_CUST;
224 clnt_encrypt = stralloc(encryptmode + strlen("encrypt-cust="));
228 srvencrypt = ENCRYPT_NONE;
230 /* get the decryption option parameter */
231 if ((decryptmode = strstr(options, "server-decrypt-option=")) != NULL) {
232 decryptend = strchr(decryptmode, ';');
235 srv_decrypt_opt = stralloc(decryptmode + strlen("server-decrypt-option="));
238 } else if ((decryptmode = strstr(options, "client-decrypt-option=")) != NULL) {
239 decryptend = strchr(decryptmode, ';');
242 clnt_decrypt_opt = stralloc(decryptmode + strlen("client-decrypt-option="));
247 if (strstr(options, "kencrypt;") != NULL) {
248 dumper_kencrypt = KENCRYPT_WILL_DO;
250 dumper_kencrypt = KENCRYPT_NONE;
263 o = oo = vstralloc("<dle>", strchr(optionstr,'<'), "</dle>", NULL);
265 dle = amxml_parse_node_CHAR(o, &errmsg);
267 error("amxml_parse_node_CHAR failed: %s\n", errmsg);
270 if (dle->compress == COMP_SERVER_FAST) {
271 srvcompress = COMP_FAST;
272 } else if (dle->compress == COMP_SERVER_BEST) {
273 srvcompress = COMP_BEST;
274 } else if (dle->compress == COMP_SERVER_CUST) {
275 srvcompress = COMP_SERVER_CUST;
276 srvcompprog = dle->compprog;
277 } else if (dle->compress == COMP_CUST) {
278 srvcompress = COMP_CUST;
279 clntcompprog = dle->compprog;
281 srvcompress = COMP_NONE;
284 if (dle->encrypt == ENCRYPT_CUST) {
285 srvencrypt = ENCRYPT_CUST;
286 clnt_encrypt = dle->clnt_encrypt;
287 clnt_decrypt_opt = dle->clnt_decrypt_opt;
288 } else if (dle->encrypt == ENCRYPT_SERV_CUST) {
289 srvencrypt = ENCRYPT_SERV_CUST;
290 srv_encrypt = dle->clnt_encrypt;
291 srv_decrypt_opt = dle->clnt_decrypt_opt;
293 srvencrypt = ENCRYPT_NONE;
303 static struct databuf db;
304 struct cmdargs *cmdargs = NULL;
307 in_port_t taper_port;
311 config_overwrites_t *cfg_ovr = NULL;
312 char *cfg_opt = NULL;
316 * Configure program for internationalization:
317 * 1) Only set the message locale for now.
318 * 2) Set textdomain for all amanda related programs to "amanda"
319 * We don't want to be forced to support dozens of message catalogs.
321 setlocale(LC_MESSAGES, "C");
322 textdomain("amanda");
324 /* drop root privileges */
325 dumper_setuid = set_root_privs(0);
331 dbopen(DBG_SUBDIR_SERVER);
333 /* Don't die when child closes pipe */
334 signal(SIGPIPE, SIG_IGN);
336 erroutput_type = (ERR_AMANDALOG|ERR_INTERACTIVE);
337 set_logerror(logerror);
339 cfg_ovr = extract_commandline_config_overwrites(&argc, &argv);
342 config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt);
343 apply_config_overwrites(cfg_ovr);
345 if (!dumper_setuid) {
346 error(_("dumper must be run setuid root"));
349 if (config_errors(NULL) >= CFGERR_ERRORS) {
350 g_critical(_("errors processing config file"));
353 safe_cd(); /* do this *after* config_init() */
355 check_running_as(RUNNING_AS_DUMPUSER);
357 dbrename(get_config_name(), DBG_SUBDIR_SERVER);
359 our_features = am_init_feature_set();
360 our_feature_string = am_feature_to_string(our_features);
362 log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid());
364 _("%s: pid %ld executable %s version %s\n"),
365 get_pname(), (long) getpid(),
369 /* now, make sure we are a valid user */
371 signal(SIGPIPE, SIG_IGN);
373 conf_dtimeout = (time_t)getconf_int(CNF_DTIMEOUT);
379 free_cmdargs(cmdargs);
383 switch(cmdargs->cmd) {
385 if(cmdargs->argc < 2)
386 error(_("error [dumper START: not enough args: timestamp]"));
387 dumper_timestamp = newstralloc(dumper_timestamp, cmdargs->argv[1]);
414 a = 1; /* skip "PORT-DUMP" */
416 if(a >= cmdargs->argc) {
417 error(_("error [dumper PORT-DUMP: not enough args: handle]"));
420 handle = newstralloc(handle, cmdargs->argv[a++]);
422 if(a >= cmdargs->argc) {
423 error(_("error [dumper PORT-DUMP: not enough args: port]"));
426 taper_port = (in_port_t)atoi(cmdargs->argv[a++]);
428 if(a >= cmdargs->argc) {
429 error(_("error [dumper PORT-DUMP: not enough args: hostname]"));
432 hostname = newstralloc(hostname, cmdargs->argv[a++]);
434 if(a >= cmdargs->argc) {
435 error(_("error [dumper PORT-DUMP: not enough args: features]"));
438 am_release_feature_set(their_features);
439 their_features = am_string_to_feature(cmdargs->argv[a++]);
441 if(a >= cmdargs->argc) {
442 error(_("error [dumper PORT-DUMP: not enough args: diskname]"));
445 diskname = newstralloc(diskname, cmdargs->argv[a++]);
446 if (qdiskname != NULL)
448 qdiskname = quote_string(diskname);
449 b64disk = amxml_format_tag("disk", diskname);
451 if(a >= cmdargs->argc) {
452 error(_("error [dumper PORT-DUMP: not enough args: device]"));
455 device = newstralloc(device, cmdargs->argv[a++]);
456 b64device = amxml_format_tag("diskdevice", device);
457 if(strcmp(device,"NODEVICE") == 0)
460 if(a >= cmdargs->argc) {
461 error(_("error [dumper PORT-DUMP: not enough args: level]"));
464 level = atoi(cmdargs->argv[a++]);
466 if(a >= cmdargs->argc) {
467 error(_("error [dumper PORT-DUMP: not enough args: dumpdate]"));
470 dumpdate = newstralloc(dumpdate, cmdargs->argv[a++]);
472 if(a >= cmdargs->argc) {
473 error(_("error [dumper PORT-DUMP: not enough args: program]"));
476 progname = newstralloc(progname, cmdargs->argv[a++]);
478 if(a >= cmdargs->argc) {
479 error(_("error [dumper PORT-DUMP: not enough args: amandad_path]"));
482 amandad_path = newstralloc(amandad_path, cmdargs->argv[a++]);
484 if(a >= cmdargs->argc) {
485 error(_("error [dumper PORT-DUMP: not enough args: client_username]"));
487 client_username = newstralloc(client_username, cmdargs->argv[a++]);
489 if(a >= cmdargs->argc) {
490 error(_("error [dumper PORT-DUMP: not enough args: ssh_keys]"));
492 ssh_keys = newstralloc(ssh_keys, cmdargs->argv[a++]);
494 if(a >= cmdargs->argc) {
495 error(_("error [dumper PORT-DUMP: not enough args: auth]"));
497 auth = newstralloc(auth, cmdargs->argv[a++]);
499 if(a >= cmdargs->argc) {
500 error(_("error [dumper PORT-DUMP: not enough args: options]"));
502 options = newstralloc(options, cmdargs->argv[a++]);
504 if(a != cmdargs->argc) {
505 error(_("error [dumper PORT-DUMP: too many args: %d != %d]"),
510 /* Double-check that 'localhost' resolves properly */
511 if ((res = resolve_hostname("localhost", 0, NULL, NULL) != 0)) {
512 errstr = newvstrallocf(errstr,
513 _("could not resolve localhost: %s"),
515 q = quote_string(errstr);
516 putresult(FAILED, "%s %s\n", handle, q);
517 log_add(L_FAIL, "%s %s %s %d [%s]", hostname, qdiskname,
518 dumper_timestamp, level, errstr);
523 /* connect outf to chunker/taper port */
525 outfd = stream_client("localhost", taper_port,
526 STREAM_BUFSIZE, 0, NULL, 0);
529 errstr = newvstrallocf(errstr, _("port open: %s"),
531 q = quote_string(errstr);
532 putresult(FAILED, "%s %s\n", handle, q);
533 log_add(L_FAIL, "%s %s %s %d [%s]", hostname, qdiskname,
534 dumper_timestamp, level, errstr);
538 databuf_init(&db, outfd);
540 if (am_has_feature(their_features, fe_req_xml))
541 xml_check_options(options);
543 check_options(options);
545 rc = startup_dump(hostname,
557 q = quote_string(errstr);
558 putresult(rc == 2? FAILED : TRYAGAIN, "%s %s\n",
561 log_add(L_FAIL, "%s %s %s %d [%s]", hostname, qdiskname,
562 dumper_timestamp, level, errstr);
566 /* try to clean up any defunct processes, since Amanda doesn't
567 wait() for them explicitly */
568 while(waitpid(-1, NULL, WNOHANG)> 0);
571 amfree(amandad_path);
572 amfree(client_username);
577 if(cmdargs->argc >= 1) {
578 q = quote_string(cmdargs->argv[0]);
580 q = stralloc(_("(no input?)"));
582 putresult(BAD_COMMAND, "%s\n", q);
589 } while(cmdargs->cmd != QUIT);
590 free_cmdargs(cmdargs);
592 log_add(L_INFO, "pid-done %ld", (long)getpid());
594 am_release_feature_set(our_features);
595 amfree(our_feature_string);
597 amfree(dumper_timestamp);
606 amfree(clntcompprog);
608 amfree(clnt_encrypt);
609 amfree(srv_decrypt_opt);
610 amfree(clnt_decrypt_opt);
614 return (0); /* exit */
619 * Initialize a databuf. Takes a writeable file descriptor.
628 db->datain = db->dataout = db->datalimit = NULL;
629 db->compresspid = -1;
635 * Updates the buffer pointer for the input data buffer. The buffer is
636 * written regardless of how much data is present, since we know we
637 * are writing to a socket (to chunker) and there is no need to maintain
646 db->buf = (char *)buf;
647 db->datain = db->datalimit = db->buf + size;
648 db->dataout = db->buf;
649 return databuf_flush(db);
653 * Write out the buffer to chunker.
663 * If there's no data, do nothing.
665 if (db->dataout >= db->datain) {
670 * Write out the buffer
672 written = full_write(db->fd, db->dataout,
673 (size_t)(db->datain - db->dataout));
675 db->dataout += written;
676 dumpbytes += (off_t)written;
678 if (dumpbytes >= (off_t)1024) {
679 dumpsize += (dumpbytes / (off_t)1024);
680 dumpbytes %= (off_t)1024;
683 m = vstrallocf(_("data write: %s"), strerror(errno));
684 errstr = quote_string(m);
688 db->datain = db->dataout = db->buf;
692 static int dump_result;
694 #define GOT_INFO_ENDLINE (1 << 0)
695 #define GOT_SIZELINE (1 << 1)
696 #define GOT_ENDLINE (1 << 2)
697 #define HEADER_DONE (1 << 3)
701 process_dumpeof(void)
703 /* process any partial line in msgbuf? !!! */
704 add_msg_data(NULL, 0);
705 if(!ISSET(status, GOT_SIZELINE) && dump_result < 2) {
706 /* make a note if there isn't already a failure */
708 _("? %s: strange [missing size line from sendbackup]\n"),
711 errstr = stralloc(_("missing size line from sendbackup"));
713 dump_result = max(dump_result, 2);
716 if(!ISSET(status, GOT_ENDLINE) && dump_result < 2) {
718 _("? %s: strange [missing end line from sendbackup]\n"),
721 errstr = stralloc(_("missing end line from sendbackup"));
723 dump_result = max(dump_result, 2);
728 * Parse an information line from the client.
729 * We ignore unknown parameters and only remember the last
736 static const struct {
741 { "BACKUP", file.program, SIZEOF(file.program) },
742 { "APPLICATION", file.application, SIZEOF(file.application) },
743 { "RECOVER_CMD", file.recover_cmd, SIZEOF(file.recover_cmd) },
744 { "COMPRESS_SUFFIX", file.comp_suffix, SIZEOF(file.comp_suffix) },
745 { "SERVER_CUSTOM_COMPRESS", file.srvcompprog, SIZEOF(file.srvcompprog) },
746 { "CLIENT_CUSTOM_COMPRESS", file.clntcompprog, SIZEOF(file.clntcompprog) },
747 { "SERVER_ENCRYPT", file.srv_encrypt, SIZEOF(file.srv_encrypt) },
748 { "CLIENT_ENCRYPT", file.clnt_encrypt, SIZEOF(file.clnt_encrypt) },
749 { "SERVER_DECRYPT_OPTION", file.srv_decrypt_opt, SIZEOF(file.srv_decrypt_opt) },
750 { "CLIENT_DECRYPT_OPTION", file.clnt_decrypt_opt, SIZEOF(file.clnt_decrypt_opt) }
755 if (strcmp(str, "end") == 0) {
756 SET(status, GOT_INFO_ENDLINE);
760 name = strtok(str, "=");
763 value = strtok(NULL, "");
767 for (i = 0; i < SIZEOF(fields) / SIZEOF(fields[0]); i++) {
768 if (strcmp(name, fields[i].name) == 0) {
769 strncpy(fields[i].value, value, fields[i].len - 1);
770 fields[i].value[fields[i].len - 1] = '\0';
786 /* normal backup output line */
789 /* sendbackup detected something strange */
790 dump_result = max(dump_result, 1);
793 /* a sendbackup line, just check them all since there are only 5 */
794 tok = strtok(buf, " ");
795 if (tok == NULL || strcmp(tok, "sendbackup:") != 0)
798 tok = strtok(NULL, " ");
802 if (strcmp(tok, "start") == 0) {
806 if (strcmp(tok, "size") == 0) {
807 tok = strtok(NULL, "");
809 origsize = OFF_T_ATOI(tok);
810 SET(status, GOT_SIZELINE);
815 if (strcmp(tok, "end") == 0) {
816 SET(status, GOT_ENDLINE);
820 if (strcmp(tok, "warning") == 0) {
821 dump_result = max(dump_result, 1);
825 if (strcmp(tok, "error") == 0) {
826 SET(status, GOT_ENDLINE);
827 dump_result = max(dump_result, 2);
829 tok = strtok(NULL, "");
830 if (!errstr) { /* report first error line */
831 if (tok == NULL || *tok != '[') {
832 errstr = newvstrallocf(errstr, _("bad remote error: %s"),
837 tok++; /* skip over '[' */
838 if ((enderr = strchr(tok, ']')) != NULL)
840 errstr = newstralloc(errstr, tok);
846 if (strcmp(tok, "info") == 0) {
847 tok = strtok(NULL, "");
849 parse_info_line(tok);
852 /* else we fall through to bad line */
856 g_fprintf(errf, "??");
857 dump_result = max(dump_result, 1);
860 g_fprintf(errf, "%s\n", str);
873 buflen = strlen(msg.buf);
878 * If our argument is NULL, then we need to flush out any remaining
884 g_fprintf(errf,_("? %s: error [partial line in msgbuf: %zu bytes]\n"),
885 get_pname(), buflen);
886 g_fprintf(errf,_("? %s: error [partial line in msgbuf: \"%s\"]\n"),
887 get_pname(), msg.buf);
893 * Expand the buffer if it can't hold the new contents.
895 if ((buflen + len + 1) > msg.size) {
899 /* round up to next y, where y is a power of 2 */
900 #define ROUND(x, y) (((x) + (y) - 1) & ~((y) - 1))
902 newsize = ROUND(buflen + (ssize_t)len + 1, 256);
903 newbuf = alloc(newsize);
905 if (msg.buf != NULL) {
906 strncpy(newbuf, msg.buf, newsize);
915 * If there was a partial line from the last call, then
916 * append the new data to the end.
918 strncat(msg.buf, str, len);
921 * Process all lines in the buffer
922 * scanning line for unqouted newline.
924 for (ch = line = msg.buf; *ch != '\0'; ch++) {
927 * Found a newline. Terminate and process line.
930 process_dumpline(line);
936 * If we did not process all of the data, move it to the front
937 * of the buffer so it is there next time.
940 buflen = strlen(line);
941 memmove(msg.buf, line, (size_t)buflen + 1);
955 if (fseek(errf, 0L, SEEK_SET) < 0) {
956 dbprintf(_("log_msgout: warning - seek failed: %s\n"), strerror(errno));
958 while ((line = agets(errf)) != NULL) {
959 if (line[0] != '\0') {
960 log_add(typ, "%s", line);
971 * Fill in the rest of the tape header
978 assert(ISSET(status, HEADER_DONE));
980 file->type = F_DUMPFILE;
981 strncpy(file->datestamp, dumper_timestamp, sizeof(file->datestamp) - 1);
982 strncpy(file->name, hostname, SIZEOF(file->name) - 1);
983 strncpy(file->disk, diskname, SIZEOF(file->disk) - 1);
984 file->dumplevel = level;
985 file->blocksize = DISK_BLOCK_BYTES;
988 * If we're doing the compression here, we need to override what
989 * sendbackup told us the compression was.
991 if (srvcompress != COMP_NONE) {
992 file->compressed = 1;
993 #ifndef UNCOMPRESS_OPT
994 #define UNCOMPRESS_OPT ""
996 if (srvcompress == COMP_SERVER_CUST) {
997 g_snprintf(file->uncompress_cmd, SIZEOF(file->uncompress_cmd),
998 " %s %s |", srvcompprog, "-d");
999 strncpy(file->comp_suffix, "cust", SIZEOF(file->comp_suffix) - 1);
1000 file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
1001 strncpy(file->srvcompprog, srvcompprog, SIZEOF(file->srvcompprog) - 1);
1002 file->srvcompprog[SIZEOF(file->srvcompprog) - 1] = '\0';
1003 } else if ( srvcompress == COMP_CUST ) {
1004 g_snprintf(file->uncompress_cmd, SIZEOF(file->uncompress_cmd),
1005 " %s %s |", clntcompprog, "-d");
1006 strncpy(file->comp_suffix, "cust", SIZEOF(file->comp_suffix) - 1);
1007 file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
1008 strncpy(file->clntcompprog, clntcompprog, SIZEOF(file->clntcompprog));
1009 file->clntcompprog[SIZEOF(file->clntcompprog) - 1] = '\0';
1011 g_snprintf(file->uncompress_cmd, SIZEOF(file->uncompress_cmd),
1012 " %s %s |", UNCOMPRESS_PATH, UNCOMPRESS_OPT);
1013 strncpy(file->comp_suffix, COMPRESS_SUFFIX,SIZEOF(file->comp_suffix) - 1);
1014 file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
1017 if (file->comp_suffix[0] == '\0') {
1018 file->compressed = 0;
1019 assert(SIZEOF(file->comp_suffix) >= 2);
1020 strncpy(file->comp_suffix, "N", SIZEOF(file->comp_suffix) - 1);
1021 file->comp_suffix[SIZEOF(file->comp_suffix) - 1] = '\0';
1023 file->compressed = 1;
1026 /* take care of the encryption header here */
1027 if (srvencrypt != ENCRYPT_NONE) {
1029 if (srvencrypt == ENCRYPT_SERV_CUST) {
1030 g_snprintf(file->decrypt_cmd, SIZEOF(file->decrypt_cmd),
1031 " %s %s |", srv_encrypt, srv_decrypt_opt);
1032 strncpy(file->encrypt_suffix, "enc", SIZEOF(file->encrypt_suffix) - 1);
1033 file->encrypt_suffix[SIZEOF(file->encrypt_suffix) - 1] = '\0';
1034 strncpy(file->srv_encrypt, srv_encrypt, SIZEOF(file->srv_encrypt) - 1);
1035 file->srv_encrypt[SIZEOF(file->srv_encrypt) - 1] = '\0';
1036 strncpy(file->srv_decrypt_opt, srv_decrypt_opt, SIZEOF(file->srv_decrypt_opt) - 1);
1037 file->srv_decrypt_opt[SIZEOF(file->srv_decrypt_opt) - 1] = '\0';
1038 } else if ( srvencrypt == ENCRYPT_CUST ) {
1039 g_snprintf(file->decrypt_cmd, SIZEOF(file->decrypt_cmd),
1040 " %s %s |", clnt_encrypt, clnt_decrypt_opt);
1041 strncpy(file->encrypt_suffix, "enc", SIZEOF(file->encrypt_suffix) - 1);
1042 file->encrypt_suffix[SIZEOF(file->encrypt_suffix) - 1] = '\0';
1043 strncpy(file->clnt_encrypt, clnt_encrypt, SIZEOF(file->clnt_encrypt) - 1);
1044 file->clnt_encrypt[SIZEOF(file->clnt_encrypt) - 1] = '\0';
1045 strncpy(file->clnt_decrypt_opt, clnt_decrypt_opt, SIZEOF(file->clnt_decrypt_opt));
1046 file->clnt_decrypt_opt[SIZEOF(file->clnt_decrypt_opt) - 1] = '\0';
1049 if (file->encrypt_suffix[0] == '\0') {
1050 file->encrypted = 0;
1051 assert(SIZEOF(file->encrypt_suffix) >= 2);
1052 strncpy(file->encrypt_suffix, "N", SIZEOF(file->encrypt_suffix) - 1);
1053 file->encrypt_suffix[SIZEOF(file->encrypt_suffix) - 1] = '\0';
1059 file->dle_str = stralloc(dle_str);
1061 file->dle_str = NULL;
1065 * Send an Amanda dump header to the output file.
1075 buffer = build_header(file, DISK_BLOCK_BYTES);
1077 written = full_write(outfd, buffer, DISK_BLOCK_BYTES);
1079 if(written == DISK_BLOCK_BYTES)
1089 char *indexfile_tmp = NULL;
1090 char *indexfile_real = NULL;
1091 char level_str[NUM_STR_SIZE];
1095 double dumptime; /* Time dump took in secs */
1096 char *errfname = NULL;
1098 pid_t indexpid = -1;
1103 if (msg.buf) msg.buf[0] = '\0'; /* reset msg buffer */
1106 dumpbytes = dumpsize = headersize = origsize = (off_t)0;
1109 g_snprintf(level_str, SIZEOF(level_str), "%d", level);
1110 fn = sanitise_filename(diskname);
1111 errfname = newvstralloc(errfname,
1119 if((errf = fopen(errfname, "w+")) == NULL) {
1120 errstr = newvstrallocf(errstr, "errfile open \"%s\": %s",
1121 errfname, strerror(errno));
1125 unlink(errfname); /* so it goes away on close */
1128 if (streams[INDEXFD].fd != NULL) {
1129 indexfile_real = getindexfname(hostname, diskname, dumper_timestamp, level);
1130 indexfile_tmp = stralloc2(indexfile_real, ".tmp");
1132 if (mkpdir(indexfile_tmp, 0755, (uid_t)-1, (gid_t)-1) == -1) {
1133 errstr = newvstrallocf(errstr,
1134 _("err create %s: %s"),
1137 amfree(indexfile_real);
1138 amfree(indexfile_tmp);
1141 indexout = open(indexfile_tmp, O_WRONLY | O_CREAT | O_TRUNC, 0600);
1142 if (indexout == -1) {
1143 errstr = newvstrallocf(errstr, _("err open %s: %s"),
1144 indexfile_tmp, strerror(errno));
1147 if (runcompress(indexout, &indexpid, COMP_BEST) < 0) {
1154 * Schedule the indexfd for relaying to the index file
1156 security_stream_read(streams[INDEXFD].fd, read_indexfd, &indexout);
1160 * We only need to process messages initially. Once we have done
1161 * the header, we will start processing data too.
1163 security_stream_read(streams[MESGFD].fd, read_mesgfd, db);
1167 * Setup a read timeout
1169 timeout(conf_dtimeout);
1172 * Start the event loop. This will exit when all three events
1173 * (read the mesgfd, read the datafd, and timeout) are removed.
1177 if (!ISSET(status, HEADER_DONE)) {
1178 dump_result = max(dump_result, 2);
1179 if (!errstr) errstr = stralloc(_("got no header information"));
1182 dumpsize -= headersize; /* don't count the header */
1183 if (dumpsize <= (off_t)0) {
1184 dumpsize = (off_t)0;
1185 dump_result = max(dump_result, 2);
1186 if (!errstr) errstr = stralloc(_("got no data"));
1189 if (!ISSET(status, HEADER_DONE)) {
1190 dump_result = max(dump_result, 2);
1191 if (!errstr) errstr = stralloc(_("got no header information"));
1194 if (dumpsize == 0) {
1195 dump_result = max(dump_result, 2);
1196 if (!errstr) errstr = stralloc(_("got no data"));
1199 if (dump_result > 1)
1202 runtime = stopclock();
1203 dumptime = g_timeval_to_double(runtime);
1206 errstr = alloc(128);
1207 g_snprintf(errstr, 128, _("sec %s kb %lld kps %3.1lf orig-kb %lld"),
1208 walltime_str(runtime),
1209 (long long)dumpsize,
1210 (isnormal(dumptime) ? ((double)dumpsize / (double)dumptime) : 0.0),
1211 (long long)origsize);
1212 m = vstrallocf("[%s]", errstr);
1213 q = quote_string(m);
1215 putresult(DONE, _("%s %lld %lld %lu %s\n"), handle,
1216 (long long)origsize,
1217 (long long)dumpsize,
1218 (unsigned long)((double)dumptime+0.5), q);
1221 switch(dump_result) {
1223 log_add(L_SUCCESS, "%s %s %s %d [%s]", hostname, qdiskname, dumper_timestamp, level, errstr);
1228 log_start_multiline();
1229 log_add(L_STRANGE, "%s %s %d [%s]", hostname, qdiskname, level, errstr);
1230 log_msgout(L_STRANGE);
1231 log_end_multiline();
1236 if (errf) afclose(errf);
1239 if (indexfile_tmp) {
1240 amwait_t index_status;
1242 /*@i@*/ aclose(indexout);
1243 waitpid(indexpid,&index_status,0);
1244 log_add(L_INFO, "pid-done %ld", (long)indexpid);
1245 if (rename(indexfile_tmp, indexfile_real) != 0) {
1246 log_add(L_WARNING, _("could not rename \"%s\" to \"%s\": %s"),
1247 indexfile_tmp, indexfile_real, strerror(errno));
1249 amfree(indexfile_tmp);
1250 amfree(indexfile_real);
1253 if(db->compresspid != -1) {
1254 waitpid(db->compresspid,NULL,0);
1255 log_add(L_INFO, "pid-done %ld", (long)db->compresspid);
1257 if(db->encryptpid != -1) {
1258 waitpid(db->encryptpid,NULL,0);
1259 log_add(L_INFO, "pid-done %ld", (long)db->encryptpid);
1263 dumpfile_free_data(&file);
1268 m = vstrallocf("[%s]", errstr);
1269 q = quote_string(m);
1270 putresult(FAILED, "%s %s\n", handle, q);
1275 /* kill all child process */
1276 if (db->compresspid != -1) {
1277 g_fprintf(stderr,_("%s: kill compress command\n"),get_pname());
1278 if (kill(db->compresspid, SIGTERM) < 0) {
1279 if (errno != ESRCH) {
1280 g_fprintf(stderr,_("%s: can't kill compress command: %s\n"),
1281 get_pname(), strerror(errno));
1283 log_add(L_INFO, "pid-done %ld", (long)db->compresspid);
1287 waitpid(db->compresspid,NULL,0);
1288 log_add(L_INFO, "pid-done %ld", (long)db->compresspid);
1292 if (db->encryptpid != -1) {
1293 g_fprintf(stderr,_("%s: kill encrypt command\n"),get_pname());
1294 if (kill(db->encryptpid, SIGTERM) < 0) {
1295 if (errno != ESRCH) {
1296 g_fprintf(stderr,_("%s: can't kill encrypt command: %s\n"),
1297 get_pname(), strerror(errno));
1299 log_add(L_INFO, "pid-done %ld", (long)db->encryptpid);
1303 waitpid(db->encryptpid,NULL,0);
1304 log_add(L_INFO, "pid-done %ld", (long)db->encryptpid);
1308 if (indexpid != -1) {
1309 g_fprintf(stderr,_("%s: kill index command\n"),get_pname());
1310 if (kill(indexpid, SIGTERM) < 0) {
1311 if (errno != ESRCH) {
1312 g_fprintf(stderr,_("%s: can't kill index command: %s\n"),
1313 get_pname(),strerror(errno));
1315 log_add(L_INFO, "pid-done %ld", (long)indexpid);
1319 waitpid(indexpid,NULL,0);
1320 log_add(L_INFO, "pid-done %ld", (long)indexpid);
1324 log_start_multiline();
1325 log_add(L_FAIL, _("%s %s %s %d [%s]"), hostname, qdiskname, dumper_timestamp,
1330 log_end_multiline();
1332 if (errf) afclose(errf);
1334 if (indexfile_tmp) {
1335 unlink(indexfile_tmp);
1336 amfree(indexfile_tmp);
1337 amfree(indexfile_real);
1344 * Callback for reads on the mesgfd stream
1352 struct databuf *db = cookie;
1358 errstr = newvstrallocf(errstr, _("mesg read: %s"),
1359 security_stream_geterror(streams[MESGFD].fd));
1366 * EOF. Just shut down the mesg stream.
1369 security_stream_close(streams[MESGFD].fd);
1370 streams[MESGFD].fd = NULL;
1372 * If the data fd and index fd has also shut down, then we're done.
1374 if ((set_datafd == 0 || streams[DATAFD].fd == NULL) &&
1375 streams[INDEXFD].fd == NULL)
1380 assert(buf != NULL);
1381 add_msg_data(buf, (size_t)size);
1382 security_stream_read(streams[MESGFD].fd, read_mesgfd, cookie);
1386 if (ISSET(status, GOT_INFO_ENDLINE) && !ISSET(status, HEADER_DONE)) {
1387 SET(status, HEADER_DONE);
1388 /* time to do the header */
1389 finish_tapeheader(&file);
1390 if (write_tapeheader(db->fd, &file)) {
1391 errstr = newvstrallocf(errstr, _("write_tapeheader: %s"),
1397 dumpsize += (off_t)DISK_BLOCK_KB;
1398 headersize += (off_t)DISK_BLOCK_KB;
1400 if (srvencrypt == ENCRYPT_SERV_CUST) {
1401 if (runencrypt(db->fd, &db->encryptpid, srvencrypt) < 0) {
1408 * Now, setup the compress for the data output, and start
1409 * reading the datafd.
1411 if ((srvcompress != COMP_NONE) && (srvcompress != COMP_CUST)) {
1412 if (runcompress(db->fd, &db->compresspid, srvcompress) < 0) {
1418 security_stream_read(streams[DATAFD].fd, read_datafd, db);
1423 * Reset the timeout for future reads
1425 timeout(conf_dtimeout);
1429 * Callback for reads on the datafd stream
1437 struct databuf *db = cookie;
1442 * The read failed. Error out
1445 errstr = newvstrallocf(errstr, _("data read: %s"),
1446 security_stream_geterror(streams[DATAFD].fd));
1452 /* The header had better be written at this point */
1453 assert(ISSET(status, HEADER_DONE));
1456 * EOF. Stop and return.
1460 if (dumpbytes != (off_t)0) {
1461 dumpsize += (off_t)1;
1463 security_stream_close(streams[DATAFD].fd);
1464 streams[DATAFD].fd = NULL;
1466 * If the mesg fd and index fd has also shut down, then we're done.
1468 if (streams[MESGFD].fd == NULL && streams[INDEXFD].fd == NULL)
1474 * We read something. Add it to the databuf and reschedule for
1477 assert(buf != NULL);
1478 if (databuf_write(db, buf, (size_t)size) < 0) {
1479 errstr = newvstrallocf(errstr, _("data write: %s"), strerror(errno));
1486 * Reset the timeout for future reads
1488 timeout(conf_dtimeout);
1490 security_stream_read(streams[DATAFD].fd, read_datafd, cookie);
1494 * Callback for reads on the index stream
1504 assert(cookie != NULL);
1505 fd = *(int *)cookie;
1508 errstr = newvstrallocf(errstr, _("index read: %s"),
1509 security_stream_geterror(streams[INDEXFD].fd));
1516 * EOF. Stop and return.
1519 security_stream_close(streams[INDEXFD].fd);
1520 streams[INDEXFD].fd = NULL;
1522 * If the mesg fd has also shut down, then we're done.
1524 if ((set_datafd == 0 || streams[DATAFD].fd == NULL) &&
1525 streams[MESGFD].fd == NULL)
1530 assert(buf != NULL);
1533 * We ignore error while writing to the index file.
1535 if (full_write(fd, buf, (size_t)size) < (size_t)size) {
1536 /* Ignore error, but schedule another read. */
1537 if(indexfderror == 0) {
1539 log_add(L_INFO, _("Index corrupted for %s:%s"), hostname, qdiskname);
1542 security_stream_read(streams[INDEXFD].fd, read_indexfd, cookie);
1546 * Startup a timeout in the event handler. If the arg is 0,
1547 * then remove the timeout.
1553 static event_handle_t *ev_timeout = NULL;
1556 * First, remove a timeout if one is active.
1558 if (ev_timeout != NULL) {
1559 event_release(ev_timeout);
1564 * Now, schedule a new one if 'seconds' is greater than 0
1567 ev_timeout = event_register((event_id_t)seconds, EV_TIME, timeout_callback, NULL);
1571 * This is the callback for timeout(). If this is reached, then we
1572 * have a data timeout.
1578 (void)unused; /* Quiet unused parameter warning */
1580 assert(unused == NULL);
1581 errstr = newstralloc(errstr, _("data timeout"));
1587 * This is called when everything needs to shut down so event_loop()
1594 struct cmdargs *cmdargs = NULL;
1596 /* Check if I have a pending ABORT command */
1597 cmdargs = get_pending_cmd();
1599 if (cmdargs->cmd != ABORT) {
1602 errstr = stralloc(cmdargs->argv[1]);
1603 free_cmdargs(cmdargs);
1606 for (i = 0; i < NSTREAMS; i++) {
1607 if (streams[i].fd != NULL) {
1608 security_stream_close(streams[i].fd);
1609 streams[i].fd = NULL;
1617 * Runs compress with the first arg as its stdout. Returns
1618 * 0 on success or negative if error, and it's pid via the second
1619 * argument. The outfd arg is dup2'd to the pipe to the compress
1628 int outpipe[2], rval;
1631 assert(pid != NULL);
1633 /* outpipe[0] is pipe's stdin, outpipe[1] is stdout. */
1634 if (pipe(outpipe) < 0) {
1635 errstr = newvstrallocf(errstr, _("pipe: %s"), strerror(errno));
1639 switch (*pid = fork()) {
1641 errstr = newvstrallocf(errstr, _("couldn't fork: %s"), strerror(errno));
1646 rval = dup2(outpipe[1], outfd);
1648 errstr = newvstrallocf(errstr, _("couldn't dup2: %s"), strerror(errno));
1653 if (dup2(outpipe[0], 0) < 0) {
1654 error(_("err dup2 in: %s"), strerror(errno));
1657 if (dup2(outfd, 1) == -1) {
1658 error(_("err dup2 out: %s"), strerror(errno));
1661 if (comptype != COMP_SERVER_CUST) {
1662 char *base = stralloc(COMPRESS_PATH);
1663 log_add(L_INFO, "%s pid %ld", basename(base), (long)getpid());
1666 execlp(COMPRESS_PATH, COMPRESS_PATH, ( comptype == COMP_BEST ?
1667 COMPRESS_BEST_OPT : COMPRESS_FAST_OPT), (char *)NULL);
1668 error(_("error: couldn't exec %s: %s"), COMPRESS_PATH, strerror(errno));
1670 } else if (*srvcompprog) {
1671 char *base = stralloc(srvcompprog);
1672 log_add(L_INFO, "%s pid %ld", basename(base), (long)getpid());
1675 execlp(srvcompprog, srvcompprog, (char *)0);
1676 error(_("error: couldn't exec server custom filter%s.\n"), srvcompprog);
1685 * Runs encrypt with the first arg as its stdout. Returns
1686 * 0 on success or negative if error, and it's pid via the second
1687 * argument. The outfd arg is dup2'd to the pipe to the encrypt
1694 encrypt_t encrypttype)
1696 int outpipe[2], rval;
1699 assert(pid != NULL);
1701 /* outpipe[0] is pipe's stdin, outpipe[1] is stdout. */
1702 if (pipe(outpipe) < 0) {
1703 errstr = newvstrallocf(errstr, _("pipe: %s"), strerror(errno));
1707 switch (*pid = fork()) {
1709 errstr = newvstrallocf(errstr, _("couldn't fork: %s"), strerror(errno));
1714 rval = dup2(outpipe[1], outfd);
1716 errstr = newvstrallocf(errstr, _("couldn't dup2: %s"), strerror(errno));
1722 if (dup2(outpipe[0], 0) < 0) {
1723 error(_("err dup2 in: %s"), strerror(errno));
1726 if (dup2(outfd, 1) < 0 ) {
1727 error(_("err dup2 out: %s"), strerror(errno));
1730 base = stralloc(srv_encrypt);
1731 log_add(L_INFO, "%s pid %ld", basename(base), (long)getpid());
1734 if ((encrypttype == ENCRYPT_SERV_CUST) && *srv_encrypt) {
1735 execlp(srv_encrypt, srv_encrypt, (char *)0);
1736 error(_("error: couldn't exec server encryption%s.\n"), srv_encrypt);
1746 /* -------------------- */
1749 sendbackup_response(
1752 security_handle_t * sech)
1754 int ports[NSTREAMS], *response_error = datap, i;
1759 assert(response_error != NULL);
1760 assert(sech != NULL);
1762 security_close_connection(sech, hostname);
1765 errstr = newvstrallocf(errstr, _("[request failed: %s]"),
1766 security_geterror(sech));
1767 *response_error = 1;
1772 memset(ports, 0, SIZEOF(ports));
1773 if (pkt->type == P_NAK) {
1774 #if defined(PACKET_DEBUG)
1775 g_fprintf(stderr, _("got nak response:\n----\n%s\n----\n\n"), pkt->body);
1778 tok = strtok(pkt->body, " ");
1779 if (tok == NULL || strcmp(tok, "ERROR") != 0)
1782 tok = strtok(NULL, "\n");
1784 errstr = newvstrallocf(errstr, "NAK: %s", tok);
1785 *response_error = 1;
1788 errstr = newvstrallocf(errstr, "request NAK");
1789 *response_error = 2;
1794 if (pkt->type != P_REP) {
1795 errstr = newvstrallocf(errstr, _("received strange packet type %s: %s"),
1796 pkt_type2str(pkt->type), pkt->body);
1797 *response_error = 1;
1801 dbprintf(_("got response:\n----\n%s\n----\n\n"), pkt->body);
1803 for(i = 0; i < NSTREAMS; i++) {
1805 streams[i].fd = NULL;
1809 while((tok = strtok(p, " \n")) != NULL) {
1813 * Error response packets have "ERROR" followed by the error message
1814 * followed by a newline.
1816 if (strcmp(tok, "ERROR") == 0) {
1817 tok = strtok(NULL, "\n");
1819 tok = _("[bogus error packet]");
1820 errstr = newvstrallocf(errstr, "%s", tok);
1821 *response_error = 2;
1826 * Regular packets have CONNECT followed by three streams
1828 if (strcmp(tok, "CONNECT") == 0) {
1831 * Parse the three stream specifiers out of the packet.
1833 for (i = 0; i < NSTREAMS; i++) {
1834 tok = strtok(NULL, " ");
1835 if (tok == NULL || strcmp(tok, streams[i].name) != 0) {
1837 _("CONNECT token is \"%s\": expected \"%s\""),
1838 tok ? tok : "(null)",
1842 tok = strtok(NULL, " \n");
1843 if (tok == NULL || sscanf(tok, "%d", &ports[i]) != 1) {
1845 _("CONNECT %s token is \"%s\": expected a port number"),
1846 streams[i].name, tok ? tok : "(null)");
1854 * OPTIONS [options string] '\n'
1856 if (strcmp(tok, "OPTIONS") == 0) {
1857 tok = strtok(NULL, "\n");
1859 extra = vstrallocf(_("OPTIONS token is missing"));
1863 while((p = strchr(tok, ';')) != NULL) {
1866 if(strncmp_const_skip(tok, "features=", tok, ch) == 0) {
1867 char *u = strchr(tok, ';');
1870 am_release_feature_set(their_features);
1871 if((their_features = am_string_to_feature(tok)) == NULL) {
1872 errstr = newvstrallocf(errstr,
1873 _("OPTIONS: bad features value: %s"),
1885 extra = vstrallocf(_("next token is \"%s\": expected \"CONNECT\", \"ERROR\" or \"OPTIONS\""),
1886 tok ? tok : "(null)");
1890 if (dumper_kencrypt == KENCRYPT_WILL_DO)
1891 dumper_kencrypt = KENCRYPT_YES;
1894 * Connect the streams to their remote ports
1896 for (i = 0; i < NSTREAMS; i++) {
1899 streams[i].fd = security_stream_client(sech, ports[i]);
1900 if (streams[i].fd == NULL) {
1901 errstr = newvstrallocf(errstr,
1902 _("[could not connect %s stream: %s]"),
1904 security_geterror(sech));
1910 * Authenticate the streams
1912 for (i = 0; i < NSTREAMS; i++) {
1913 if (streams[i].fd == NULL)
1915 #ifdef KRB4_SECURITY
1917 * XXX krb4 historically never authenticated the index stream!
1918 * We need to reproduce this lossage here to preserve compatibility
1920 * It is wrong to delve into sech, but we have no choice here.
1922 if (strcasecmp(sech->driver->name, "krb4") == 0 && i == INDEXFD)
1925 if (security_stream_auth(streams[i].fd) < 0) {
1926 errstr = newvstrallocf(errstr,
1927 _("[could not authenticate %s stream: %s]"),
1929 security_stream_geterror(streams[i].fd));
1935 * The MESGFD and DATAFD streams are mandatory. If we didn't get
1938 if (streams[MESGFD].fd == NULL || streams[DATAFD].fd == NULL) {
1939 errstr = newvstrallocf(errstr, _("[couldn't open MESG or INDEX streams]"));
1943 /* everything worked */
1944 *response_error = 0;
1948 errstr = newvstrallocf(errstr,
1949 _("[parse of reply message failed: %s]"),
1950 extra ? extra : _("(no additional information)"));
1952 *response_error = 2;
1957 *response_error = 1;
1961 dumper_get_security_conf(
1965 (void)arg; /* Quiet unused parameter warning */
1967 if(!string || !*string)
1970 if(strcmp(string, "krb5principal")==0) {
1971 return(getconf_str(CNF_KRB5PRINCIPAL));
1972 } else if(strcmp(string, "krb5keytab")==0) {
1973 return(getconf_str(CNF_KRB5KEYTAB));
1974 } else if(strcmp(string, "amandad_path")==0) {
1975 return (amandad_path);
1976 } else if(strcmp(string, "client_username")==0) {
1977 return (client_username);
1978 } else if(strcmp(string, "ssh_keys")==0) {
1980 } else if(strcmp(string, "kencrypt")==0) {
1981 if (dumper_kencrypt == KENCRYPT_YES)
1991 const char *hostname,
1995 const char *dumpdate,
1996 const char *progname,
1997 const char *amandad_path,
1998 const char *client_username,
1999 const char *ssh_keys,
2001 const char *options)
2003 char level_string[NUM_STR_SIZE];
2007 const security_driver_t *secdrv;
2008 char *application_api;
2014 (void)disk; /* Quiet unused parameter warning */
2015 (void)amandad_path; /* Quiet unused parameter warning */
2016 (void)client_username; /* Quiet unused parameter warning */
2017 (void)ssh_keys; /* Quiet unused parameter warning */
2018 (void)auth; /* Quiet unused parameter warning */
2020 has_features = am_has_feature(their_features, fe_req_options_features);
2021 has_hostname = am_has_feature(their_features, fe_req_options_hostname);
2022 has_config = am_has_feature(their_features, fe_req_options_config);
2023 has_device = am_has_feature(their_features, fe_sendbackup_req_device);
2026 * Default to bsd authentication if none specified. This is gross.
2028 * Options really need to be pre-parsed into some sort of structure
2029 * much earlier, and then flattened out again before transmission.
2032 g_snprintf(level_string, SIZEOF(level_string), "%d", level);
2033 if(strcmp(progname, "DUMP") == 0
2034 || strcmp(progname, "GNUTAR") == 0) {
2035 application_api = "";
2037 application_api = "BACKUP ";
2039 req = vstralloc("SERVICE sendbackup\n",
2041 has_features ? "features=" : "",
2042 has_features ? our_feature_string : "",
2043 has_features ? ";" : "",
2044 has_hostname ? "hostname=" : "",
2045 has_hostname ? hostname : "",
2046 has_hostname ? ";" : "",
2047 has_config ? "config=" : "",
2048 has_config ? get_config_name() : "",
2049 has_config ? ";" : "",
2054 if (am_has_feature(their_features, fe_req_xml)) {
2057 vstrextend(&p, "<dle>\n", NULL);
2058 if (*application_api != '\0') {
2059 vstrextend(&p, " <program>APPLICATION</program>\n", NULL);
2061 vstrextend(&p, " <program>", progname, "</program>\n", NULL);
2063 vstrextend(&p, " ", b64disk, "\n", NULL);
2064 if (device && has_device) {
2065 vstrextend(&p, " ", b64device, "\n",
2068 vstrextend(&p, " <level>", level_string, "</level>\n", NULL);
2069 vstrextend(&p, options+1, "</dle>\n", NULL);
2070 pclean = clean_dle_str_for_client(p);
2071 vstrextend(&req, pclean, NULL);
2074 } else if (*application_api != '\0') {
2075 errstr = newvstrallocf(errstr,
2076 _("[does not support application-api]"));
2080 authopt = strstr(options, "auth=");
2087 " ", device && has_device ? device : "",
2090 " OPTIONS ", options,
2091 /* compat: if authopt=krb4, send krb4-auth */
2092 (authopt && strcasecmp(authopt, "krb4") ? "" : "krb4-auth"),
2097 dbprintf(_("send request:\n----\n%s\n----\n\n"), req);
2098 secdrv = security_getdriver(auth);
2099 if (secdrv == NULL) {
2100 errstr = newvstrallocf(errstr,
2101 _("[could not find security driver '%s']"), auth);
2106 protocol_sendreq(hostname, secdrv, dumper_get_security_conf, req,
2107 STARTUP_TIMEOUT, sendbackup_response, &response_error);
2112 return (response_error);