From: <ssm...@us...> - 2006-10-17 14:31:16
|
Revision: 2052 http://svn.sourceforge.net/selinux/?rev=2052&view=rev Author: ssmalley Date: 2006-10-17 07:31:08 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Author: Karl MacMillan Email: kma...@me... Subject: Reworked patch for restorecon Date: Fri, 06 Oct 2006 18:09:53 -0400 This patch makes the following changes to restorecon: -i flag to tell restorecon to ignore missing files -o now takes "-" to allow it to output file list to stdout Check to make sure restorecon has at least one input file This patch is based on Dan's patch from Sep. 26 but only includes the restorecon changes (see http://marc.theaimsgroup.com/?l=selinux&m=115928447719072&w=2). Please apply. [drop change_ctr changes: sd...@ty...> Signed-off-by: Karl MacMillan <kma...@me...> Acked-by: Stephen Smalley <sd...@ty...> Modified Paths: -------------- trunk/policycoreutils/restorecon/restorecon.8 trunk/policycoreutils/restorecon/restorecon.c Modified: trunk/policycoreutils/restorecon/restorecon.8 =================================================================== --- trunk/policycoreutils/restorecon/restorecon.8 2006-10-17 14:22:47 UTC (rev 2051) +++ trunk/policycoreutils/restorecon/restorecon.8 2006-10-17 14:31:08 UTC (rev 2052) @@ -23,6 +23,9 @@ .SH "OPTIONS" .TP +.B \-i +ignore files that do not exist +.TP .B \-f infilename infilename contains a list of files to be processed by application. Use \- for stdin. .TP Modified: trunk/policycoreutils/restorecon/restorecon.c =================================================================== --- trunk/policycoreutils/restorecon/restorecon.c 2006-10-17 14:22:47 UTC (rev 2051) +++ trunk/policycoreutils/restorecon/restorecon.c 2006-10-17 14:31:08 UTC (rev 2052) @@ -11,9 +11,10 @@ * restorecon [-Rnv] pathname... * * -e Specify directory to exclude + * -i Ignore error if file does not exist * -n Do not change any file labels. * -v Show changes in file labels. - * -o filename save list of files with incorrect context + * -o filename save list of files with incorrect context * -F Force reset of context to match file_context for customizable files * * pathname... The file(s) to label @@ -47,6 +48,7 @@ static char *progname; static int errors = 0; static int recurse = 0; +static int file_exist = 1; static int force = 0; #define STAT_BLOCK_SIZE 1 static int pipe_fds[2] = { -1, -1 }; @@ -62,6 +64,7 @@ static int add_exclude(const char *directory) { struct stat sb; + size_t len = 0; if (directory == NULL || directory[0] != '/') { fprintf(stderr, "Full path required for exclude: %s.\n", directory); @@ -85,12 +88,17 @@ return 1; } - excludeArray[excludeCtr].directory = strdup(directory); - if (!excludeArray[excludeCtr].directory) { + len = strlen(directory); + while (len > 1 && directory[len - 1] == '/') { + len--; + } + excludeArray[excludeCtr].directory = strndup(directory, len); + + if (excludeArray[excludeCtr].directory == NULL) { fprintf(stderr, "Out of memory.\n"); return 1; } - excludeArray[excludeCtr++].size = strlen(directory); + excludeArray[excludeCtr++].size = len; return 0; } @@ -129,7 +137,7 @@ void usage(const char *const name) { fprintf(stderr, - "usage: %s [-FnrRv] [-e excludedir ] [-o filename ] [-f filename | pathname... ]\n", + "usage: %s [-iFnrRv] [-e excludedir ] [-o filename ] [-f filename | pathname... ]\n", name); exit(1); } @@ -160,6 +168,8 @@ } if (lstat(filename, &st) != 0) { + if (!file_exist && errno == ENOENT) + return 0; fprintf(stderr, "lstat(%s) failed: %s\n", filename, strerror(errno)); return 1; @@ -249,7 +259,8 @@ freecon(scontext); return 1; } - } + } + if (verbose) printf("%s reset %s context %s->%s\n", progname, filename, @@ -322,6 +333,8 @@ close(pipe_fds[1]); if (rc == -1 || rc > 0) { if (nftw(buf, apply_spec, 1024, FTW_PHYS)) { + if (!file_exist && errno == ENOENT) + return; fprintf(stderr, "%s: error while labeling files under %s\n", progname, buf); @@ -351,13 +364,17 @@ progname = argv[0]; if (is_selinux_enabled() <= 0) exit(0); + set_matchpathcon_flags(MATCHPATHCON_NOTRANS); - while ((opt = getopt(argc, argv, "pFrRnvf:o:e:")) > 0) { + while ((opt = getopt(argc, argv, "ipFrRnvf:o:e:")) > 0) { switch (opt) { case 'n': change = 0; break; + case 'i': + file_exist = 0; + break; case 'r': case 'R': recurse = 1; @@ -370,13 +387,18 @@ exit(1); break; case 'o': - outfile = fopen(optarg, "w"); - if (!outfile) { - fprintf(stderr, "Error opening %s: %s\n", - optarg, strerror(errno)); - usage(argv[0]); + if (strcmp(optarg, "-") == 0) + outfile = stdout; + else { + outfile = fopen(optarg, "w"); + if (!outfile) { + fprintf(stderr, + "Error opening %s: %s\n", + optarg, strerror(errno)); + usage(argv[0]); + } + __fsetlocking(outfile, FSETLOCKING_BYCALLER); } - __fsetlocking(outfile, FSETLOCKING_BYCALLER); break; case 'v': if (progress) { @@ -421,6 +443,8 @@ if (strcmp(file_name, "-") != 0) fclose(f); } else { + if (optind >= argc) + usage(argv[0]); for (i = optind; i < argc; i++) { process(argv[i]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |