X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=client-src%2Fselfcheck.c;h=8d8ae757edb5460c31a9e051917c95e475578345;hb=12179dea039515c06168c0037d048566a3f623de;hp=0cfade85051f7b59c193d1f6e8e5e00ffa5d2d84;hpb=3ab887b9bc819a846c75dd7f2ee5d41fac22b19f;p=debian%2Famanda diff --git a/client-src/selfcheck.c b/client-src/selfcheck.c index 0cfade8..8d8ae75 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 2003/11/18 18:04:26 martinea 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 "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 "clientconf.h" +#include "amandad.h" #ifdef SAMBA_CLIENT #include "findpass.h" @@ -58,72 +60,94 @@ int need_vxrestore=0; int need_runtar=0; int need_gnutar=0; int need_compress_path=0; +int need_calcsize=0; +int program_is_wrapper=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 *disk, char *device, option_t *options)); -static void check_disk P((char *program, 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, char *optstr); +static void check_overall(void); +static void check_access(char *filename, int mode); +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; + char *conffile; + option_t *options; int ch; - int fd; +#if defined(USE_DBMALLOC) unsigned long malloc_hist_1, malloc_size_1; unsigned long malloc_hist_2, malloc_size_2; - option_t *options; +#endif /* initialize */ - for(fd = 3; fd < FD_SETSIZE; fd++) { - /* - * Make sure nobody spoofs us with a lot of extra open files - * that would cause an open we do to get a very high file - * descriptor, which in turn might be used as an index into - * an array (e.g. an fd_set). - */ - close(fd); - } - + safe_fd(-1, 0); safe_cd(); set_pname("selfcheck"); + /* Don't die when child closes pipe */ + signal(SIGPIPE, SIG_IGN); + +#if defined(USE_DBMALLOC) malloc_size_1 = malloc_inuse(&malloc_hist_1); +#endif erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG); - dbopen(); + dbopen(DBG_SUBDIR_CLIENT); startclock(); - dbprintf(("%s: version %s\n", argv[0], version())); + dbprintf(("%s: version %s\n", get_pname(), version())); + + if(argc > 2 && strcmp(argv[1], "amandad") == 0) { + amandad_auth = stralloc(argv[2]); + } + + conffile = vstralloc(CONFIG_DIR, "/", "amanda-client.conf", NULL); + if (read_clientconf(conffile) > 0) { + printf("ERROR [reading conffile: %s]\n", conffile); + error("error reading conffile: %s", conffile); + /*NOTREACHED*/ + } + amfree(conffile); 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)) { + /*@end@*/ + if (line[0] == '\0') + continue; + #define sc "OPTIONS " - if(strncmp(line, sc, sizeof(sc)-1) == 0) { + if(strncmp(line, sc, SIZEOF(sc)-1) == 0) { #undef sc g_options = parse_g_options(line+8, 1); if(!g_options->hostname) { @@ -141,6 +165,20 @@ char **argv; } printf("\n"); fflush(stdout); + + if (g_options->config) { + conffile = vstralloc(CONFIG_DIR, "/", g_options->config, "/", + "amanda-client.conf", NULL); + if (read_clientconf(conffile) > 0) { + printf("ERROR [reading conffile: %s]\n", conffile); + error("error reading conffile: %s", conffile); + /*NOTREACHED*/ + } + amfree(conffile); + + dbrename(g_options->config, DBG_SUBDIR_CLIENT); + } + continue; } @@ -155,13 +193,39 @@ char **argv; skip_non_whitespace(s, ch); s[-1] = '\0'; /* terminate the program name */ + program_is_wrapper = 0; + if(strcmp(program,"DUMPER")==0) { + program_is_wrapper = 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(program, "CALCSIZE", 8) == 0) { + skip_whitespace(s, ch); /* find program name */ + if (ch == '\0') { + goto err; /* no program */ + } + calcprog = s - 1; + skip_non_whitespace(s, ch); + s[-1] = '\0'; + } + else { + calcprog = NULL; + } + skip_whitespace(s, ch); /* find disk name */ 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') { @@ -169,13 +233,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 */ @@ -186,8 +251,8 @@ char **argv; skip_whitespace(s, ch); #define sc "OPTIONS " - if (ch && strncmp (s - 1, sc, sizeof(sc)-1) == 0) { - s += sizeof(sc)-1; + if (ch && strncmp (s - 1, sc, SIZEOF(sc)-1) == 0) { + s += SIZEOF(sc)-1; ch = s[-1]; #undef sc skip_whitespace(s, ch); /* find the option string */ @@ -195,15 +260,18 @@ char **argv; 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, disk, device, options); - check_disk(program, 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, &optstr[2]); + /*@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') { @@ -221,11 +289,15 @@ char **argv; need_runtar=1; need_gnutar=1; need_compress_path=1; - check_disk(program, disk, device, level); + need_calcsize=1; + /*@ignore@*/ + check_disk(program, calcprog, disk, amdevice, level, ""); + /*@end@*/ } else { goto err; /* bad syntax */ } - amfree(device); + amfree(disk); + amfree(amdevice); } check_overall(); @@ -240,15 +312,15 @@ char **argv; amfree(g_options->hostname); amfree(g_options); +#if defined(USE_DBMALLOC) 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 } +#endif dbclose(); return 0; @@ -265,13 +337,43 @@ char **argv; static void -check_options(program, disk, device, options) - char *program, *disk, *device; - option_t *options; +check_options( + char * program, + char * calcprog, + char * disk, + char * amdevice, + option_t * options) { - if(strcmp(program,"GNUTAR") == 0) { + 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); + + need_calcsize=1; + if (calcprog == NULL) { + 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"); } @@ -299,8 +401,8 @@ check_options(program, 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); @@ -308,7 +410,8 @@ check_options(program, disk, device, options) need_runtar=1; } } - if(strcmp(program,"DUMP") == 0) { + + if(strcmp(myprogram,"DUMP") == 0) { if(options->exclude_file && options->exclude_file->nb_element > 0) { printf("ERROR [DUMP does not support exclude file]\n"); } @@ -327,7 +430,7 @@ check_options(program, 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 @@ -341,7 +444,7 @@ check_options(program, 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 @@ -355,7 +458,7 @@ check_options(program, 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 @@ -378,37 +481,68 @@ check_options(program, disk, device, options) need_restore=1; #endif } - if(options->compress == COMPR_BEST || options->compress == COMPR_FAST) + if ((options->compress == COMPR_BEST) || (options->compress == COMPR_FAST) + || (options->compress == COMPR_CUST)) { need_compress_path=1; + } + if(options->auth && amandad_auth) { + if(strcasecmp(options->auth, amandad_auth) != 0) { + fprintf(stdout,"ERROR [client configured for auth=%s while server requested '%s']\n", + amandad_auth, options->auth); + } + } } -static void check_disk(program, disk, amdevice, level) -char *program, *disk, *amdevice; -int level; +static void +check_disk( + char * program, + char * calcprog, + char * disk, + char * amdevice, + int level, + char * optstr) { - 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; + + (void)level; /* Quiet unused parameter warning */ + + dbprintf(("%s: checking disk %s\n", debug_prefix_time(NULL), qdisk)); - dbprintf(("%s: checking disk %s\n", debug_prefix_time(NULL), disk)); + if(strcmp(myprogram,"CALCSIZE") == 0) { + if(amdevice[0] == '/' && amdevice[1] == '/') { + err = vstralloc("Can't use CALCSIZE for samba estimate,", + " use CLIENT: ", + amdevice, + NULL); + goto common_exit; + } + myprogram = calcprog; + } - if (strcmp(program, "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; + pid_t wpid; int ret, sig, rc; char *line; char *sep; @@ -438,13 +572,18 @@ int level; 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); goto common_exit; } - nullfd = open("/dev/null", O_RDWR); + if ((nullfd = open("/dev/null", O_RDWR)) == -1) { + err = stralloc2("Cannot access /dev/null : ", strerror(errno)); + goto common_exit; + } + if (pwtext_len > 0) { pw_fd_env = "PASSWD_FD"; } else { @@ -466,12 +605,11 @@ 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) { + /*@ignore@*/ + if ((pwtext_len > 0) + && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) { err = vstralloc("password write failed: ", amdevice, ": ", @@ -480,13 +618,21 @@ int level; 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) { + 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 = ": "; @@ -513,7 +659,7 @@ int level; } else { strappend(err, "returned "); } - ap_snprintf(number, sizeof(number), "%d", ret); + snprintf(number, (size_t)sizeof(number), "%d", ret); strappend(err, number); } } @@ -528,17 +674,18 @@ int level; amfree(extra_info); } #else - err = stralloc2("This client is not configured for samba: ", amdevice); + err = stralloc2("This client is not configured for samba: ", qdisk); #endif goto common_exit; } amode = F_OK; + amfree(device); device = amname_to_dirname(amdevice); - } else { + } else if (strcmp(program, "DUMP") == 0) { if(amdevice[0] == '/' && amdevice[1] == '/') { err = vstralloc("The DUMP program cannot handle samba shares,", " use GNUTAR: ", - amdevice, + qdisk, NULL); goto common_exit; } @@ -549,11 +696,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; @@ -562,8 +711,43 @@ int level; #endif } } + else { /* program_is_wrapper==1 */ + pid_t pid_wrapper; + fflush(stdout);fflush(stdin); + switch (pid_wrapper = fork()) { + case -1: + printf("ERROR [fork: %s]\n", strerror(errno)); + error("fork: %s", strerror(errno)); + /*NOTREACHED*/ + + case 0: /* child */ + { + char *argvchild[6]; + char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL); + argvchild[0] = program; + argvchild[1] = "selfcheck"; + argvchild[2] = disk; + argvchild[3] = amdevice; + argvchild[4] = optstr; + argvchild[5] = NULL; + execve(cmd,argvchild,safe_env()); + exit(127); + } + default: /* parent */ + { + int status; + waitpid(pid_wrapper, &status, 0); + } + } + fflush(stdout);fflush(stdin); + amfree(device); + amfree(qamdevice); + amfree(qdisk); + return; + } - dbprintf(("%s: device %s\n", debug_prefix_time(NULL), device)); + qdevice = quote_string(device); + dbprintf(("%s: device %s\n", debug_prefix_time(NULL), qdevice)); /* skip accessability test if this is an AFS entry */ if(strncmp(device, "afs:", 4) != 0) { @@ -575,8 +759,8 @@ int level; access_type = "access"; #endif if(access_result == -1) { - err = vstralloc("could not ", access_type, " ", device, - " (", disk, "): ", strerror(errno), NULL); + err = vstralloc("could not ", access_type, " ", qdevice, + " (", qdisk, "): ", strerror(errno), NULL); } #ifdef CHECK_FOR_ACCESS_WITH_OPEN aclose(access_result); @@ -588,41 +772,44 @@ 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)); 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)); + printf("OK %s\n", qdisk); + dbprintf(("%s: disk %s OK\n", debug_prefix_time(NULL), qdisk)); + printf("OK %s\n", qamdevice); + dbprintf(("%s: amdevice %s OK\n", + debug_prefix_time(NULL), qamdevice)); + printf("OK %s\n", qdevice); + dbprintf(("%s: device %s OK\n", debug_prefix_time(NULL), qdevice)); } if(extra_info) { dbprintf(("%s: extra info: %s\n", debug_prefix_time(NULL), 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 ) { @@ -710,12 +897,27 @@ static void check_overall() #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); -#endif + need_amandates = 1; + gnutar_list_dir = client_getconf_str(CLN_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 = client_getconf_str(CLN_AMANDATES); + check_file(amandates_file, R_OK|W_OK); + } + if( need_calcsize ) { + char *cmd; + + cmd = vstralloc(libexecdir, "/", "calcsize", versionsuffix(), NULL); + + check_file(cmd, X_OK); + + amfree(cmd); } if( need_samba ) { @@ -743,9 +945,8 @@ static void check_overall() } } - if( need_compress_path ) { + if( need_compress_path ) check_file(COMPRESS_PATH, X_OK); - } if( need_dump || need_xfsdump ) check_file("/etc/dumpdates", @@ -756,40 +957,48 @@ static void check_overall() #endif ); - if (need_vdump) { + if (need_vdump) 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; - - 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); + char *quoted = quote_string(dir); + + if(get_fs_stats(dir, &statp) == -1) { + printf("ERROR [cannot statfs %s: %s]\n", quoted, strerror(errno)); + } else if(statp.avail < kbytes) { + printf("ERROR [dir %s needs " OFF_T_FMT "KB, only has " + OFF_T_FMT "KB available.]\n", quoted, + (OFF_T_FMT_TYPE)kbytes, + (OFF_T_FMT_TYPE)statp.avail); + } else { + printf("OK %s has more than " OFF_T_FMT " KB available.\n", + quoted, (OFF_T_FMT_TYPE)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"; @@ -801,34 +1010,44 @@ int mode; noun = "access", adjective = "accessible"; if(access(filename, mode) == -1) - printf("ERROR [can not %s %s: %s]\n", noun, filename, strerror(errno)); + printf("ERROR [can not %s %s: %s]\n", noun, quoted, strerror(errno)); else - printf("OK %s %s\n", filename, adjective); + printf("OK %s %s\n", quoted, adjective); + amfree(quoted); } -static void check_file(filename, mode) -char *filename; -int mode; +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); + 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); + printf("ERROR [%s is not a directory]\n", quoted); + amfree(quoted); } } dir = stralloc2(dirname, "/."); @@ -836,22 +1055,28 @@ 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 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); + 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); + printf("ERROR [%s is not SUID root]\n", quoted); } } else { - printf("ERROR [can not stat %s]\n",filename); + printf("ERROR [can not stat %s]\n", quoted); } + amfree(quoted); +#else + (void)filename; /* Quiet unused parameter warning */ #endif }