2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 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 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: diskfile.c,v 1.95 2006/07/26 15:17:37 martinea Exp $
40 static am_host_t *hostlist;
41 static netif_t *all_netifs;
44 static char *upcase(char *st);
45 static int parse_diskline(disklist_t *, const char *, FILE *, int *, char **);
46 static void disk_parserror(const char *, int, const char *, ...)
61 lst->head = lst->tail = NULL;
64 /* if we already have config errors, then don't bother */
65 if (config_errors(NULL) >= CFGERR_ERRORS) {
66 return config_errors(NULL);
69 if ((diskf = fopen(filename, "r")) == NULL) {
70 config_add_error(CFGERR_ERRORS,
71 vstrallocf(_("Could not open '%s': %s"), filename, strerror(errno)));
76 while ((line = agets(diskf)) != NULL) {
78 if (line[0] != '\0') {
79 if (parse_diskline(lst, filename, diskf, &line_num, &line) < 0) {
89 return config_errors(NULL);
98 for (p = hostlist; p != NULL; p = p->next) {
99 if(strcasecmp(p->hostname, hostname) == 0) return p;
106 const char *hostname,
107 const char *diskname)
112 host = lookup_host(hostname);
116 for (disk = host->disks; disk != NULL; disk = disk->hostnext) {
117 if (strcmp(disk->name, diskname) == 0)
125 * put disk on end of queue
133 if(list->tail == NULL) list->head = disk;
134 else list->tail->next = disk;
135 disk->prev = list->tail;
143 * put disk on head of queue
151 if(list->head == NULL) list->tail = disk;
152 else list->head->prev = disk;
153 disk->next = list->head;
161 * insert in sorted order
168 int (*cmp)(disk_t *a, disk_t *b))
176 if(cmp(disk, ptr) < 0) break;
183 if(prev == NULL) list->head = disk;
184 else prev->next = disk;
185 if(ptr == NULL) list->tail = disk;
186 else ptr->prev = disk;
198 disk = alloc(SIZEOF(disk_t));
199 bzero(disk, SIZEOF(disk_t));
201 disk->tape_splitsize = (off_t)0;
202 disk->split_diskbuffer = NULL;
203 disk->fallback_splitsize = (off_t)0;
204 disk->hostname = stralloc(hostname);
205 disk->name = stralloc(diskname);
206 disk->device = stralloc(diskname);
209 disk->compress = COMP_NONE;
210 disk->encrypt = ENCRYPT_NONE;
214 disk->exclude_list = NULL;
215 disk->exclude_file = NULL;
216 disk->include_list = NULL;
217 disk->include_file = NULL;
218 disk->application = NULL;
219 disk->pp_scriptlist = NULL;
221 host = lookup_host(hostname);
223 host = alloc(SIZEOF(am_host_t));
224 host->next = hostlist;
227 host->hostname = stralloc(hostname);
229 host->inprogress = 0;
234 host->features = NULL;
235 host->pre_script = 0;
236 host->post_script = 0;
238 enqueue_disk(list, disk);
241 disk->hostnext = host->disks;
249 * check if disk is present in list. Return true if so, false otherwise.
260 while ((t != NULL) && (t != disk)) {
275 int (*cmp)(disk_t *a, disk_t *b))
280 tmp = in; /* just in case in == out */
282 out->head = (disk_t *)0;
283 out->tail = (disk_t *)0;
285 while((disk = dequeue_disk(tmp)))
286 insert_disk(out, disk, cmp);
291 * remove disk from front of queue
300 if(list->head == NULL) return NULL;
303 list->head = disk->next;
305 if(list->head == NULL) list->tail = NULL;
306 else list->head->prev = NULL;
308 disk->prev = disk->next = NULL; /* for debugging */
317 if(disk->prev == NULL) list->head = disk->next;
318 else disk->prev->next = disk->next;
320 if(disk->next == NULL) list->tail = disk->prev;
321 else disk->next->prev = disk->prev;
323 disk->prev = disk->next = NULL;
331 am_host_t *host, *hostnext;
332 netif_t *netif, *next_if;
334 while (dl->head != NULL) {
335 dp = dequeue_disk(dl);
337 amfree(dp->hostname);
339 free_sl(dp->exclude_file);
340 free_sl(dp->exclude_list);
341 free_sl(dp->include_file);
342 free_sl(dp->include_list);
346 for(host=hostlist; host != NULL; host = hostnext) {
347 amfree(host->hostname);
348 am_release_feature_set(host->features);
349 host->features = NULL;
350 hostnext = host->next;
355 for (netif = all_netifs; netif != NULL; netif = next_if) {
356 next_if = netif->next;
369 if(islower((int)*s)) *s = (char)toupper((int)*s);
376 /* return 0 on success */
377 /* return -1 on error */
381 const char *filename,
384 /*@keep@*/ char ** line_p)
389 netif_t *netif = NULL;
390 interface_t *cfg_if = NULL;
391 char *hostname = NULL;
392 char *diskname, *diskdevice;
396 char *line = *line_p;
397 int line_num = *line_num_p;
405 assert(filename != NULL);
406 assert(line_num > 0);
407 assert(line != NULL);
411 skip_whitespace(s, ch);
412 if(ch == '\0' || ch == '#')
416 skip_non_whitespace(s, ch);
418 host = lookup_host(fp);
420 hostname = stralloc(fp);
422 hostname = stralloc(host->hostname);
423 if (strcmp(host->hostname, fp) != 0) {
424 disk_parserror(filename, line_num, _("Same host with different case: \"%s\" and \"%s\"."), host->hostname, fp);
429 shost = sanitise_filename(hostname);
430 for (p = hostlist; p != NULL; p = p->next) {
431 char *shostp = sanitise_filename(p->hostname);
432 if (strcmp(hostname, p->hostname) &&
433 !strcmp(shost, shostp)) {
434 disk_parserror(filename, line_num, _("Two hosts are mapping to the same name: \"%s\" and \"%s\""), p->hostname, hostname);
437 else if (strcasecmp(hostname, p->hostname) &&
438 match_host(hostname, p->hostname) &&
439 match_host(p->hostname, hostname)) {
440 disk_parserror(filename, line_num, _("Duplicate host name: \"%s\" and \"%s\""), p->hostname, hostname);
447 skip_whitespace(s, ch);
448 if(ch == '\0' || ch == '#') {
449 disk_parserror(filename, line_num, _("disk device name expected"));
455 skip_quoted_string(s, ch);
457 diskname = unquote_string(fp);
458 if (strlen(diskname) == 0) {
459 disk_parserror(filename, line_num, _("invalid empty diskname"));
463 skip_whitespace(s, ch);
464 if(ch == '\0' || ch == '#') {
465 disk_parserror(filename, line_num, _("disk dumptype expected"));
471 skip_quoted_string(s, ch);
478 dumptype = unquote_string(fp);
479 if (strlen(dumptype) == 0) {
480 disk_parserror(filename, line_num, _("invalid empty diskdevice"));
484 if ((dtype = lookup_dumptype(dumptype)) == NULL) {
485 diskdevice = dumptype;
486 skip_whitespace(s, ch);
487 if(ch == '\0' || ch == '#') {
488 disk_parserror(filename, line_num,
489 _("disk dumptype '%s' not found"), dumptype);
497 skip_quoted_string(s, ch);
500 dumptype = unquote_string(fp);
505 /* check for duplicate disk */
508 if ((disk = lookup_disk(hostname, diskname)) != NULL) {
514 a1 = clean_regex(diskname, 1);
515 a2 = clean_regex(disk->name, 1);
517 if (match_disk(a1, disk->name) && match_disk(a2, diskname)) {
520 disk = disk->hostnext;
525 while (dup == 0 && disk != NULL);
528 disk_parserror(filename, line_num,
529 _("duplicate disk record, previous on line %d"),
534 disk = alloc(SIZEOF(disk_t));
535 disk->line = line_num;
536 disk->hostname = hostname;
537 disk->name = diskname;
538 disk->device = diskdevice;
541 disk->inprogress = 0;
542 disk->application = NULL;
543 disk->pp_scriptlist = NULL;
544 disk->dataport_list = NULL;
548 sdisk = sanitise_filename(diskname);
549 for (dp = host->disks; dp != NULL; dp = dp->hostnext) {
550 char *sdiskp = sanitise_filename(dp->name);
551 if (strcmp(diskname, dp->name) != 0 &&
552 strcmp(sdisk, sdiskp) == 0) {
553 disk_parserror(filename, line_num,
554 _("Two disks are mapping to the same name: \"%s\" and \"%s\"; you must use different diskname"),
566 skip_whitespace(s, ch);
567 if (ch != '\0' && ch != '#') {
568 disk_parserror(filename, line_num,
569 _("expected line break after `{\', ignoring rest of line"));
572 if (strchr(s-1, '}') &&
573 (strchr(s-1, '#') == NULL ||
574 strchr(s-1, '}') < strchr(s-1, '#'))) {
575 disk_parserror(filename, line_num,_("'}' on same line than '{'"));
578 amfree(disk->device);
587 dtype = read_dumptype(vstralloc("custom(", hostname,
588 ":", disk->name, ")",
589 ".", anonymous_value(), NULL),
590 diskf, (char*)filename, line_num_p);
591 if (dtype == NULL || dup) {
592 disk_parserror(filename, line_num,
593 _("read of custom dumptype failed"));
596 amfree(disk->device);
607 *line_p = line = agets(diskf);
608 line_num = *line_num_p; /* no incr, read_dumptype did it already */
611 *line_p = line = stralloc("");
615 if((dtype = lookup_dumptype(dumptype)) == NULL) {
616 char *qdt = quote_string(dumptype);
618 disk_parserror(filename, line_num, _("undefined dumptype `%s'"), qdt);
622 amfree(disk->device);
635 /* disk_parserror already called, above */
636 g_assert(config_errors(NULL) != CFGERR_OK);
643 disk->dtype_name = dumptype_name(dtype);
644 disk->program = dumptype_get_program(dtype);
645 disk->exclude_list = duplicate_sl(dumptype_get_exclude(dtype).sl_list);
646 disk->exclude_file = duplicate_sl(dumptype_get_exclude(dtype).sl_file);
647 disk->exclude_optional = dumptype_get_exclude(dtype).optional;
648 disk->include_list = duplicate_sl(dumptype_get_include(dtype).sl_list);
649 disk->include_file = duplicate_sl(dumptype_get_include(dtype).sl_file);
650 disk->include_optional = dumptype_get_include(dtype).optional;
651 disk->priority = dumptype_get_priority(dtype);
652 disk->dumpcycle = dumptype_get_dumpcycle(dtype);
653 /* disk->frequency = dumptype_get_frequency(dtype);*/
654 disk->auth = dumptype_get_auth(dtype);
655 disk->maxdumps = dumptype_get_maxdumps(dtype);
656 disk->tape_splitsize = dumptype_get_tape_splitsize(dtype);
657 disk->split_diskbuffer = dumptype_get_split_diskbuffer(dtype);
658 disk->fallback_splitsize = dumptype_get_fallback_splitsize(dtype);
659 disk->maxpromoteday = dumptype_get_maxpromoteday(dtype);
660 disk->bumppercent = dumptype_get_bumppercent(dtype);
661 disk->bumpsize = dumptype_get_bumpsize(dtype);
662 disk->bumpdays = dumptype_get_bumpdays(dtype);
663 disk->bumpmult = dumptype_get_bumpmult(dtype);
664 disk->starttime = dumptype_get_starttime(dtype);
665 disk->application = dumptype_get_application(dtype);
666 disk->pp_scriptlist = dumptype_get_scriptlist(dtype);
668 if (disk->starttime > 0) {
671 stm = localtime(&st);
672 disk->start_t -= stm->tm_sec + 60 * stm->tm_min + 3600 * stm->tm_hour;
673 disk->start_t += disk->starttime / 100 * 3600 +
674 disk->starttime % 100 * 60;
675 if ((disk->start_t - st) < -43200)
676 disk->start_t += 86400;
678 disk->strategy = dumptype_get_strategy(dtype);
679 disk->ignore = dumptype_get_ignore(dtype);
680 disk->estimatelist = dumptype_get_estimatelist(dtype);
681 disk->compress = dumptype_get_compress(dtype);
682 disk->srvcompprog = dumptype_get_srvcompprog(dtype);
683 disk->clntcompprog = dumptype_get_clntcompprog(dtype);
684 disk->encrypt = dumptype_get_encrypt(dtype);
685 disk->srv_decrypt_opt = dumptype_get_srv_decrypt_opt(dtype);
686 disk->clnt_decrypt_opt = dumptype_get_clnt_decrypt_opt(dtype);
687 disk->srv_encrypt = dumptype_get_srv_encrypt(dtype);
688 disk->clnt_encrypt = dumptype_get_clnt_encrypt(dtype);
689 disk->amandad_path = dumptype_get_amandad_path(dtype);
690 disk->client_username = dumptype_get_client_username(dtype);
691 disk->client_port = dumptype_get_client_port(dtype);
692 disk->ssh_keys = dumptype_get_ssh_keys(dtype);
693 disk->comprate[0] = dumptype_get_comprate(dtype)[0];
694 disk->comprate[1] = dumptype_get_comprate(dtype)[1];
695 disk->data_path = dumptype_get_data_path(dtype);
698 * Boolean parameters with no value (Appears here as value 2) defaults
699 * to TRUE for backward compatibility and for logical consistency.
701 disk->record = dumptype_get_record(dtype) != 0;
702 disk->skip_incr = dumptype_get_skip_incr(dtype) != 0;
703 disk->skip_full = dumptype_get_skip_full(dtype) != 0;
704 disk->to_holdingdisk = dumptype_get_to_holdingdisk(dtype);
705 disk->kencrypt = dumptype_get_kencrypt(dtype) != 0;
706 disk->index = dumptype_get_index(dtype) != 0;
710 skip_whitespace(s, ch);
712 if(ch && ch != '#') { /* get optional spindle number */
716 skip_non_whitespace(s, ch);
719 if (*fp1 == '-') fp1++;
720 for(;*fp1!='\0';fp1++) {
721 if(!isdigit((int)*fp1)) {
726 disk_parserror(filename, line_num, _("non-integer spindle `%s'"), fp);
732 disk->spindle = atoi(fp);
736 skip_whitespace(s, ch);
738 if(ch && ch != '#') { /* get optional network interface */
739 skip_non_whitespace(s, ch);
741 if((cfg_if = lookup_interface(upcase(fp))) == NULL) {
742 disk_parserror(filename, line_num,
743 _("undefined network interface `%s'"), fp);
750 cfg_if = lookup_interface("default");
753 /* see if we already have a netif_t for this interface */
754 for (netif = all_netifs; netif != NULL; netif = netif->next) {
755 if (netif->config == cfg_if)
759 /* nope; make up a new one */
761 netif = alloc(sizeof(*netif));
762 netif->next = all_netifs;
764 netif->config = cfg_if;
768 skip_whitespace(s, ch);
769 if(ch && ch != '#') { /* now we have garbage, ignore it */
770 disk_parserror(filename, line_num, _("end of line expected"));
773 if (disk->program && disk->application &&
774 strcmp(disk->program,"APPLICATION")) {
775 disk_parserror(filename, line_num,
776 _("Both program and application set"));
779 if (disk->program && strcmp(disk->program,"APPLICATION")==0 &&
780 !disk->application) {
781 disk_parserror(filename, line_num,
782 _("program set to APPLICATION but no application set"));
785 if (disk->application) {
786 application_t *application;
789 application = lookup_application(disk->application);
790 g_assert(application != NULL);
791 plugin = application_get_plugin(application);
792 if (!plugin || strlen(plugin) == 0) {
793 disk_parserror(filename, line_num,
794 _("plugin not set for application"));
798 for (pp_iter = disk->pp_scriptlist; pp_iter != NULL;
799 pp_iter = pp_iter->next) {
800 pp_script_t *pp_script;
802 char *pp_script_name;
804 pp_script_name = (char*)pp_iter->data;
805 pp_script = lookup_pp_script(pp_script_name);
806 g_assert(pp_script != NULL);
807 plugin = pp_script_get_plugin(pp_script);
808 if (!plugin || strlen(plugin) == 0) {
809 disk_parserror(filename, line_num, _("plugin not set for script"));
813 /* success, add disk to lists */
815 if(host == NULL) { /* new host */
816 host = alloc(SIZEOF(am_host_t));
817 host->next = hostlist;
820 host->hostname = stralloc(hostname);
823 host->inprogress = 0;
824 host->maxdumps = 1; /* will be overwritten */
828 host->features = NULL;
829 host->pre_script = 0;
830 host->post_script = 0;
835 enqueue_disk(lst, disk);
838 disk->hostnext = host->disks;
840 host->maxdumps = disk->maxdumps;
846 printf_arglist_function2(void disk_parserror, const char *, filename,
847 int, line_num, const char *, format)
853 /* format the error message and hand it off to conffile */
855 arglist_start(argp, format);
856 msg = g_strdup_vprintf(format, argp);
857 errstr = g_strdup_printf("\"%s\", line %d: %s", filename, line_num, msg);
861 config_add_error(CFGERR_ERRORS, errstr);
869 int npr, /* we print first npr disks on queue, plus last two */
877 g_fprintf(f, _("%s QUEUE: empty\n"), st);
880 g_fprintf(f, _("%s QUEUE:\n"), st);
881 for(pos = 0, d = q.head, p = NULL; d != NULL; p = d, d = d->next, pos++) {
882 qname = quote_string(d->name);
883 if(pos < npr) g_fprintf(f, "%3d: %-10s %-4s\n",
884 pos, d->host->hostname, qname);
888 if(pos > npr+2) g_fprintf(f, " ...\n");
891 g_fprintf(f, "%3d: %-10s %-4s\n", pos-2, d->host->hostname, d->name);
894 g_fprintf(f, "%3d: %-10s %-4s\n", pos-1, d->host->hostname, d->name);
905 am_feature_t *their_features = dp->host->features;
908 assert(dp->host != NULL);
910 errarray = g_ptr_array_new();
912 if (!am_has_feature(their_features, fe_options_auth)) {
913 if (strcasecmp(dp->auth, "bsd") == 0)
914 if (!am_has_feature(their_features, fe_options_bsd_auth))
915 g_ptr_array_add(errarray, _("does not support auth"));
918 switch(dp->compress) {
920 if (!am_has_feature(their_features, fe_options_compress_fast)) {
921 g_ptr_array_add(errarray, _("does not support fast compression"));
925 if (!am_has_feature(their_features, fe_options_compress_best)) {
926 g_ptr_array_add(errarray, _("does not support best compression"));
930 if (am_has_feature(their_features, fe_options_compress_cust)) {
931 if (dp->clntcompprog == NULL || strlen(dp->clntcompprog) == 0) {
932 g_ptr_array_add(errarray, _("client custom compression with no compression program specified"));
935 g_ptr_array_add(errarray, _("does not support client custom compression"));
938 case COMP_SERVER_FAST:
940 case COMP_SERVER_BEST:
942 case COMP_SERVER_CUST:
943 if (dp->srvcompprog == NULL || strlen(dp->srvcompprog) == 0) {
944 g_ptr_array_add(errarray, _("server custom compression with no compression program specified"));
949 switch(dp->encrypt) {
951 if (am_has_feature(their_features, fe_options_encrypt_cust)) {
952 if (dp->clnt_decrypt_opt) {
953 if (!am_has_feature(their_features, fe_options_client_decrypt_option)) {
954 g_ptr_array_add(errarray, _("does not support client decrypt option"));
957 if (dp->clnt_encrypt == NULL || strlen(dp->clnt_encrypt) == 0) {
958 g_ptr_array_add(errarray, _("encrypt client with no encryption program specified"));
960 if (dp->compress == COMP_SERVER_FAST ||
961 dp->compress == COMP_SERVER_BEST ||
962 dp->compress == COMP_SERVER_CUST ) {
963 g_ptr_array_add(errarray, _("Client encryption with server compression is not supported. See amanda.conf(5) for detail"));
966 g_ptr_array_add(errarray, _("does not support client data encryption"));
969 case ENCRYPT_SERV_CUST:
970 if (dp->srv_encrypt == NULL || strlen(dp->srv_encrypt) == 0) {
971 g_ptr_array_add(errarray, _("No encryption program specified in dumptypes, Change the dumptype in the disklist or mention the encryption program to use in the dumptypes file"));
977 if (!am_has_feature(their_features, fe_options_no_record)) {
978 g_ptr_array_add(errarray, _("does not support no record"));
983 if (!am_has_feature(their_features, fe_options_index)) {
984 g_ptr_array_add(errarray, _("does not support index"));
989 if (!am_has_feature(their_features, fe_options_kencrypt)) {
990 g_ptr_array_add(errarray, _("does not support kencrypt"));
995 if (dp->exclude_file != NULL && dp->exclude_file->nb_element > 0) {
996 nb_exclude = dp->exclude_file->nb_element;
997 if (!am_has_feature(their_features, fe_options_exclude_file)) {
998 g_ptr_array_add(errarray, _("does not support exclude file"));
1002 if (dp->exclude_list != NULL && dp->exclude_list->nb_element > 0) {
1003 nb_exclude += dp->exclude_list->nb_element;
1004 if (!am_has_feature(their_features, fe_options_exclude_list)) {
1005 g_ptr_array_add(errarray, _("does not support exclude list"));
1009 if (nb_exclude > 1 &&
1010 !am_has_feature(their_features, fe_options_multiple_exclude)) {
1011 g_ptr_array_add(errarray, _("does not support multiple exclude"));
1015 if (dp->include_file != NULL && dp->include_file->nb_element > 0) {
1016 nb_include = dp->include_file->nb_element;
1017 if (!am_has_feature(their_features, fe_options_include_file)) {
1018 g_ptr_array_add(errarray, ("does not support include file"));
1022 if (dp->include_list != NULL && dp->include_list->nb_element > 0) {
1023 nb_include += dp->include_list->nb_element;
1024 if (!am_has_feature(their_features, fe_options_include_list)) {
1025 g_ptr_array_add(errarray, _("does not support include list"));
1029 if (nb_include > 1 &&
1030 !am_has_feature(their_features, fe_options_multiple_exclude)) {
1031 g_ptr_array_add(errarray, _("does not support multiple include"));
1034 if (dp->exclude_optional) {
1035 if (!am_has_feature(their_features, fe_options_optional_exclude)) {
1036 g_ptr_array_add(errarray, _("does not support optional exclude"));
1039 if (dp->include_optional) {
1040 if (!am_has_feature(their_features, fe_options_optional_include)) {
1041 g_ptr_array_add(errarray, _("does not support optional include"));
1052 char *auth_opt = NULL;
1053 char *kencrypt_opt = "";
1054 char *compress_opt = "";
1055 char *encrypt_opt = stralloc("");
1056 char *decrypt_opt = stralloc("");
1057 char *record_opt = "";
1058 char *index_opt = "";
1059 char *exclude_file = NULL;
1060 char *exclude_list = NULL;
1061 char *include_file = NULL;
1062 char *include_list = NULL;
1063 char *excl_opt = "";
1064 char *incl_opt = "";
1066 char *result = NULL;
1070 am_feature_t *their_features = dp->host->features;
1073 assert(dp->host != NULL);
1075 qdpname = quote_string(dp->name);
1076 if (am_has_feature(their_features, fe_options_auth)) {
1077 auth_opt = vstralloc("auth=", dp->auth, ";", NULL);
1078 } else if(strcasecmp(dp->auth, "bsd") == 0) {
1079 if(am_has_feature(their_features, fe_options_bsd_auth))
1080 auth_opt = stralloc("bsd-auth;");
1083 switch(dp->compress) {
1085 compress_opt = "compress-fast;";
1088 compress_opt = "compress-best;";
1091 compress_opt = vstralloc("comp-cust=", dp->clntcompprog, ";", NULL);
1093 case COMP_SERVER_FAST:
1094 compress_opt = "srvcomp-fast;";
1096 case COMP_SERVER_BEST:
1097 compress_opt = "srvcomp-best;";
1099 case COMP_SERVER_CUST:
1100 compress_opt = vstralloc("srvcomp-cust=", dp->srvcompprog, ";", NULL);
1104 switch(dp->encrypt) {
1106 encrypt_opt = newvstralloc(encrypt_opt, "encrypt-cust=",
1107 dp->clnt_encrypt, ";", NULL);
1108 if (dp->clnt_decrypt_opt) {
1109 decrypt_opt = newvstralloc(decrypt_opt, "client-decrypt-option=",
1110 dp->clnt_decrypt_opt, ";", NULL);
1113 case ENCRYPT_SERV_CUST:
1114 encrypt_opt = newvstralloc(encrypt_opt, "encrypt-serv-cust=",
1115 dp->srv_encrypt, ";", NULL);
1116 if (dp->srv_decrypt_opt) {
1117 decrypt_opt = newvstralloc(decrypt_opt, "server-decrypt-option=",
1118 dp->srv_decrypt_opt, ";", NULL);
1124 record_opt = "no-record;";
1128 index_opt = "index;";
1132 kencrypt_opt = "kencrypt;";
1135 exclude_file = stralloc("");
1136 if (dp->exclude_file != NULL && dp->exclude_file->nb_element > 0) {
1137 for(excl = dp->exclude_file->first; excl != NULL;
1138 excl = excl->next) {
1139 qname = quote_string(excl->name);
1140 exc = newvstralloc( exc, "exclude-file=", qname, ";", NULL);
1141 strappend(exclude_file, exc);
1145 exclude_list = stralloc("");
1146 if (dp->exclude_list != NULL && dp->exclude_list->nb_element > 0) {
1147 for(excl = dp->exclude_list->first; excl != NULL;
1148 excl = excl->next) {
1149 qname = quote_string(excl->name);
1150 exc = newvstralloc( exc, "exclude-list=", qname, ";", NULL);
1151 strappend(exclude_list, exc);
1156 include_file = stralloc("");
1157 if (dp->include_file != NULL && dp->include_file->nb_element > 0) {
1158 for(excl = dp->include_file->first; excl != NULL;
1159 excl = excl->next) {
1160 qname = quote_string(excl->name);
1161 exc = newvstralloc(exc, "include-file=", qname, ";", NULL);
1162 strappend(include_file, exc);
1166 include_list = stralloc("");
1167 if (dp->include_list != NULL && dp->include_list->nb_element > 0) {
1168 for(excl = dp->include_list->first; excl != NULL;
1169 excl = excl->next) {
1170 qname = quote_string(excl->name);
1171 exc = newvstralloc(exc, "include-list=", qname, ";", NULL);
1172 strappend(include_list, exc);
1177 if (dp->exclude_optional) {
1178 excl_opt = "exclude-optional;";
1180 if (dp->include_optional) {
1181 incl_opt = "include-optional;";
1184 result = vstralloc(";",
1201 amfree(exclude_list);
1202 amfree(exclude_file);
1203 amfree(include_file);
1204 amfree(include_list);
1206 amfree(decrypt_opt);
1207 amfree(encrypt_opt);
1209 /* result contains at least 'auth=...' */
1219 char *auth_opt = stralloc("");
1220 char *kencrypt_opt = stralloc("");
1221 char *compress_opt = stralloc("");
1222 char *encrypt_opt = stralloc("");
1223 char *decrypt_opt = stralloc("");
1224 char *record_opt = stralloc("");
1225 char *index_opt = stralloc("");
1226 char *data_path_opt = stralloc("");
1227 char *exclude = stralloc("");
1228 char *exclude_file = NULL;
1229 char *exclude_list = NULL;
1230 char *include = stralloc("");
1231 char *include_file = NULL;
1232 char *include_list = NULL;
1233 char *excl_opt = "";
1234 char *incl_opt = "";
1237 char *result = NULL;
1241 am_feature_t *their_features = dp->host->features;
1244 assert(dp->host != NULL);
1246 qdpname = quote_string(dp->name);
1247 if (am_has_feature(their_features, fe_options_auth)) {
1248 auth_opt = vstralloc(" <auth>", dp->auth, "</auth>\n", NULL);
1251 switch(dp->compress) {
1253 compress_opt = " <compress>FAST</compress>\n";
1256 compress_opt = " <compress>BEST</compress>\n";
1259 compress_opt = vstralloc(" <compress>CUSTOM"
1260 "<custom-compress-program>",
1262 "</custom-compress-program>\n"
1263 " </compress>\n", NULL);
1265 case COMP_SERVER_FAST:
1266 compress_opt = " <compress>SERVER-FAST</compress>\n";
1268 case COMP_SERVER_BEST:
1269 compress_opt = " <compress>SERVER-BEST</compress>\n";
1271 case COMP_SERVER_CUST:
1272 compress_opt = " <compress>SERVER-CUSTOM</compress>\n";
1273 compress_opt = vstralloc(" <compress>SERVER-CUSTOM"
1274 "<custom-compress-program>",
1276 "</custom-compress-program>\n"
1277 " </compress>\n", NULL);
1281 switch(dp->encrypt) {
1283 if (dp->clnt_decrypt_opt) {
1284 decrypt_opt = newvstralloc(decrypt_opt,
1285 " <decrypt-option>",
1286 dp->clnt_decrypt_opt,
1287 "</decrypt-option>\n", NULL);
1290 encrypt_opt = newvstralloc(encrypt_opt,
1292 "<custom-encrypt-program>",
1294 "</custom-encrypt-program>\n",
1296 " </encrypt>\n", NULL);
1299 case ENCRYPT_SERV_CUST:
1301 decrypt_opt = newvstralloc(decrypt_opt,
1302 " <decrypt-option>",
1303 dp->srv_decrypt_opt,
1304 "</decrypt-option>\n", NULL);
1305 encrypt_opt = newvstralloc(encrypt_opt,
1306 " <encrypt>SERVER-CUSTOM"
1307 "<custom-encrypt-program>",
1309 "</custom-encrypt-program>\n",
1311 " </encrypt>\n", NULL);
1317 record_opt = " <record>NO</record>\n";
1319 record_opt = " <record>YES</record>\n";
1323 index_opt = " <index>YES</index>\n";
1327 kencrypt_opt = " <kencrypt>YES</kencrypt>\n";
1330 if (am_has_feature(their_features, fe_xml_data_path)) {
1331 switch(dp->data_path) {
1332 case DATA_PATH_AMANDA:
1333 data_path_opt = stralloc(" <datapath>AMANDA</datapath>\n");
1335 case DATA_PATH_DIRECTTCP:
1336 { /* dp->dataport_list is not set for selfcheck/sendsize */
1337 if (am_has_feature(their_features, fe_xml_directtcp_list)) {
1339 char *value, *b64value;
1341 data_path_opt = stralloc(" <datapath>DIRECTTCP");
1342 if (dp->dataport_list) {
1343 s = sc = stralloc(dp->dataport_list);
1351 b64value = amxml_format_tag("directtcp", value);
1352 vstrextend(&data_path_opt, "\n ", b64value, NULL);
1356 strappend(data_path_opt, "\n ");
1358 strappend(data_path_opt, "</datapath>\n");
1365 exclude_file = stralloc("");
1366 if (dp->exclude_file != NULL && dp->exclude_file->nb_element > 0) {
1367 for(excl = dp->exclude_file->first; excl != NULL;
1368 excl = excl->next) {
1369 q64name = amxml_format_tag("file", excl->name);
1370 exc = newvstralloc( exc, " ", q64name, "\n", NULL);
1371 strappend(exclude_file, exc);
1375 exclude_list = stralloc("");
1376 if (dp->exclude_list != NULL && dp->exclude_list->nb_element > 0) {
1377 for(excl = dp->exclude_list->first; excl != NULL;
1378 excl = excl->next) {
1379 q64name = amxml_format_tag("list", excl->name);
1380 exc = newvstralloc(exc, " ", q64name, "\n", NULL);
1381 strappend(exclude_list, exc);
1386 include_file = stralloc("");
1387 if (dp->include_file != NULL && dp->include_file->nb_element > 0) {
1388 for(excl = dp->include_file->first; excl != NULL;
1389 excl = excl->next) {
1390 q64name = amxml_format_tag("file", excl->name);
1391 exc = newvstralloc( exc, " ", q64name, "\n", NULL);
1392 strappend(include_file, exc);
1396 include_list = stralloc("");
1397 if (dp->include_list != NULL && dp->include_list->nb_element > 0) {
1398 for(excl = dp->include_list->first; excl != NULL;
1399 excl = excl->next) {
1400 q64name = amxml_format_tag("list", excl->name);
1401 exc = newvstralloc( exc, " ", q64name, "\n", NULL);
1402 strappend(include_list, exc);
1407 if (dp->exclude_optional) {
1408 excl_opt = " <optional>YES</optional>\n";
1410 if (dp->include_optional) {
1411 incl_opt = " <optional>YES</optional>\n";
1414 if (dp->exclude_file || dp->exclude_list)
1415 exclude = newvstralloc(exclude,
1420 " </exclude>\n", NULL);
1421 if (dp->include_file || dp->include_list)
1422 include = newvstralloc(include,
1427 " </include>\n", NULL);
1428 script_opt = xml_scripts(dp->pp_scriptlist, their_features);
1429 result = vstralloc(auth_opt,
1443 amfree(data_path_opt);
1445 amfree(exclude_list);
1446 amfree(exclude_file);
1448 amfree(include_file);
1449 amfree(include_list);
1451 amfree(decrypt_opt);
1452 amfree(encrypt_opt);
1454 /* result contains at least 'auth=...' */
1460 estimatelist_t estimatelist,
1461 am_feature_t *their_features)
1466 if (am_has_feature(their_features, fe_xml_estimatelist)) {
1467 vstrextend(&l, " <estimate>", NULL);
1468 for (el=estimatelist; el != NULL; el = el->next) {
1469 switch (GPOINTER_TO_INT(el->data)) {
1470 case ES_CLIENT : vstrextend(&l, "CLIENT ", NULL); break;
1471 case ES_SERVER : vstrextend(&l, "SERVER ", NULL); break;
1472 case ES_CALCSIZE: vstrextend(&l, "CALCSIZE ", NULL); break;
1475 vstrextend(&l, "</estimate>", NULL);
1476 } else { /* add the first estimate only */
1477 if (am_has_feature(their_features, fe_xml_estimate)) {
1478 vstrextend(&l, " <estimate>", NULL);
1479 switch (GPOINTER_TO_INT(estimatelist->data)) {
1480 case ES_CLIENT : vstrextend(&l, "CLIENT", NULL); break;
1481 case ES_SERVER : vstrextend(&l, "SERVER", NULL); break;
1482 case ES_CALCSIZE: vstrextend(&l, "CALCSIZE", NULL); break;
1485 vstrextend(&l, "</estimate>", NULL);
1486 if (GPOINTER_TO_INT(estimatelist->data) == ES_CALCSIZE) {
1487 vstrextend(&l, " <calcsize>YES</calcsize>", NULL);
1495 clean_dle_str_for_client(
1499 char *hack1, *hack2;
1504 rval_dle_str = stralloc(dle_str);
1506 /* Remove everything between " <encrypt>SERVER-CUSTOM" and "</encrypt>\n"
1508 #define SC "</encrypt>\n"
1509 #define SC_LEN strlen(SC)
1510 hack1 = strstr(rval_dle_str, " <encrypt>SERVER-CUSTOM");
1512 hack2 = strstr(hack1, SC);
1513 /* +1 is to also move the trailing '\0' */
1514 memmove(hack1, hack2 + SC_LEN, strlen(hack2 + SC_LEN) + 1);
1519 return rval_dle_str;
1523 am_feature_t *features;
1527 /* A GHFunc (callback for g_hash_table_foreach) */
1528 static void xml_property(
1531 gpointer user_data_p)
1533 char *property_s = key_p;
1535 property_t *property = value_p;
1536 char *b64value_data;
1537 xml_app_t *xml_app = user_data_p;
1540 b64property = amxml_format_tag("name", property_s);
1541 vstrextend(&xml_app->result, " <property>\n",
1542 " ", b64property, "\n", NULL);
1543 // TODO if client have fe_xml_property_priority
1544 if (property->priority &&
1545 am_has_feature(xml_app->features, fe_xml_property_priority)) {
1546 vstrextend(&xml_app->result, " <priority>yes</priority>\n", NULL);
1548 for(value = property->values; value != NULL; value = value->next) {
1549 b64value_data = amxml_format_tag("value", value->data);
1550 vstrextend(&xml_app->result, " ", b64value_data, "\n", NULL);
1551 amfree(b64value_data);
1553 vstrextend(&xml_app->result, " </property>\n", NULL);
1555 amfree(b64property);
1560 disk_t *dp G_GNUC_UNUSED,
1561 application_t *application,
1562 am_feature_t *their_features)
1567 proplist_t proplist;
1569 xml_app.features = their_features;
1570 xml_app.result = NULL;
1571 plugin = application_get_plugin(application);
1572 b64plugin = amxml_format_tag("plugin", plugin);
1573 xml_app.result = vstralloc(" <backup-program>\n",
1574 " ", b64plugin, "\n",
1576 proplist = application_get_property(application);
1577 g_hash_table_foreach(proplist, xml_property, &xml_app);
1579 vstrextend(&xml_app.result, " </backup-program>\n", NULL);
1583 return xml_app.result;
1589 identlist_t pp_scriptlist,
1590 am_feature_t *their_features)
1599 execute_on_t execute_on;
1601 proplist_t proplist;
1602 identlist_t pp_iter;
1603 pp_script_t *pp_script;
1606 xml_app.features = their_features;
1608 xml_scr = stralloc("");
1609 for (pp_iter = pp_scriptlist; pp_iter != NULL;
1610 pp_iter = pp_iter->next) {
1611 char *pp_script_name = pp_iter->data;
1612 pp_script = lookup_pp_script(pp_script_name);
1613 g_assert(pp_script != NULL);
1614 plugin = pp_script_get_plugin(pp_script);
1615 b64plugin = amxml_format_tag("plugin", plugin);
1616 xml_scr1 = vstralloc(" <script>\n",
1617 " ", b64plugin, "\n",
1620 execute_where = pp_script_get_execute_where(pp_script);
1621 switch (execute_where) {
1622 case ES_CLIENT: str = "CLIENT"; break;
1623 case ES_SERVER: str = "SERVER"; break;
1625 xml_scr1 = vstrextend(&xml_scr1, " <execute_where>",
1626 str, "</execute_where>\n", NULL);
1628 execute_on = pp_script_get_execute_on(pp_script);
1631 if (execute_on & EXECUTE_ON_PRE_DLE_AMCHECK) {
1632 eo_str = vstrextend(&eo_str, sep, "PRE-DLE-AMCHECK", NULL);
1635 if (execute_on & EXECUTE_ON_PRE_HOST_AMCHECK) {
1636 eo_str = vstrextend(&eo_str, sep, "PRE-HOST-AMCHECK", NULL);
1639 if (execute_on & EXECUTE_ON_POST_DLE_AMCHECK) {
1640 eo_str = vstrextend(&eo_str, sep, "POST-DLE-AMCHECK", NULL);
1643 if (execute_on & EXECUTE_ON_POST_HOST_AMCHECK) {
1644 eo_str = vstrextend(&eo_str, sep, "POST-HOST-AMCHECK", NULL);
1647 if (execute_on & EXECUTE_ON_PRE_DLE_ESTIMATE) {
1648 eo_str = vstrextend(&eo_str, sep, "PRE-DLE-ESTIMATE", NULL);
1651 if (execute_on & EXECUTE_ON_PRE_HOST_ESTIMATE) {
1652 eo_str = vstrextend(&eo_str, sep, "PRE-HOST-ESTIMATE", NULL);
1655 if (execute_on & EXECUTE_ON_POST_DLE_ESTIMATE) {
1656 eo_str = vstrextend(&eo_str, sep, "POST-DLE-ESTIMATE", NULL);
1659 if (execute_on & EXECUTE_ON_POST_HOST_ESTIMATE) {
1660 eo_str = vstrextend(&eo_str, sep, "POST-HOST-ESTIMATE", NULL);
1663 if (execute_on & EXECUTE_ON_PRE_DLE_BACKUP) {
1664 eo_str = vstrextend(&eo_str, sep, "PRE-DLE-BACKUP", NULL);
1667 if (execute_on & EXECUTE_ON_PRE_HOST_BACKUP) {
1668 eo_str = vstrextend(&eo_str, sep, "PRE-HOST-BACKUP", NULL);
1671 if (execute_on & EXECUTE_ON_POST_DLE_BACKUP) {
1672 eo_str = vstrextend(&eo_str, sep, "POST-DLE-BACKUP", NULL);
1675 if (execute_on & EXECUTE_ON_POST_HOST_BACKUP) {
1676 eo_str = vstrextend(&eo_str, sep, "POST-HOST-BACKUP", NULL);
1679 if (execute_on & EXECUTE_ON_PRE_RECOVER) {
1680 eo_str = vstrextend(&eo_str, sep, "PRE-RECOVER", NULL);
1683 if (execute_on & EXECUTE_ON_POST_RECOVER) {
1684 eo_str = vstrextend(&eo_str, sep, "POST-RECOVER", NULL);
1687 if (execute_on & EXECUTE_ON_PRE_LEVEL_RECOVER) {
1688 eo_str = vstrextend(&eo_str, sep, "PRE-LEVEL-RECOVER", NULL);
1691 if (execute_on & EXECUTE_ON_POST_LEVEL_RECOVER) {
1692 eo_str = vstrextend(&eo_str, sep, "POST-LEVEL-RECOVER", NULL);
1695 if (execute_on & EXECUTE_ON_INTER_LEVEL_RECOVER) {
1696 eo_str = vstrextend(&eo_str, sep, "INTER-LEVEL-RECOVER", NULL);
1699 if (execute_on != 0)
1700 xml_scr1 = vstrextend(&xml_scr1,
1701 " <execute_on>", eo_str,
1702 "</execute_on>\n", NULL);
1704 proplist = pp_script_get_property(pp_script);
1705 xml_app.result = stralloc("");
1706 g_hash_table_foreach(proplist, xml_property, &xml_app);
1707 xml_scr = vstrextend(&xml_scr, xml_scr1, xml_app.result, " </script>\n", NULL);
1709 amfree(xml_app.result);
1721 for (dp = origqp->head; dp != NULL; dp = dp->next) {
1722 if (dp->ignore || dp->strategy == DS_SKIP)
1734 char *prevhost = NULL;
1735 char *errstr = NULL;
1746 for(dp = origqp->head; dp != NULL; dp = dp->next) {
1752 for(i=0;i<sargc;i++) {
1754 for(dp = origqp->head; dp != NULL; dp = dp->next) {
1755 if(match_host(sargv[i], dp->host->hostname))
1760 for(dp = origqp->head; dp != NULL; dp = dp->next) {
1761 if(prevhost != NULL &&
1762 match_host(prevhost, dp->host->hostname) &&
1763 (match_disk(sargv[i], dp->name) ||
1764 (dp->device && match_disk(sargv[i], dp->device)))) {
1766 error(_("Argument %s cannot be both a host and a disk"),sargv[i]);
1770 if(dp->todo == -1) {
1774 } else { /* dp->todo == 0 */
1783 if(match_a_host == 1) {
1784 if(prev_match == 1) { /* all disk of the previous host */
1785 for(dp = origqp->head; dp != NULL; dp = dp->next) {
1786 if(match_host(prevhost,dp->host->hostname))
1787 if(dp->todo == -1) {
1792 if (!match_a_disk) {
1794 errstr1 = vstrallocf(_("All disks on host '%s' are ignored or have strategy \"skip\".\n"), prevhost);
1795 vstrextend(&errstr, errstr1, NULL);
1799 prevhost = sargv[i];
1804 if (strchr(sargv[i], (int)'\\')) {
1805 errstr1 = vstrallocf(_("Argument '%s' matches neither a host nor a disk; quoting may not be correct.\n"), sargv[i]);
1807 errstr1 = vstrallocf(_("Argument '%s' matches neither a host nor a disk.\n"), sargv[i]);
1809 vstrextend(&errstr, errstr1, NULL);
1813 } else if (dp_skip) {
1815 if (dp_skip->strategy == DS_SKIP) {
1816 errstr1 = vstrallocf(_("Argument '%s' matches a disk with strategy \"skip\".\n"), sargv[i]);
1818 errstr1 = vstrallocf(_("Argument '%s' matches a disk marked \"ignore\".\n"), sargv[i]);
1820 vstrextend(&errstr, errstr1, NULL);
1826 if(prev_match == 1) { /* all disk of the previous host */
1828 for(dp = origqp->head; dp != NULL; dp = dp->next) {
1829 if(match_host(prevhost,dp->host->hostname))
1830 if(dp->todo == -1) {
1835 if (!match_a_disk) {
1837 errstr1 = vstrallocf(_("All disks on host '%s' are ignored or have strategy \"skip\".\n"), prevhost);
1838 vstrextend(&errstr, errstr1, NULL);
1843 for(dp = origqp->head; dp != NULL; dp = dp->next) {
1852 disklist_netifs(void)
1859 static void dump_disk(const disk_t *);
1860 static void dump_disklist(const disklist_t *);
1861 int main(int, char *[]);
1867 g_printf(_(" DISK %s (HOST %s, LINE %d) TYPE %s NAME %s SPINDLE %d\n"),
1868 dp->name, dp->host->hostname, dp->line, dp->dtype_name,
1869 dp->name == NULL? "(null)": dp->name,
1875 const disklist_t * lst)
1877 const disk_t *dp, *prev;
1878 const am_host_t *hp;
1880 if(hostlist == NULL) {
1881 g_printf(_("DISKLIST not read in\n"));
1885 g_printf(_("DISKLIST BY HOSTNAME:\n"));
1887 for(hp = hostlist; hp != NULL; hp = hp->next) {
1888 char *if_name = NULL;
1889 if (hp->netif && hp->netif->config)
1890 if_name = interface_name(hp->netif->config);
1892 g_printf(_("HOST %s INTERFACE %s\n"),
1894 if_name ? _("(null)") : if_name);
1895 for(dp = hp->disks; dp != NULL; dp = dp->hostnext)
1901 g_printf(_("DISKLIST IN FILE ORDER:\n"));
1904 for(dp = lst->head; dp != NULL; prev = dp, dp = dp->next) {
1906 /* check pointers */
1907 if(dp->prev != prev) g_printf(_("*** prev pointer mismatch!\n"));
1908 if(dp->next == NULL && lst->tail != dp) g_printf(_("tail mismatch!\n"));
1918 char *conf_diskfile;
1923 * Configure program for internationalization:
1924 * 1) Only set the message locale for now.
1925 * 2) Set textdomain for all amanda related programs to "amanda"
1926 * We don't want to be forced to support dozens of message catalogs.
1928 setlocale(LC_MESSAGES, "C");
1929 textdomain("amanda");
1933 set_pname("diskfile");
1935 dbopen(DBG_SUBDIR_SERVER);
1937 /* Don't die when child closes pipe */
1938 signal(SIGPIPE, SIG_IGN);
1941 config_init(CONFIG_INIT_EXPLICIT_NAME, argv[1]);
1943 config_init(CONFIG_INIT_USE_CWD, NULL)
1946 if (config_errors(NULL) >= CFGERR_WARNINGS) {
1947 config_print_errors();
1948 if (config_errors(NULL) >= CFGERR_ERRORS) {
1949 g_critical(_("errors processing config file"));
1953 conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE));
1954 result = read_diskfile(conf_diskfile, &lst);
1955 if(result == CFGERR_OK) {
1956 dump_disklist(&lst);
1958 config_print_errors();
1960 amfree(conf_diskfile);