X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=client-src%2Fselfcheck.c;h=8787a8245f40c0a055d6e7f8197662d10e4e8ad5;hb=94a044f90357edefa6f4ae9f0b1d5885b0e34aee;hp=4f08d1ef873583ff413834a3c1398465b8fec963;hpb=2df780bff19c457b0debb7adc29972a0bc2a5dc2;p=debian%2Famanda diff --git a/client-src/selfcheck.c b/client-src/selfcheck.c index 4f08d1e..8787a82 100644 --- a/client-src/selfcheck.c +++ b/client-src/selfcheck.c @@ -25,21 +25,23 @@ * University of Maryland at College Park */ /* - * $Id: selfcheck.c,v 1.40.2.3.4.4.2.22.2.3 2005/09/20 21:31:52 jrjackson Exp $ + * $Id: selfcheck.c,v 1.95 2006/08/29 11:21:00 martinea Exp $ * * do self-check and send back any error messages */ #include "amanda.h" -#include "clock.h" -#include "statfs.h" +#include "fsusage.h" #include "version.h" #include "getfsent.h" #include "amandates.h" +#include "clock.h" #include "util.h" #include "pipespawn.h" #include "amfeatures.h" #include "client_util.h" +#include "conffile.h" +#include "amandad.h" #ifdef SAMBA_CLIENT #include "findpass.h" @@ -59,64 +61,89 @@ int need_runtar=0; int need_gnutar=0; int need_compress_path=0; int need_calcsize=0; +int program_is_backup_api=0; +static char *amandad_auth = NULL; static am_feature_t *our_features = NULL; static char *our_feature_string = NULL; static g_option_t *g_options = NULL; /* local functions */ -int main P((int argc, char **argv)); - -static void check_options P((char *program, char *calcprog, char *disk, char *device, option_t *options)); -static void check_disk P((char *program, char *calcprog, char *disk, char *amdevice, int level)); -static void check_overall P((void)); -static void check_access P((char *filename, int mode)); -static void check_file P((char *filename, int mode)); -static void check_dir P((char *dirname, int mode)); -static void check_suid P((char *filename)); -static void check_space P((char *dir, long kbytes)); - -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv); + +static void check_options(char *program, char *calcprog, char *disk, char *amdevice, option_t *options); +static void check_disk(char *program, char *calcprog, char *disk, char *amdevice, int level, option_t *options); +static void check_overall(void); +static void check_access(char *filename, int mode); +static int check_file_exist(char *filename); +static void check_file(char *filename, int mode); +static void check_dir(char *dirname, int mode); +static void check_suid(char *filename); +static void check_space(char *dir, off_t kbytes); + +int +main( + int argc, + char ** argv) { int level; char *line = NULL; char *program = NULL; char *calcprog = NULL; char *disk = NULL; - char *device = NULL; + char *qdisk = NULL; + char *amdevice = NULL; + char *qamdevice = NULL; char *optstr = NULL; char *err_extra = NULL; char *s, *fp; - int ch; - unsigned long malloc_hist_1, malloc_size_1; - unsigned long malloc_hist_2, malloc_size_2; option_t *options; + int ch; /* initialize */ + /* + * Configure program for internationalization: + * 1) Only set the message locale for now. + * 2) Set textdomain for all amanda related programs to "amanda" + * We don't want to be forced to support dozens of message catalogs. + */ + setlocale(LC_MESSAGES, "C"); + textdomain("amanda"); + safe_fd(-1, 0); safe_cd(); set_pname("selfcheck"); - malloc_size_1 = malloc_inuse(&malloc_hist_1); + /* Don't die when child closes pipe */ + signal(SIGPIPE, SIG_IGN); erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG); - dbopen(); + dbopen(DBG_SUBDIR_CLIENT); startclock(); - dbprintf(("%s: version %s\n", argv[0], version())); + dbprintf(_("version %s\n"), version()); + + if(argc > 2 && strcmp(argv[1], "amandad") == 0) { + amandad_auth = stralloc(argv[2]); + } + + config_init(CONFIG_INIT_CLIENT, NULL); + + check_running_as(RUNNING_AS_CLIENT_LOGIN); our_features = am_init_feature_set(); our_feature_string = am_feature_to_string(our_features); /* handle all service requests */ + /*@ignore@*/ for(; (line = agets(stdin)) != NULL; free(line)) { -#define sc "OPTIONS " - if(strncmp(line, sc, sizeof(sc)-1) == 0) { -#undef sc + /*@end@*/ + if (line[0] == '\0') + continue; + + if(strncmp_const(line, "OPTIONS ") == 0) { g_options = parse_g_options(line+8, 1); if(!g_options->hostname) { g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1); @@ -124,15 +151,24 @@ char **argv; g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0'; } - printf("OPTIONS "); + g_printf("OPTIONS "); if(am_has_feature(g_options->features, fe_rep_options_features)) { - printf("features=%s;", our_feature_string); + g_printf("features=%s;", our_feature_string); } if(am_has_feature(g_options->features, fe_rep_options_hostname)) { - printf("hostname=%s;", g_options->hostname); + g_printf("hostname=%s;", g_options->hostname); } - printf("\n"); + g_printf("\n"); fflush(stdout); + + if (g_options->config) { + /* overlay this configuration on the existing (nameless) configuration */ + config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY, + g_options->config); + + dbrename(config_name, DBG_SUBDIR_CLIENT); + } + continue; } @@ -147,7 +183,19 @@ char **argv; skip_non_whitespace(s, ch); s[-1] = '\0'; /* terminate the program name */ - if(strncmp(program, "CALCSIZE", 8) == 0) { + program_is_backup_api = 0; + if(strcmp(program,"BACKUP")==0) { + program_is_backup_api = 1; + skip_whitespace(s, ch); /* find dumper name */ + if (ch == '\0') { + goto err; /* no program */ + } + program = s - 1; + skip_non_whitespace(s, ch); + s[-1] = '\0'; /* terminate the program name */ + } + + if(strncmp_const(program, "CALCSIZE") == 0) { skip_whitespace(s, ch); /* find program name */ if (ch == '\0') { goto err; /* no program */ @@ -164,9 +212,10 @@ char **argv; if (ch == '\0') { goto err; /* no disk */ } - disk = s - 1; - skip_non_whitespace(s, ch); + qdisk = s - 1; + skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the disk name */ + disk = unquote_string(qdisk); skip_whitespace(s, ch); /* find the device or level */ if (ch == '\0') { @@ -174,13 +223,14 @@ char **argv; } if(!isdigit((int)s[-1])) { fp = s - 1; - skip_non_whitespace(s, ch); - s[-1] = '\0'; /* terminate the device */ - device = stralloc(fp); + skip_quoted_string(s, ch); + s[-1] = '\0'; /* terminate the device */ + qamdevice = stralloc(fp); + amdevice = unquote_string(qamdevice); skip_whitespace(s, ch); /* find level number */ } else { - device = stralloc(disk); + amdevice = stralloc(disk); } /* find level number */ @@ -190,25 +240,24 @@ char **argv; skip_integer(s, ch); skip_whitespace(s, ch); -#define sc "OPTIONS " - if (ch && strncmp (s - 1, sc, sizeof(sc)-1) == 0) { - s += sizeof(sc)-1; - ch = s[-1]; -#undef sc + if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) { skip_whitespace(s, ch); /* find the option string */ if(ch == '\0') { goto err; /* bad options string */ } optstr = s - 1; - skip_non_whitespace(s, ch); + skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the options */ - options = parse_options(optstr, disk, device, g_options->features, 1); - check_options(program, calcprog, disk, device, options); - check_disk(program, calcprog, disk, device, level); + options = parse_options(optstr, disk, amdevice, g_options->features, 1); + /*@ignore@*/ + check_options(program, calcprog, disk, amdevice, options); + check_disk(program, calcprog, disk, amdevice, level, options); + /*@end@*/ free_sl(options->exclude_file); free_sl(options->exclude_list); free_sl(options->include_file); free_sl(options->include_list); + amfree(options->auth); amfree(options->str); amfree(options); } else if (ch == '\0') { @@ -227,11 +276,20 @@ char **argv; need_gnutar=1; need_compress_path=1; need_calcsize=1; - check_disk(program, calcprog, disk, device, level); + /*@ignore@*/ + check_disk(program, calcprog, disk, amdevice, level, NULL); + /*@end@*/ } else { goto err; /* bad syntax */ } - amfree(device); + amfree(disk); + amfree(qamdevice); + amfree(amdevice); + } + if (g_options == NULL) { + printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n")); + error(_("Missing OPTIONS line in selfcheck input\n")); + /*NOTREACHED*/ } check_overall(); @@ -240,40 +298,28 @@ char **argv; amfree(our_feature_string); am_release_feature_set(our_features); our_features = NULL; - am_release_feature_set(g_options->features); - g_options->features = NULL; - amfree(g_options->str); - amfree(g_options->hostname); - amfree(g_options); - - malloc_size_2 = malloc_inuse(&malloc_hist_2); - - if(malloc_size_1 != malloc_size_2) { -#if defined(USE_DBMALLOC) - extern int dbfd; - - malloc_list(dbfd(), malloc_hist_1, malloc_hist_2); -#endif - } + free_g_options(g_options); dbclose(); return 0; err: - printf("ERROR [BOGUS REQUEST PACKET]\n"); - dbprintf(("%s: REQ packet is bogus%s%s\n", - debug_prefix_time(NULL), + g_printf(_("ERROR [BOGUS REQUEST PACKET]\n")); + dbprintf(_("REQ packet is bogus%s%s\n"), err_extra ? ": " : "", - err_extra ? err_extra : "")); + err_extra ? err_extra : ""); dbclose(); return 1; } static void -check_options(program, calcprog, disk, device, options) - char *program, *calcprog, *disk, *device; - option_t *options; +check_options( + char * program, + char * calcprog, + char * disk, + char * amdevice, + option_t * options) { char *myprogram = program; @@ -288,32 +334,36 @@ check_options(program, calcprog, disk, device, options) if(options->include_file) nb_include += options->include_file->nb_element; if(options->include_list) nb_include += options->include_list->nb_element; - if(nb_exclude > 0) file_exclude = build_exclude(disk, device, options, 1); - if(nb_include > 0) file_include = build_include(disk, device, options, 1); + if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1); + if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1); amfree(file_exclude); amfree(file_include); need_calcsize=1; - myprogram = calcprog; + if (calcprog == NULL) { + g_printf(_("ERROR [no program name for calcsize]\n")); + } else { + myprogram = calcprog; + } } if(strcmp(myprogram,"GNUTAR") == 0) { need_gnutar=1; - if(disk[0] == '/' && disk[1] == '/') { + if(amdevice[0] == '/' && amdevice[1] == '/') { if(options->exclude_file && options->exclude_file->nb_element > 1) { - printf("ERROR [samba support only one exclude file]\n"); + g_printf(_("ERROR [samba support only one exclude file]\n")); } if(options->exclude_list && options->exclude_list->nb_element > 0 && options->exclude_optional==0) { - printf("ERROR [samba does not support exclude list]\n"); + g_printf(_("ERROR [samba does not support exclude list]\n")); } if(options->include_file && options->include_file->nb_element > 0) { - printf("ERROR [samba does not support include file]\n"); + g_printf(_("ERROR [samba does not support include file]\n")); } if(options->include_list && options->include_list->nb_element > 0 && options->include_optional==0) { - printf("ERROR [samba does not support include list]\n"); + g_printf(_("ERROR [samba does not support include list]\n")); } need_samba=1; } @@ -328,8 +378,8 @@ check_options(program, calcprog, disk, device, options) if(options->include_file) nb_include += options->include_file->nb_element; if(options->include_list) nb_include += options->include_list->nb_element; - if(nb_exclude > 0) file_exclude = build_exclude(disk, device, options, 1); - if(nb_include > 0) file_include = build_include(disk, device, options, 1); + if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1); + if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1); amfree(file_exclude); amfree(file_include); @@ -340,16 +390,16 @@ check_options(program, calcprog, disk, device, options) if(strcmp(myprogram,"DUMP") == 0) { if(options->exclude_file && options->exclude_file->nb_element > 0) { - printf("ERROR [DUMP does not support exclude file]\n"); + g_printf(_("ERROR [DUMP does not support exclude file]\n")); } if(options->exclude_list && options->exclude_list->nb_element > 0) { - printf("ERROR [DUMP does not support exclude list]\n"); + g_printf(_("ERROR [DUMP does not support exclude list]\n")); } if(options->include_file && options->include_file->nb_element > 0) { - printf("ERROR [DUMP does not support include file]\n"); + g_printf(_("ERROR [DUMP does not support include file]\n")); } if(options->include_list && options->include_list->nb_element > 0) { - printf("ERROR [DUMP does not support include list]\n"); + g_printf(_("ERROR [DUMP does not support include list]\n")); } #ifdef USE_RUNDUMP need_rundump=1; @@ -357,7 +407,7 @@ check_options(program, calcprog, disk, device, options) #ifndef AIX_BACKUP #ifdef VDUMP #ifdef DUMP - if (strcmp(amname_to_fstype(disk), "advfs") == 0) + if (strcmp(amname_to_fstype(amdevice), "advfs") == 0) #else if (1) #endif @@ -371,7 +421,7 @@ check_options(program, calcprog, disk, device, options) #endif /* VDUMP */ #ifdef XFSDUMP #ifdef DUMP - if (strcmp(amname_to_fstype(disk), "xfs") == 0) + if (strcmp(amname_to_fstype(amdevice), "xfs") == 0) #else if (1) #endif @@ -385,7 +435,7 @@ check_options(program, calcprog, disk, device, options) #endif /* XFSDUMP */ #ifdef VXDUMP #ifdef DUMP - if (strcmp(amname_to_fstype(disk), "vxfs") == 0) + if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0) #else if (1) #endif @@ -408,50 +458,80 @@ check_options(program, calcprog, disk, device, options) need_restore=1; #endif } - if(options->compress == COMPR_BEST || options->compress == COMPR_FAST) + if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST) + || (options->compress == COMP_CUST)) { need_compress_path=1; + } + if(options->auth && amandad_auth) { + if(strcasecmp(options->auth, amandad_auth) != 0) { + g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"), + amandad_auth, options->auth); + if(strcmp(options->auth, "ssh") == 0) { + g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys " + "should be \"--auth=ssh\", or use another auth " + " for the DLE]\n")); + } + else { + g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration " + " must be the same as the DLE]\n")); + } + } + } } -static void check_disk(program, calcprog, disk, amdevice, level) -char *program, *calcprog, *disk, *amdevice; -int level; +static void +check_disk( + char * program, + char * calcprog, + char * disk, + char * amdevice, + int level, + option_t *options) { - char *device = NULL; + char *device = stralloc("nodevice"); char *err = NULL; - char *user_and_password = NULL, *domain = NULL; + char *user_and_password = NULL; + char *domain = NULL; char *share = NULL, *subdir = NULL; - int lpass = 0; + size_t lpass = 0; int amode; int access_result; char *access_type; char *extra_info = NULL; char *myprogram = program; + char *qdisk = quote_string(disk); + char *qamdevice = quote_string(amdevice); + char *qdevice = NULL; + FILE *toolin; + + (void)level; /* Quiet unused parameter warning */ + + dbprintf(_("checking disk %s\n"), qdisk); if(strcmp(myprogram,"CALCSIZE") == 0) { if(amdevice[0] == '/' && amdevice[1] == '/') { - err = vstralloc("Can't use CALCSIZE for samba estimate,", - " use CLIENT: ", - amdevice, - NULL); + err = vstrallocf(_("Can't use CALCSIZE for samba estimate, use CLIENT: %s"), + amdevice); + goto common_exit; + } + if (calcprog == NULL) { + err = _("no program for calcsize"); goto common_exit; } myprogram = calcprog; } - dbprintf(("%s: checking disk %s\n", debug_prefix_time(NULL), disk)); - - if (strcmp(myprogram, "GNUTAR") == 0) { + if (strcmp(myprogram, "GNUTAR")==0) { if(amdevice[0] == '/' && amdevice[1] == '/') { #ifdef SAMBA_CLIENT int nullfd, checkerr; int passwdfd; char *pwtext; - int pwtext_len; - int checkpid; + size_t pwtext_len; + pid_t checkpid; amwait_t retstat; - char number[NUM_STR_SIZE]; - int wpid; - int ret, sig, rc; + pid_t wpid; + int rc; char *line; char *sep; FILE *ferr; @@ -460,33 +540,36 @@ int level; parsesharename(amdevice, &share, &subdir); if (!share) { - err = stralloc2("cannot parse for share/subdir disk entry ", amdevice); + err = vstrallocf(_("cannot parse for share/subdir disk entry %s"), amdevice); goto common_exit; } if ((subdir) && (SAMBA_VERSION < 2)) { - err = vstralloc("subdirectory specified for share '", - amdevice, - "' but samba not v2 or better", - NULL); + err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"), + amdevice); goto common_exit; } if ((user_and_password = findpass(share, &domain)) == NULL) { - err = stralloc2("cannot find password for ", amdevice); + err = vstrallocf(_("cannot find password for %s"), amdevice); goto common_exit; } lpass = strlen(user_and_password); if ((pwtext = strchr(user_and_password, '%')) == NULL) { - err = stralloc2("password field not \'user%pass\' for ", amdevice); + err = vstrallocf(_("password field not \'user%%pass\' for %s"), amdevice); goto common_exit; } *pwtext++ = '\0'; - pwtext_len = strlen(pwtext); + pwtext_len = (size_t)strlen(pwtext); + amfree(device); if ((device = makesharename(share, 0)) == NULL) { - err = stralloc2("cannot make share name of ", share); + err = vstrallocf(_("cannot make share name of %s"), share); + goto common_exit; + } + + if ((nullfd = open("/dev/null", O_RDWR)) == -1) { + err = vstrallocf(_("Cannot access /dev/null : %s"), strerror(errno)); goto common_exit; } - nullfd = open("/dev/null", O_RDWR); if (pwtext_len > 0) { pw_fd_env = "PASSWD_FD"; } else { @@ -508,27 +591,31 @@ int level; #endif "-c", "quit", NULL); - if (domain) { - memset(domain, '\0', strlen(domain)); - amfree(domain); - } + amfree(domain); aclose(nullfd); - if (pwtext_len > 0 && fullwrite(passwdfd, pwtext, pwtext_len) < 0) { - err = vstralloc("password write failed: ", - amdevice, - ": ", - strerror(errno), - NULL); + /*@ignore@*/ + if ((pwtext_len > 0) + && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) { + err = vstrallocf(_("password write failed: %s: %s"), + amdevice, strerror(errno)); aclose(passwdfd); goto common_exit; } - memset(user_and_password, '\0', lpass); + /*@end@*/ + memset(user_and_password, '\0', (size_t)lpass); amfree(user_and_password); aclose(passwdfd); ferr = fdopen(checkerr, "r"); + if (!ferr) { + g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno)); + error(_("Can't fdopen: %s"), strerror(errno)); + /*NOTREACHED*/ + } sep = ""; errdos = 0; for(sep = ""; (line = agets(ferr)) != NULL; free(line)) { + if (line[0] == '\0') + continue; strappend(extra_info, sep); strappend(extra_info, line); sep = ": "; @@ -539,49 +626,42 @@ int level; afclose(ferr); checkerr = -1; rc = 0; + sep = ""; while ((wpid = wait(&retstat)) != -1) { - if (WIFSIGNALED(retstat)) { - ret = 0; - rc = sig = WTERMSIG(retstat); - } else { - sig = 0; - rc = ret = WEXITSTATUS(retstat); - } - if (rc != 0) { - strappend(err, sep); - if (ret == 0) { - strappend(err, "got signal "); - ret = sig; - } else { - strappend(err, "returned "); - } - ap_snprintf(number, sizeof(number), "%d", ret); - strappend(err, number); + if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) { + char *exitstr = str_exit_status("smbclient", retstat); + err = newvstralloc(err, err, sep, exitstr); + sep = "\n"; + amfree(exitstr); + + rc = 1; } } if (errdos != 0 || rc != 0) { - err = newvstralloc(err, - "samba access error: ", - amdevice, - ": ", - extra_info ? extra_info : "", - err, - NULL); - amfree(extra_info); + if (extra_info) { + err = newvstrallocf(err, + _("samba access error: %s: %s %s"), + amdevice, extra_info, err); + amfree(extra_info); + } else { + err = newvstrallocf(err, _("samba access error: %s: %s"), + amdevice, err); + } } #else - err = stralloc2("This client is not configured for samba: ", amdevice); + err = vstrallocf(_("This client is not configured for samba: %s"), + qdisk); #endif goto common_exit; } amode = F_OK; + amfree(device); device = amname_to_dirname(amdevice); - } else { + } else if (strcmp(myprogram, "DUMP") == 0) { if(amdevice[0] == '/' && amdevice[1] == '/') { - err = vstralloc("The DUMP program cannot handle samba shares,", - " use GNUTAR: ", - amdevice, - NULL); + err = vstrallocf( + _("The DUMP program cannot handle samba shares, use GNUTAR: %s"), + qdisk); goto common_exit; } #ifdef VDUMP /* { */ @@ -591,11 +671,13 @@ int level; if (1) #endif /* } */ { + amfree(device); device = amname_to_dirname(amdevice); amode = F_OK; } else #endif /* } */ { + amfree(device); device = amname_to_devname(amdevice); #ifdef USE_RUNDUMP amode = F_OK; @@ -604,11 +686,103 @@ int level; #endif } } + else { /* program_is_backup_api==1 */ + pid_t backup_api_pid; + int property_pipe[2]; + backup_support_option_t *bsu; + + bsu = backup_support_option(program, g_options, disk, amdevice); - dbprintf(("%s: device %s\n", debug_prefix_time(NULL), device)); + if (pipe(property_pipe) < 0) { + err = vstrallocf(_("pipe failed: %s"), strerror(errno)); + goto common_exit; + } + fflush(stdout);fflush(stderr); + + switch (backup_api_pid = fork()) { + case -1: + err = vstrallocf(_("fork failed: %s"), strerror(errno)); + goto common_exit; + + case 0: /* child */ + { + char *argvchild[14]; + char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL); + int j=0; + argvchild[j++] = program; + argvchild[j++] = "selfcheck"; + if (bsu->message_line == 1) { + argvchild[j++] = "--message"; + argvchild[j++] = "line"; + } + if (g_options->config != NULL && bsu->config == 1) { + argvchild[j++] = "--config"; + argvchild[j++] = g_options->config; + } + if (g_options->hostname != NULL && bsu->host == 1) { + argvchild[j++] = "--host"; + argvchild[j++] = g_options->hostname; + } + if (disk != NULL && bsu->disk == 1) { + argvchild[j++] = "--disk"; + argvchild[j++] = disk; + } + argvchild[j++] = "--device"; + argvchild[j++] = amdevice; + if(options && options->createindex && bsu->index_line == 1) { + argvchild[j++] = "--index"; + argvchild[j++] = "line"; + } + if (!options->no_record && bsu->record == 1) { + argvchild[j++] = "--record"; + } + argvchild[j++] = NULL; + dup2(property_pipe[0], 0); + aclose(property_pipe[1]); + safe_fd(-1, 0); + execve(cmd,argvchild,safe_env()); + g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno)); + exit(127); + } + default: /* parent */ + { + int status; + aclose(property_pipe[0]); + toolin = fdopen(property_pipe[1],"w"); + if (!toolin) { + err = vstrallocf(_("Can't fdopen: %s"), strerror(errno)); + goto common_exit; + } + output_tool_property(toolin, options); + fflush(toolin); + fclose(toolin); + if (waitpid(backup_api_pid, &status, 0) < 0) { + if (!WIFEXITED(status)) { + err = vstrallocf(_("Tool exited with signal %d"), + WTERMSIG(status)); + } else if (WEXITSTATUS(status) != 0) { + err = vstrallocf(_("Tool exited with status %d"), + WEXITSTATUS(status)); + } else { + err = vstrallocf(_("waitpid returned negative value")); + } + goto common_exit; + } + } + } + amfree(bsu); + fflush(stdout);fflush(stderr); + amfree(device); + amfree(qamdevice); + amfree(qdisk); + return; + } + + qdevice = quote_string(device); + dbprintf(_("device %s\n"), qdevice); /* skip accessability test if this is an AFS entry */ - if(strncmp(device, "afs:", 4) != 0) { + if(strncmp_const(device, "afs:") != 0) { #ifdef CHECK_FOR_ACCESS_WITH_OPEN access_result = open(device, O_RDONLY); access_type = "open"; @@ -617,8 +791,8 @@ int level; access_type = "access"; #endif if(access_result == -1) { - err = vstralloc("could not ", access_type, " ", device, - " (", disk, "): ", strerror(errno), NULL); + err = vstrallocf(_("Could not access %s (%s): %s"), + qdevice, qdisk, strerror(errno)); } #ifdef CHECK_FOR_ACCESS_WITH_OPEN aclose(access_result); @@ -630,45 +804,47 @@ common_exit: amfree(share); amfree(subdir); if(user_and_password) { - memset(user_and_password, '\0', lpass); + memset(user_and_password, '\0', (size_t)lpass); amfree(user_and_password); } - if(domain) { - memset(domain, '\0', strlen(domain)); - amfree(domain); - } + amfree(domain); if(err) { - printf("ERROR [%s]\n", err); - dbprintf(("%s: %s\n", debug_prefix_time(NULL), err)); + g_printf(_("ERROR [%s]\n"), err); + dbprintf(_("%s\n"), err); amfree(err); } else { - printf("OK %s\n", disk); - dbprintf(("%s: disk \"%s\" OK\n", debug_prefix_time(NULL), disk)); - printf("OK %s\n", amdevice); - dbprintf(("%s: amdevice \"%s\" OK\n", - debug_prefix_time(NULL), amdevice)); - printf("OK %s\n", device); - dbprintf(("%s: device \"%s\" OK\n", debug_prefix_time(NULL), device)); + g_printf("OK %s\n", qdisk); + dbprintf(_("disk %s OK\n"), qdisk); + g_printf("OK %s\n", qamdevice); + dbprintf(_("amdevice %s OK\n"), qamdevice); + g_printf("OK %s\n", qdevice); + dbprintf(_("device %s OK\n"), qdevice); } if(extra_info) { - dbprintf(("%s: extra info: %s\n", debug_prefix_time(NULL), extra_info)); + dbprintf(_("extra info: %s\n"), extra_info); amfree(extra_info); } + amfree(qdisk); + amfree(qdevice); + amfree(qamdevice); amfree(device); /* XXX perhaps do something with level: read dumpdates and sanity check */ } -static void check_overall() +static void +check_overall(void) { char *cmd; struct stat buf; int testfd; + char *gnutar_list_dir; + int need_amandates = 0; if( need_runtar ) { - cmd = vstralloc(libexecdir, "/", "runtar", versionsuffix(), NULL); + cmd = vstralloc(amlibexecdir, "/", "runtar", versionsuffix(), NULL); check_file(cmd,X_OK); check_suid(cmd); amfree(cmd); @@ -676,7 +852,7 @@ static void check_overall() if( need_rundump ) { - cmd = vstralloc(libexecdir, "/", "rundump", versionsuffix(), NULL); + cmd = vstralloc(amlibexecdir, "/", "rundump", versionsuffix(), NULL); check_file(cmd,X_OK); check_suid(cmd); amfree(cmd); @@ -686,7 +862,7 @@ static void check_overall() #ifdef DUMP check_file(DUMP, X_OK); #else - printf("ERROR [DUMP program not available]\n"); + g_printf(_("ERROR [DUMP program not available]\n")); #endif } @@ -694,7 +870,7 @@ static void check_overall() #ifdef RESTORE check_file(RESTORE, X_OK); #else - printf("ERROR [RESTORE program not available]\n"); + g_printf(_("ERROR [RESTORE program not available]\n")); #endif } @@ -702,7 +878,7 @@ static void check_overall() #ifdef VDUMP check_file(VDUMP, X_OK); #else - printf("ERROR [VDUMP program not available]\n"); + g_printf(_("ERROR [VDUMP program not available]\n")); #endif } @@ -710,7 +886,7 @@ static void check_overall() #ifdef VRESTORE check_file(VRESTORE, X_OK); #else - printf("ERROR [VRESTORE program not available]\n"); + g_printf(_("ERROR [VRESTORE program not available]\n")); #endif } @@ -718,7 +894,7 @@ static void check_overall() #ifdef XFSDUMP check_file(XFSDUMP, F_OK); #else - printf("ERROR [XFSDUMP program not available]\n"); + g_printf(_("ERROR [XFSDUMP program not available]\n")); #endif } @@ -726,7 +902,7 @@ static void check_overall() #ifdef XFSRESTORE check_file(XFSRESTORE, X_OK); #else - printf("ERROR [XFSRESTORE program not available]\n"); + g_printf(_("ERROR [XFSRESTORE program not available]\n")); #endif } @@ -734,7 +910,7 @@ static void check_overall() #ifdef VXDUMP check_file(VXDUMP, X_OK); #else - printf("ERROR [VXDUMP program not available]\n"); + g_printf(_("ERROR [VXDUMP program not available]\n")); #endif } @@ -742,7 +918,7 @@ static void check_overall() #ifdef VXRESTORE check_file(VXRESTORE, X_OK); #else - printf("ERROR [VXRESTORE program not available]\n"); + g_printf(_("ERROR [VXRESTORE program not available]\n")); #endif } @@ -750,20 +926,25 @@ static void check_overall() #ifdef GNUTAR check_file(GNUTAR, X_OK); #else - printf("ERROR [GNUTAR program not available]\n"); -#endif -#ifdef AMANDATES_FILE - check_file(AMANDATES_FILE, R_OK|W_OK); -#endif -#ifdef GNUTAR_LISTED_INCREMENTAL_DIR - check_dir(GNUTAR_LISTED_INCREMENTAL_DIR,R_OK|W_OK); + g_printf(_("ERROR [GNUTAR program not available]\n")); #endif + need_amandates = 1; + gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR); + if (strlen(gnutar_list_dir) == 0) + gnutar_list_dir = NULL; + if (gnutar_list_dir) + check_dir(gnutar_list_dir, R_OK|W_OK); } + if (need_amandates) { + char *amandates_file; + amandates_file = getconf_str(CNF_AMANDATES); + check_file(amandates_file, R_OK|W_OK); + } if( need_calcsize ) { char *cmd; - cmd = vstralloc(libexecdir, "/", "calcsize", versionsuffix(), NULL); + cmd = vstralloc(amlibexecdir, "/", "calcsize", versionsuffix(), NULL); check_file(cmd, X_OK); @@ -774,74 +955,103 @@ static void check_overall() #ifdef SAMBA_CLIENT check_file(SAMBA_CLIENT, X_OK); #else - printf("ERROR [SMBCLIENT program not available]\n"); + g_printf(_("ERROR [SMBCLIENT program not available]\n")); #endif testfd = open("/etc/amandapass", R_OK); if (testfd >= 0) { if(fstat(testfd, &buf) == 0) { if ((buf.st_mode & 0x7) != 0) { - printf("ERROR [/etc/amandapass is world readable!]\n"); + g_printf(_("ERROR [/etc/amandapass is world readable!]\n")); } else { - printf("OK [/etc/amandapass is readable, but not by all]\n"); + g_printf(_("OK [/etc/amandapass is readable, but not by all]\n")); } } else { - printf("OK [unable to stat /etc/amandapass: %s]\n", + g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"), strerror(errno)); } aclose(testfd); } else { - printf("ERROR [unable to open /etc/amandapass: %s]\n", + g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"), strerror(errno)); } } - if( need_compress_path ) { + if (need_compress_path ) check_file(COMPRESS_PATH, X_OK); - } - if( need_dump || need_xfsdump ) - check_file("/etc/dumpdates", + if (need_dump || need_xfsdump ) { + if (check_file_exist("/etc/dumpdates")) { + check_file("/etc/dumpdates", #ifdef USE_RUNDUMP - F_OK + F_OK #else - R_OK|W_OK + R_OK|W_OK +#endif + ); + } else { +#ifndef USE_RUNDUMP + if (access("/etc", R_OK|W_OK) == -1) { + g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno)); + } #endif - ); + } + } if (need_vdump) { - check_file("/etc/vdumpdates", F_OK); + if (check_file_exist("/etc/vdumpdates")) { + check_file("/etc/vdumpdates", F_OK); + } } check_access("/dev/null", R_OK|W_OK); - check_space(AMANDA_TMPDIR, 64); /* for amandad i/o */ + check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */ #ifdef AMANDA_DBGDIR - check_space(AMANDA_DBGDIR, 64); /* for amandad i/o */ + check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */ #endif - check_space("/etc", 64); /* for /etc/dumpdates writing */ + check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */ } -static void check_space(dir, kbytes) -char *dir; -long kbytes; +static void +check_space( + char * dir, + off_t kbytes) { - generic_fs_stats_t statp; + struct fs_usage fsusage; + char *quoted = quote_string(dir); + intmax_t kb_avail; + + if(get_fs_usage(dir, NULL, &fsusage) == -1) { + g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno)); + amfree(quoted); + return; + } - if(get_fs_stats(dir, &statp) == -1) - printf("ERROR [cannot statfs %s: %s]\n", dir, strerror(errno)); - else if(statp.avail < kbytes) - printf("ERROR [dir %s needs %ldKB, only has %ldKB available.]\n", - dir, kbytes, statp.avail); - else - printf("OK %s has more than %ld KB available.\n", dir, kbytes); + /* do the division first to avoid potential integer overflow */ + kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize; + + if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) { + g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted, + (long long)kbytes); + } else if (kb_avail < kbytes) { + g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted, + (long long)kbytes, + (long long)kb_avail); + } else { + g_printf(_("OK %s has more than %lldKB available.\n"), + quoted, (long long)kbytes); + } + amfree(quoted); } -static void check_access(filename, mode) -char *filename; -int mode; +static void +check_access( + char * filename, + int mode) { char *noun, *adjective; + char *quoted = quote_string(filename); if(mode == F_OK) noun = "find", adjective = "exists"; @@ -853,34 +1063,58 @@ int mode; noun = "access", adjective = "accessible"; if(access(filename, mode) == -1) - printf("ERROR [can not %s %s: %s]\n", noun, filename, strerror(errno)); + g_printf(_("ERROR [can not %s %s: %s]\n"), noun, quoted, strerror(errno)); else - printf("OK %s %s\n", filename, adjective); + g_printf(_("OK %s %s\n"), quoted, adjective); + amfree(quoted); } -static void check_file(filename, mode) -char *filename; -int mode; +static int +check_file_exist( + char *filename) { struct stat stat_buf; + + if (stat(filename, &stat_buf) != 0) { + if(errno == ENOENT) { + return 0; + } + } + return 1; +} + +static void +check_file( + char * filename, + int mode) +{ + struct stat stat_buf; + char *quoted; + if(!stat(filename, &stat_buf)) { if(!S_ISREG(stat_buf.st_mode)) { - printf("ERROR [%s is not a file]\n", filename); + quoted = quote_string(filename); + g_printf(_("ERROR [%s is not a file]\n"), quoted); + amfree(quoted); } } check_access(filename, mode); } -static void check_dir(dirname, mode) -char *dirname; -int mode; +static void +check_dir( + char * dirname, + int mode) { struct stat stat_buf; + char *quoted; char *dir; if(!stat(dirname, &stat_buf)) { if(!S_ISDIR(stat_buf.st_mode)) { - printf("ERROR [%s is not a directory]\n", dirname); + quoted = quote_string(dirname); + g_printf(_("ERROR [%s is not a directory]\n"), quoted); + amfree(quoted); } } dir = stralloc2(dirname, "/."); @@ -888,22 +1122,27 @@ int mode; amfree(dir); } -static void check_suid(filename) -char *filename; +static void +check_suid( + char * filename) { -/* The following is only valid for real Unixs */ -#ifndef IGNORE_UID_CHECK +#ifndef SINGLE_USERID struct stat stat_buf; + char *quoted = quote_string(filename); + if(!stat(filename, &stat_buf)) { if(stat_buf.st_uid != 0 ) { - printf("ERROR [%s is not owned by root]\n",filename); + g_printf(_("ERROR [%s is not owned by root]\n"), quoted); } if((stat_buf.st_mode & S_ISUID) != S_ISUID) { - printf("ERROR [%s is not SUID root]\n",filename); + g_printf(_("ERROR [%s is not SUID root]\n"), quoted); } } else { - printf("ERROR [can not stat %s]\n",filename); + g_printf(_("ERROR [can not stat %s]\n"), quoted); } + amfree(quoted); +#else + (void)filename; /* Quiet unused parameter warning */ #endif }