X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=client-src%2Fselfcheck.c;h=416daf297d4e29de77478ca872f65b08fc127a60;hb=ae82bdf8b1748623ea97a99d3a2c76d36ee573af;hp=8787a8245f40c0a055d6e7f8197662d10e4e8ad5;hpb=94a044f90357edefa6f4ae9f0b1d5885b0e34aee;p=debian%2Famanda diff --git a/client-src/selfcheck.c b/client-src/selfcheck.c index 8787a82..416daf2 100644 --- a/client-src/selfcheck.c +++ b/client-src/selfcheck.c @@ -25,7 +25,7 @@ * University of Maryland at College Park */ /* - * $Id: selfcheck.c,v 1.95 2006/08/29 11:21:00 martinea Exp $ + * $Id: selfcheck.c 10421 2008-03-06 18:48:30Z martineau $ * * do self-check and send back any error messages */ @@ -42,6 +42,8 @@ #include "client_util.h" #include "conffile.h" #include "amandad.h" +#include "amxml.h" +#include "base64.h" #ifdef SAMBA_CLIENT #include "findpass.h" @@ -61,7 +63,7 @@ int need_runtar=0; int need_gnutar=0; int need_compress_path=0; int need_calcsize=0; -int program_is_backup_api=0; +int program_is_application_api=0; static char *amandad_auth = NULL; static am_feature_t *our_features = NULL; @@ -71,14 +73,10 @@ static g_option_t *g_options = NULL; /* local functions */ 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_options(dle_t *dle); +static void check_disk(dle_t *dle); 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 @@ -86,19 +84,16 @@ main( int argc, char ** argv) { - int level; char *line = NULL; - char *program = NULL; - char *calcprog = NULL; - char *disk = NULL; char *qdisk = NULL; - char *amdevice = NULL; char *qamdevice = NULL; char *optstr = NULL; char *err_extra = NULL; char *s, *fp; - option_t *options; int ch; + dle_t *dle; + int level; + GSList *errlist; /* initialize */ @@ -129,6 +124,7 @@ main( } config_init(CONFIG_INIT_CLIENT, NULL); + /* (check for config errors comes later) */ check_running_as(RUNNING_AS_CLIENT_LOGIN); @@ -166,12 +162,24 @@ main( config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY, g_options->config); - dbrename(config_name, DBG_SUBDIR_CLIENT); + dbrename(get_config_name(), DBG_SUBDIR_CLIENT); + } + + /* check for any config errors now */ + if (config_errors(&errlist) >= CFGERR_ERRORS) { + char *errstr = config_errors_to_error_string(errlist); + g_printf("%s\n", errstr); + dbclose(); + return 1; } + if (am_has_feature(g_options->features, fe_req_xml)) { + break; + } continue; } + dle = alloc_dle(); s = line; ch = *s++; @@ -179,33 +187,34 @@ main( if (ch == '\0') { goto err; /* no program */ } - program = s - 1; + dle->program = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; /* terminate the program name */ - program_is_backup_api = 0; - if(strcmp(program,"BACKUP")==0) { - program_is_backup_api = 1; + dle->program_is_application_api = 0; + if(strcmp(dle->program,"APPLICATION")==0) { + dle->program_is_application_api = 1; skip_whitespace(s, ch); /* find dumper name */ if (ch == '\0') { goto err; /* no program */ } - program = s - 1; + dle->program = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; /* terminate the program name */ } - if(strncmp_const(program, "CALCSIZE") == 0) { + if(strncmp_const(dle->program, "CALCSIZE") == 0) { skip_whitespace(s, ch); /* find program name */ if (ch == '\0') { goto err; /* no program */ } - calcprog = s - 1; + dle->program = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; + dle->calcsize = 1; } else { - calcprog = NULL; + dle->calcsize = 0; } skip_whitespace(s, ch); /* find disk name */ @@ -215,7 +224,7 @@ main( qdisk = s - 1; skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the disk name */ - disk = unquote_string(qdisk); + dle->disk = unquote_string(qdisk); skip_whitespace(s, ch); /* find the device or level */ if (ch == '\0') { @@ -226,17 +235,19 @@ main( skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the device */ qamdevice = stralloc(fp); - amdevice = unquote_string(qamdevice); + dle->device = unquote_string(qamdevice); skip_whitespace(s, ch); /* find level number */ } else { - amdevice = stralloc(disk); + dle->device = stralloc(dle->disk); + qamdevice = stralloc(qdisk); } /* find level number */ if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) { goto err; /* bad level */ } + dle->level = g_slist_append(dle->level, GINT_TO_POINTER(level)); skip_integer(s, ch); skip_whitespace(s, ch); @@ -248,18 +259,13 @@ main( optstr = s - 1; skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the options */ - options = parse_options(optstr, disk, amdevice, g_options->features, 1); + parse_options(optstr, dle, g_options->features, 1); /*@ignore@*/ - check_options(program, calcprog, disk, amdevice, options); - check_disk(program, calcprog, disk, amdevice, level, options); + + check_options(dle); + check_disk(dle); + /*@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') { /* check all since no option */ need_samba=1; @@ -277,21 +283,46 @@ main( need_compress_path=1; need_calcsize=1; /*@ignore@*/ - check_disk(program, calcprog, disk, amdevice, level, NULL); + check_disk(dle); /*@end@*/ } else { goto err; /* bad syntax */ } - amfree(disk); amfree(qamdevice); - amfree(amdevice); } if (g_options == NULL) { - printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n")); + g_printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n")); error(_("Missing OPTIONS line in selfcheck input\n")); /*NOTREACHED*/ } + if (am_has_feature(g_options->features, fe_req_xml)) { + char *errmsg = NULL; + dle_t *dles, *dle; + + dles = amxml_parse_node_FILE(stdin, &errmsg); + if (errmsg) { + err_extra = errmsg; + goto err; + } + for (dle = dles; dle != NULL; dle = dle->next) { + run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle, + stdout); + } + for (dle = dles; dle != NULL; dle = dle->next) { + check_options(dle); + run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle, + stdout); + check_disk(dle); + run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle, + stdout); + } + for (dle = dles; dle != NULL; dle = dle->next) { + run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle, + stdout); + } + } + check_overall(); amfree(line); @@ -304,10 +335,13 @@ main( return 0; err: - g_printf(_("ERROR [BOGUS REQUEST PACKET]\n")); - dbprintf(_("REQ packet is bogus%s%s\n"), - err_extra ? ": " : "", - err_extra ? err_extra : ""); + if (err_extra) { + g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra); + dbprintf(_("REQ packet is bogus: %s\n"), err_extra); + } else { + g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n")); + dbprintf(_("REQ packet is bogus\n")); + } dbclose(); return 1; } @@ -315,71 +349,43 @@ main( static void check_options( - char * program, - char * calcprog, - char * disk, - char * amdevice, - option_t * options) + dle_t *dle) { - char *myprogram = program; - - if(strcmp(myprogram,"CALCSIZE") == 0) { - int nb_exclude = 0; - int nb_include = 0; - char *file_exclude = NULL; - char *file_include = NULL; - - if(options->exclude_file) nb_exclude += options->exclude_file->nb_element; - if(options->exclude_list) nb_exclude += options->exclude_list->nb_element; - 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, amdevice, options, 1); - if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1); - - amfree(file_exclude); - amfree(file_include); - + if (dle->calcsize == 1) { need_calcsize=1; - if (calcprog == NULL) { - g_printf(_("ERROR [no program name for calcsize]\n")); - } else { - myprogram = calcprog; - } } - if(strcmp(myprogram,"GNUTAR") == 0) { + if (strcmp(dle->program,"GNUTAR") == 0) { need_gnutar=1; - if(amdevice[0] == '/' && amdevice[1] == '/') { - if(options->exclude_file && options->exclude_file->nb_element > 1) { + if(dle->device[0] == '/' && dle->device[1] == '/') { + if(dle->exclude_file && dle->exclude_file->nb_element > 1) { g_printf(_("ERROR [samba support only one exclude file]\n")); } - if(options->exclude_list && options->exclude_list->nb_element > 0 && - options->exclude_optional==0) { + if (dle->exclude_list && dle->exclude_list->nb_element > 0 && + dle->exclude_optional==0) { g_printf(_("ERROR [samba does not support exclude list]\n")); } - if(options->include_file && options->include_file->nb_element > 0) { + if (dle->include_file && dle->include_file->nb_element > 0) { g_printf(_("ERROR [samba does not support include file]\n")); } - if(options->include_list && options->include_list->nb_element > 0 && - options->include_optional==0) { + if (dle->include_list && dle->include_list->nb_element > 0 && + dle->include_optional==0) { g_printf(_("ERROR [samba does not support include list]\n")); } need_samba=1; - } - else { + } else { int nb_exclude = 0; int nb_include = 0; char *file_exclude = NULL; char *file_include = NULL; - if(options->exclude_file) nb_exclude += options->exclude_file->nb_element; - if(options->exclude_list) nb_exclude += options->exclude_list->nb_element; - if(options->include_file) nb_include += options->include_file->nb_element; - if(options->include_list) nb_include += options->include_list->nb_element; + if (dle->exclude_file) nb_exclude += dle->exclude_file->nb_element; + if (dle->exclude_list) nb_exclude += dle->exclude_list->nb_element; + if (dle->include_file) nb_include += dle->include_file->nb_element; + if (dle->include_list) nb_include += dle->include_list->nb_element; - if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1); - if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1); + if (nb_exclude > 0) file_exclude = build_exclude(dle, 1); + if (nb_include > 0) file_include = build_include(dle, 1); amfree(file_exclude); amfree(file_include); @@ -388,17 +394,17 @@ check_options( } } - if(strcmp(myprogram,"DUMP") == 0) { - if(options->exclude_file && options->exclude_file->nb_element > 0) { + if (strcmp(dle->program,"DUMP") == 0) { + if (dle->exclude_file && dle->exclude_file->nb_element > 0) { g_printf(_("ERROR [DUMP does not support exclude file]\n")); } - if(options->exclude_list && options->exclude_list->nb_element > 0) { + if (dle->exclude_list && dle->exclude_list->nb_element > 0) { g_printf(_("ERROR [DUMP does not support exclude list]\n")); } - if(options->include_file && options->include_file->nb_element > 0) { + if (dle->include_file && dle->include_file->nb_element > 0) { g_printf(_("ERROR [DUMP does not support include file]\n")); } - if(options->include_list && options->include_list->nb_element > 0) { + if (dle->include_list && dle->include_list->nb_element > 0) { g_printf(_("ERROR [DUMP does not support include list]\n")); } #ifdef USE_RUNDUMP @@ -407,66 +413,66 @@ check_options( #ifndef AIX_BACKUP #ifdef VDUMP #ifdef DUMP - if (strcmp(amname_to_fstype(amdevice), "advfs") == 0) + if (strcmp(amname_to_fstype(dle->device), "advfs") == 0) #else if (1) #endif { need_vdump=1; need_rundump=1; - if (options->createindex) + if (dle->create_index) need_vrestore=1; } else #endif /* VDUMP */ #ifdef XFSDUMP #ifdef DUMP - if (strcmp(amname_to_fstype(amdevice), "xfs") == 0) + if (strcmp(amname_to_fstype(dle->device), "xfs") == 0) #else if (1) #endif { need_xfsdump=1; need_rundump=1; - if (options->createindex) + if (dle->create_index) need_xfsrestore=1; } else #endif /* XFSDUMP */ #ifdef VXDUMP #ifdef DUMP - if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0) + if (strcmp(amname_to_fstype(dle->device), "vxfs") == 0) #else if (1) #endif { need_vxdump=1; - if (options->createindex) + if (dle->create-index) need_vxrestore=1; } else #endif /* VXDUMP */ { need_dump=1; - if (options->createindex) + if (dle->create_index) need_restore=1; } #else /* AIX backup program */ need_dump=1; - if (options->createindex) + if (dle->create_index) need_restore=1; #endif } - if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST) - || (options->compress == COMP_CUST)) { + if ((dle->compress == COMP_BEST) || (dle->compress == COMP_FAST) + || (dle->compress == COMP_CUST)) { need_compress_path=1; } - if(options->auth && amandad_auth) { - if(strcasecmp(options->auth, amandad_auth) != 0) { + if (dle->auth && amandad_auth) { + if (strcasecmp(dle->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) { + amandad_auth, dle->auth); + if (strcmp(dle->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")); @@ -481,12 +487,7 @@ check_options( static void check_disk( - char * program, - char * calcprog, - char * disk, - char * amdevice, - int level, - option_t *options) + dle_t *dle) { char *device = stralloc("nodevice"); char *err = NULL; @@ -498,31 +499,21 @@ check_disk( int access_result; char *access_type; char *extra_info = NULL; - char *myprogram = program; - char *qdisk = quote_string(disk); - char *qamdevice = quote_string(amdevice); + char *qdisk = quote_string(dle->disk); + char *qamdevice = quote_string(dle->device); 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] == '/') { + if (dle->calcsize == 1) { + if (dle->device[0] == '/' && dle->device[1] == '/') { err = vstrallocf(_("Can't use CALCSIZE for samba estimate, use CLIENT: %s"), - amdevice); - goto common_exit; - } - if (calcprog == NULL) { - err = _("no program for calcsize"); + dle->device); goto common_exit; } - myprogram = calcprog; } - if (strcmp(myprogram, "GNUTAR")==0) { - if(amdevice[0] == '/' && amdevice[1] == '/') { + if (strcmp(dle->program, "GNUTAR")==0) { + if(dle->device[0] == '/' && dle->device[1] == '/') { #ifdef SAMBA_CLIENT int nullfd, checkerr; int passwdfd; @@ -538,23 +529,23 @@ check_disk( char *pw_fd_env; int errdos; - parsesharename(amdevice, &share, &subdir); + parsesharename(dle->device, &share, &subdir); if (!share) { - err = vstrallocf(_("cannot parse for share/subdir disk entry %s"), amdevice); + err = vstrallocf(_("cannot parse for share/subdir disk entry %s"), dle->device); goto common_exit; } if ((subdir) && (SAMBA_VERSION < 2)) { err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"), - amdevice); + dle->device); goto common_exit; } if ((user_and_password = findpass(share, &domain)) == NULL) { - err = vstrallocf(_("cannot find password for %s"), amdevice); + err = vstrallocf(_("cannot find password for %s"), dle->device); goto common_exit; } lpass = strlen(user_and_password); if ((pwtext = strchr(user_and_password, '%')) == NULL) { - err = vstrallocf(_("password field not \'user%%pass\' for %s"), amdevice); + err = vstrallocf(_("password field not \'user%%pass\' for %s"), dle->device); goto common_exit; } *pwtext++ = '\0'; @@ -575,7 +566,7 @@ check_disk( } else { pw_fd_env = "dummy_PASSWD_FD"; } - checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, + checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, 0, &nullfd, &nullfd, &checkerr, pw_fd_env, &passwdfd, "smbclient", @@ -595,9 +586,9 @@ check_disk( aclose(nullfd); /*@ignore@*/ if ((pwtext_len > 0) - && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) { + && full_write(passwdfd, pwtext, pwtext_len) < pwtext_len) { err = vstrallocf(_("password write failed: %s: %s"), - amdevice, strerror(errno)); + dle->device, strerror(errno)); aclose(passwdfd); goto common_exit; } @@ -630,7 +621,8 @@ check_disk( while ((wpid = wait(&retstat)) != -1) { if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) { char *exitstr = str_exit_status("smbclient", retstat); - err = newvstralloc(err, err, sep, exitstr); + strappend(err, sep); + strappend(err, exitstr); sep = "\n"; amfree(exitstr); @@ -641,11 +633,11 @@ check_disk( if (extra_info) { err = newvstrallocf(err, _("samba access error: %s: %s %s"), - amdevice, extra_info, err); + dle->device, extra_info, err); amfree(extra_info); } else { err = newvstrallocf(err, _("samba access error: %s: %s"), - amdevice, err); + dle->device, err); } } #else @@ -656,9 +648,9 @@ check_disk( } amode = F_OK; amfree(device); - device = amname_to_dirname(amdevice); - } else if (strcmp(myprogram, "DUMP") == 0) { - if(amdevice[0] == '/' && amdevice[1] == '/') { + device = amname_to_dirname(dle->device); + } else if (strcmp(dle->program, "DUMP") == 0) { + if(dle->device[0] == '/' && dle->device[1] == '/') { err = vstrallocf( _("The DUMP program cannot handle samba shares, use GNUTAR: %s"), qdisk); @@ -666,19 +658,19 @@ check_disk( } #ifdef VDUMP /* { */ #ifdef DUMP /* { */ - if (strcmp(amname_to_fstype(amdevice), "advfs") == 0) + if (strcmp(amname_to_fstype(dle->device), "advfs") == 0) #else /* }{ */ if (1) #endif /* } */ { amfree(device); - device = amname_to_dirname(amdevice); + device = amname_to_dirname(dle->device); amode = F_OK; } else #endif /* } */ { amfree(device); - device = amname_to_devname(amdevice); + device = amname_to_devname(dle->device); #ifdef USE_RUNDUMP amode = F_OK; #else @@ -686,30 +678,97 @@ check_disk( #endif } } - else { /* program_is_backup_api==1 */ - pid_t backup_api_pid; - int property_pipe[2]; + else { /* program_is_application_api==1 */ + pid_t application_api_pid; backup_support_option_t *bsu; + int app_err[2]; + GPtrArray *errarray; + + bsu = backup_support_option(dle->program, g_options, dle->disk, + dle->device, &errarray); + + if (!bsu) { + char *line; + guint i; + for (i=0; i < errarray->len; i++) { + line = g_ptr_array_index(errarray, i); + fprintf(stdout, _("ERROR Application '%s': %s\n"), + dle->program, line); + amfree(line); + } + err = vstrallocf(_("Application '%s': can't run support command"), + dle->program); + goto common_exit; + } - bsu = backup_support_option(program, g_options, disk, amdevice); + if (dle->calcsize && !bsu->calcsize) { + g_printf("ERROR application %s doesn't support calcsize estimate\n", + dle->program); + } + if (dle->include_file && dle->include_file->nb_element > 0 && + !bsu->include_file) { + g_printf("ERROR application %s doesn't support include-file\n", + dle->program); + } + if (dle->include_list && dle->include_list->nb_element > 0 && + !bsu->include_list) { + g_printf("ERROR application %s doesn't support include-list\n", + dle->program); + } + if (dle->include_optional && !bsu->include_optional) { + g_printf("ERROR application %s doesn't support optional include\n", + dle->program); + } + if (dle->exclude_file && dle->exclude_file->nb_element > 0 && + !bsu->exclude_file) { + g_printf("ERROR application %s doesn't support exclude-file\n", + dle->program); + } + if (dle->exclude_list && dle->exclude_list->nb_element > 0 && + !bsu->exclude_list) { + g_printf("ERROR application %s doesn't support exclude-list\n", + dle->program); + } + if (dle->exclude_optional && !bsu->exclude_optional) { + g_printf("ERROR application %s doesn't support optional exclude\n", + dle->program); + } + fflush(stdout);fflush(stderr); - if (pipe(property_pipe) < 0) { - err = vstrallocf(_("pipe failed: %s"), strerror(errno)); + if (pipe(app_err) < 0) { + err = vstrallocf(_("Application '%s': can't create pipe"), + dle->program); goto common_exit; } - fflush(stdout);fflush(stderr); - - switch (backup_api_pid = fork()) { + + switch (application_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); + char **argvchild, **arg; + char *cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL); + GSList *scriptlist; + script_t *script; + char *cmdline; int j=0; - argvchild[j++] = program; + int k; + + aclose(app_err[0]); + dup2(app_err[1], 2); + + k = application_property_argv_size(dle); + for (scriptlist = dle->scriptlist; scriptlist != NULL; + scriptlist = scriptlist->next) { + script = (script_t *)scriptlist->data; + if (script->result && script->result->proplist) { + k += property_argv_size(script->result->proplist); + } + } + argvchild = g_new0(char *, 18 + k); + argvchild[j++] = dle->program; argvchild[j++] = "selfcheck"; if (bsu->message_line == 1) { argvchild[j++] = "--message"; @@ -723,49 +782,76 @@ check_disk( argvchild[j++] = "--host"; argvchild[j++] = g_options->hostname; } - if (disk != NULL && bsu->disk == 1) { + if (dle->disk != NULL && bsu->disk == 1) { argvchild[j++] = "--disk"; - argvchild[j++] = disk; + argvchild[j++] = dle->disk; } argvchild[j++] = "--device"; - argvchild[j++] = amdevice; - if(options && options->createindex && bsu->index_line == 1) { + argvchild[j++] = dle->device; + if (dle->create_index && bsu->index_line == 1) { argvchild[j++] = "--index"; argvchild[j++] = "line"; } - if (!options->no_record && bsu->record == 1) { + if (dle->record && bsu->record == 1) { argvchild[j++] = "--record"; } + if (dle->calcsize && bsu->calcsize == 1) { + argvchild[j++] = "--calcsize"; + } + j += application_property_add_to_argv(&argvchild[j], dle, bsu); + + for (scriptlist = dle->scriptlist; scriptlist != NULL; + scriptlist = scriptlist->next) { + script = (script_t *)scriptlist->data; + if (script->result && script->result->proplist) { + j += property_add_to_argv(&argvchild[j], + script->result->proplist); + } + } + argvchild[j++] = NULL; - dup2(property_pipe[0], 0); - aclose(property_pipe[1]); + + cmdline = stralloc(cmd); + for(arg = argvchild; *arg != NULL; arg++) { + char *quoted = quote_string(*arg); + cmdline = vstrextend(&cmdline, " ", quoted, NULL); + amfree(quoted); + } + dbprintf(_("Spawning \"%s\" in pipeline\n"), cmdline); + amfree(cmdline); + safe_fd(-1, 0); - execve(cmd,argvchild,safe_env()); + 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")); + int status; + FILE *app_stderr; + char *line; + + aclose(app_err[1]); + app_stderr = fdopen(app_err[0], "r"); + while((line = agets(app_stderr)) != NULL) { + if (strlen(line) > 0) { + fprintf(stdout, "ERROR Application '%s': %s\n", + dle->program, line); + dbprintf("ERROR %s\n", line); } + amfree(line); + } + if (waitpid(application_api_pid, &status, 0) < 0) { + err = vstrallocf(_("waitpid failed: %s"), + strerror(errno)); + goto common_exit; + } else if (!WIFEXITED(status)) { + err = vstrallocf(_("Application '%s': exited with signal %d"), + dle->program, WTERMSIG(status)); + goto common_exit; + } else if (WEXITSTATUS(status) != 0) { + err = vstrallocf(_("Application '%s': exited with status %d"), + dle->program, WEXITSTATUS(status)); goto common_exit; } } @@ -801,6 +887,9 @@ check_disk( common_exit: + if (!qdevice) + qdevice = quote_string(device); + amfree(share); amfree(subdir); if(user_and_password) { @@ -810,7 +899,7 @@ common_exit: amfree(domain); if(err) { - g_printf(_("ERROR [%s]\n"), err); + g_printf(_("ERROR %s\n"), err); dbprintf(_("%s\n"), err); amfree(err); } else { @@ -928,19 +1017,18 @@ check_overall(void) #else 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) + if (gnutar_list_dir) { + /* make sure our listed-incremental dir is ready */ check_dir(gnutar_list_dir, R_OK|W_OK); + } else { + /* no listed-incremental dir, so check that amandates is ready */ + need_amandates = 1; + } } - 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; @@ -949,6 +1037,15 @@ check_overall(void) check_file(cmd, X_OK); amfree(cmd); + + /* calcsize uses amandates */ + need_amandates = 1; + } + + if (need_amandates) { + char *amandates_file; + amandates_file = getconf_str(CNF_AMANDATES); + check_file(amandates_file, R_OK|W_OK); } if( need_samba ) { @@ -1045,30 +1142,6 @@ check_space( amfree(quoted); } -static void -check_access( - char * filename, - int mode) -{ - char *noun, *adjective; - char *quoted = quote_string(filename); - - if(mode == F_OK) - noun = "find", adjective = "exists"; - else if((mode & X_OK) == X_OK) - noun = "execute", adjective = "executable"; - else if((mode & (W_OK|R_OK)) == (W_OK|R_OK)) - noun = "read/write", adjective = "read/writable"; - else - noun = "access", adjective = "accessible"; - - if(access(filename, mode) == -1) - g_printf(_("ERROR [can not %s %s: %s]\n"), noun, quoted, strerror(errno)); - else - g_printf(_("OK %s %s\n"), quoted, adjective); - amfree(quoted); -} - static int check_file_exist( char *filename) @@ -1083,66 +1156,3 @@ check_file_exist( 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)) { - quoted = quote_string(filename); - g_printf(_("ERROR [%s is not a file]\n"), quoted); - amfree(quoted); - } - } - check_access(filename, 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)) { - quoted = quote_string(dirname); - g_printf(_("ERROR [%s is not a directory]\n"), quoted); - amfree(quoted); - } - } - dir = stralloc2(dirname, "/."); - check_access(dir, mode); - amfree(dir); -} - -static void -check_suid( - char * filename) -{ -#ifndef SINGLE_USERID - struct stat stat_buf; - char *quoted = quote_string(filename); - - if(!stat(filename, &stat_buf)) { - if(stat_buf.st_uid != 0 ) { - g_printf(_("ERROR [%s is not owned by root]\n"), quoted); - } - if((stat_buf.st_mode & S_ISUID) != S_ISUID) { - g_printf(_("ERROR [%s is not SUID root]\n"), quoted); - } - } - else { - g_printf(_("ERROR [can not stat %s]\n"), quoted); - } - amfree(quoted); -#else - (void)filename; /* Quiet unused parameter warning */ -#endif -}