Skip to contentSkip to conversation

I added back in matchpathcon to libselinux rpm.

PATCH Daniel J Walsh 1 participant 1 message Apr 21, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

Some people were coming up with some interesting ways of using chcon

chcon matchpathcon -n /etc/passwd /usr/local/mypasswd

So I added -n qualifier to not display path. Also added man page.

Dan

man/man3/selinux_policy_root.3 new file +17 -0
@@ -0,0 +1,17 @@
+.TH "selinux_policy_root" "3" "25 May 2004" "[email protected]" "SE Linux API documentation"
+.SH "NAME"
+selinux_policy_root \- return the path of the SELinux policy files for this machine.
+.SH "SYNOPSIS"
+.B #include <selinux/selinux.h>
+.sp
+.B char *selinux_policy_root();
+.br
+
+.SH "DESCRIPTION"
+.B selinux_policy_root
+Reads the contents of the /etc/selinux/config file to determine which policy files should be used for this machine.
+.SH "RETURN VALUE"
+On success, returns a directory path containing the SELinux policy files.
+On failure, NULL is returned.
+
+
man/man8/matchpathcon.8 renamed from man/man8/matchpathcon.8.rhat +20 -0
@@ -0,0 +1,20 @@
+.TH "matchpathcon" "8" "21 April 2005" "[email protected]" "SE Linux Command Line documentation"
+.SH "NAME"
+matchpathcon \- get the default security context for the specified path from the file contexts configuration.
+
+.SH "SYNOPSIS"
+.B matchpathcon [-n] filepath...
+
+.SH "DESCRIPTION"
+.B matchpathcon
+Prints the file path and the default security context associated with it.
+.br
+If the -n option is given, do not display path.
+
+.SH AUTHOR	
+This manual page was written by Dan Walsh <[email protected]>.
+.br
+The program was written by NSA
+
+.SH "SEE ALSO"
+.BR mathpathcon "(3), " 
utils/matchpathcon.c renamed from utils/matchpathcon.c.rhat +24 -6
@@ -1,25 +1,43 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <getopt.h>
 #include <selinux/selinux.h>
 
+void usage(const char *progname) 
+{
+	fprintf(stderr, "usage:  %s [-n] path...\n", progname);
+	exit(1);
+}
+
 int main(int argc, char **argv) 
 {
 	char *buf;
 	int rc, i;
+	int header=1, opt;
 
-	if (argc < 2) {
-		fprintf(stderr, "usage:  %s path...\n", argv[0]);
-		return 1;
-	}
+	if (argc < 2) usage(argv[0]);
 
-	for (i = 1; i < argc; i++) {
+	while ((opt = getopt(argc, argv, "n")) > 0) {
+		switch (opt) {
+		case 'n':
+			header=0;
+			break;
+		default:
+			usage(argv[0]);
+		}
+	}
+	for (i = optind; i < argc; i++) {
 		rc = matchpathcon(argv[i], 0, &buf);
 		if (rc < 0) {
 			fprintf(stderr, "%s:  matchpathcon(%s) failed\n", argv[0], argv[i]);
 			return 2;
 		}
-		printf("%s\t%s\n", argv[i], buf);
+		if (header)
+			printf("%s\t%s\n", argv[i], buf);
+		else
+			printf("%s\n", buf);
+
 		freecon(buf);
 	}
 	return 0;