PERFORCE change 15965 for review
Chris Vance
cvance at freebsd.org
Wed Aug 14 14:37:54 GMT 2002
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=15965
Change 15965 by cvance at cvance_laptop on 2002/08/14 07:37:43
Don't print out labeling messages unless the verbose flag is used
Also clean up lame use of argv[0] instead of programname.
Affected files ...
.. //depot/projects/trustedbsd/mac/sbin/sebsd_setfiles/setfiles.c#3 edit
Differences ...
==== //depot/projects/trustedbsd/mac/sbin/sebsd_setfiles/setfiles.c#3 (text+ko) ====
@@ -50,16 +50,14 @@
#include <flask.h>
#include <sebsd.h>
-/*
- * Program name and error message buffer.
- */
-static char errbuf[255 + 1];
+static char errbuf[255 + 1]; /* Error message buffer */
+static int verbose = 0;
/*
* A file security context specification.
*/
typedef struct spec {
- char *regex_str; /* regular expession string for diagnostic messages */
+ char *regex_str; /* regular expession string for diagnostics messages */
char *type_str; /* type string for diagnostic messages */
char *context; /* context string */
int contextlen; /* length of context string */
@@ -147,16 +145,17 @@
* But not now, just always label.
*/
- if (spec[idx].type_str) {
- printf("%s matched by (%s,%s,%s)\n",
- path, spec[idx].regex_str,
- spec[idx].type_str, spec[idx].context);
- } else {
- printf("%s matched by (%s,%s)\n",
- path, spec[idx].regex_str,
- spec[idx].context);
+ if (verbose) {
+ if (spec[idx].type_str) {
+ printf("%s matched by (%s,%s,%s)\n",
+ path, spec[idx].regex_str,
+ spec[idx].type_str, spec[idx].context);
+ } else {
+ printf("%s matched by (%s,%s)\n",
+ path, spec[idx].regex_str,
+ spec[idx].context);
+ }
}
-
if (strcmp(spec[idx].context, "<<none>>") == 0) {
printf("File %s matches spec <<none>>, Not labeling it!\n",
path);
@@ -188,26 +187,49 @@
return;
}
+void
+printUsage()
+{
+ fprintf(stderr, "Invalid Argument.\n");
+ fprintf(stderr, "sebsd_setfiles: [-v] <file_contexts> "
+ "<path_1> [<path_2> ... <path_n>]\n");
+ fprintf(stderr, " -v\tverbose reporting\n");
+}
+
int main(int argc, char **argv)
{
FILE *fp;
char buf[255 + 1], *buf_p;
char regex[1024], type[1024], context[1024];
char *anchored_regex;
- int items, len, lineno, pass, nerr, regerr;
+ int ch, items, len, lineno, pass, nerr, regerr;
char **fts_path;
FTSENT *ftsent;
FTS *fts;
- if (argc < 3) {
- fprintf(stderr, "Invalid Argument.\n");
- fprintf(stderr, "%s: <file_contexts> <path_1> [<path_2> ... <path_n>]\n", argv[0]);
+ while ((ch = getopt(argc, argv, "vh")) != -1) {
+ switch (ch) {
+ case 'v':
+ verbose = 1;
+ break;
+ case 'h':
+ case '?':
+ default:
+ printUsage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ printf("optind = %d, argc now %d\n", optind, argc);
+
+ if (argc < 2) {
+ printUsage();
return (-1);
}
- fts_path = &argv[2];
+ fts_path = &argv[1];
/* Open the specification file. */
- if ((fp = fopen(argv[1], "r")) == NULL) {
- perror(argv[1]);
+ if ((fp = fopen(argv[0], "r")) == NULL) {
+ perror(argv[0]);
exit(1);
}
@@ -228,8 +250,8 @@
len = strlen(buf);
if (buf[len - 1] != '\n') {
fprintf(stderr,
- "%s: no newline on line number %d (only read %s)\n",
- argv[0], lineno, buf);
+ "sebsd_setfiles: no newline on line number %d (only read %s)\n",
+ lineno, buf);
nerr++;
continue;
}
@@ -243,9 +265,7 @@
items =
sscanf(buf, "%s %s %s", regex, type, context);
if (items < 2) {
- fprintf(stderr,
- "%s: line number %d is missing fields (only read %s)\n",
- argv[0], lineno, buf);
+ fprintf(stderr, "sebsd_setfiles: line number %d is missing fields (only read %s)\n", lineno, buf);
nerr++;
if (items == 1)
regex[0] = '\0';
@@ -265,8 +285,7 @@
anchored_regex = malloc(len + 3);
if (!anchored_regex) {
fprintf(stderr,
- "%s: insufficient memory for anchored regexp on line %d\n",
- argv[0], lineno);
+ "sebsd_setfiles: insufficient memory for anchored regexp on line %d\n", lineno);
exit(1);
}
sprintf(anchored_regex, "^%s$", regex);
@@ -281,8 +300,7 @@
&spec[nspec].regex,
errbuf, sizeof errbuf);
fprintf(stderr,
- "%s: unable to compile regular expression %s on line number %d: %s\n",
- argv[0], regex, lineno,
+ "sebsd_setfiles: unable to compile regular expression %s on line number %d: %s\n", regex, lineno,
errbuf);
nerr++;
}
@@ -296,8 +314,7 @@
len = strlen(type);
if (type[0] != '-' || len != 2) {
fprintf(stderr,
- "%s: invalid type specifier %s on line number %d\n",
- argv[0], type, lineno);
+ "sebsd_setfiles: invalid type specifier %s on line number %d\n", type, lineno);
nerr++;
goto skip_type;
}
@@ -324,9 +341,7 @@
spec[nspec].mode = S_IFREG;
break;
default:
- fprintf(stderr,
- "%s: invalid type specifier %s on line number %d\n",
- argv[0], type, lineno);
+ fprintf(stderr, "sebsd_setfiles: invalid type specifier %s on line number %d\n", type, lineno);
nerr++;
}
@@ -365,15 +380,12 @@
exit(1);
if (pass == 0) {
- printf("%s: read %d specifications\n", argv[0],
- nspec);
+ printf("sebsd_setfiles: read %d specifications\n", nspec);
if (nspec == 0)
exit(0);
if ((spec = malloc(sizeof(spec_t) * nspec)) ==
NULL) {
- fprintf(stderr,
- "%s: insufficient memory for specifications\n",
- argv[0]);
+ fprintf(stderr,"sebsd_setfiles: insufficient memory for specifications\n");
exit(1);
}
bzero(spec, sizeof(spec_t) * nspec);
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list