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;
109 #if defined(USE_DBMALLOC)
110 unsigned long malloc_hist_1, malloc_size_1;
111 unsigned long malloc_hist_2, malloc_size_2;
119 set_pname("selfcheck");
121 /* Don't die when child closes pipe */
122 signal(SIGPIPE, SIG_IGN);
124 #if defined(USE_DBMALLOC)
125 malloc_size_1 = malloc_inuse(&malloc_hist_1);
128 erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
129 dbopen(DBG_SUBDIR_CLIENT);
131 dbprintf(("%s: version %s\n", get_pname(), version()));
133 if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
134 amandad_auth = stralloc(argv[2]);
137 conffile = vstralloc(CONFIG_DIR, "/", "amanda-client.conf", NULL);
138 if (read_clientconf(conffile) > 0) {
139 printf("ERROR [reading conffile: %s]\n", conffile);
140 error("error reading conffile: %s", conffile);
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';
165 if(am_has_feature(g_options->features, fe_rep_options_features)) {
166 printf("features=%s;", our_feature_string);
168 if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
169 printf("hostname=%s;", g_options->hostname);
174 if (g_options->config) {
175 conffile = vstralloc(CONFIG_DIR, "/", g_options->config, "/",
176 "amanda-client.conf", NULL);
177 if (read_clientconf(conffile) > 0) {
178 printf("ERROR [reading conffile: %s]\n", conffile);
179 error("error reading conffile: %s", conffile);
184 dbrename(g_options->config, DBG_SUBDIR_CLIENT);
193 skip_whitespace(s, ch); /* find program name */
195 goto err; /* no program */
198 skip_non_whitespace(s, ch);
199 s[-1] = '\0'; /* terminate the program name */
201 program_is_backup_api = 0;
202 if(strcmp(program,"BACKUP")==0) {
203 program_is_backup_api = 1;
204 skip_whitespace(s, ch); /* find dumper name */
206 goto err; /* no program */
209 skip_non_whitespace(s, ch);
210 s[-1] = '\0'; /* terminate the program name */
213 if(strncmp_const(program, "CALCSIZE") == 0) {
214 skip_whitespace(s, ch); /* find program name */
216 goto err; /* no program */
219 skip_non_whitespace(s, ch);
226 skip_whitespace(s, ch); /* find disk name */
228 goto err; /* no disk */
231 skip_quoted_string(s, ch);
232 s[-1] = '\0'; /* terminate the disk name */
233 disk = unquote_string(qdisk);
235 skip_whitespace(s, ch); /* find the device or level */
237 goto err; /* no device or level */
239 if(!isdigit((int)s[-1])) {
241 skip_quoted_string(s, ch);
242 s[-1] = '\0'; /* terminate the device */
243 qamdevice = stralloc(fp);
244 amdevice = unquote_string(qamdevice);
245 skip_whitespace(s, ch); /* find level number */
248 amdevice = stralloc(disk);
251 /* find level number */
252 if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
253 goto err; /* bad level */
257 skip_whitespace(s, ch);
258 if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) {
259 skip_whitespace(s, ch); /* find the option string */
261 goto err; /* bad options string */
264 skip_quoted_string(s, ch);
265 s[-1] = '\0'; /* terminate the options */
266 options = parse_options(optstr, disk, amdevice, g_options->features, 1);
268 check_options(program, calcprog, disk, amdevice, options);
269 check_disk(program, calcprog, disk, amdevice, level, options);
271 free_sl(options->exclude_file);
272 free_sl(options->exclude_list);
273 free_sl(options->include_file);
274 free_sl(options->include_list);
275 amfree(options->auth);
276 amfree(options->str);
278 } else if (ch == '\0') {
279 /* check all since no option */
292 need_compress_path=1;
295 check_disk(program, calcprog, disk, amdevice, level, NULL);
298 goto err; /* bad syntax */
307 amfree(our_feature_string);
308 am_release_feature_set(our_features);
310 am_release_feature_set(g_options->features);
311 g_options->features = NULL;
312 amfree(g_options->str);
313 amfree(g_options->hostname);
316 #if defined(USE_DBMALLOC)
317 malloc_size_2 = malloc_inuse(&malloc_hist_2);
319 if(malloc_size_1 != malloc_size_2) {
322 malloc_list(dbfd(), malloc_hist_1, malloc_hist_2);
330 printf("ERROR [BOGUS REQUEST PACKET]\n");
331 dbprintf(("%s: REQ packet is bogus%s%s\n",
332 debug_prefix_time(NULL),
333 err_extra ? ": " : "",
334 err_extra ? err_extra : ""));
348 char *myprogram = program;
350 if(strcmp(myprogram,"CALCSIZE") == 0) {
353 char *file_exclude = NULL;
354 char *file_include = NULL;
356 if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
357 if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
358 if(options->include_file) nb_include += options->include_file->nb_element;
359 if(options->include_list) nb_include += options->include_list->nb_element;
361 if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
362 if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
364 amfree(file_exclude);
365 amfree(file_include);
368 if (calcprog == NULL) {
369 printf("ERROR [no program name for calcsize]\n");
371 myprogram = calcprog;
375 if(strcmp(myprogram,"GNUTAR") == 0) {
377 if(amdevice[0] == '/' && amdevice[1] == '/') {
378 if(options->exclude_file && options->exclude_file->nb_element > 1) {
379 printf("ERROR [samba support only one exclude file]\n");
381 if(options->exclude_list && options->exclude_list->nb_element > 0 &&
382 options->exclude_optional==0) {
383 printf("ERROR [samba does not support exclude list]\n");
385 if(options->include_file && options->include_file->nb_element > 0) {
386 printf("ERROR [samba does not support include file]\n");
388 if(options->include_list && options->include_list->nb_element > 0 &&
389 options->include_optional==0) {
390 printf("ERROR [samba does not support include list]\n");
397 char *file_exclude = NULL;
398 char *file_include = NULL;
400 if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
401 if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
402 if(options->include_file) nb_include += options->include_file->nb_element;
403 if(options->include_list) nb_include += options->include_list->nb_element;
405 if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
406 if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
408 amfree(file_exclude);
409 amfree(file_include);
415 if(strcmp(myprogram,"DUMP") == 0) {
416 if(options->exclude_file && options->exclude_file->nb_element > 0) {
417 printf("ERROR [DUMP does not support exclude file]\n");
419 if(options->exclude_list && options->exclude_list->nb_element > 0) {
420 printf("ERROR [DUMP does not support exclude list]\n");
422 if(options->include_file && options->include_file->nb_element > 0) {
423 printf("ERROR [DUMP does not support include file]\n");
425 if(options->include_list && options->include_list->nb_element > 0) {
426 printf("ERROR [DUMP does not support include list]\n");
434 if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
441 if (options->createindex)
448 if (strcmp(amname_to_fstype(amdevice), "xfs") == 0)
455 if (options->createindex)
462 if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0)
468 if (options->createindex)
475 if (options->createindex)
479 /* AIX backup program */
481 if (options->createindex)
485 if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST)
486 || (options->compress == COMP_CUST)) {
487 need_compress_path=1;
489 if(options->auth && amandad_auth) {
490 if(strcasecmp(options->auth, amandad_auth) != 0) {
491 fprintf(stdout,"ERROR [client configured for auth=%s while server requested '%s']\n",
492 amandad_auth, options->auth);
506 char *device = stralloc("nodevice");
508 char *user_and_password = NULL;
510 char *share = NULL, *subdir = NULL;
515 char *extra_info = NULL;
516 char *myprogram = program;
517 char *qdisk = quote_string(disk);
518 char *qamdevice = quote_string(amdevice);
519 char *qdevice = NULL;
521 char number[NUM_STR_SIZE];
523 (void)level; /* Quiet unused parameter warning */
525 dbprintf(("%s: checking disk %s\n", debug_prefix_time(NULL), qdisk));
527 if(strcmp(myprogram,"CALCSIZE") == 0) {
528 if(amdevice[0] == '/' && amdevice[1] == '/') {
529 err = vstralloc("Can't use CALCSIZE for samba estimate,",
535 myprogram = calcprog;
538 if (strcmp(myprogram, "GNUTAR")==0) {
539 if(amdevice[0] == '/' && amdevice[1] == '/') {
541 int nullfd, checkerr;
547 char number[NUM_STR_SIZE];
556 parsesharename(amdevice, &share, &subdir);
558 err = stralloc2("cannot parse for share/subdir disk entry ", amdevice);
561 if ((subdir) && (SAMBA_VERSION < 2)) {
562 err = vstralloc("subdirectory specified for share '",
564 "' but samba not v2 or better",
568 if ((user_and_password = findpass(share, &domain)) == NULL) {
569 err = stralloc2("cannot find password for ", amdevice);
572 lpass = strlen(user_and_password);
573 if ((pwtext = strchr(user_and_password, '%')) == NULL) {
574 err = stralloc2("password field not \'user%pass\' for ", amdevice);
578 pwtext_len = (size_t)strlen(pwtext);
580 if ((device = makesharename(share, 0)) == NULL) {
581 err = stralloc2("cannot make share name of ", share);
585 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
586 err = stralloc2("Cannot access /dev/null : ", strerror(errno));
590 if (pwtext_len > 0) {
591 pw_fd_env = "PASSWD_FD";
593 pw_fd_env = "dummy_PASSWD_FD";
595 checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE,
596 &nullfd, &nullfd, &checkerr,
597 pw_fd_env, &passwdfd,
600 *user_and_password ? "-U" : skip_argument,
601 *user_and_password ? user_and_password : skip_argument,
603 domain ? "-W" : skip_argument,
604 domain ? domain : skip_argument,
605 #if SAMBA_VERSION >= 2
606 subdir ? "-D" : skip_argument,
607 subdir ? subdir : skip_argument,
615 && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) {
616 err = vstralloc("password write failed: ",
625 memset(user_and_password, '\0', (size_t)lpass);
626 amfree(user_and_password);
628 ferr = fdopen(checkerr, "r");
630 printf("ERROR [Can't fdopen: %s]\n", strerror(errno));
631 error("Can't fdopen: %s", strerror(errno));
636 for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
639 strappend(extra_info, sep);
640 strappend(extra_info, line);
642 if(strstr(line, "ERRDOS") != NULL) {
649 while ((wpid = wait(&retstat)) != -1) {
650 if (WIFSIGNALED(retstat)) {
652 rc = sig = WTERMSIG(retstat);
655 rc = ret = WEXITSTATUS(retstat);
660 strappend(err, "got signal ");
663 strappend(err, "returned ");
665 snprintf(number, (size_t)sizeof(number), "%d", ret);
666 strappend(err, number);
669 if (errdos != 0 || rc != 0) {
670 err = newvstralloc(err,
671 "samba access error: ",
674 extra_info ? extra_info : "",
680 err = stralloc2("This client is not configured for samba: ", qdisk);
686 device = amname_to_dirname(amdevice);
687 } else if (strcmp(myprogram, "DUMP") == 0) {
688 if(amdevice[0] == '/' && amdevice[1] == '/') {
689 err = vstralloc("The DUMP program cannot handle samba shares,",
697 if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
703 device = amname_to_dirname(amdevice);
709 device = amname_to_devname(amdevice);
717 else { /* program_is_backup_api==1 */
718 pid_t backup_api_pid;
719 int property_pipe[2];
720 backup_support_option_t *bsu;
722 bsu = backup_support_option(program, g_options, disk, amdevice);
724 if (pipe(property_pipe) < 0) {
725 err = vstralloc("pipe failed: ", strerror(errno), NULL);
728 fflush(stdout);fflush(stderr);
730 switch (backup_api_pid = fork()) {
732 err = vstralloc("fork failed: ", strerror(errno), NULL);
738 char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL);
740 argvchild[j++] = program;
741 argvchild[j++] = "selfcheck";
742 if (bsu->message_line == 1) {
743 argvchild[j++] = "--message";
744 argvchild[j++] = "line";
746 if (g_options->config != NULL && bsu->config == 1) {
747 argvchild[j++] = "--config";
748 argvchild[j++] = g_options->config;
750 if (g_options->hostname != NULL && bsu->host == 1) {
751 argvchild[j++] = "--host";
752 argvchild[j++] = g_options->hostname;
754 if (disk != NULL && bsu->disk == 1) {
755 argvchild[j++] = "--disk";
756 argvchild[j++] = disk;
758 argvchild[j++] = "--device";
759 argvchild[j++] = amdevice;
760 if(options && options->createindex && bsu->index_line == 1) {
761 argvchild[j++] = "--index";
762 argvchild[j++] = "line";
764 if (!options->no_record && bsu->record == 1) {
765 argvchild[j++] = "--record";
767 argvchild[j++] = NULL;
768 dup2(property_pipe[0], 0);
769 aclose(property_pipe[1]);
770 execve(cmd,argvchild,safe_env());
771 printf("ERROR [Can't execute %s: %s]\n", cmd, strerror(errno));
774 default: /* parent */
777 aclose(property_pipe[0]);
778 toolin = fdopen(property_pipe[1],"w");
780 err = vstralloc("Can't fdopen: ", strerror(errno), NULL);
783 output_tool_property(toolin, options);
786 if (waitpid(backup_api_pid, &status, 0) < 0) {
787 if (!WIFEXITED(status)) {
788 snprintf(number, SIZEOF(number), "%d",
789 (int)WTERMSIG(status));
790 err = vstralloc("Tool exited with signal ", number,
792 } else if (WEXITSTATUS(status) != 0) {
793 snprintf(number, SIZEOF(number), "%d",
794 (int)WEXITSTATUS(status));
795 err = vstralloc("Tool exited with status ", number,
798 err = stralloc("waitpid returned negative value");
805 fflush(stdout);fflush(stderr);
812 qdevice = quote_string(device);
813 dbprintf(("%s: device %s\n", debug_prefix_time(NULL), qdevice));
815 /* skip accessability test if this is an AFS entry */
816 if(strncmp_const(device, "afs:") != 0) {
817 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
818 access_result = open(device, O_RDONLY);
819 access_type = "open";
821 access_result = access(device, amode);
822 access_type = "access";
824 if(access_result == -1) {
825 err = vstralloc("could not ", access_type, " ", qdevice,
826 " (", qdisk, "): ", strerror(errno), NULL);
828 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
829 aclose(access_result);
837 if(user_and_password) {
838 memset(user_and_password, '\0', (size_t)lpass);
839 amfree(user_and_password);
844 printf("ERROR [%s]\n", err);
845 dbprintf(("%s: %s\n", debug_prefix_time(NULL), err));
848 printf("OK %s\n", qdisk);
849 dbprintf(("%s: disk %s OK\n", debug_prefix_time(NULL), qdisk));
850 printf("OK %s\n", qamdevice);
851 dbprintf(("%s: amdevice %s OK\n",
852 debug_prefix_time(NULL), qamdevice));
853 printf("OK %s\n", qdevice);
854 dbprintf(("%s: device %s OK\n", debug_prefix_time(NULL), qdevice));
857 dbprintf(("%s: extra info: %s\n", debug_prefix_time(NULL), extra_info));
865 /* XXX perhaps do something with level: read dumpdates and sanity check */
874 char *gnutar_list_dir;
875 int need_amandates = 0;
879 cmd = vstralloc(libexecdir, "/", "runtar", versionsuffix(), NULL);
880 check_file(cmd,X_OK);
887 cmd = vstralloc(libexecdir, "/", "rundump", versionsuffix(), NULL);
888 check_file(cmd,X_OK);
895 check_file(DUMP, X_OK);
897 printf("ERROR [DUMP program not available]\n");
903 check_file(RESTORE, X_OK);
905 printf("ERROR [RESTORE program not available]\n");
911 check_file(VDUMP, X_OK);
913 printf("ERROR [VDUMP program not available]\n");
917 if ( need_vrestore ) {
919 check_file(VRESTORE, X_OK);
921 printf("ERROR [VRESTORE program not available]\n");
927 check_file(XFSDUMP, F_OK);
929 printf("ERROR [XFSDUMP program not available]\n");
933 if( need_xfsrestore ) {
935 check_file(XFSRESTORE, X_OK);
937 printf("ERROR [XFSRESTORE program not available]\n");
943 check_file(VXDUMP, X_OK);
945 printf("ERROR [VXDUMP program not available]\n");
949 if( need_vxrestore ) {
951 check_file(VXRESTORE, X_OK);
953 printf("ERROR [VXRESTORE program not available]\n");
959 check_file(GNUTAR, X_OK);
961 printf("ERROR [GNUTAR program not available]\n");
964 gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
965 if (strlen(gnutar_list_dir) == 0)
966 gnutar_list_dir = NULL;
968 check_dir(gnutar_list_dir, R_OK|W_OK);
971 if (need_amandates) {
972 char *amandates_file;
973 amandates_file = getconf_str(CNF_AMANDATES);
974 check_file(amandates_file, R_OK|W_OK);
976 if( need_calcsize ) {
979 cmd = vstralloc(libexecdir, "/", "calcsize", versionsuffix(), NULL);
981 check_file(cmd, X_OK);
988 check_file(SAMBA_CLIENT, X_OK);
990 printf("ERROR [SMBCLIENT program not available]\n");
992 testfd = open("/etc/amandapass", R_OK);
994 if(fstat(testfd, &buf) == 0) {
995 if ((buf.st_mode & 0x7) != 0) {
996 printf("ERROR [/etc/amandapass is world readable!]\n");
998 printf("OK [/etc/amandapass is readable, but not by all]\n");
1001 printf("OK [unable to stat /etc/amandapass: %s]\n",
1006 printf("ERROR [unable to open /etc/amandapass: %s]\n",
1011 if (need_compress_path )
1012 check_file(COMPRESS_PATH, X_OK);
1014 if (need_dump || need_xfsdump ) {
1015 if (check_file_exist("/etc/dumpdates")) {
1016 check_file("/etc/dumpdates",
1025 if (access("/etc", R_OK|W_OK) == -1) {
1026 printf("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n", strerror(errno));
1033 if (check_file_exist("/etc/vdumpdates")) {
1034 check_file("/etc/vdumpdates", F_OK);
1038 check_access("/dev/null", R_OK|W_OK);
1039 check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
1041 #ifdef AMANDA_DBGDIR
1042 check_space(AMANDA_DBGDIR, (off_t)64); /* for amandad i/o */
1045 check_space("/etc", (off_t)64); /* for /etc/dumpdates writing */
1053 generic_fs_stats_t statp;
1054 char *quoted = quote_string(dir);
1056 if(get_fs_stats(dir, &statp) == -1) {
1057 printf("ERROR [cannot statfs %s: %s]\n", quoted, strerror(errno));
1058 } else if(statp.avail < kbytes) {
1059 printf("ERROR [dir %s needs " OFF_T_FMT "KB, only has "
1060 OFF_T_FMT "KB available.]\n", quoted,
1061 (OFF_T_FMT_TYPE)kbytes,
1062 (OFF_T_FMT_TYPE)statp.avail);
1064 printf("OK %s has more than " OFF_T_FMT " KB available.\n",
1065 quoted, (OFF_T_FMT_TYPE)kbytes);
1075 char *noun, *adjective;
1076 char *quoted = quote_string(filename);
1079 noun = "find", adjective = "exists";
1080 else if((mode & X_OK) == X_OK)
1081 noun = "execute", adjective = "executable";
1082 else if((mode & (W_OK|R_OK)) == (W_OK|R_OK))
1083 noun = "read/write", adjective = "read/writable";
1085 noun = "access", adjective = "accessible";
1087 if(access(filename, mode) == -1)
1088 printf("ERROR [can not %s %s: %s]\n", noun, quoted, strerror(errno));
1090 printf("OK %s %s\n", quoted, adjective);
1098 struct stat stat_buf;
1100 if (stat(filename, &stat_buf) != 0) {
1101 if(errno == ENOENT) {
1113 struct stat stat_buf;
1116 if(!stat(filename, &stat_buf)) {
1117 if(!S_ISREG(stat_buf.st_mode)) {
1118 quoted = quote_string(filename);
1119 printf("ERROR [%s is not a file]\n", quoted);
1123 check_access(filename, mode);
1131 struct stat stat_buf;
1135 if(!stat(dirname, &stat_buf)) {
1136 if(!S_ISDIR(stat_buf.st_mode)) {
1137 quoted = quote_string(dirname);
1138 printf("ERROR [%s is not a directory]\n", quoted);
1142 dir = stralloc2(dirname, "/.");
1143 check_access(dir, mode);
1151 /* The following is only valid for real Unixs */
1152 #ifndef IGNORE_UID_CHECK
1153 struct stat stat_buf;
1154 char *quoted = quote_string(filename);
1156 if(!stat(filename, &stat_buf)) {
1157 if(stat_buf.st_uid != 0 ) {
1158 printf("ERROR [%s is not owned by root]\n", quoted);
1160 if((stat_buf.st_mode & S_ISUID) != S_ISUID) {
1161 printf("ERROR [%s is not SUID root]\n", quoted);
1165 printf("ERROR [can not stat %s]\n", quoted);
1169 (void)filename; /* Quiet unused parameter warning */