2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
4 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of U.M. not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. U.M. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
17 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: James da Silva, Systems Design and Analysis Group
25 * Computer Science Department
26 * University of Maryland at College Park
29 * $Id: selfcheck.c 10421 2008-03-06 18:48:30Z martineau $
31 * do self-check and send back any error messages
37 #include "amandates.h"
40 #include "pipespawn.h"
41 #include "amfeatures.h"
42 #include "client_util.h"
59 int need_xfsrestore=0;
64 int need_compress_path=0;
66 int need_global_check=0;
67 int program_is_application_api=0;
69 static char *amandad_auth = NULL;
70 static am_feature_t *our_features = NULL;
71 static char *our_feature_string = NULL;
72 static g_option_t *g_options = NULL;
75 int main(int argc, char **argv);
77 static void check_options(dle_t *dle);
78 static void check_disk(dle_t *dle);
79 static void check_overall(void);
80 static int check_file_exist(char *filename);
81 static void check_space(char *dir, off_t kbytes);
82 static void print_platform(void);
91 char *qamdevice = NULL;
93 char *err_extra = NULL;
101 if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) {
102 printf("selfcheck-%s\n", VERSION);
109 * Configure program for internationalization:
110 * 1) Only set the message locale for now.
111 * 2) Set textdomain for all amanda related programs to "amanda"
112 * We don't want to be forced to support dozens of message catalogs.
114 setlocale(LC_MESSAGES, "C");
115 textdomain("amanda");
121 set_pname("selfcheck");
123 /* Don't die when child closes pipe */
124 signal(SIGPIPE, SIG_IGN);
126 add_amanda_log_handler(amanda_log_stderr);
127 add_amanda_log_handler(amanda_log_syslog);
128 dbopen(DBG_SUBDIR_CLIENT);
130 dbprintf(_("version %s\n"), VERSION);
131 g_printf("OK version %s\n", VERSION);
134 if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
135 amandad_auth = stralloc(argv[2]);
138 config_init(CONFIG_INIT_CLIENT, NULL);
139 /* (check for config errors comes later) */
141 check_running_as(RUNNING_AS_CLIENT_LOGIN);
143 our_features = am_init_feature_set();
144 our_feature_string = am_feature_to_string(our_features);
146 /* handle all service requests */
149 for(; (line = agets(stdin)) != NULL; free(line)) {
154 if(strncmp_const(line, "OPTIONS ") == 0) {
155 g_options = parse_g_options(line+8, 1);
156 if(!g_options->hostname) {
157 g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1);
158 gethostname(g_options->hostname, MAX_HOSTNAME_LENGTH);
159 g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0';
162 g_printf("OPTIONS ");
163 if(am_has_feature(g_options->features, fe_rep_options_features)) {
164 g_printf("features=%s;", our_feature_string);
166 if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
167 g_printf("hostname=%s;", g_options->hostname);
172 if (g_options->config) {
173 /* overlay this configuration on the existing (nameless) configuration */
174 config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
177 dbrename(get_config_name(), DBG_SUBDIR_CLIENT);
180 /* check for any config errors now */
181 if (config_errors(&errlist) >= CFGERR_ERRORS) {
182 char *errstr = config_errors_to_error_string(errlist);
183 g_printf("%s\n", errstr);
188 if (am_has_feature(g_options->features, fe_req_xml)) {
198 skip_whitespace(s, ch); /* find program name */
200 goto err; /* no program */
202 dle->program = s - 1;
203 skip_non_whitespace(s, ch);
204 s[-1] = '\0'; /* terminate the program name */
206 dle->program_is_application_api = 0;
207 if(strcmp(dle->program,"APPLICATION")==0) {
208 dle->program_is_application_api = 1;
209 skip_whitespace(s, ch); /* find dumper name */
211 goto err; /* no program */
213 dle->program = s - 1;
214 skip_non_whitespace(s, ch);
215 s[-1] = '\0'; /* terminate the program name */
218 if(strncmp_const(dle->program, "CALCSIZE") == 0) {
219 skip_whitespace(s, ch); /* find program name */
221 goto err; /* no program */
223 dle->program = s - 1;
224 skip_non_whitespace(s, ch);
226 dle->estimatelist = g_slist_append(dle->estimatelist,
227 GINT_TO_POINTER(ES_CALCSIZE));
230 dle->estimatelist = g_slist_append(dle->estimatelist,
231 GINT_TO_POINTER(ES_CLIENT));
234 skip_whitespace(s, ch); /* find disk name */
236 goto err; /* no disk */
239 skip_quoted_string(s, ch);
240 s[-1] = '\0'; /* terminate the disk name */
241 dle->disk = unquote_string(qdisk);
243 skip_whitespace(s, ch); /* find the device or level */
245 goto err; /* no device or level */
247 if(!isdigit((int)s[-1])) {
249 skip_quoted_string(s, ch);
250 s[-1] = '\0'; /* terminate the device */
251 qamdevice = stralloc(fp);
252 dle->device = unquote_string(qamdevice);
253 skip_whitespace(s, ch); /* find level number */
256 dle->device = stralloc(dle->disk);
257 qamdevice = stralloc(qdisk);
260 /* find level number */
261 if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
262 goto err; /* bad level */
264 alevel = g_new0(am_level_t, 1);
265 alevel->level = level;
266 dle->levellist = g_slist_append(dle->levellist, alevel);
269 skip_whitespace(s, ch);
270 if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) {
271 skip_whitespace(s, ch); /* find the option string */
273 goto err; /* bad options string */
276 skip_quoted_string(s, ch);
277 s[-1] = '\0'; /* terminate the options */
278 parse_options(optstr, dle, g_options->features, 1);
285 } else if (ch == '\0') {
286 /* check all since no option */
299 need_compress_path=1;
306 goto err; /* bad syntax */
310 if (g_options == NULL) {
311 g_printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
312 error(_("Missing OPTIONS line in selfcheck input\n"));
316 if (am_has_feature(g_options->features, fe_req_xml)) {
318 dle_t *dles, *dle, *dle_next;
320 dles = amxml_parse_node_FILE(stdin, &errmsg);
325 if (merge_dles_properties(dles, 1) == 0) {
328 for (dle = dles; dle != NULL; dle = dle->next) {
329 run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle,
332 for (dle = dles; dle != NULL; dle = dle->next) {
334 run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle,
337 run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle,
340 for (dle = dles; dle != NULL; dle = dle->next) {
341 run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle,
344 for (dle = dles; dle != NULL; dle = dle_next) {
345 dle_next = dle->next;
354 amfree(our_feature_string);
355 am_release_feature_set(our_features);
357 free_g_options(g_options);
364 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra);
365 dbprintf(_("REQ packet is bogus: %s\n"), err_extra);
367 g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n"));
368 dbprintf(_("REQ packet is bogus\n"));
379 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
383 if (strcmp(dle->program,"GNUTAR") == 0) {
385 if(dle->device && dle->device[0] == '/' && dle->device[1] == '/') {
386 if(dle->exclude_file && dle->exclude_file->nb_element > 1) {
387 g_printf(_("ERROR [samba support only one exclude file]\n"));
389 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
390 dle->exclude_optional==0) {
391 g_printf(_("ERROR [samba does not support exclude list]\n"));
393 if (dle->include_file && dle->include_file->nb_element > 0) {
394 g_printf(_("ERROR [samba does not support include file]\n"));
396 if (dle->include_list && dle->include_list->nb_element > 0 &&
397 dle->include_optional==0) {
398 g_printf(_("ERROR [samba does not support include list]\n"));
404 char *file_exclude = NULL;
405 char *file_include = NULL;
407 if (dle->exclude_file) nb_exclude += dle->exclude_file->nb_element;
408 if (dle->exclude_list) nb_exclude += dle->exclude_list->nb_element;
409 if (dle->include_file) nb_include += dle->include_file->nb_element;
410 if (dle->include_list) nb_include += dle->include_list->nb_element;
412 if (nb_exclude > 0) file_exclude = build_exclude(dle, 1);
413 if (nb_include > 0) file_include = build_include(dle, 1);
415 amfree(file_exclude);
416 amfree(file_include);
422 if (strcmp(dle->program,"DUMP") == 0) {
423 if (dle->exclude_file && dle->exclude_file->nb_element > 0) {
424 g_printf(_("ERROR [DUMP does not support exclude file]\n"));
426 if (dle->exclude_list && dle->exclude_list->nb_element > 0) {
427 g_printf(_("ERROR [DUMP does not support exclude list]\n"));
429 if (dle->include_file && dle->include_file->nb_element > 0) {
430 g_printf(_("ERROR [DUMP does not support include file]\n"));
432 if (dle->include_list && dle->include_list->nb_element > 0) {
433 g_printf(_("ERROR [DUMP does not support include list]\n"));
441 if (dle->device && strcmp(amname_to_fstype(dle->device), "advfs") == 0)
448 if (dle->create_index)
455 if (dle->device && strcmp(amname_to_fstype(dle->device), "xfs") == 0)
462 if (dle->create_index)
469 if (dle->device && strcmp(amname_to_fstype(dle->device), "vxfs") == 0)
475 if (dle->create_index)
482 if (dle->create_index)
486 /* AIX backup program */
488 if (dle->create_index)
492 if ((dle->compress == COMP_BEST) || (dle->compress == COMP_FAST)
493 || (dle->compress == COMP_CUST)) {
494 need_compress_path=1;
496 if (dle->auth && amandad_auth) {
497 if (strcasecmp(dle->auth, amandad_auth) != 0) {
498 g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
499 amandad_auth, dle->auth);
500 if (strcmp(dle->auth, "ssh") == 0) {
501 g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
502 "should be \"--auth=ssh\", or use another auth "
506 g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration "
507 " must be the same as the DLE]\n"));
519 char *user_and_password = NULL;
521 char *share = NULL, *subdir = NULL;
526 char *extra_info = NULL;
528 char *qamdevice = NULL;
529 char *qdevice = NULL;
533 qdisk = quote_string(dle->disk);
534 qamdevice = quote_string(dle->device);
535 device = stralloc("nodevice");
536 dbprintf(_("checking disk %s\n"), qdisk);
537 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
538 if (dle->device[0] == '/' && dle->device[1] == '/') {
540 _("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
546 if (strcmp(dle->program, "GNUTAR")==0) {
547 if(dle->device[0] == '/' && dle->device[1] == '/') {
549 int nullfd, checkerr;
563 parsesharename(dle->device, &share, &subdir);
566 _("cannot parse for share/subdir disk entry %s"),
570 if ((subdir) && (SAMBA_VERSION < 2)) {
571 err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
575 if ((user_and_password = findpass(share, &domain)) == NULL) {
576 err = vstrallocf(_("cannot find password for %s"),
580 lpass = strlen(user_and_password);
581 if ((pwtext = strchr(user_and_password, '%')) == NULL) {
583 _("password field not \'user%%pass\' for %s"),
588 pwtext_len = (size_t)strlen(pwtext);
590 if ((device = makesharename(share, 0)) == NULL) {
591 err = vstrallocf(_("cannot make share name of %s"), share);
595 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
596 err = vstrallocf(_("Cannot access /dev/null : %s"),
601 if (pwtext_len > 0) {
602 pw_fd_env = "PASSWD_FD";
604 pw_fd_env = "dummy_PASSWD_FD";
606 checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, 0,
607 &nullfd, &nullfd, &checkerr,
608 pw_fd_env, &passwdfd,
611 *user_and_password ? "-U" : skip_argument,
612 *user_and_password ? user_and_password
615 domain ? "-W" : skip_argument,
616 domain ? domain : skip_argument,
617 #if SAMBA_VERSION >= 2
618 subdir ? "-D" : skip_argument,
619 subdir ? subdir : skip_argument,
627 if ((pwtext_len > 0) &&
628 full_write(passwdfd, pwtext, pwtext_len) < pwtext_len) {
629 err = vstrallocf(_("password write failed: %s: %s"),
630 dle->device, strerror(errno));
635 memset(user_and_password, '\0', (size_t)lpass);
636 amfree(user_and_password);
638 ferr = fdopen(checkerr, "r");
640 g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
641 error(_("Can't fdopen: %s"), strerror(errno));
646 for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
649 strappend(extra_info, sep);
650 strappend(extra_info, line);
652 if(strstr(line, "ERRDOS") != NULL) {
660 while ((wpid = wait(&retstat)) != -1) {
661 if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
662 char *exitstr = str_exit_status("smbclient", retstat);
664 strappend(err, exitstr);
671 if (errdos != 0 || rc != 0) {
673 err = newvstrallocf(err,
674 _("samba access error: %s: %s %s"),
675 dle->device, extra_info, err);
678 err = newvstrallocf(err,
679 _("samba access error: %s: %s"),
685 _("This client is not configured for samba: %s"),
692 device = amname_to_dirname(dle->device);
693 } else if (strcmp(dle->program, "DUMP") == 0) {
694 if(dle->device[0] == '/' && dle->device[1] == '/') {
696 _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
702 if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
708 device = amname_to_dirname(dle->device);
714 device = amname_to_devname(dle->device);
723 if (dle->program_is_application_api) {
724 pid_t application_api_pid;
725 backup_support_option_t *bsu;
729 bsu = backup_support_option(dle->program, g_options, dle->disk,
730 dle->device, &errarray);
735 for (i=0; i < errarray->len; i++) {
736 line = g_ptr_array_index(errarray, i);
737 fprintf(stdout, _("ERROR Application '%s': %s\n"),
741 err = vstrallocf(_("Application '%s': can't run support command"),
746 if (dle->data_path == DATA_PATH_AMANDA &&
747 (bsu->data_path_set & DATA_PATH_AMANDA)==0) {
748 g_printf("ERROR application %s doesn't support amanda data-path\n",
751 if (dle->data_path == DATA_PATH_DIRECTTCP &&
752 (bsu->data_path_set & DATA_PATH_DIRECTTCP)==0) {
753 g_printf("ERROR application %s doesn't support directtcp data-path\n",
756 if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE &&
758 g_printf("ERROR application %s doesn't support calcsize estimate\n",
761 if (dle->include_file && dle->include_file->nb_element > 0 &&
762 !bsu->include_file) {
763 g_printf("ERROR application %s doesn't support include-file\n",
766 if (dle->include_list && dle->include_list->nb_element > 0 &&
767 !bsu->include_list) {
768 g_printf("ERROR application %s doesn't support include-list\n",
771 if (dle->include_optional && !bsu->include_optional) {
772 g_printf("ERROR application %s doesn't support optional include\n",
775 if (dle->exclude_file && dle->exclude_file->nb_element > 0 &&
776 !bsu->exclude_file) {
777 g_printf("ERROR application %s doesn't support exclude-file\n",
780 if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
781 !bsu->exclude_list) {
782 g_printf("ERROR application %s doesn't support exclude-list\n",
785 if (dle->exclude_optional && !bsu->exclude_optional) {
786 g_printf("ERROR application %s doesn't support optional exclude\n",
789 fflush(stdout);fflush(stderr);
791 if (pipe(app_err) < 0) {
792 err = vstrallocf(_("Application '%s': can't create pipe"),
797 switch (application_api_pid = fork()) {
799 err = vstrallocf(_("fork failed: %s"), strerror(errno));
804 GPtrArray *argv_ptr = g_ptr_array_new();
806 char *cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
815 g_ptr_array_add(argv_ptr, stralloc(dle->program));
816 g_ptr_array_add(argv_ptr, stralloc("selfcheck"));
817 if (bsu->message_line == 1) {
818 g_ptr_array_add(argv_ptr, stralloc("--message"));
819 g_ptr_array_add(argv_ptr, stralloc("line"));
821 if (g_options->config != NULL && bsu->config == 1) {
822 g_ptr_array_add(argv_ptr, stralloc("--config"));
823 g_ptr_array_add(argv_ptr, stralloc(g_options->config));
825 if (g_options->hostname != NULL && bsu->host == 1) {
826 g_ptr_array_add(argv_ptr, stralloc("--host"));
827 g_ptr_array_add(argv_ptr, stralloc(g_options->hostname));
829 if (dle->disk != NULL && bsu->disk == 1) {
830 g_ptr_array_add(argv_ptr, stralloc("--disk"));
831 g_ptr_array_add(argv_ptr, stralloc(dle->disk));
834 g_ptr_array_add(argv_ptr, stralloc("--device"));
835 g_ptr_array_add(argv_ptr, stralloc(dle->device));
837 if (dle->create_index && bsu->index_line == 1) {
838 g_ptr_array_add(argv_ptr, stralloc("--index"));
839 g_ptr_array_add(argv_ptr, stralloc("line"));
841 if (dle->record && bsu->record == 1) {
842 g_ptr_array_add(argv_ptr, stralloc("--record"));
845 for (el = dle->estimatelist; el != NULL; el=el->next) {
846 estimate_t estimate = (estimate_t)GPOINTER_TO_INT(el->data);
847 if (estimate == ES_CALCSIZE && bsu->calcsize == 1) {
848 g_ptr_array_add(argv_ptr, stralloc("--calcsize"));
851 application_property_add_to_argv(argv_ptr, dle, bsu,
852 g_options->features);
854 for (scriptlist = dle->scriptlist; scriptlist != NULL;
855 scriptlist = scriptlist->next) {
856 script = (script_t *)scriptlist->data;
857 if (script->result && script->result->proplist) {
858 property_add_to_argv(argv_ptr,
859 script->result->proplist);
863 g_ptr_array_add(argv_ptr, NULL);
865 cmdline = stralloc(cmd);
866 for (i = 0; i < argv_ptr->len-1; i++) {
867 char *quoted = quote_string(
868 (char *)g_ptr_array_index(argv_ptr,i));
869 cmdline = vstrextend(&cmdline, " ", quoted, NULL);
872 dbprintf(_("Spawning \"%s\" in pipeline\n"), cmdline);
876 execve(cmd, (char **)argv_ptr->pdata, safe_env());
877 g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
880 default: /* parent */
887 app_stderr = fdopen(app_err[0], "r");
888 while((line = agets(app_stderr)) != NULL) {
889 if (strlen(line) > 0) {
890 fprintf(stdout, "ERROR Application '%s': %s\n",
892 dbprintf("ERROR %s\n", line);
897 if (waitpid(application_api_pid, &status, 0) < 0) {
898 err = vstrallocf(_("waitpid failed: %s"),
901 } else if (!WIFEXITED(status)) {
902 err = vstrallocf(_("Application '%s': exited with signal %d"),
903 dle->program, WTERMSIG(status));
905 } else if (WEXITSTATUS(status) != 0) {
906 err = vstrallocf(_("Application '%s': exited with status %d"),
907 dle->program, WEXITSTATUS(status));
913 fflush(stdout);fflush(stderr);
921 qdevice = quote_string(device);
922 dbprintf(_("device %s\n"), qdevice);
924 /* skip accessability test if this is an AFS entry */
925 if(strncmp_const(device, "afs:") != 0) {
926 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
927 access_result = open(device, O_RDONLY);
928 access_type = "open";
930 access_result = access(device, amode);
931 access_type = "access";
933 if(access_result == -1) {
934 err = vstrallocf(_("Could not %s %s (%s): %s"),
935 access_type, qdevice, qdisk, strerror(errno));
937 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
938 aclose(access_result);
946 qdevice = quote_string(device);
950 if(user_and_password) {
951 memset(user_and_password, '\0', (size_t)lpass);
952 amfree(user_and_password);
957 g_printf(_("ERROR %s\n"), err);
958 dbprintf(_("%s\n"), err);
962 g_printf("OK %s\n", qdisk);
963 dbprintf(_("disk %s OK\n"), qdisk);
966 g_printf("OK %s\n", qamdevice);
967 dbprintf(_("amdevice %s OK\n"), qamdevice);
970 g_printf("OK %s\n", qdevice);
971 dbprintf(_("device %s OK\n"), qdevice);
975 dbprintf(_("extra info: %s\n"), extra_info);
983 /* XXX perhaps do something with level: read dumpdates and sanity check */
992 char *gnutar_list_dir;
993 int need_amandates = 0;
997 cmd = vstralloc(amlibexecdir, "/", "runtar", NULL);
998 check_file(cmd,X_OK);
1005 cmd = vstralloc(amlibexecdir, "/", "rundump", NULL);
1006 check_file(cmd,X_OK);
1013 check_file(DUMP, X_OK);
1015 g_printf(_("ERROR [DUMP program not available]\n"));
1019 if( need_restore ) {
1021 check_file(RESTORE, X_OK);
1023 g_printf(_("ERROR [RESTORE program not available]\n"));
1029 check_file(VDUMP, X_OK);
1031 g_printf(_("ERROR [VDUMP program not available]\n"));
1035 if ( need_vrestore ) {
1037 check_file(VRESTORE, X_OK);
1039 g_printf(_("ERROR [VRESTORE program not available]\n"));
1043 if( need_xfsdump ) {
1045 check_file(XFSDUMP, F_OK);
1047 g_printf(_("ERROR [XFSDUMP program not available]\n"));
1051 if( need_xfsrestore ) {
1053 check_file(XFSRESTORE, X_OK);
1055 g_printf(_("ERROR [XFSRESTORE program not available]\n"));
1061 check_file(VXDUMP, X_OK);
1063 g_printf(_("ERROR [VXDUMP program not available]\n"));
1067 if( need_vxrestore ) {
1069 check_file(VXRESTORE, X_OK);
1071 g_printf(_("ERROR [VXRESTORE program not available]\n"));
1077 check_file(GNUTAR, X_OK);
1079 g_printf(_("ERROR [GNUTAR program not available]\n"));
1081 gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
1082 if (strlen(gnutar_list_dir) == 0)
1083 gnutar_list_dir = NULL;
1084 if (gnutar_list_dir) {
1085 /* make sure our listed-incremental dir is ready */
1086 check_dir(gnutar_list_dir, R_OK|W_OK);
1088 /* no listed-incremental dir, so check that amandates is ready */
1093 if( need_calcsize ) {
1096 cmd = vstralloc(amlibexecdir, "/", "calcsize", NULL);
1098 check_file(cmd, X_OK);
1102 /* calcsize uses amandates */
1106 if (need_amandates) {
1107 char *amandates_file;
1108 amandates_file = getconf_str(CNF_AMANDATES);
1109 check_file(amandates_file, R_OK|W_OK);
1114 check_file(SAMBA_CLIENT, X_OK);
1116 g_printf(_("ERROR [SMBCLIENT program not available]\n"));
1118 testfd = open("/etc/amandapass", R_OK);
1120 if(fstat(testfd, &buf) == 0) {
1121 if ((buf.st_mode & 0x7) != 0) {
1122 g_printf(_("ERROR [/etc/amandapass is world readable!]\n"));
1124 g_printf(_("OK [/etc/amandapass is readable, but not by all]\n"));
1127 g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"),
1132 g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"),
1137 if (need_compress_path )
1138 check_file(COMPRESS_PATH, X_OK);
1140 if (need_dump || need_xfsdump ) {
1141 if (check_file_exist("/etc/dumpdates")) {
1142 check_file("/etc/dumpdates",
1151 if (access("/etc", R_OK|W_OK) == -1) {
1152 g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
1159 if (check_file_exist("/etc/vdumpdates")) {
1160 check_file("/etc/vdumpdates", F_OK);
1164 if (need_global_check) {
1165 check_access("/dev/null", R_OK|W_OK);
1166 check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
1168 #ifdef AMANDA_DBGDIR
1169 check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
1172 check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
1181 struct fs_usage fsusage;
1182 char *quoted = quote_string(dir);
1185 if(get_fs_usage(dir, NULL, &fsusage) == -1) {
1186 g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
1191 /* do the division first to avoid potential integer overflow */
1192 kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;
1194 if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
1195 g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
1197 } else if (kb_avail < kbytes) {
1198 g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
1200 (long long)kb_avail);
1202 g_printf(_("OK %s has more than %lldKB available.\n"),
1203 quoted, (long long)kbytes);
1212 struct stat stat_buf;
1214 if (stat(filename, &stat_buf) != 0) {
1215 if(errno == ENOENT) {
1223 print_platform(void)
1225 struct stat stat_buf;
1227 char *distro = NULL;
1228 char *platform = NULL;
1230 GPtrArray *argv_ptr;
1232 if (stat("/etc/lsb-release", &stat_buf) == 0) {
1233 FILE *release = fopen("/etc/lsb-release", "r");
1236 while (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);