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 for (dle = dles; dle != NULL; dle = dle->next) {
317 run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle,
320 for (dle = dles; dle != NULL; dle = dle->next) {
322 run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle,
325 run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle,
328 for (dle = dles; dle != NULL; dle = dle->next) {
329 run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle,
332 for (dle = dles; dle != NULL; dle = dle_next) {
333 dle_next = dle->next;
341 amfree(our_feature_string);
342 am_release_feature_set(our_features);
344 free_g_options(g_options);
351 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra);
352 dbprintf(_("REQ packet is bogus: %s\n"), err_extra);
354 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n"));
355 dbprintf(_("REQ packet is bogus\n"));
366 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
370 if (strcmp(dle->program,"GNUTAR") == 0) {
372 if(dle->device && dle->device[0] == '/' && dle->device[1] == '/') {
373 if(dle->exclude_file && dle->exclude_file->nb_element > 1) {
374 g_printf(_("ERROR [samba support only one exclude file]\n"));
376 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
377 dle->exclude_optional==0) {
378 g_printf(_("ERROR [samba does not support exclude list]\n"));
380 if (dle->include_file && dle->include_file->nb_element > 0) {
381 g_printf(_("ERROR [samba does not support include file]\n"));
383 if (dle->include_list && dle->include_list->nb_element > 0 &&
384 dle->include_optional==0) {
385 g_printf(_("ERROR [samba does not support include list]\n"));
391 char *file_exclude = NULL;
392 char *file_include = NULL;
394 if (dle->exclude_file) nb_exclude += dle->exclude_file->nb_element;
395 if (dle->exclude_list) nb_exclude += dle->exclude_list->nb_element;
396 if (dle->include_file) nb_include += dle->include_file->nb_element;
397 if (dle->include_list) nb_include += dle->include_list->nb_element;
399 if (nb_exclude > 0) file_exclude = build_exclude(dle, 1);
400 if (nb_include > 0) file_include = build_include(dle, 1);
402 amfree(file_exclude);
403 amfree(file_include);
409 if (strcmp(dle->program,"DUMP") == 0) {
410 if (dle->exclude_file && dle->exclude_file->nb_element > 0) {
411 g_printf(_("ERROR [DUMP does not support exclude file]\n"));
413 if (dle->exclude_list && dle->exclude_list->nb_element > 0) {
414 g_printf(_("ERROR [DUMP does not support exclude list]\n"));
416 if (dle->include_file && dle->include_file->nb_element > 0) {
417 g_printf(_("ERROR [DUMP does not support include file]\n"));
419 if (dle->include_list && dle->include_list->nb_element > 0) {
420 g_printf(_("ERROR [DUMP does not support include list]\n"));
428 if (dle->device && strcmp(amname_to_fstype(dle->device), "advfs") == 0)
435 if (dle->create_index)
442 if (dle->device && strcmp(amname_to_fstype(dle->device), "xfs") == 0)
449 if (dle->create_index)
456 if (dle->device && strcmp(amname_to_fstype(dle->device), "vxfs") == 0)
462 if (dle->create_index)
469 if (dle->create_index)
473 /* AIX backup program */
475 if (dle->create_index)
479 if ((dle->compress == COMP_BEST) || (dle->compress == COMP_FAST)
480 || (dle->compress == COMP_CUST)) {
481 need_compress_path=1;
483 if (dle->auth && amandad_auth) {
484 if (strcasecmp(dle->auth, amandad_auth) != 0) {
485 g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
486 amandad_auth, dle->auth);
487 if (strcmp(dle->auth, "ssh") == 0) {
488 g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
489 "should be \"--auth=ssh\", or use another auth "
493 g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration "
494 " must be the same as the DLE]\n"));
506 char *user_and_password = NULL;
508 char *share = NULL, *subdir = NULL;
513 char *extra_info = NULL;
515 char *qamdevice = NULL;
516 char *qdevice = NULL;
520 qdisk = quote_string(dle->disk);
521 qamdevice = quote_string(dle->device);
522 device = stralloc("nodevice");
523 dbprintf(_("checking disk %s\n"), qdisk);
524 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
525 if (dle->device[0] == '/' && dle->device[1] == '/') {
527 _("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
533 if (strcmp(dle->program, "GNUTAR")==0) {
534 if(dle->device[0] == '/' && dle->device[1] == '/') {
536 int nullfd, checkerr;
550 parsesharename(dle->device, &share, &subdir);
553 _("cannot parse for share/subdir disk entry %s"),
557 if ((subdir) && (SAMBA_VERSION < 2)) {
558 err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
562 if ((user_and_password = findpass(share, &domain)) == NULL) {
563 err = vstrallocf(_("cannot find password for %s"),
567 lpass = strlen(user_and_password);
568 if ((pwtext = strchr(user_and_password, '%')) == NULL) {
570 _("password field not \'user%%pass\' for %s"),
575 pwtext_len = (size_t)strlen(pwtext);
577 if ((device = makesharename(share, 0)) == NULL) {
578 err = vstrallocf(_("cannot make share name of %s"), share);
582 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
583 err = vstrallocf(_("Cannot access /dev/null : %s"),
588 if (pwtext_len > 0) {
589 pw_fd_env = "PASSWD_FD";
591 pw_fd_env = "dummy_PASSWD_FD";
593 checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, 0,
594 &nullfd, &nullfd, &checkerr,
595 pw_fd_env, &passwdfd,
598 *user_and_password ? "-U" : skip_argument,
599 *user_and_password ? user_and_password
602 domain ? "-W" : skip_argument,
603 domain ? domain : skip_argument,
604 #if SAMBA_VERSION >= 2
605 subdir ? "-D" : skip_argument,
606 subdir ? subdir : skip_argument,
613 if ((pwtext_len > 0) &&
614 full_write(passwdfd, pwtext, pwtext_len) < pwtext_len) {
615 err = vstrallocf(_("password write failed: %s: %s"),
616 dle->device, strerror(errno));
621 memset(user_and_password, '\0', (size_t)lpass);
622 amfree(user_and_password);
624 ferr = fdopen(checkerr, "r");
626 g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
627 error(_("Can't fdopen: %s"), strerror(errno));
632 for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
635 strappend(extra_info, sep);
636 strappend(extra_info, line);
638 if(strstr(line, "ERRDOS") != NULL) {
646 while ((wpid = wait(&retstat)) != -1) {
647 if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
648 char *exitstr = str_exit_status("smbclient", retstat);
650 strappend(err, exitstr);
657 if (errdos != 0 || rc != 0) {
659 err = newvstrallocf(err,
660 _("samba access error: %s: %s %s"),
661 dle->device, extra_info, err);
664 err = newvstrallocf(err,
665 _("samba access error: %s: %s"),
671 _("This client is not configured for samba: %s"),
678 device = amname_to_dirname(dle->device);
679 } else if (strcmp(dle->program, "DUMP") == 0) {
680 if(dle->device[0] == '/' && dle->device[1] == '/') {
682 _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
688 if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
694 device = amname_to_dirname(dle->device);
700 device = amname_to_devname(dle->device);
709 if (dle->program_is_application_api) {
710 pid_t application_api_pid;
711 backup_support_option_t *bsu;
715 bsu = backup_support_option(dle->program, g_options, dle->disk,
716 dle->device, &errarray);
721 for (i=0; i < errarray->len; i++) {
722 line = g_ptr_array_index(errarray, i);
723 fprintf(stdout, _("ERROR Application '%s': %s\n"),
727 err = vstrallocf(_("Application '%s': can't run support command"),
732 if (dle->data_path == DATA_PATH_AMANDA &&
733 (bsu->data_path_set & DATA_PATH_AMANDA)==0) {
734 g_printf("ERROR application %s doesn't support amanda data-path\n",
737 if (dle->data_path == DATA_PATH_DIRECTTCP &&
738 (bsu->data_path_set & DATA_PATH_DIRECTTCP)==0) {
739 g_printf("ERROR application %s doesn't support directtcp data-path\n",
742 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE &&
744 g_printf("ERROR application %s doesn't support calcsize estimate\n",
747 if (dle->include_file && dle->include_file->nb_element > 0 &&
748 !bsu->include_file) {
749 g_printf("ERROR application %s doesn't support include-file\n",
752 if (dle->include_list && dle->include_list->nb_element > 0 &&
753 !bsu->include_list) {
754 g_printf("ERROR application %s doesn't support include-list\n",
757 if (dle->include_optional && !bsu->include_optional) {
758 g_printf("ERROR application %s doesn't support optional include\n",
761 if (dle->exclude_file && dle->exclude_file->nb_element > 0 &&
762 !bsu->exclude_file) {
763 g_printf("ERROR application %s doesn't support exclude-file\n",
766 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
767 !bsu->exclude_list) {
768 g_printf("ERROR application %s doesn't support exclude-list\n",
771 if (dle->exclude_optional && !bsu->exclude_optional) {
772 g_printf("ERROR application %s doesn't support optional exclude\n",
775 fflush(stdout);fflush(stderr);
777 if (pipe(app_err) < 0) {
778 err = vstrallocf(_("Application '%s': can't create pipe"),
783 switch (application_api_pid = fork()) {
785 err = vstrallocf(_("fork failed: %s"), strerror(errno));
790 GPtrArray *argv_ptr = g_ptr_array_new();
792 char *cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
801 g_ptr_array_add(argv_ptr, stralloc(dle->program));
802 g_ptr_array_add(argv_ptr, stralloc("selfcheck"));
803 if (bsu->message_line == 1) {
804 g_ptr_array_add(argv_ptr, stralloc("--message"));
805 g_ptr_array_add(argv_ptr, stralloc("line"));
807 if (g_options->config != NULL && bsu->config == 1) {
808 g_ptr_array_add(argv_ptr, stralloc("--config"));
809 g_ptr_array_add(argv_ptr, stralloc(g_options->config));
811 if (g_options->hostname != NULL && bsu->host == 1) {
812 g_ptr_array_add(argv_ptr, stralloc("--host"));
813 g_ptr_array_add(argv_ptr, stralloc(g_options->hostname));
815 if (dle->disk != NULL && bsu->disk == 1) {
816 g_ptr_array_add(argv_ptr, stralloc("--disk"));
817 g_ptr_array_add(argv_ptr, stralloc(dle->disk));
820 g_ptr_array_add(argv_ptr, stralloc("--device"));
821 g_ptr_array_add(argv_ptr, stralloc(dle->device));
823 if (dle->create_index && bsu->index_line == 1) {
824 g_ptr_array_add(argv_ptr, stralloc("--index"));
825 g_ptr_array_add(argv_ptr, stralloc("line"));
827 if (dle->record && bsu->record == 1) {
828 g_ptr_array_add(argv_ptr, stralloc("--record"));
831 for (el = dle->estimatelist; el != NULL; el=el->next) {
832 estimate_t estimate = (estimate_t)GPOINTER_TO_INT(el->data);
833 if (estimate == ES_CALCSIZE && bsu->calcsize == 1) {
834 g_ptr_array_add(argv_ptr, stralloc("--calcsize"));
837 application_property_add_to_argv(argv_ptr, dle, bsu,
838 g_options->features);
840 for (scriptlist = dle->scriptlist; scriptlist != NULL;
841 scriptlist = scriptlist->next) {
842 script = (script_t *)scriptlist->data;
843 if (script->result && script->result->proplist) {
844 property_add_to_argv(argv_ptr,
845 script->result->proplist);
849 g_ptr_array_add(argv_ptr, NULL);
851 cmdline = stralloc(cmd);
852 for (i = 0; i < argv_ptr->len-1; i++) {
853 char *quoted = quote_string(
854 (char *)g_ptr_array_index(argv_ptr,i));
855 cmdline = vstrextend(&cmdline, " ", quoted, NULL);
858 dbprintf(_("Spawning \"%s\" in pipeline\n"), cmdline);
862 execve(cmd, (char **)argv_ptr->pdata, safe_env());
863 g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
866 default: /* parent */
873 app_stderr = fdopen(app_err[0], "r");
874 while((line = agets(app_stderr)) != NULL) {
875 if (strlen(line) > 0) {
876 fprintf(stdout, "ERROR Application '%s': %s\n",
878 dbprintf("ERROR %s\n", line);
883 if (waitpid(application_api_pid, &status, 0) < 0) {
884 err = vstrallocf(_("waitpid failed: %s"),
887 } else if (!WIFEXITED(status)) {
888 err = vstrallocf(_("Application '%s': exited with signal %d"),
889 dle->program, WTERMSIG(status));
891 } else if (WEXITSTATUS(status) != 0) {
892 err = vstrallocf(_("Application '%s': exited with status %d"),
893 dle->program, WEXITSTATUS(status));
899 fflush(stdout);fflush(stderr);
907 qdevice = quote_string(device);
908 dbprintf(_("device %s\n"), qdevice);
910 /* skip accessability test if this is an AFS entry */
911 if(strncmp_const(device, "afs:") != 0) {
912 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
913 access_result = open(device, O_RDONLY);
914 access_type = "open";
916 access_result = access(device, amode);
917 access_type = "access";
919 if(access_result == -1) {
920 err = vstrallocf(_("Could not access %s (%s): %s"),
921 qdevice, qdisk, strerror(errno));
923 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
924 aclose(access_result);
932 qdevice = quote_string(device);
936 if(user_and_password) {
937 memset(user_and_password, '\0', (size_t)lpass);
938 amfree(user_and_password);
943 g_printf(_("ERROR %s\n"), err);
944 dbprintf(_("%s\n"), err);
948 g_printf("OK %s\n", qdisk);
949 dbprintf(_("disk %s OK\n"), qdisk);
952 g_printf("OK %s\n", qamdevice);
953 dbprintf(_("amdevice %s OK\n"), qamdevice);
956 g_printf("OK %s\n", qdevice);
957 dbprintf(_("device %s OK\n"), qdevice);
961 dbprintf(_("extra info: %s\n"), extra_info);
969 /* XXX perhaps do something with level: read dumpdates and sanity check */
978 char *gnutar_list_dir;
979 int need_amandates = 0;
983 cmd = vstralloc(amlibexecdir, "/", "runtar", NULL);
984 check_file(cmd,X_OK);
991 cmd = vstralloc(amlibexecdir, "/", "rundump", NULL);
992 check_file(cmd,X_OK);
999 check_file(DUMP, X_OK);
1001 g_printf(_("ERROR [DUMP program not available]\n"));
1005 if( need_restore ) {
1007 check_file(RESTORE, X_OK);
1009 g_printf(_("ERROR [RESTORE program not available]\n"));
1015 check_file(VDUMP, X_OK);
1017 g_printf(_("ERROR [VDUMP program not available]\n"));
1021 if ( need_vrestore ) {
1023 check_file(VRESTORE, X_OK);
1025 g_printf(_("ERROR [VRESTORE program not available]\n"));
1029 if( need_xfsdump ) {
1031 check_file(XFSDUMP, F_OK);
1033 g_printf(_("ERROR [XFSDUMP program not available]\n"));
1037 if( need_xfsrestore ) {
1039 check_file(XFSRESTORE, X_OK);
1041 g_printf(_("ERROR [XFSRESTORE program not available]\n"));
1047 check_file(VXDUMP, X_OK);
1049 g_printf(_("ERROR [VXDUMP program not available]\n"));
1053 if( need_vxrestore ) {
1055 check_file(VXRESTORE, X_OK);
1057 g_printf(_("ERROR [VXRESTORE program not available]\n"));
1063 check_file(GNUTAR, X_OK);
1065 g_printf(_("ERROR [GNUTAR program not available]\n"));
1067 gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
1068 if (strlen(gnutar_list_dir) == 0)
1069 gnutar_list_dir = NULL;
1070 if (gnutar_list_dir) {
1071 /* make sure our listed-incremental dir is ready */
1072 check_dir(gnutar_list_dir, R_OK|W_OK);
1074 /* no listed-incremental dir, so check that amandates is ready */
1079 if( need_calcsize ) {
1082 cmd = vstralloc(amlibexecdir, "/", "calcsize", NULL);
1084 check_file(cmd, X_OK);
1088 /* calcsize uses amandates */
1092 if (need_amandates) {
1093 char *amandates_file;
1094 amandates_file = getconf_str(CNF_AMANDATES);
1095 check_file(amandates_file, R_OK|W_OK);
1100 check_file(SAMBA_CLIENT, X_OK);
1102 g_printf(_("ERROR [SMBCLIENT program not available]\n"));
1104 testfd = open("/etc/amandapass", R_OK);
1106 if(fstat(testfd, &buf) == 0) {
1107 if ((buf.st_mode & 0x7) != 0) {
1108 g_printf(_("ERROR [/etc/amandapass is world readable!]\n"));
1110 g_printf(_("OK [/etc/amandapass is readable, but not by all]\n"));
1113 g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"),
1118 g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"),
1123 if (need_compress_path )
1124 check_file(COMPRESS_PATH, X_OK);
1126 if (need_dump || need_xfsdump ) {
1127 if (check_file_exist("/var/lib/dumpdates")) {
1128 check_file("/var/lib/dumpdates",
1137 if (access("/etc", R_OK|W_OK) == -1) {
1138 g_printf(_("ERROR [dump will not be able to create the /var/lib/dumpdates file: %s]\n"), strerror(errno));
1145 if (check_file_exist("/var/lib/vdumpdates")) {
1146 check_file("/var/lib/vdumpdates", F_OK);
1150 if (need_global_check) {
1151 check_access("/dev/null", R_OK|W_OK);
1152 check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
1154 #ifdef AMANDA_DBGDIR
1155 check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
1158 check_space("/var/lib", (off_t)64); /* for /var/lib/dumpdates writing */
1159 check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
1168 struct fs_usage fsusage;
1169 char *quoted = quote_string(dir);
1172 if(get_fs_usage(dir, NULL, &fsusage) == -1) {
1173 g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
1178 /* do the division first to avoid potential integer overflow */
1179 kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;
1181 if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
1182 g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
1184 } else if (kb_avail < kbytes) {
1185 g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
1187 (long long)kb_avail);
1189 g_printf(_("OK %s has more than %lldKB available.\n"),
1190 quoted, (long long)kbytes);
1199 struct stat stat_buf;
1201 if (stat(filename, &stat_buf) != 0) {
1202 if(errno == ENOENT) {