PERFORCE change 18356 for review

Robert Watson rwatson at freebsd.org
Mon Sep 30 03:48:41 GMT 2002


http://people.freebsd.org/~peter/p4db/chv.cgi?CH=18356

Change 18356 by rwatson at rwatson_tislabs on 2002/09/29 20:47:41

	Teach getfmac and setfmac about the _link() versions of MAC
	label get/set calls for files.  Add '-s' argument that
	indicates if the target of a set operation is a symlink, not
	to follow the symlink and rather, relabel the symlink itself.
	In the process, teach setfmac about getopt.

Affected files ...

.. //depot/projects/trustedbsd/mac/usr.sbin/getfmac/getfmac.c#4 edit
.. //depot/projects/trustedbsd/mac/usr.sbin/setfmac/setfmac.c#4 edit

Differences ...

==== //depot/projects/trustedbsd/mac/usr.sbin/getfmac/getfmac.c#4 (text+ko) ====

@@ -15,7 +15,8 @@
 usage(void)
 {
 
-	fprintf(stderr, "getfmac [-l list,of,labels] [file1] [file2 ...]\n");
+	fprintf(stderr,
+	    "getfmac [-s] [-l list,of,labels] [file1] [file2 ...]\n");
 	exit (EX_USAGE);
 }
 
@@ -24,16 +25,21 @@
 {
 	char ch, *labellist, *string;
 	mac_t label;
+	int sflag;
 	int error, i;
 
 	labellist = NULL;
-	while ((ch = getopt(argc, argv, "l:")) != -1) {
+	sflag = 0;
+	while ((ch = getopt(argc, argv, "l:s")) != -1) {
 		switch (ch) {
 		case 'l':
 			if (labellist != NULL)
 				usage();
 			labellist = argv[optind - 1];
 			break;
+		case 's':
+			sflag = 1;
+			break;
 		default:
 			usage();
 		}
@@ -51,7 +57,10 @@
 			return (-1);
 		}
 
-		error = mac_get_file(argv[i], label);
+		if (sflag)
+			error = mac_get_link(argv[i], label);
+		else
+			error = mac_get_file(argv[i], label);
 		if (error) {
 			perror(argv[i]);
 			mac_free(label);

==== //depot/projects/trustedbsd/mac/usr.sbin/setfmac/setfmac.c#4 (text+ko) ====

@@ -15,27 +15,46 @@
 usage(void)
 {
 
-	fprintf(stderr, "setfmac [label] [file1] [file2 ...]\n");
+	fprintf(stderr, "setfmac [-s] [label] [file1] [file2 ...]\n");
 	exit (EX_USAGE);
 }
 
 int
 main(int argc, char *argv[])
 {
+	char ch;
 	mac_t label;
+	int sflag;
 	int error, i;
 
-	if (argc < 3)
+	sflag = 0;
+	while ((ch = getopt(argc, argv, "s")) != -1) {
+		switch (ch) {
+		case 's':
+			sflag = 1;
+			break;
+		default:
+			usage();
+		}
+	}
+
+	argv += optind;
+	argc -= optind;
+
+	if (argc < 2)
 		usage();
 
-	error = mac_from_text(&label, argv[1]);
+	error = mac_from_text(&label, argv[0]);
 	if (error != MAC_SUCCESS) {
 		fprintf(stderr, "mac_from_text: %s\n", mac_error(error));
 		return (-1);
 	}
 
-	for (i = 2; i < argc; i++) {
-		error = mac_set_file(argv[i], label);
+	for (i = 1; i < argc; i++) {
+		if (sflag)
+			error = mac_set_link(argv[i], label);
+		else
+			error = mac_set_file(argv[i], label);
 		if (error) {
 			perror(argv[i]);
 			return (-1);
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