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);
81 static void print_platform(void);
90 char *qamdevice = NULL;
92 char *err_extra = NULL;
100 if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) {
101 printf("selfcheck-%s\n", VERSION);
108 * Configure program for internationalization:
109 * 1) Only set the message locale for now.
110 * 2) Set textdomain for all amanda related programs to "amanda"
111 * We don't want to be forced to support dozens of message catalogs.
113 setlocale(LC_MESSAGES, "C");
114 textdomain("amanda");
120 set_pname("selfcheck");
122 /* Don't die when child closes pipe */
123 signal(SIGPIPE, SIG_IGN);
125 add_amanda_log_handler(amanda_log_stderr);
126 add_amanda_log_handler(amanda_log_syslog);
127 dbopen(DBG_SUBDIR_CLIENT);
129 dbprintf(_("version %s\n"), VERSION);
130 g_printf("OK version %s\n", VERSION);
133 if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
134 amandad_auth = stralloc(argv[2]);
137 config_init(CONFIG_INIT_CLIENT, NULL);
138 /* (check for config errors comes later) */
140 check_running_as(RUNNING_AS_CLIENT_LOGIN);
142 our_features = am_init_feature_set();
143 our_feature_string = am_feature_to_string(our_features);
145 /* handle all service requests */
148 for(; (line = agets(stdin)) != NULL; free(line)) {
153 if(strncmp_const(line, "OPTIONS ") == 0) {
154 g_options = parse_g_options(line+8, 1);
155 if(!g_options->hostname) {
156 g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1);
157 gethostname(g_options->hostname, MAX_HOSTNAME_LENGTH);
158 g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0';
161 g_printf("OPTIONS ");
162 if(am_has_feature(g_options->features, fe_rep_options_features)) {
163 g_printf("features=%s;", our_feature_string);
165 if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
166 g_printf("hostname=%s;", g_options->hostname);
171 if (g_options->config) {
172 /* overlay this configuration on the existing (nameless) configuration */
173 config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
176 dbrename(get_config_name(), DBG_SUBDIR_CLIENT);
179 /* check for any config errors now */
180 if (config_errors(&errlist) >= CFGERR_ERRORS) {
181 char *errstr = config_errors_to_error_string(errlist);
182 g_printf("%s\n", errstr);
187 if (am_has_feature(g_options->features, fe_req_xml)) {
197 skip_whitespace(s, ch); /* find program name */
199 goto err; /* no program */
201 dle->program = s - 1;
202 skip_non_whitespace(s, ch);
203 s[-1] = '\0'; /* terminate the program name */
205 dle->program_is_application_api = 0;
206 if(strcmp(dle->program,"APPLICATION")==0) {
207 dle->program_is_application_api = 1;
208 skip_whitespace(s, ch); /* find dumper name */
210 goto err; /* no program */
212 dle->program = s - 1;
213 skip_non_whitespace(s, ch);
214 s[-1] = '\0'; /* terminate the program name */
217 if(strncmp_const(dle->program, "CALCSIZE") == 0) {
218 skip_whitespace(s, ch); /* find program name */
220 goto err; /* no program */
222 dle->program = s - 1;
223 skip_non_whitespace(s, ch);
225 dle->estimatelist = g_slist_append(dle->estimatelist,
226 GINT_TO_POINTER(ES_CALCSIZE));
229 dle->estimatelist = g_slist_append(dle->estimatelist,
230 GINT_TO_POINTER(ES_CLIENT));
233 skip_whitespace(s, ch); /* find disk name */
235 goto err; /* no disk */
238 skip_quoted_string(s, ch);
239 s[-1] = '\0'; /* terminate the disk name */
240 dle->disk = unquote_string(qdisk);
242 skip_whitespace(s, ch); /* find the device or level */
244 goto err; /* no device or level */
246 if(!isdigit((int)s[-1])) {
248 skip_quoted_string(s, ch);
249 s[-1] = '\0'; /* terminate the device */
250 qamdevice = stralloc(fp);
251 dle->device = unquote_string(qamdevice);
252 skip_whitespace(s, ch); /* find level number */
255 dle->device = stralloc(dle->disk);
256 qamdevice = stralloc(qdisk);
259 /* find level number */
260 if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
261 goto err; /* bad level */
263 alevel = g_new0(level_t, 1);
264 alevel->level = level;
265 dle->levellist = g_slist_append(dle->levellist, alevel);
268 skip_whitespace(s, ch);
269 if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) {
270 skip_whitespace(s, ch); /* find the option string */
272 goto err; /* bad options string */
275 skip_quoted_string(s, ch);
276 s[-1] = '\0'; /* terminate the options */
277 parse_options(optstr, dle, g_options->features, 1);
284 } else if (ch == '\0') {
285 /* check all since no option */
298 need_compress_path=1;
305 goto err; /* bad syntax */
309 if (g_options == NULL) {
310 g_printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
311 error(_("Missing OPTIONS line in selfcheck input\n"));
315 if (am_has_feature(g_options->features, fe_req_xml)) {
317 dle_t *dles, *dle, *dle_next;
319 dles = amxml_parse_node_FILE(stdin, &errmsg);
324 if (merge_dles_properties(dles, 1) == 0) {
327 for (dle = dles; dle != NULL; dle = dle->next) {
328 run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle,
331 for (dle = dles; dle != NULL; dle = dle->next) {
333 run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle,
336 run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle,
339 for (dle = dles; dle != NULL; dle = dle->next) {
340 run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle,
343 for (dle = dles; dle != NULL; dle = dle_next) {
344 dle_next = dle->next;
353 amfree(our_feature_string);
354 am_release_feature_set(our_features);
356 free_g_options(g_options);
363 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra);
364 dbprintf(_("REQ packet is bogus: %s\n"), err_extra);
366 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n"));
367 dbprintf(_("REQ packet is bogus\n"));
378 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
382 if (strcmp(dle->program,"GNUTAR") == 0) {
384 if(dle->device && dle->device[0] == '/' && dle->device[1] == '/') {
385 if(dle->exclude_file && dle->exclude_file->nb_element > 1) {
386 g_printf(_("ERROR [samba support only one exclude file]\n"));
388 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
389 dle->exclude_optional==0) {
390 g_printf(_("ERROR [samba does not support exclude list]\n"));
392 if (dle->include_file && dle->include_file->nb_element > 0) {
393 g_printf(_("ERROR [samba does not support include file]\n"));
395 if (dle->include_list && dle->include_list->nb_element > 0 &&
396 dle->include_optional==0) {
397 g_printf(_("ERROR [samba does not support include list]\n"));
403 char *file_exclude = NULL;
404 char *file_include = NULL;
406 if (dle->exclude_file) nb_exclude += dle->exclude_file->nb_element;
407 if (dle->exclude_list) nb_exclude += dle->exclude_list->nb_element;
408 if (dle->include_file) nb_include += dle->include_file->nb_element;
409 if (dle->include_list) nb_include += dle->include_list->nb_element;
411 if (nb_exclude > 0) file_exclude = build_exclude(dle, 1);
412 if (nb_include > 0) file_include = build_include(dle, 1);
414 amfree(file_exclude);
415 amfree(file_include);
421 if (strcmp(dle->program,"DUMP") == 0) {
422 if (dle->exclude_file && dle->exclude_file->nb_element > 0) {
423 g_printf(_("ERROR [DUMP does not support exclude file]\n"));
425 if (dle->exclude_list && dle->exclude_list->nb_element > 0) {
426 g_printf(_("ERROR [DUMP does not support exclude list]\n"));
428 if (dle->include_file && dle->include_file->nb_element > 0) {
429 g_printf(_("ERROR [DUMP does not support include file]\n"));
431 if (dle->include_list && dle->include_list->nb_element > 0) {
432 g_printf(_("ERROR [DUMP does not support include list]\n"));
440 if (dle->device && strcmp(amname_to_fstype(dle->device), "advfs") == 0)
447 if (dle->create_index)
454 if (dle->device && strcmp(amname_to_fstype(dle->device), "xfs") == 0)
461 if (dle->create_index)
468 if (dle->device && strcmp(amname_to_fstype(dle->device), "vxfs") == 0)
474 if (dle->create_index)
481 if (dle->create_index)
485 /* AIX backup program */
487 if (dle->create_index)
491 if ((dle->compress == COMP_BEST) || (dle->compress == COMP_FAST)
492 || (dle->compress == COMP_CUST)) {
493 need_compress_path=1;
495 if (dle->auth && amandad_auth) {
496 if (strcasecmp(dle->auth, amandad_auth) != 0) {
497 g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
498 amandad_auth, dle->auth);
499 if (strcmp(dle->auth, "ssh") == 0) {
500 g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
501 "should be \"--auth=ssh\", or use another auth "
505 g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration "
506 " must be the same as the DLE]\n"));
518 char *user_and_password = NULL;
520 char *share = NULL, *subdir = NULL;
525 char *extra_info = NULL;
527 char *qamdevice = NULL;
528 char *qdevice = NULL;
532 qdisk = quote_string(dle->disk);
533 qamdevice = quote_string(dle->device);
534 device = stralloc("nodevice");
535 dbprintf(_("checking disk %s\n"), qdisk);
536 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
537 if (dle->device[0] == '/' && dle->device[1] == '/') {
539 _("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
545 if (strcmp(dle->program, "GNUTAR")==0) {
546 if(dle->device[0] == '/' && dle->device[1] == '/') {
548 int nullfd, checkerr;
562 parsesharename(dle->device, &share, &subdir);
565 _("cannot parse for share/subdir disk entry %s"),
569 if ((subdir) && (SAMBA_VERSION < 2)) {
570 err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
574 if ((user_and_password = findpass(share, &domain)) == NULL) {
575 err = vstrallocf(_("cannot find password for %s"),
579 lpass = strlen(user_and_password);
580 if ((pwtext = strchr(user_and_password, '%')) == NULL) {
582 _("password field not \'user%%pass\' for %s"),
587 pwtext_len = (size_t)strlen(pwtext);
589 if ((device = makesharename(share, 0)) == NULL) {
590 err = vstrallocf(_("cannot make share name of %s"), share);
594 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
595 err = vstrallocf(_("Cannot access /dev/null : %s"),
600 if (pwtext_len > 0) {
601 pw_fd_env = "PASSWD_FD";
603 pw_fd_env = "dummy_PASSWD_FD";
605 checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, 0,
606 &nullfd, &nullfd, &checkerr,
607 pw_fd_env, &passwdfd,
610 *user_and_password ? "-U" : skip_argument,
611 *user_and_password ? user_and_password
614 domain ? "-W" : skip_argument,
615 domain ? domain : skip_argument,
616 #if SAMBA_VERSION >= 2
617 subdir ? "-D" : skip_argument,
618 subdir ? subdir : skip_argument,
626 if ((pwtext_len > 0) &&
627 full_write(passwdfd, pwtext, pwtext_len) < pwtext_len) {
628 err = vstrallocf(_("password write failed: %s: %s"),
629 dle->device, strerror(errno));
634 memset(user_and_password, '\0', (size_t)lpass);
635 amfree(user_and_password);
637 ferr = fdopen(checkerr, "r");
639 g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
640 error(_("Can't fdopen: %s"), strerror(errno));
645 for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
648 strappend(extra_info, sep);
649 strappend(extra_info, line);
651 if(strstr(line, "ERRDOS") != NULL) {
659 while ((wpid = wait(&retstat)) != -1) {
660 if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
661 char *exitstr = str_exit_status("smbclient", retstat);
663 strappend(err, exitstr);
670 if (errdos != 0 || rc != 0) {
672 err = newvstrallocf(err,
673 _("samba access error: %s: %s %s"),
674 dle->device, extra_info, err);
677 err = newvstrallocf(err,
678 _("samba access error: %s: %s"),
684 _("This client is not configured for samba: %s"),
691 device = amname_to_dirname(dle->device);
692 } else if (strcmp(dle->program, "DUMP") == 0) {
693 if(dle->device[0] == '/' && dle->device[1] == '/') {
695 _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
701 if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
707 device = amname_to_dirname(dle->device);
713 device = amname_to_devname(dle->device);
722 if (dle->program_is_application_api) {
723 pid_t application_api_pid;
724 backup_support_option_t *bsu;
728 bsu = backup_support_option(dle->program, g_options, dle->disk,
729 dle->device, &errarray);
734 for (i=0; i < errarray->len; i++) {
735 line = g_ptr_array_index(errarray, i);
736 fprintf(stdout, _("ERROR Application '%s': %s\n"),
740 err = vstrallocf(_("Application '%s': can't run support command"),
745 if (dle->data_path == DATA_PATH_AMANDA &&
746 (bsu->data_path_set & DATA_PATH_AMANDA)==0) {
747 g_printf("ERROR application %s doesn't support amanda data-path\n",
750 if (dle->data_path == DATA_PATH_DIRECTTCP &&
751 (bsu->data_path_set & DATA_PATH_DIRECTTCP)==0) {
752 g_printf("ERROR application %s doesn't support directtcp data-path\n",
755 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE &&
757 g_printf("ERROR application %s doesn't support calcsize estimate\n",
760 if (dle->include_file && dle->include_file->nb_element > 0 &&
761 !bsu->include_file) {
762 g_printf("ERROR application %s doesn't support include-file\n",
765 if (dle->include_list && dle->include_list->nb_element > 0 &&
766 !bsu->include_list) {
767 g_printf("ERROR application %s doesn't support include-list\n",
770 if (dle->include_optional && !bsu->include_optional) {
771 g_printf("ERROR application %s doesn't support optional include\n",
774 if (dle->exclude_file && dle->exclude_file->nb_element > 0 &&
775 !bsu->exclude_file) {
776 g_printf("ERROR application %s doesn't support exclude-file\n",
779 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
780 !bsu->exclude_list) {
781 g_printf("ERROR application %s doesn't support exclude-list\n",
784 if (dle->exclude_optional && !bsu->exclude_optional) {
785 g_printf("ERROR application %s doesn't support optional exclude\n",
788 fflush(stdout);fflush(stderr);
790 if (pipe(app_err) < 0) {
791 err = vstrallocf(_("Application '%s': can't create pipe"),
796 switch (application_api_pid = fork()) {
798 err = vstrallocf(_("fork failed: %s"), strerror(errno));
803 GPtrArray *argv_ptr = g_ptr_array_new();
805 char *cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
814 g_ptr_array_add(argv_ptr, stralloc(dle->program));
815 g_ptr_array_add(argv_ptr, stralloc("selfcheck"));
816 if (bsu->message_line == 1) {
817 g_ptr_array_add(argv_ptr, stralloc("--message"));
818 g_ptr_array_add(argv_ptr, stralloc("line"));
820 if (g_options->config != NULL && bsu->config == 1) {
821 g_ptr_array_add(argv_ptr, stralloc("--config"));
822 g_ptr_array_add(argv_ptr, stralloc(g_options->config));
824 if (g_options->hostname != NULL && bsu->host == 1) {
825 g_ptr_array_add(argv_ptr, stralloc("--host"));
826 g_ptr_array_add(argv_ptr, stralloc(g_options->hostname));
828 if (dle->disk != NULL && bsu->disk == 1) {
829 g_ptr_array_add(argv_ptr, stralloc("--disk"));
830 g_ptr_array_add(argv_ptr, stralloc(dle->disk));
833 g_ptr_array_add(argv_ptr, stralloc("--device"));
834 g_ptr_array_add(argv_ptr, stralloc(dle->device));
836 if (dle->create_index && bsu->index_line == 1) {
837 g_ptr_array_add(argv_ptr, stralloc("--index"));
838 g_ptr_array_add(argv_ptr, stralloc("line"));
840 if (dle->record && bsu->record == 1) {
841 g_ptr_array_add(argv_ptr, stralloc("--record"));
844 for (el = dle->estimatelist; el != NULL; el=el->next) {
845 estimate_t estimate = (estimate_t)GPOINTER_TO_INT(el->data);
846 if (estimate == ES_CALCSIZE && bsu->calcsize == 1) {
847 g_ptr_array_add(argv_ptr, stralloc("--calcsize"));
850 application_property_add_to_argv(argv_ptr, dle, bsu,
851 g_options->features);
853 for (scriptlist = dle->scriptlist; scriptlist != NULL;
854 scriptlist = scriptlist->next) {
855 script = (script_t *)scriptlist->data;
856 if (script->result && script->result->proplist) {
857 property_add_to_argv(argv_ptr,
858 script->result->proplist);
862 g_ptr_array_add(argv_ptr, NULL);
864 cmdline = stralloc(cmd);
865 for (i = 0; i < argv_ptr->len-1; i++) {
866 char *quoted = quote_string(
867 (char *)g_ptr_array_index(argv_ptr,i));
868 cmdline = vstrextend(&cmdline, " ", quoted, NULL);
871 dbprintf(_("Spawning \"%s\" in pipeline\n"), cmdline);
875 execve(cmd, (char **)argv_ptr->pdata, safe_env());
876 g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
879 default: /* parent */
886 app_stderr = fdopen(app_err[0], "r");
887 while((line = agets(app_stderr)) != NULL) {
888 if (strlen(line) > 0) {
889 fprintf(stdout, "ERROR Application '%s': %s\n",
891 dbprintf("ERROR %s\n", line);
896 if (waitpid(application_api_pid, &status, 0) < 0) {
897 err = vstrallocf(_("waitpid failed: %s"),
900 } else if (!WIFEXITED(status)) {
901 err = vstrallocf(_("Application '%s': exited with signal %d"),
902 dle->program, WTERMSIG(status));
904 } else if (WEXITSTATUS(status) != 0) {
905 err = vstrallocf(_("Application '%s': exited with status %d"),
906 dle->program, WEXITSTATUS(status));
912 fflush(stdout);fflush(stderr);
920 qdevice = quote_string(device);
921 dbprintf(_("device %s\n"), qdevice);
923 /* skip accessability test if this is an AFS entry */
924 if(strncmp_const(device, "afs:") != 0) {
925 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
926 access_result = open(device, O_RDONLY);
927 access_type = "open";
929 access_result = access(device, amode);
930 access_type = "access";
932 if(access_result == -1) {
933 err = vstrallocf(_("Could not %s %s (%s): %s"),
934 access_type, qdevice, qdisk, strerror(errno));
936 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
937 aclose(access_result);
945 qdevice = quote_string(device);
949 if(user_and_password) {
950 memset(user_and_password, '\0', (size_t)lpass);
951 amfree(user_and_password);
956 g_printf(_("ERROR %s\n"), err);
957 dbprintf(_("%s\n"), err);
961 g_printf("OK %s\n", qdisk);
962 dbprintf(_("disk %s OK\n"), qdisk);
965 g_printf("OK %s\n", qamdevice);
966 dbprintf(_("amdevice %s OK\n"), qamdevice);
969 g_printf("OK %s\n", qdevice);
970 dbprintf(_("device %s OK\n"), qdevice);
974 dbprintf(_("extra info: %s\n"), extra_info);
982 /* XXX perhaps do something with level: read dumpdates and sanity check */
991 char *gnutar_list_dir;
992 int need_amandates = 0;
996 cmd = vstralloc(amlibexecdir, "/", "runtar", NULL);
997 check_file(cmd,X_OK);
1004 cmd = vstralloc(amlibexecdir, "/", "rundump", NULL);
1005 check_file(cmd,X_OK);
1012 check_file(DUMP, X_OK);
1014 g_printf(_("ERROR [DUMP program not available]\n"));
1018 if( need_restore ) {
1020 check_file(RESTORE, X_OK);
1022 g_printf(_("ERROR [RESTORE program not available]\n"));
1028 check_file(VDUMP, X_OK);
1030 g_printf(_("ERROR [VDUMP program not available]\n"));
1034 if ( need_vrestore ) {
1036 check_file(VRESTORE, X_OK);
1038 g_printf(_("ERROR [VRESTORE program not available]\n"));
1042 if( need_xfsdump ) {
1044 check_file(XFSDUMP, F_OK);
1046 g_printf(_("ERROR [XFSDUMP program not available]\n"));
1050 if( need_xfsrestore ) {
1052 check_file(XFSRESTORE, X_OK);
1054 g_printf(_("ERROR [XFSRESTORE program not available]\n"));
1060 check_file(VXDUMP, X_OK);
1062 g_printf(_("ERROR [VXDUMP program not available]\n"));
1066 if( need_vxrestore ) {
1068 check_file(VXRESTORE, X_OK);
1070 g_printf(_("ERROR [VXRESTORE program not available]\n"));
1076 check_file(GNUTAR, X_OK);
1078 g_printf(_("ERROR [GNUTAR program not available]\n"));
1080 gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
1081 if (strlen(gnutar_list_dir) == 0)
1082 gnutar_list_dir = NULL;
1083 if (gnutar_list_dir) {
1084 /* make sure our listed-incremental dir is ready */
1085 check_dir(gnutar_list_dir, R_OK|W_OK);
1087 /* no listed-incremental dir, so check that amandates is ready */
1092 if( need_calcsize ) {
1095 cmd = vstralloc(amlibexecdir, "/", "calcsize", NULL);
1097 check_file(cmd, X_OK);
1101 /* calcsize uses amandates */
1105 if (need_amandates) {
1106 char *amandates_file;
1107 amandates_file = getconf_str(CNF_AMANDATES);
1108 check_file(amandates_file, R_OK|W_OK);
1113 check_file(SAMBA_CLIENT, X_OK);
1115 g_printf(_("ERROR [SMBCLIENT program not available]\n"));
1117 testfd = open("/etc/amandapass", R_OK);
1119 if(fstat(testfd, &buf) == 0) {
1120 if ((buf.st_mode & 0x7) != 0) {
1121 g_printf(_("ERROR [/etc/amandapass is world readable!]\n"));
1123 g_printf(_("OK [/etc/amandapass is readable, but not by all]\n"));
1126 g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"),
1131 g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"),
1136 if (need_compress_path )
1137 check_file(COMPRESS_PATH, X_OK);
1139 if (need_dump || need_xfsdump ) {
1140 if (check_file_exist("/etc/dumpdates")) {
1141 check_file("/etc/dumpdates",
1150 if (access("/etc", R_OK|W_OK) == -1) {
1151 g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
1158 if (check_file_exist("/etc/vdumpdates")) {
1159 check_file("/etc/vdumpdates", F_OK);
1163 if (need_global_check) {
1164 check_access("/dev/null", R_OK|W_OK);
1165 check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
1167 #ifdef AMANDA_DBGDIR
1168 check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
1171 check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
1180 struct fs_usage fsusage;
1181 char *quoted = quote_string(dir);
1184 if(get_fs_usage(dir, NULL, &fsusage) == -1) {
1185 g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
1190 /* do the division first to avoid potential integer overflow */
1191 kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;
1193 if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
1194 g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
1196 } else if (kb_avail < kbytes) {
1197 g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
1199 (long long)kb_avail);
1201 g_printf(_("OK %s has more than %lldKB available.\n"),
1202 quoted, (long long)kbytes);
1211 struct stat stat_buf;
1213 if (stat(filename, &stat_buf) != 0) {
1214 if(errno == ENOENT) {
1222 print_platform(void)
1224 struct stat stat_buf;
1226 char *distro = NULL;
1227 char *platform = NULL;
1229 GPtrArray *argv_ptr;
1231 if (stat("/etc/lsb-release", &stat_buf) == 0) {
1232 FILE *release = fopen("/etc/lsb-release", "r");
1236 while ((result = fgets(line, 1024, release))) {
1237 if (strstr(line, "DESCRIPTION")) {
1238 platform = strchr(line, '=');
1239 if (platform) platform++;
1244 } else if (stat("/etc/redhat-release", &stat_buf) == 0) {
1245 FILE *release = fopen("/etc/redhat-release", "r");
1249 result = fgets(line, 1024, release);
1255 } else if (stat("/etc/debian_version", &stat_buf) == 0) {
1256 FILE *release = fopen("/etc/debian_version", "r");
1260 result = fgets(line, 1024, release);
1267 argv_ptr = g_ptr_array_new();
1269 g_ptr_array_add(argv_ptr, UNAME_PATH);
1270 g_ptr_array_add(argv_ptr, "-s");
1271 g_ptr_array_add(argv_ptr, NULL);
1272 uname = get_first_line(argv_ptr);
1274 if (strncmp(uname, "SunOS", 5) == 0) {
1275 FILE *release = fopen("/etc/release", "r");
1279 result = fgets(line, 1024, release);
1288 g_ptr_array_free(argv_ptr, TRUE);
1295 platform = "Unknown";
1297 if (platform[strlen(platform) -1] == '\n') {
1298 platform[strlen(platform) -1] = '\0';
1300 g_fprintf(stdout, "OK distro %s\n", distro);
1301 g_fprintf(stdout, "OK platform %s\n", platform);