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"
57 int need_xfsrestore=0;
62 int need_compress_path=0;
64 int program_is_backup_api=0;
66 static char *amandad_auth = NULL;
67 static am_feature_t *our_features = NULL;
68 static char *our_feature_string = NULL;
69 static g_option_t *g_options = NULL;
72 int main(int argc, char **argv);
74 static void check_options(char *program, char *calcprog, char *disk, char *amdevice, option_t *options);
75 static void check_disk(char *program, char *calcprog, char *disk, char *amdevice, int level, option_t *options);
76 static void check_overall(void);
77 static void check_access(char *filename, int mode);
78 static int check_file_exist(char *filename);
79 static void check_file(char *filename, int mode);
80 static void check_dir(char *dirname, int mode);
81 static void check_suid(char *filename);
82 static void check_space(char *dir, off_t kbytes);
92 char *calcprog = NULL;
95 char *amdevice = NULL;
96 char *qamdevice = NULL;
98 char *err_extra = NULL;
106 * Configure program for internationalization:
107 * 1) Only set the message locale for now.
108 * 2) Set textdomain for all amanda related programs to "amanda"
109 * We don't want to be forced to support dozens of message catalogs.
111 setlocale(LC_MESSAGES, "C");
112 textdomain("amanda");
117 set_pname("selfcheck");
119 /* Don't die when child closes pipe */
120 signal(SIGPIPE, SIG_IGN);
122 erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
123 dbopen(DBG_SUBDIR_CLIENT);
125 dbprintf(_("version %s\n"), version());
127 if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
128 amandad_auth = stralloc(argv[2]);
131 config_init(CONFIG_INIT_CLIENT, NULL);
133 check_running_as(RUNNING_AS_CLIENT_LOGIN);
135 our_features = am_init_feature_set();
136 our_feature_string = am_feature_to_string(our_features);
138 /* handle all service requests */
141 for(; (line = agets(stdin)) != NULL; free(line)) {
146 if(strncmp_const(line, "OPTIONS ") == 0) {
147 g_options = parse_g_options(line+8, 1);
148 if(!g_options->hostname) {
149 g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1);
150 gethostname(g_options->hostname, MAX_HOSTNAME_LENGTH);
151 g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0';
154 g_printf("OPTIONS ");
155 if(am_has_feature(g_options->features, fe_rep_options_features)) {
156 g_printf("features=%s;", our_feature_string);
158 if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
159 g_printf("hostname=%s;", g_options->hostname);
164 if (g_options->config) {
165 /* overlay this configuration on the existing (nameless) configuration */
166 config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
169 dbrename(config_name, DBG_SUBDIR_CLIENT);
178 skip_whitespace(s, ch); /* find program name */
180 goto err; /* no program */
183 skip_non_whitespace(s, ch);
184 s[-1] = '\0'; /* terminate the program name */
186 program_is_backup_api = 0;
187 if(strcmp(program,"BACKUP")==0) {
188 program_is_backup_api = 1;
189 skip_whitespace(s, ch); /* find dumper name */
191 goto err; /* no program */
194 skip_non_whitespace(s, ch);
195 s[-1] = '\0'; /* terminate the program name */
198 if(strncmp_const(program, "CALCSIZE") == 0) {
199 skip_whitespace(s, ch); /* find program name */
201 goto err; /* no program */
204 skip_non_whitespace(s, ch);
211 skip_whitespace(s, ch); /* find disk name */
213 goto err; /* no disk */
216 skip_quoted_string(s, ch);
217 s[-1] = '\0'; /* terminate the disk name */
218 disk = unquote_string(qdisk);
220 skip_whitespace(s, ch); /* find the device or level */
222 goto err; /* no device or level */
224 if(!isdigit((int)s[-1])) {
226 skip_quoted_string(s, ch);
227 s[-1] = '\0'; /* terminate the device */
228 qamdevice = stralloc(fp);
229 amdevice = unquote_string(qamdevice);
230 skip_whitespace(s, ch); /* find level number */
233 amdevice = stralloc(disk);
236 /* find level number */
237 if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
238 goto err; /* bad level */
242 skip_whitespace(s, ch);
243 if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) {
244 skip_whitespace(s, ch); /* find the option string */
246 goto err; /* bad options string */
249 skip_quoted_string(s, ch);
250 s[-1] = '\0'; /* terminate the options */
251 options = parse_options(optstr, disk, amdevice, g_options->features, 1);
253 check_options(program, calcprog, disk, amdevice, options);
254 check_disk(program, calcprog, disk, amdevice, level, options);
256 free_sl(options->exclude_file);
257 free_sl(options->exclude_list);
258 free_sl(options->include_file);
259 free_sl(options->include_list);
260 amfree(options->auth);
261 amfree(options->str);
263 } else if (ch == '\0') {
264 /* check all since no option */
277 need_compress_path=1;
280 check_disk(program, calcprog, disk, amdevice, level, NULL);
283 goto err; /* bad syntax */
289 if (g_options == NULL) {
290 printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
291 error(_("Missing OPTIONS line in selfcheck input\n"));
298 amfree(our_feature_string);
299 am_release_feature_set(our_features);
301 free_g_options(g_options);
307 g_printf(_("ERROR [BOGUS REQUEST PACKET]\n"));
308 dbprintf(_("REQ packet is bogus%s%s\n"),
309 err_extra ? ": " : "",
310 err_extra ? err_extra : "");
324 char *myprogram = program;
326 if(strcmp(myprogram,"CALCSIZE") == 0) {
329 char *file_exclude = NULL;
330 char *file_include = NULL;
332 if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
333 if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
334 if(options->include_file) nb_include += options->include_file->nb_element;
335 if(options->include_list) nb_include += options->include_list->nb_element;
337 if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
338 if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
340 amfree(file_exclude);
341 amfree(file_include);
344 if (calcprog == NULL) {
345 g_printf(_("ERROR [no program name for calcsize]\n"));
347 myprogram = calcprog;
351 if(strcmp(myprogram,"GNUTAR") == 0) {
353 if(amdevice[0] == '/' && amdevice[1] == '/') {
354 if(options->exclude_file && options->exclude_file->nb_element > 1) {
355 g_printf(_("ERROR [samba support only one exclude file]\n"));
357 if(options->exclude_list && options->exclude_list->nb_element > 0 &&
358 options->exclude_optional==0) {
359 g_printf(_("ERROR [samba does not support exclude list]\n"));
361 if(options->include_file && options->include_file->nb_element > 0) {
362 g_printf(_("ERROR [samba does not support include file]\n"));
364 if(options->include_list && options->include_list->nb_element > 0 &&
365 options->include_optional==0) {
366 g_printf(_("ERROR [samba does not support include list]\n"));
373 char *file_exclude = NULL;
374 char *file_include = NULL;
376 if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
377 if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
378 if(options->include_file) nb_include += options->include_file->nb_element;
379 if(options->include_list) nb_include += options->include_list->nb_element;
381 if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
382 if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
384 amfree(file_exclude);
385 amfree(file_include);
391 if(strcmp(myprogram,"DUMP") == 0) {
392 if(options->exclude_file && options->exclude_file->nb_element > 0) {
393 g_printf(_("ERROR [DUMP does not support exclude file]\n"));
395 if(options->exclude_list && options->exclude_list->nb_element > 0) {
396 g_printf(_("ERROR [DUMP does not support exclude list]\n"));
398 if(options->include_file && options->include_file->nb_element > 0) {
399 g_printf(_("ERROR [DUMP does not support include file]\n"));
401 if(options->include_list && options->include_list->nb_element > 0) {
402 g_printf(_("ERROR [DUMP does not support include list]\n"));
410 if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
417 if (options->createindex)
424 if (strcmp(amname_to_fstype(amdevice), "xfs") == 0)
431 if (options->createindex)
438 if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0)
444 if (options->createindex)
451 if (options->createindex)
455 /* AIX backup program */
457 if (options->createindex)
461 if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST)
462 || (options->compress == COMP_CUST)) {
463 need_compress_path=1;
465 if(options->auth && amandad_auth) {
466 if(strcasecmp(options->auth, amandad_auth) != 0) {
467 g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
468 amandad_auth, options->auth);
469 if(strcmp(options->auth, "ssh") == 0) {
470 g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
471 "should be \"--auth=ssh\", or use another auth "
475 g_fprintf(stderr, _("ERROR [The auth in the inetd/xinetd configuration "
476 " must be the same as the DLE]\n"));
491 char *device = stralloc("nodevice");
493 char *user_and_password = NULL;
495 char *share = NULL, *subdir = NULL;
500 char *extra_info = NULL;
501 char *myprogram = program;
502 char *qdisk = quote_string(disk);
503 char *qamdevice = quote_string(amdevice);
504 char *qdevice = NULL;
507 (void)level; /* Quiet unused parameter warning */
509 dbprintf(_("checking disk %s\n"), qdisk);
511 if(strcmp(myprogram,"CALCSIZE") == 0) {
512 if(amdevice[0] == '/' && amdevice[1] == '/') {
513 err = vstrallocf(_("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
517 if (calcprog == NULL) {
518 err = _("no program for calcsize");
521 myprogram = calcprog;
524 if (strcmp(myprogram, "GNUTAR")==0) {
525 if(amdevice[0] == '/' && amdevice[1] == '/') {
527 int nullfd, checkerr;
541 parsesharename(amdevice, &share, &subdir);
543 err = vstrallocf(_("cannot parse for share/subdir disk entry %s"), amdevice);
546 if ((subdir) && (SAMBA_VERSION < 2)) {
547 err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
551 if ((user_and_password = findpass(share, &domain)) == NULL) {
552 err = vstrallocf(_("cannot find password for %s"), amdevice);
555 lpass = strlen(user_and_password);
556 if ((pwtext = strchr(user_and_password, '%')) == NULL) {
557 err = vstrallocf(_("password field not \'user%%pass\' for %s"), amdevice);
561 pwtext_len = (size_t)strlen(pwtext);
563 if ((device = makesharename(share, 0)) == NULL) {
564 err = vstrallocf(_("cannot make share name of %s"), share);
568 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
569 err = vstrallocf(_("Cannot access /dev/null : %s"), strerror(errno));
573 if (pwtext_len > 0) {
574 pw_fd_env = "PASSWD_FD";
576 pw_fd_env = "dummy_PASSWD_FD";
578 checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE,
579 &nullfd, &nullfd, &checkerr,
580 pw_fd_env, &passwdfd,
583 *user_and_password ? "-U" : skip_argument,
584 *user_and_password ? user_and_password : skip_argument,
586 domain ? "-W" : skip_argument,
587 domain ? domain : skip_argument,
588 #if SAMBA_VERSION >= 2
589 subdir ? "-D" : skip_argument,
590 subdir ? subdir : skip_argument,
598 && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) {
599 err = vstrallocf(_("password write failed: %s: %s"),
600 amdevice, strerror(errno));
605 memset(user_and_password, '\0', (size_t)lpass);
606 amfree(user_and_password);
608 ferr = fdopen(checkerr, "r");
610 g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
611 error(_("Can't fdopen: %s"), strerror(errno));
616 for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
619 strappend(extra_info, sep);
620 strappend(extra_info, line);
622 if(strstr(line, "ERRDOS") != NULL) {
630 while ((wpid = wait(&retstat)) != -1) {
631 if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
632 char *exitstr = str_exit_status("smbclient", retstat);
633 err = newvstralloc(err, err, sep, exitstr);
640 if (errdos != 0 || rc != 0) {
642 err = newvstrallocf(err,
643 _("samba access error: %s: %s %s"),
644 amdevice, extra_info, err);
647 err = newvstrallocf(err, _("samba access error: %s: %s"),
652 err = vstrallocf(_("This client is not configured for samba: %s"),
659 device = amname_to_dirname(amdevice);
660 } else if (strcmp(myprogram, "DUMP") == 0) {
661 if(amdevice[0] == '/' && amdevice[1] == '/') {
663 _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
669 if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
675 device = amname_to_dirname(amdevice);
681 device = amname_to_devname(amdevice);
689 else { /* program_is_backup_api==1 */
690 pid_t backup_api_pid;
691 int property_pipe[2];
692 backup_support_option_t *bsu;
694 bsu = backup_support_option(program, g_options, disk, amdevice);
696 if (pipe(property_pipe) < 0) {
697 err = vstrallocf(_("pipe failed: %s"), strerror(errno));
700 fflush(stdout);fflush(stderr);
702 switch (backup_api_pid = fork()) {
704 err = vstrallocf(_("fork failed: %s"), strerror(errno));
710 char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL);
712 argvchild[j++] = program;
713 argvchild[j++] = "selfcheck";
714 if (bsu->message_line == 1) {
715 argvchild[j++] = "--message";
716 argvchild[j++] = "line";
718 if (g_options->config != NULL && bsu->config == 1) {
719 argvchild[j++] = "--config";
720 argvchild[j++] = g_options->config;
722 if (g_options->hostname != NULL && bsu->host == 1) {
723 argvchild[j++] = "--host";
724 argvchild[j++] = g_options->hostname;
726 if (disk != NULL && bsu->disk == 1) {
727 argvchild[j++] = "--disk";
728 argvchild[j++] = disk;
730 argvchild[j++] = "--device";
731 argvchild[j++] = amdevice;
732 if(options && options->createindex && bsu->index_line == 1) {
733 argvchild[j++] = "--index";
734 argvchild[j++] = "line";
736 if (!options->no_record && bsu->record == 1) {
737 argvchild[j++] = "--record";
739 argvchild[j++] = NULL;
740 dup2(property_pipe[0], 0);
741 aclose(property_pipe[1]);
743 execve(cmd,argvchild,safe_env());
744 g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
747 default: /* parent */
750 aclose(property_pipe[0]);
751 toolin = fdopen(property_pipe[1],"w");
753 err = vstrallocf(_("Can't fdopen: %s"), strerror(errno));
756 output_tool_property(toolin, options);
759 if (waitpid(backup_api_pid, &status, 0) < 0) {
760 if (!WIFEXITED(status)) {
761 err = vstrallocf(_("Tool exited with signal %d"),
763 } else if (WEXITSTATUS(status) != 0) {
764 err = vstrallocf(_("Tool exited with status %d"),
765 WEXITSTATUS(status));
767 err = vstrallocf(_("waitpid returned negative value"));
774 fflush(stdout);fflush(stderr);
781 qdevice = quote_string(device);
782 dbprintf(_("device %s\n"), qdevice);
784 /* skip accessability test if this is an AFS entry */
785 if(strncmp_const(device, "afs:") != 0) {
786 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
787 access_result = open(device, O_RDONLY);
788 access_type = "open";
790 access_result = access(device, amode);
791 access_type = "access";
793 if(access_result == -1) {
794 err = vstrallocf(_("Could not access %s (%s): %s"),
795 qdevice, qdisk, strerror(errno));
797 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
798 aclose(access_result);
806 if(user_and_password) {
807 memset(user_and_password, '\0', (size_t)lpass);
808 amfree(user_and_password);
813 g_printf(_("ERROR [%s]\n"), err);
814 dbprintf(_("%s\n"), err);
817 g_printf("OK %s\n", qdisk);
818 dbprintf(_("disk %s OK\n"), qdisk);
819 g_printf("OK %s\n", qamdevice);
820 dbprintf(_("amdevice %s OK\n"), qamdevice);
821 g_printf("OK %s\n", qdevice);
822 dbprintf(_("device %s OK\n"), qdevice);
825 dbprintf(_("extra info: %s\n"), extra_info);
833 /* XXX perhaps do something with level: read dumpdates and sanity check */
842 char *gnutar_list_dir;
843 int need_amandates = 0;
847 cmd = vstralloc(amlibexecdir, "/", "runtar", versionsuffix(), NULL);
848 check_file(cmd,X_OK);
855 cmd = vstralloc(amlibexecdir, "/", "rundump", versionsuffix(), NULL);
856 check_file(cmd,X_OK);
863 check_file(DUMP, X_OK);
865 g_printf(_("ERROR [DUMP program not available]\n"));
871 check_file(RESTORE, X_OK);
873 g_printf(_("ERROR [RESTORE program not available]\n"));
879 check_file(VDUMP, X_OK);
881 g_printf(_("ERROR [VDUMP program not available]\n"));
885 if ( need_vrestore ) {
887 check_file(VRESTORE, X_OK);
889 g_printf(_("ERROR [VRESTORE program not available]\n"));
895 check_file(XFSDUMP, F_OK);
897 g_printf(_("ERROR [XFSDUMP program not available]\n"));
901 if( need_xfsrestore ) {
903 check_file(XFSRESTORE, X_OK);
905 g_printf(_("ERROR [XFSRESTORE program not available]\n"));
911 check_file(VXDUMP, X_OK);
913 g_printf(_("ERROR [VXDUMP program not available]\n"));
917 if( need_vxrestore ) {
919 check_file(VXRESTORE, X_OK);
921 g_printf(_("ERROR [VXRESTORE program not available]\n"));
927 check_file(GNUTAR, X_OK);
929 g_printf(_("ERROR [GNUTAR program not available]\n"));
932 gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
933 if (strlen(gnutar_list_dir) == 0)
934 gnutar_list_dir = NULL;
936 check_dir(gnutar_list_dir, R_OK|W_OK);
939 if (need_amandates) {
940 char *amandates_file;
941 amandates_file = getconf_str(CNF_AMANDATES);
942 check_file(amandates_file, R_OK|W_OK);
944 if( need_calcsize ) {
947 cmd = vstralloc(amlibexecdir, "/", "calcsize", versionsuffix(), NULL);
949 check_file(cmd, X_OK);
956 check_file(SAMBA_CLIENT, X_OK);
958 g_printf(_("ERROR [SMBCLIENT program not available]\n"));
960 testfd = open("/etc/amandapass", R_OK);
962 if(fstat(testfd, &buf) == 0) {
963 if ((buf.st_mode & 0x7) != 0) {
964 g_printf(_("ERROR [/etc/amandapass is world readable!]\n"));
966 g_printf(_("OK [/etc/amandapass is readable, but not by all]\n"));
969 g_printf(_("OK [unable to stat /etc/amandapass: %s]\n"),
974 g_printf(_("ERROR [unable to open /etc/amandapass: %s]\n"),
979 if (need_compress_path )
980 check_file(COMPRESS_PATH, X_OK);
982 if (need_dump || need_xfsdump ) {
983 if (check_file_exist("/etc/dumpdates")) {
984 check_file("/etc/dumpdates",
993 if (access("/etc", R_OK|W_OK) == -1) {
994 g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
1001 if (check_file_exist("/etc/vdumpdates")) {
1002 check_file("/etc/vdumpdates", F_OK);
1006 check_access("/dev/null", R_OK|W_OK);
1007 check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
1009 #ifdef AMANDA_DBGDIR
1010 check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
1013 check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
1021 struct fs_usage fsusage;
1022 char *quoted = quote_string(dir);
1025 if(get_fs_usage(dir, NULL, &fsusage) == -1) {
1026 g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
1031 /* do the division first to avoid potential integer overflow */
1032 kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;
1034 if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
1035 g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
1037 } else if (kb_avail < kbytes) {
1038 g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
1040 (long long)kb_avail);
1042 g_printf(_("OK %s has more than %lldKB available.\n"),
1043 quoted, (long long)kbytes);
1053 char *noun, *adjective;
1054 char *quoted = quote_string(filename);
1057 noun = "find", adjective = "exists";
1058 else if((mode & X_OK) == X_OK)
1059 noun = "execute", adjective = "executable";
1060 else if((mode & (W_OK|R_OK)) == (W_OK|R_OK))
1061 noun = "read/write", adjective = "read/writable";
1063 noun = "access", adjective = "accessible";
1065 if(access(filename, mode) == -1)
1066 g_printf(_("ERROR [can not %s %s: %s]\n"), noun, quoted, strerror(errno));
1068 g_printf(_("OK %s %s\n"), quoted, adjective);
1076 struct stat stat_buf;
1078 if (stat(filename, &stat_buf) != 0) {
1079 if(errno == ENOENT) {
1091 struct stat stat_buf;
1094 if(!stat(filename, &stat_buf)) {
1095 if(!S_ISREG(stat_buf.st_mode)) {
1096 quoted = quote_string(filename);
1097 g_printf(_("ERROR [%s is not a file]\n"), quoted);
1101 check_access(filename, mode);
1109 struct stat stat_buf;
1113 if(!stat(dirname, &stat_buf)) {
1114 if(!S_ISDIR(stat_buf.st_mode)) {
1115 quoted = quote_string(dirname);
1116 g_printf(_("ERROR [%s is not a directory]\n"), quoted);
1120 dir = stralloc2(dirname, "/.");
1121 check_access(dir, mode);
1129 #ifndef SINGLE_USERID
1130 struct stat stat_buf;
1131 char *quoted = quote_string(filename);
1133 if(!stat(filename, &stat_buf)) {
1134 if(stat_buf.st_uid != 0 ) {
1135 g_printf(_("ERROR [%s is not owned by root]\n"), quoted);
1137 if((stat_buf.st_mode & S_ISUID) != S_ISUID) {
1138 g_printf(_("ERROR [%s is not SUID root]\n"), quoted);
1142 g_printf(_("ERROR [can not stat %s]\n"), quoted);
1146 (void)filename; /* Quiet unused parameter warning */