setfiles patch
The attached patch for the latest setfiles makes the usage information consistent and more accurate, it removes the unused "-p" and "-x" options, and it limits the number of messages about bad contexts to 10 when not in debug mode.
I added the limit to error messages because when I tried running setfiles on a machine without the policy loaded (something I anticipate to be a common error, and an error that may even be performed repeatedly by scripts) it took 30 seconds to display the error messages on my test machine (and also logged lots of messages via syslog).
10 error messages is enough to indicate that there is a serious problem and to allow the administrator to get busy solving the problem. More messages just wastes time and disk space without adding value IMHO. The "-d" option causes all the messages to be displayed (but maybe "-v" is more appropriate for that).
Signature · 4 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page
setfiles.c +31 -24
@@ -511,6 +511,25 @@return 0 ; } +void usage (const char *const name) +{ +fprintf (stderr, +"usage: %s [-dnqvW] spec_file pathname...\n" +"usage: %s -s [-dnqvW] spec_file\n" , name, name); +exit (1 ); +} + +static int nerr =0 ; + +void inc_err () +{ + nerr++; +if (nerr >9 && !debug) + { +fprintf (stderr,"Exiting after 10 errors.\n" ); +exit (1 ); + } +}int main (int argc,char **argv) {
@@ -518,10 +537,10 @@char buf[255 +1 ], *buf_p;char *regex, *type, *context;char *anchored_regex; -int opt, items, len, lineno, pass, nerr, regerr, i; +int opt, items, len, lineno, pass, regerr, i;/* Process any options. */ -while ((opt =getopt (argc, argv,"dnpqsvxW" )) >0 ) { +while ((opt =getopt (argc, argv,"dnqsvW" )) >0 ) {switch (opt) {case 'd' : debug =1 ;
@@ -539,33 +558,22 @@case 'v' : verbose =1 ;break ; -case 'x' : -/* now the default */ -break ;case 'W' : warn_no_match =1 ;break ;case '?' : -fprintf (stderr, -"usage: %s [-dnpqsvW] spec_file pathname...\n" , argv[0 ]); -exit (1 ); +usage (argv[0 ]); } }if (use_stdin) {if (optind != (argc -1 )) {/* Cannot mix with pathname arguments. */ -fprintf (stderr, -"usage: %s -s [-dnqvW] spec_file\n" , argv[0 ]); -exit (1 ); +usage (argv[0 ]); } }else { -if (optind > (argc -2 )) { -fprintf (stderr, -"usage: %s [-dnpqvW] spec_file pathname...\n" , - argv[0 ]); -exit (1 ); - } +if (optind > (argc -2 )) +usage (argv[0 ]); }/* Open the specification file. */
@@ -586,7 +594,6 @@for (pass =0 ; pass <2 ; pass++) { lineno =0 ; nspec =0 ; - nerr =0 ;while (fgets (buf,sizeof buf, fp)) { lineno++; len =strlen (buf);
@@ -594,7 +601,7 @@fprintf (stderr,"%s: no newline on line number %d (only read %s)\n" , argv[0 ], lineno, buf); - nerr++; +inc_err ();continue ; } buf[len -1 ] =0 ;
@@ -611,7 +618,7 @@fprintf (stderr,"%s: line number %d is missing fields (only read %s)\n" , argv[0 ], lineno, buf); - nerr++; +inc_err ();if (items ==1 )free (regex);continue ;
@@ -650,7 +657,7 @@"%s: unable to compile regular expression %s on line number %d: %s\n" , argv[0 ], regex, lineno, errbuf); - nerr++; +inc_err (); }free (anchored_regex);
@@ -664,7 +671,7 @@fprintf (stderr,"%s: invalid type specifier %s on line number %d\n" , argv[0 ], type, lineno); - nerr++; +inc_err (); goto skip_type; }switch (type[1 ]) {
@@ -693,7 +700,7 @@fprintf (stderr,"%s: invalid type specifier %s on line number %d\n" , argv[0 ], type, lineno); - nerr++; +inc_err (); } skip_type:
@@ -706,7 +713,7 @@"%s: invalid context %s on line number %d\n" , argv[0 ], context, lineno); - nerr++; +inc_err (); } }