2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: selfcheck.c,v 1.95 2006/08/29 11:21:00 martinea Exp $
30 * 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"
50 #define selfcheck_debug(i,x) do { \
51 if ((i) <= debug_selfcheck) { \
63 int need_xfsrestore=0;
68 int need_compress_path=0;
70 int program_is_backup_api=0;
72 static char *amandad_auth = NULL;
73 static am_feature_t *our_features = NULL;
74 static char *our_feature_string = NULL;
75 static g_option_t *g_options = NULL;
78 int main(int argc, char **argv);
80 static void check_options(char *program, char *calcprog, char *disk, char *amdevice, option_t *options);
81 static void check_disk(char *program, char *calcprog, char *disk, char *amdevice, int level, option_t *options);
82 static void check_overall(void);
83 static void check_access(char *filename, int mode);
84 static int check_file_exist(char *filename);
85 static void check_file(char *filename, int mode);
86 static void check_dir(char *dirname, int mode);
87 static void check_suid(char *filename);
88 static void check_space(char *dir, off_t kbytes);
98 char *calcprog = NULL;
101 char *amdevice = NULL;
102 char *qamdevice = NULL;
104 char *err_extra = NULL;
112 * Configure program for internationalization:
113 * 1) Only set the message locale for now.
114 * 2) Set textdomain for all amanda related programs to "amanda"
115 * We don't want to be forced to support dozens of message catalogs.
117 setlocale(LC_MESSAGES, "C");
118 textdomain("amanda");
123 set_pname("selfcheck");
125 /* Don't die when child closes pipe */
126 signal(SIGPIPE, SIG_IGN);
128 #if defined(USE_DBMALLOC)
129 malloc_size_1 = malloc_inuse(&malloc_hist_1);
132 erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
133 dbopen(DBG_SUBDIR_CLIENT);
135 dbprintf(_("version %s\n"), version());
137 if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
138 amandad_auth = stralloc(argv[2]);
141 config_init(CONFIG_INIT_CLIENT, NULL);
143 check_running_as(RUNNING_AS_CLIENT_LOGIN);
145 our_features = am_init_feature_set();
146 our_feature_string = am_feature_to_string(our_features);
148 /* handle all service requests */
151 for(; (line = agets(stdin)) != NULL; free(line)) {
156 if(strncmp_const(line, "OPTIONS ") == 0) {
157 g_options = parse_g_options(line+8, 1);
158 if(!g_options->hostname) {
159 g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1);
160 gethostname(g_options->hostname, MAX_HOSTNAME_LENGTH);
161 g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0';
164 g_printf("OPTIONS ");
165 if(am_has_feature(g_options->features, fe_rep_options_features)) {
166 g_printf("features=%s;", our_feature_string);
168 if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
169 g_printf("hostname=%s;", g_options->hostname);
174 if (g_options->config) {
175 /* overlay this configuration on the existing (nameless) configuration */
176 config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
179 dbrename(config_name, DBG_SUBDIR_CLIENT);
188 skip_whitespace(s, ch); /* find program name */
190 goto err; /* no program */
193 skip_non_whitespace(s, ch);
194 s[-1] = '\0'; /* terminate the program name */
196 program_is_backup_api = 0;
197 if(strcmp(program,"BACKUP")==0) {
198 program_is_backup_api = 1;
199 skip_whitespace(s, ch); /* find dumper name */
201 goto err; /* no program */
204 skip_non_whitespace(s, ch);
205 s[-1] = '\0'; /* terminate the program name */
208 if(strncmp_const(program, "CALCSIZE") == 0) {
209 skip_whitespace(s, ch); /* find program name */
211 goto err; /* no program */
214 skip_non_whitespace(s, ch);
221 skip_whitespace(s, ch); /* find disk name */
223 goto err; /* no disk */
226 skip_quoted_string(s, ch);
227 s[-1] = '\0'; /* terminate the disk name */
228 disk = unquote_string(qdisk);
230 skip_whitespace(s, ch); /* find the device or level */
232 goto err; /* no device or level */
234 if(!isdigit((int)s[-1])) {
236 skip_quoted_string(s, ch);
237 s[-1] = '\0'; /* terminate the device */
238 qamdevice = stralloc(fp);
239 amdevice = unquote_string(qamdevice);
240 skip_whitespace(s, ch); /* find level number */
243 amdevice = stralloc(disk);
246 /* find level number */
247 if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
248 goto err; /* bad level */
252 skip_whitespace(s, ch);
253 if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) {
254 skip_whitespace(s, ch); /* find the option string */
256 goto err; /* bad options string */
259 skip_quoted_string(s, ch);
260 s[-1] = '\0'; /* terminate the options */
261 options = parse_options(optstr, disk, amdevice, g_options->features, 1);
263 check_options(program, calcprog, disk, amdevice, options);
264 check_disk(program, calcprog, disk, amdevice, level, options);
266 free_sl(options->exclude_file);
267 free_sl(options->exclude_list);
268 free_sl(options->include_file);
269 free_sl(options->include_list);
270 amfree(options->auth);
271 amfree(options->str);
273 } else if (ch == '\0') {
274 /* check all since no option */
287 need_compress_path=1;
290 check_disk(program, calcprog, disk, amdevice, level, NULL);
293 goto err; /* bad syntax */
299 if (g_options == NULL) {
300 printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
301 error(_("Missing OPTIONS line in selfcheck input\n"));
308 amfree(our_feature_string);
309 am_release_feature_set(our_features);
311 free_g_options(g_options);
317 g_printf(_("ERROR [BOGUS REQUEST PACKET]\n"));
318 dbprintf(_("REQ packet is bogus%s%s\n"),
319 err_extra ? ": " : "",
320 err_extra ? err_extra : "");
334 char *myprogram = program;
336 if(strcmp(myprogram,"CALCSIZE") == 0) {
339 char *file_exclude = NULL;
340 char *file_include = NULL;
342 if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
343 if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
344 if(options->include_file) nb_include += options->include_file->nb_element;
345 if(options->include_list) nb_include += options->include_list->nb_element;
347 if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
348 if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
350 amfree(file_exclude);
351 amfree(file_include);
354 if (calcprog == NULL) {
355 g_printf(_("ERROR [no program name for calcsize]\n"));
357 myprogram = calcprog;
361 if(strcmp(myprogram,"GNUTAR") == 0) {
363 if(amdevice[0] == '/' && amdevice[1] == '/') {
364 if(options->exclude_file && options->exclude_file->nb_element > 1) {
365 g_printf(_("ERROR [samba support only one exclude file]\n"));
367 if(options->exclude_list && options->exclude_list->nb_element > 0 &&
368 options->exclude_optional==0) {
369 g_printf(_("ERROR [samba does not support exclude list]\n"));
371 if(options->include_file && options->include_file->nb_element > 0) {
372 g_printf(_("ERROR [samba does not support include file]\n"));
374 if(options->include_list && options->include_list->nb_element > 0 &&
375 options->include_optional==0) {
376 g_printf(_("ERROR [samba does not support include list]\n"));
383 char *file_exclude = NULL;
384 char *file_include = NULL;
386 if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
387 if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
388 if(options->include_file) nb_include += options->include_file->nb_element;
389 if(options->include_list) nb_include += options->include_list->nb_element;
391 if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
392 if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
394 amfree(file_exclude);
395 amfree(file_include);
401 if(strcmp(myprogram,"DUMP") == 0) {
402 if(options->exclude_file && options->exclude_file->nb_element > 0) {
403 g_printf(_("ERROR [DUMP does not support exclude file]\n"));
405 if(options->exclude_list && options->exclude_list->nb_element > 0) {
406 g_printf(_("ERROR [DUMP does not support exclude list]\n"));
408 if(options->include_file && options->include_file->nb_element > 0) {
409 g_printf(_("ERROR [DUMP does not support include file]\n"));
411 if(options->include_list && options->include_list->nb_element > 0) {
412 g_printf(_("ERROR [DUMP does not support include list]\n"));
420 if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
427 if (options->createindex)
434 if (strcmp(amname_to_fstype(amdevice), "xfs") == 0)
441 if (options->createindex)
448 if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0)
454 if (options->createindex)
461 if (options->createindex)
465 /* AIX backup program */
467 if (options->createindex)
471 if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST)
472 || (options->compress == COMP_CUST)) {
473 need_compress_path=1;
475 if(options->auth && amandad_auth) {
476 if(strcasecmp(options->auth, amandad_auth) != 0) {
477 g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
478 amandad_auth, options->auth);
479 if(strcmp(options->auth, "ssh") == 0) {
480 g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
481 "should be \"--auth=ssh\", or use another auth "
485 g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration "
486 " must be the same as the DLE]\n"));
501 char *device = stralloc("nodevice");
503 char *user_and_password = NULL;
505 char *share = NULL, *subdir = NULL;
510 char *extra_info = NULL;
511 char *myprogram = program;
512 char *qdisk = quote_string(disk);
513 char *qamdevice = quote_string(amdevice);
514 char *qdevice = NULL;
517 (void)level; /* Quiet unused parameter warning */
519 dbprintf(_("checking disk %s\n"), qdisk);
521 if(strcmp(myprogram,"CALCSIZE") == 0) {
522 if(amdevice[0] == '/' && amdevice[1] == '/') {
523 err = vstrallocf(_("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
527 if (calcprog == NULL) {
528 err = _("no program for calcsize");
531 myprogram = calcprog;
534 if (strcmp(myprogram, "GNUTAR")==0) {
535 if(amdevice[0] == '/' && amdevice[1] == '/') {
537 int nullfd, checkerr;
551 parsesharename(amdevice, &share, &subdir);
553 err = vstrallocf(_("cannot parse for share/subdir disk entry %s"), amdevice);
556 if ((subdir) && (SAMBA_VERSION < 2)) {
557 err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
561 if ((user_and_password = findpass(share, &domain)) == NULL) {
562 err = vstrallocf(_("cannot find password for %s"), amdevice);
565 lpass = strlen(user_and_password);
566 if ((pwtext = strchr(user_and_password, '%')) == NULL) {
567 err = vstrallocf(_("password field not \'user%%pass\' for %s"), amdevice);
571 pwtext_len = (size_t)strlen(pwtext);
573 if ((device = makesharename(share, 0)) == NULL) {
574 err = vstrallocf(_("cannot make share name of %s"), share);
578 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
579 err = vstrallocf(_("Cannot access /dev/null : %s"), strerror(errno));
583 if (pwtext_len > 0) {
584 pw_fd_env = "PASSWD_FD";
586 pw_fd_env = "dummy_PASSWD_FD";
588 checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE,
589 &nullfd, &nullfd, &checkerr,
590 pw_fd_env, &passwdfd,
593 *user_and_password ? "-U" : skip_argument,
594 *user_and_password ? user_and_password : skip_argument,
596 domain ? "-W" : skip_argument,
597 domain ? domain : skip_argument,
598 #if SAMBA_VERSION >= 2
599 subdir ? "-D" : skip_argument,
600 subdir ? subdir : skip_argument,
608 && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) {
609 err = vstrallocf(_("password write failed: %s: %s"),
610 amdevice, strerror(errno));
615 memset(user_and_password, '\0', (size_t)lpass);
616 amfree(user_and_password);
618 ferr = fdopen(checkerr, "r");
620 g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
621 error(_("Can't fdopen: %s"), strerror(errno));
626 for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
629 strappend(extra_info, sep);
630 strappend(extra_info, line);
632 if(strstr(line, "ERRDOS") != NULL) {
640 while ((wpid = wait(&retstat)) != -1) {
641 if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
642 char *exitstr = str_exit_status("smbclient", retstat);
643 err = newvstralloc(err, err, sep, exitstr);
650 if (errdos != 0 || rc != 0) {
652 err = newvstrallocf(err,
653 _("samba access error: %s: %s %s"),
654 amdevice, extra_info, err);
657 err = newvstrallocf(err, _("samba access error: %s: %s"),
662 err = vstrallocf(_("This client is not configured for samba: %s"),
669 device = amname_to_dirname(amdevice);
670 } else if (strcmp(myprogram, "DUMP") == 0) {
671 if(amdevice[0] == '/' && amdevice[1] == '/') {
673 _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
679 if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
685 device = amname_to_dirname(amdevice);
691 device = amname_to_devname(amdevice);
699 else { /* program_is_backup_api==1 */
700 pid_t backup_api_pid;
701 int property_pipe[2];
702 backup_support_option_t *bsu;
704 bsu = backup_support_option(program, g_options, disk, amdevice);
706 if (pipe(property_pipe) < 0) {
707 err = vstrallocf(_("pipe failed: %s"), strerror(errno));
710 fflush(stdout);fflush(stderr);
712 switch (backup_api_pid = fork()) {
714 err = vstrallocf(_("fork failed: %s"), strerror(errno));
720 char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL);
722 argvchild[j++] = program;
723 argvchild[j++] = "selfcheck";
724 if (bsu->message_line == 1) {
725 argvchild[j++] = "--message";
726 argvchild[j++] = "line";
728 if (g_options->config != NULL && bsu->config == 1) {
729 argvchild[j++] = "--config";
730 argvchild[j++] = g_options->config;
732 if (g_options->hostname != NULL && bsu->host == 1) {
733 argvchild[j++] = "--host";
734 argvchild[j++] = g_options->hostname;
736 if (disk != NULL && bsu->disk == 1) {
737 argvchild[j++] = "--disk";
738 argvchild[j++] = disk;
740 argvchild[j++] = "--device";
741 argvchild[j++] = amdevice;
742 if(options && options->createindex && bsu->index_line == 1) {
743 argvchild[j++] = "--index";
744 argvchild[j++] = "line";
746 if (!options->no_record && bsu->record == 1) {
747 argvchild[j++] = "--record";
749 argvchild[j++] = NULL;
750 dup2(property_pipe[0], 0);
751 aclose(property_pipe[1]);
753 execve(cmd,argvchild,safe_env());
754 g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
757 default: /* parent */
760 aclose(property_pipe[0]);
761 toolin = fdopen(property_pipe[1],"w");
763 err = vstrallocf(_("Can't fdopen: %s"), strerror(errno));
766 output_tool_property(toolin, options);
769 if (waitpid(backup_api_pid, &status, 0) < 0) {
770 if (!WIFEXITED(status)) {
771 err = vstrallocf(_("Tool exited with signal %d"),
773 } else if (WEXITSTATUS(status) != 0) {
774 err = vstrallocf(_("Tool exited with status %d"),
775 WEXITSTATUS(status));
777 err = vstrallocf(_("waitpid returned negative value"));
784 fflush(stdout);fflush(stderr);
791 qdevice = quote_string(device);
792 dbprintf(_("device %s\n"), qdevice);
794 /* skip accessability test if this is an AFS entry */
795 if(strncmp_const(device, "afs:") != 0) {
796 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
797 access_result = open(device, O_RDONLY);
798 access_type = "open";
800 access_result = access(device, amode);
801 access_type = "access";
803 if(access_result == -1) {
804 err = vstrallocf(_("Could not access %s (%s): %s"),
805 qdevice, qdisk, strerror(errno));
807 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
808 aclose(access_result);
816 if(user_and_password) {
817 memset(user_and_password, '\0', (size_t)lpass);
818 amfree(user_and_password);
823 g_printf(_("ERROR [%s]\n"), err);
824 dbprintf(_("%s\n"), err);
827 g_printf("OK %s\n", qdisk);
828 dbprintf(_("disk %s OK\n"), qdisk);
829 g_printf("OK %s\n", qamdevice);
830 dbprintf(_("amdevice %s OK\n"), qamdevice);
831 g_printf("OK %s\n", qdevice);
832 dbprintf(_("device %s OK\n"), qdevice);
835 dbprintf(_("extra info: %s\n"), extra_info);
843 /* XXX perhaps do something with level: read dumpdates and sanity check */
852 char *gnutar_list_dir;
853 int need_amandates = 0;
857 cmd = vstralloc(amlibexecdir, "/", "runtar", versionsuffix(), NULL);
858 check_file(cmd,X_OK);
865 cmd = vstralloc(amlibexecdir, "/", "rundump", versionsuffix(), NULL);
866 check_file(cmd,X_OK);
873 check_file(DUMP, X_OK);
875 g_printf(_("ERROR [DUMP program not available]\n"));
881 check_file(RESTORE, X_OK);
883 g_printf(_("ERROR [RESTORE program not available]\n"));
889 check_file(VDUMP, X_OK);
891 g_printf(_("ERROR [VDUMP program not available]\n"));
895 if ( need_vrestore ) {
897 check_file(VRESTORE, X_OK);
899 g_printf(_("ERROR [VRESTORE program not available]\n"));
905 check_file(XFSDUMP, F_OK);
907 g_printf(_("ERROR [XFSDUMP program not available]\n"));
911 if( need_xfsrestore ) {
913 check_file(XFSRESTORE, X_OK);
915 g_printf(_("ERROR [XFSRESTORE program not available]\n"));
921 check_file(VXDUMP, X_OK);
923 g_printf(_("ERROR [VXDUMP program not available]\n"));
927 if( need_vxrestore ) {
929 check_file(VXRESTORE, X_OK);
931 g_printf(_("ERROR [VXRESTORE program not available]\n"));
937 check_file(GNUTAR, X_OK);
939 g_printf(_("ERROR [GNUTAR program not available]\n"));
942 gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
943 if (strlen(gnutar_list_dir) == 0)
944 gnutar_list_dir = NULL;
946 check_dir(gnutar_list_dir, R_OK|W_OK);
949 if (need_amandates) {
950 char *amandates_file;
951 amandates_file = getconf_str(CNF_AMANDATES);
952 check_file(amandates_file, R_OK|W_OK);
954 if( need_calcsize ) {
957 cmd = vstralloc(amlibexecdir, "/", "calcsize", versionsuffix(), NULL);
959 check_file(cmd, X_OK);
966 check_file(SAMBA_CLIENT, X_OK);
968 g_printf(_("ERROR [SMBCLIENT program not available]\n"));
970 testfd = open("/etc/amandapass", R_OK);
972 if(fstat(testfd, &buf) == 0) {
973 if ((buf.st_mode & 0x7) != 0) {
974 g_printf(_("ERROR [/etc/amandapass is world readable!]\n"));
976 g_printf(_("OK [/etc/amandapass is readable, but not by all]\n"));
979 g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"),
984 g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"),
989 if (need_compress_path )
990 check_file(COMPRESS_PATH, X_OK);
992 if (need_dump || need_xfsdump ) {
993 if (check_file_exist("/etc/dumpdates")) {
994 check_file("/etc/dumpdates",
1003 if (access("/etc", R_OK|W_OK) == -1) {
1004 g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
1011 if (check_file_exist("/etc/vdumpdates")) {
1012 check_file("/etc/vdumpdates", F_OK);
1016 check_access("/dev/null", R_OK|W_OK);
1017 check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
1019 #ifdef AMANDA_DBGDIR
1020 check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
1023 check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
1031 struct fs_usage fsusage;
1032 char *quoted = quote_string(dir);
1035 if(get_fs_usage(dir, NULL, &fsusage) == -1) {
1036 g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
1041 /* do the division first to avoid potential integer overflow */
1042 kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;
1044 if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
1045 g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
1047 } else if (kb_avail < kbytes) {
1048 g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
1050 (long long)kb_avail);
1052 g_printf(_("OK %s has more than %lldKB available.\n"),
1053 quoted, (long long)kbytes);
1063 char *noun, *adjective;
1064 char *quoted = quote_string(filename);
1067 noun = "find", adjective = "exists";
1068 else if((mode & X_OK) == X_OK)
1069 noun = "execute", adjective = "executable";
1070 else if((mode & (W_OK|R_OK)) == (W_OK|R_OK))
1071 noun = "read/write", adjective = "read/writable";
1073 noun = "access", adjective = "accessible";
1075 if(access(filename, mode) == -1)
1076 g_printf(_("ERROR [can not %s %s: %s]\n"), noun, quoted, strerror(errno));
1078 g_printf(_("OK %s %s\n"), quoted, adjective);
1086 struct stat stat_buf;
1088 if (stat(filename, &stat_buf) != 0) {
1089 if(errno == ENOENT) {
1101 struct stat stat_buf;
1104 if(!stat(filename, &stat_buf)) {
1105 if(!S_ISREG(stat_buf.st_mode)) {
1106 quoted = quote_string(filename);
1107 g_printf(_("ERROR [%s is not a file]\n"), quoted);
1111 check_access(filename, mode);
1119 struct stat stat_buf;
1123 if(!stat(dirname, &stat_buf)) {
1124 if(!S_ISDIR(stat_buf.st_mode)) {
1125 quoted = quote_string(dirname);
1126 g_printf(_("ERROR [%s is not a directory]\n"), quoted);
1130 dir = stralloc2(dirname, "/.");
1131 check_access(dir, mode);
1139 #ifndef SINGLE_USERID
1140 struct stat stat_buf;
1141 char *quoted = quote_string(filename);
1143 if(!stat(filename, &stat_buf)) {
1144 if(stat_buf.st_uid != 0 ) {
1145 g_printf(_("ERROR [%s is not owned by root]\n"), quoted);
1147 if((stat_buf.st_mode & S_ISUID) != S_ISUID) {
1148 g_printf(_("ERROR [%s is not SUID root]\n"), quoted);
1152 g_printf(_("ERROR [can not stat %s]\n"), quoted);
1156 (void)filename; /* Quiet unused parameter warning */