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: selfcheck.c 10421 2008-03-06 18:48:30Z martineau $
30 * do self-check and send back any error messages
36 #include "amandates.h"
39 #include "pipespawn.h"
40 #include "amfeatures.h"
41 #include "client_util.h"
58 int need_xfsrestore=0;
63 int need_compress_path=0;
65 int need_global_check=0;
66 int program_is_application_api=0;
68 static char *amandad_auth = NULL;
69 static am_feature_t *our_features = NULL;
70 static char *our_feature_string = NULL;
71 static g_option_t *g_options = NULL;
74 int main(int argc, char **argv);
76 static void check_options(dle_t *dle);
77 static void check_disk(dle_t *dle);
78 static void check_overall(void);
79 static int check_file_exist(char *filename);
80 static void check_space(char *dir, off_t kbytes);
89 char *qamdevice = NULL;
91 char *err_extra = NULL;
102 * Configure program for internationalization:
103 * 1) Only set the message locale for now.
104 * 2) Set textdomain for all amanda related programs to "amanda"
105 * We don't want to be forced to support dozens of message catalogs.
107 setlocale(LC_MESSAGES, "C");
108 textdomain("amanda");
114 set_pname("selfcheck");
116 /* Don't die when child closes pipe */
117 signal(SIGPIPE, SIG_IGN);
119 add_amanda_log_handler(amanda_log_stderr);
120 add_amanda_log_handler(amanda_log_syslog);
121 dbopen(DBG_SUBDIR_CLIENT);
123 dbprintf(_("version %s\n"), VERSION);
125 if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
126 amandad_auth = stralloc(argv[2]);
129 config_init(CONFIG_INIT_CLIENT, NULL);
130 /* (check for config errors comes later) */
132 check_running_as(RUNNING_AS_CLIENT_LOGIN);
134 our_features = am_init_feature_set();
135 our_feature_string = am_feature_to_string(our_features);
137 /* handle all service requests */
140 for(; (line = agets(stdin)) != NULL; free(line)) {
145 if(strncmp_const(line, "OPTIONS ") == 0) {
146 g_options = parse_g_options(line+8, 1);
147 if(!g_options->hostname) {
148 g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1);
149 gethostname(g_options->hostname, MAX_HOSTNAME_LENGTH);
150 g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0';
153 g_printf("OPTIONS ");
154 if(am_has_feature(g_options->features, fe_rep_options_features)) {
155 g_printf("features=%s;", our_feature_string);
157 if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
158 g_printf("hostname=%s;", g_options->hostname);
163 if (g_options->config) {
164 /* overlay this configuration on the existing (nameless) configuration */
165 config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
168 dbrename(get_config_name(), DBG_SUBDIR_CLIENT);
171 /* check for any config errors now */
172 if (config_errors(&errlist) >= CFGERR_ERRORS) {
173 char *errstr = config_errors_to_error_string(errlist);
174 g_printf("%s\n", errstr);
179 if (am_has_feature(g_options->features, fe_req_xml)) {
189 skip_whitespace(s, ch); /* find program name */
191 goto err; /* no program */
193 dle->program = s - 1;
194 skip_non_whitespace(s, ch);
195 s[-1] = '\0'; /* terminate the program name */
197 dle->program_is_application_api = 0;
198 if(strcmp(dle->program,"APPLICATION")==0) {
199 dle->program_is_application_api = 1;
200 skip_whitespace(s, ch); /* find dumper name */
202 goto err; /* no program */
204 dle->program = s - 1;
205 skip_non_whitespace(s, ch);
206 s[-1] = '\0'; /* terminate the program name */
209 if(strncmp_const(dle->program, "CALCSIZE") == 0) {
210 skip_whitespace(s, ch); /* find program name */
212 goto err; /* no program */
214 dle->program = s - 1;
215 skip_non_whitespace(s, ch);
217 dle->estimatelist = g_slist_append(dle->estimatelist,
218 GINT_TO_POINTER(ES_CALCSIZE));
221 dle->estimatelist = g_slist_append(dle->estimatelist,
222 GINT_TO_POINTER(ES_CLIENT));
225 skip_whitespace(s, ch); /* find disk name */
227 goto err; /* no disk */
230 skip_quoted_string(s, ch);
231 s[-1] = '\0'; /* terminate the disk name */
232 dle->disk = unquote_string(qdisk);
234 skip_whitespace(s, ch); /* find the device or level */
236 goto err; /* no device or level */
238 if(!isdigit((int)s[-1])) {
240 skip_quoted_string(s, ch);
241 s[-1] = '\0'; /* terminate the device */
242 qamdevice = stralloc(fp);
243 dle->device = unquote_string(qamdevice);
244 skip_whitespace(s, ch); /* find level number */
247 dle->device = stralloc(dle->disk);
248 qamdevice = stralloc(qdisk);
251 /* find level number */
252 if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
253 goto err; /* bad level */
255 alevel = g_new0(level_t, 1);
256 alevel->level = level;
257 dle->levellist = g_slist_append(dle->levellist, alevel);
260 skip_whitespace(s, ch);
261 if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) {
262 skip_whitespace(s, ch); /* find the option string */
264 goto err; /* bad options string */
267 skip_quoted_string(s, ch);
268 s[-1] = '\0'; /* terminate the options */
269 parse_options(optstr, dle, g_options->features, 1);
276 } else if (ch == '\0') {
277 /* check all since no option */
290 need_compress_path=1;
297 goto err; /* bad syntax */
301 if (g_options == NULL) {
302 g_printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
303 error(_("Missing OPTIONS line in selfcheck input\n"));
307 if (am_has_feature(g_options->features, fe_req_xml)) {
309 dle_t *dles, *dle, *dle_next;
311 dles = amxml_parse_node_FILE(stdin, &errmsg);
316 if (merge_dles_properties(dles, 1) == 0) {
319 for (dle = dles; dle != NULL; dle = dle->next) {
320 run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle,
323 for (dle = dles; dle != NULL; dle = dle->next) {
325 run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle,
328 run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle,
331 for (dle = dles; dle != NULL; dle = dle->next) {
332 run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle,
335 for (dle = dles; dle != NULL; dle = dle_next) {
336 dle_next = dle->next;
345 amfree(our_feature_string);
346 am_release_feature_set(our_features);
348 free_g_options(g_options);
355 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra);
356 dbprintf(_("REQ packet is bogus: %s\n"), err_extra);
358 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n"));
359 dbprintf(_("REQ packet is bogus\n"));
370 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
374 if (strcmp(dle->program,"GNUTAR") == 0) {
376 if(dle->device && dle->device[0] == '/' && dle->device[1] == '/') {
377 if(dle->exclude_file && dle->exclude_file->nb_element > 1) {
378 g_printf(_("ERROR [samba support only one exclude file]\n"));
380 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
381 dle->exclude_optional==0) {
382 g_printf(_("ERROR [samba does not support exclude list]\n"));
384 if (dle->include_file && dle->include_file->nb_element > 0) {
385 g_printf(_("ERROR [samba does not support include file]\n"));
387 if (dle->include_list && dle->include_list->nb_element > 0 &&
388 dle->include_optional==0) {
389 g_printf(_("ERROR [samba does not support include list]\n"));
395 char *file_exclude = NULL;
396 char *file_include = NULL;
398 if (dle->exclude_file) nb_exclude += dle->exclude_file->nb_element;
399 if (dle->exclude_list) nb_exclude += dle->exclude_list->nb_element;
400 if (dle->include_file) nb_include += dle->include_file->nb_element;
401 if (dle->include_list) nb_include += dle->include_list->nb_element;
403 if (nb_exclude > 0) file_exclude = build_exclude(dle, 1);
404 if (nb_include > 0) file_include = build_include(dle, 1);
406 amfree(file_exclude);
407 amfree(file_include);
413 if (strcmp(dle->program,"DUMP") == 0) {
414 if (dle->exclude_file && dle->exclude_file->nb_element > 0) {
415 g_printf(_("ERROR [DUMP does not support exclude file]\n"));
417 if (dle->exclude_list && dle->exclude_list->nb_element > 0) {
418 g_printf(_("ERROR [DUMP does not support exclude list]\n"));
420 if (dle->include_file && dle->include_file->nb_element > 0) {
421 g_printf(_("ERROR [DUMP does not support include file]\n"));
423 if (dle->include_list && dle->include_list->nb_element > 0) {
424 g_printf(_("ERROR [DUMP does not support include list]\n"));
432 if (dle->device && strcmp(amname_to_fstype(dle->device), "advfs") == 0)
439 if (dle->create_index)
446 if (dle->device && strcmp(amname_to_fstype(dle->device), "xfs") == 0)
453 if (dle->create_index)
460 if (dle->device && strcmp(amname_to_fstype(dle->device), "vxfs") == 0)
466 if (dle->create_index)
473 if (dle->create_index)
477 /* AIX backup program */
479 if (dle->create_index)
483 if ((dle->compress == COMP_BEST) || (dle->compress == COMP_FAST)
484 || (dle->compress == COMP_CUST)) {
485 need_compress_path=1;
487 if (dle->auth && amandad_auth) {
488 if (strcasecmp(dle->auth, amandad_auth) != 0) {
489 g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
490 amandad_auth, dle->auth);
491 if (strcmp(dle->auth, "ssh") == 0) {
492 g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
493 "should be \"--auth=ssh\", or use another auth "
497 g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration "
498 " must be the same as the DLE]\n"));
510 char *user_and_password = NULL;
512 char *share = NULL, *subdir = NULL;
517 char *extra_info = NULL;
519 char *qamdevice = NULL;
520 char *qdevice = NULL;
524 qdisk = quote_string(dle->disk);
525 qamdevice = quote_string(dle->device);
526 device = stralloc("nodevice");
527 dbprintf(_("checking disk %s\n"), qdisk);
528 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
529 if (dle->device[0] == '/' && dle->device[1] == '/') {
531 _("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
537 if (strcmp(dle->program, "GNUTAR")==0) {
538 if(dle->device[0] == '/' && dle->device[1] == '/') {
540 int nullfd, checkerr;
554 parsesharename(dle->device, &share, &subdir);
557 _("cannot parse for share/subdir disk entry %s"),
561 if ((subdir) && (SAMBA_VERSION < 2)) {
562 err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
566 if ((user_and_password = findpass(share, &domain)) == NULL) {
567 err = vstrallocf(_("cannot find password for %s"),
571 lpass = strlen(user_and_password);
572 if ((pwtext = strchr(user_and_password, '%')) == NULL) {
574 _("password field not \'user%%pass\' for %s"),
579 pwtext_len = (size_t)strlen(pwtext);
581 if ((device = makesharename(share, 0)) == NULL) {
582 err = vstrallocf(_("cannot make share name of %s"), share);
586 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
587 err = vstrallocf(_("Cannot access /dev/null : %s"),
592 if (pwtext_len > 0) {
593 pw_fd_env = "PASSWD_FD";
595 pw_fd_env = "dummy_PASSWD_FD";
597 checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, 0,
598 &nullfd, &nullfd, &checkerr,
599 pw_fd_env, &passwdfd,
602 *user_and_password ? "-U" : skip_argument,
603 *user_and_password ? user_and_password
606 domain ? "-W" : skip_argument,
607 domain ? domain : skip_argument,
608 #if SAMBA_VERSION >= 2
609 subdir ? "-D" : skip_argument,
610 subdir ? subdir : skip_argument,
617 if ((pwtext_len > 0) &&
618 full_write(passwdfd, pwtext, pwtext_len) < pwtext_len) {
619 err = vstrallocf(_("password write failed: %s: %s"),
620 dle->device, strerror(errno));
625 memset(user_and_password, '\0', (size_t)lpass);
626 amfree(user_and_password);
628 ferr = fdopen(checkerr, "r");
630 g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
631 error(_("Can't fdopen: %s"), strerror(errno));
636 for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
639 strappend(extra_info, sep);
640 strappend(extra_info, line);
642 if(strstr(line, "ERRDOS") != NULL) {
650 while ((wpid = wait(&retstat)) != -1) {
651 if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
652 char *exitstr = str_exit_status("smbclient", retstat);
654 strappend(err, exitstr);
661 if (errdos != 0 || rc != 0) {
663 err = newvstrallocf(err,
664 _("samba access error: %s: %s %s"),
665 dle->device, extra_info, err);
668 err = newvstrallocf(err,
669 _("samba access error: %s: %s"),
675 _("This client is not configured for samba: %s"),
682 device = amname_to_dirname(dle->device);
683 } else if (strcmp(dle->program, "DUMP") == 0) {
684 if(dle->device[0] == '/' && dle->device[1] == '/') {
686 _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
692 if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
698 device = amname_to_dirname(dle->device);
704 device = amname_to_devname(dle->device);
713 if (dle->program_is_application_api) {
714 pid_t application_api_pid;
715 backup_support_option_t *bsu;
719 bsu = backup_support_option(dle->program, g_options, dle->disk,
720 dle->device, &errarray);
725 for (i=0; i < errarray->len; i++) {
726 line = g_ptr_array_index(errarray, i);
727 fprintf(stdout, _("ERROR Application '%s': %s\n"),
731 err = vstrallocf(_("Application '%s': can't run support command"),
736 if (dle->data_path == DATA_PATH_AMANDA &&
737 (bsu->data_path_set & DATA_PATH_AMANDA)==0) {
738 g_printf("ERROR application %s doesn't support amanda data-path\n",
741 if (dle->data_path == DATA_PATH_DIRECTTCP &&
742 (bsu->data_path_set & DATA_PATH_DIRECTTCP)==0) {
743 g_printf("ERROR application %s doesn't support directtcp data-path\n",
746 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE &&
748 g_printf("ERROR application %s doesn't support calcsize estimate\n",
751 if (dle->include_file && dle->include_file->nb_element > 0 &&
752 !bsu->include_file) {
753 g_printf("ERROR application %s doesn't support include-file\n",
756 if (dle->include_list && dle->include_list->nb_element > 0 &&
757 !bsu->include_list) {
758 g_printf("ERROR application %s doesn't support include-list\n",
761 if (dle->include_optional && !bsu->include_optional) {
762 g_printf("ERROR application %s doesn't support optional include\n",
765 if (dle->exclude_file && dle->exclude_file->nb_element > 0 &&
766 !bsu->exclude_file) {
767 g_printf("ERROR application %s doesn't support exclude-file\n",
770 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
771 !bsu->exclude_list) {
772 g_printf("ERROR application %s doesn't support exclude-list\n",
775 if (dle->exclude_optional && !bsu->exclude_optional) {
776 g_printf("ERROR application %s doesn't support optional exclude\n",
779 fflush(stdout);fflush(stderr);
781 if (pipe(app_err) < 0) {
782 err = vstrallocf(_("Application '%s': can't create pipe"),
787 switch (application_api_pid = fork()) {
789 err = vstrallocf(_("fork failed: %s"), strerror(errno));
794 GPtrArray *argv_ptr = g_ptr_array_new();
796 char *cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
805 g_ptr_array_add(argv_ptr, stralloc(dle->program));
806 g_ptr_array_add(argv_ptr, stralloc("selfcheck"));
807 if (bsu->message_line == 1) {
808 g_ptr_array_add(argv_ptr, stralloc("--message"));
809 g_ptr_array_add(argv_ptr, stralloc("line"));
811 if (g_options->config != NULL && bsu->config == 1) {
812 g_ptr_array_add(argv_ptr, stralloc("--config"));
813 g_ptr_array_add(argv_ptr, stralloc(g_options->config));
815 if (g_options->hostname != NULL && bsu->host == 1) {
816 g_ptr_array_add(argv_ptr, stralloc("--host"));
817 g_ptr_array_add(argv_ptr, stralloc(g_options->hostname));
819 if (dle->disk != NULL && bsu->disk == 1) {
820 g_ptr_array_add(argv_ptr, stralloc("--disk"));
821 g_ptr_array_add(argv_ptr, stralloc(dle->disk));
824 g_ptr_array_add(argv_ptr, stralloc("--device"));
825 g_ptr_array_add(argv_ptr, stralloc(dle->device));
827 if (dle->create_index && bsu->index_line == 1) {
828 g_ptr_array_add(argv_ptr, stralloc("--index"));
829 g_ptr_array_add(argv_ptr, stralloc("line"));
831 if (dle->record && bsu->record == 1) {
832 g_ptr_array_add(argv_ptr, stralloc("--record"));
835 for (el = dle->estimatelist; el != NULL; el=el->next) {
836 estimate_t estimate = (estimate_t)GPOINTER_TO_INT(el->data);
837 if (estimate == ES_CALCSIZE && bsu->calcsize == 1) {
838 g_ptr_array_add(argv_ptr, stralloc("--calcsize"));
841 application_property_add_to_argv(argv_ptr, dle, bsu,
842 g_options->features);
844 for (scriptlist = dle->scriptlist; scriptlist != NULL;
845 scriptlist = scriptlist->next) {
846 script = (script_t *)scriptlist->data;
847 if (script->result && script->result->proplist) {
848 property_add_to_argv(argv_ptr,
849 script->result->proplist);
853 g_ptr_array_add(argv_ptr, NULL);
855 cmdline = stralloc(cmd);
856 for (i = 0; i < argv_ptr->len-1; i++) {
857 char *quoted = quote_string(
858 (char *)g_ptr_array_index(argv_ptr,i));
859 cmdline = vstrextend(&cmdline, " ", quoted, NULL);
862 dbprintf(_("Spawning \"%s\" in pipeline\n"), cmdline);
866 execve(cmd, (char **)argv_ptr->pdata, safe_env());
867 g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
870 default: /* parent */
877 app_stderr = fdopen(app_err[0], "r");
878 while((line = agets(app_stderr)) != NULL) {
879 if (strlen(line) > 0) {
880 fprintf(stdout, "ERROR Application '%s': %s\n",
882 dbprintf("ERROR %s\n", line);
887 if (waitpid(application_api_pid, &status, 0) < 0) {
888 err = vstrallocf(_("waitpid failed: %s"),
891 } else if (!WIFEXITED(status)) {
892 err = vstrallocf(_("Application '%s': exited with signal %d"),
893 dle->program, WTERMSIG(status));
895 } else if (WEXITSTATUS(status) != 0) {
896 err = vstrallocf(_("Application '%s': exited with status %d"),
897 dle->program, WEXITSTATUS(status));
903 fflush(stdout);fflush(stderr);
911 qdevice = quote_string(device);
912 dbprintf(_("device %s\n"), qdevice);
914 /* skip accessability test if this is an AFS entry */
915 if(strncmp_const(device, "afs:") != 0) {
916 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
917 access_result = open(device, O_RDONLY);
918 access_type = "open";
920 access_result = access(device, amode);
921 access_type = "access";
923 if(access_result == -1) {
924 err = vstrallocf(_("Could not access %s (%s): %s"),
925 qdevice, qdisk, strerror(errno));
927 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
928 aclose(access_result);
936 qdevice = quote_string(device);
940 if(user_and_password) {
941 memset(user_and_password, '\0', (size_t)lpass);
942 amfree(user_and_password);
947 g_printf(_("ERROR %s\n"), err);
948 dbprintf(_("%s\n"), err);
952 g_printf("OK %s\n", qdisk);
953 dbprintf(_("disk %s OK\n"), qdisk);
956 g_printf("OK %s\n", qamdevice);
957 dbprintf(_("amdevice %s OK\n"), qamdevice);
960 g_printf("OK %s\n", qdevice);
961 dbprintf(_("device %s OK\n"), qdevice);
965 dbprintf(_("extra info: %s\n"), extra_info);
973 /* XXX perhaps do something with level: read dumpdates and sanity check */
982 char *gnutar_list_dir;
983 int need_amandates = 0;
987 cmd = vstralloc(amlibexecdir, "/", "runtar", NULL);
988 check_file(cmd,X_OK);
995 cmd = vstralloc(amlibexecdir, "/", "rundump", NULL);
996 check_file(cmd,X_OK);
1003 check_file(DUMP, X_OK);
1005 g_printf(_("ERROR [DUMP program not available]\n"));
1009 if( need_restore ) {
1011 check_file(RESTORE, X_OK);
1013 g_printf(_("ERROR [RESTORE program not available]\n"));
1019 check_file(VDUMP, X_OK);
1021 g_printf(_("ERROR [VDUMP program not available]\n"));
1025 if ( need_vrestore ) {
1027 check_file(VRESTORE, X_OK);
1029 g_printf(_("ERROR [VRESTORE program not available]\n"));
1033 if( need_xfsdump ) {
1035 check_file(XFSDUMP, F_OK);
1037 g_printf(_("ERROR [XFSDUMP program not available]\n"));
1041 if( need_xfsrestore ) {
1043 check_file(XFSRESTORE, X_OK);
1045 g_printf(_("ERROR [XFSRESTORE program not available]\n"));
1051 check_file(VXDUMP, X_OK);
1053 g_printf(_("ERROR [VXDUMP program not available]\n"));
1057 if( need_vxrestore ) {
1059 check_file(VXRESTORE, X_OK);
1061 g_printf(_("ERROR [VXRESTORE program not available]\n"));
1067 check_file(GNUTAR, X_OK);
1069 g_printf(_("ERROR [GNUTAR program not available]\n"));
1071 gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
1072 if (strlen(gnutar_list_dir) == 0)
1073 gnutar_list_dir = NULL;
1074 if (gnutar_list_dir) {
1075 /* make sure our listed-incremental dir is ready */
1076 check_dir(gnutar_list_dir, R_OK|W_OK);
1078 /* no listed-incremental dir, so check that amandates is ready */
1083 if( need_calcsize ) {
1086 cmd = vstralloc(amlibexecdir, "/", "calcsize", NULL);
1088 check_file(cmd, X_OK);
1092 /* calcsize uses amandates */
1096 if (need_amandates) {
1097 char *amandates_file;
1098 amandates_file = getconf_str(CNF_AMANDATES);
1099 check_file(amandates_file, R_OK|W_OK);
1104 check_file(SAMBA_CLIENT, X_OK);
1106 g_printf(_("ERROR [SMBCLIENT program not available]\n"));
1108 testfd = open("/etc/amandapass", R_OK);
1110 if(fstat(testfd, &buf) == 0) {
1111 if ((buf.st_mode & 0x7) != 0) {
1112 g_printf(_("ERROR [/etc/amandapass is world readable!]\n"));
1114 g_printf(_("OK [/etc/amandapass is readable, but not by all]\n"));
1117 g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"),
1122 g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"),
1127 if (need_compress_path )
1128 check_file(COMPRESS_PATH, X_OK);
1130 if (need_dump || need_xfsdump ) {
1131 if (check_file_exist("/etc/dumpdates")) {
1132 check_file("/etc/dumpdates",
1141 if (access("/etc", R_OK|W_OK) == -1) {
1142 g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
1149 if (check_file_exist("/etc/vdumpdates")) {
1150 check_file("/etc/vdumpdates", F_OK);
1154 if (need_global_check) {
1155 check_access("/dev/null", R_OK|W_OK);
1156 check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
1158 #ifdef AMANDA_DBGDIR
1159 check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
1162 check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
1171 struct fs_usage fsusage;
1172 char *quoted = quote_string(dir);
1175 if(get_fs_usage(dir, NULL, &fsusage) == -1) {
1176 g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
1181 /* do the division first to avoid potential integer overflow */
1182 kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;
1184 if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
1185 g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
1187 } else if (kb_avail < kbytes) {
1188 g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
1190 (long long)kb_avail);
1192 g_printf(_("OK %s has more than %lldKB available.\n"),
1193 quoted, (long long)kbytes);
1202 struct stat stat_buf;
1204 if (stat(filename, &stat_buf) != 0) {
1205 if(errno == ENOENT) {