Skip to contentSkip to conversation

Fixes for libselinux/matchpathcon

PATCH Daniel J Walsh 2 participants 3 messages Apr 1, 2009 – May 7, 2009 SELinux security module

lore
Share & tools
lore
#0 lore raw

Removing trailing / if given to matchpathcon.

If matchpathcon returns ENOENT, we return <<none>>

utils/matchpathcon.c +12 -3
@@ -22,9 +22,13 @@
 	char *buf;
 	int rc = matchpathcon(path, mode, &buf);
 	if (rc < 0) {
-		fprintf(stderr, "matchpathcon(%s) failed: %s\n", path,
-			strerror(errno));
-		return 1;
+		if (errno == ENOENT) {
+			buf=strdup("<<none>>");
+		} else {
+			fprintf(stderr, "matchpathcon(%s) failed: %s\n", path,
+				strerror(errno));
+			return 1;
+		}
 	}
 	if (header)
 		printf("%s\t%s\n", path, buf);
@@ -101,6 +105,11 @@
 	for (i = optind; i < argc; i++) {
 		int mode = 0;
 		struct stat buf;
+		int len = strlen(argv[i]);
+		if (len > 1  && argv[i][len - 1 ] == '/') {
+			argv[i][len - 1 ] = '\0';
+		}
+
 		if (lstat(argv[i], &buf) == 0)
 			mode = buf.st_mode;
 
#1 lore raw

On 4/1/09 10:19 AM, "Daniel J Walsh" <[email protected]> wrote:
<snip>

Quoted 2 lines

If matchpathcon returns ENOENT, we return <<none>>

matchpathcon doesn't set errno. The underlying selabel functions do, which is why this works sometimes. Unfortunately, you don't know which of the underlying functions set errno, so you display <<none>> if any of them set errno to ENOENT. For instance, if the file_contexts file is missing, the selabel_open() call sets errno to ENOENT. It would be better to change matchpathcon() itself (and possibly it's underlying functions like matchpathcon_init()) to report back errors depending on what failed.

Thanks,
Chad

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 12 lines · Chad Sellers

On 4/1/09 10:19 AM, "Daniel J Walsh"<[email protected]> wrote:
<snip>

Quoted 1 line

If matchpathcon returns ENOENT, we return<<none>>

matchpathcon doesn't set errno. The underlying selabel functions do, which is why this works sometimes. Unfortunately, you don't know which of the underlying functions set errno, so you display<<none>> if any of them set errno to ENOENT. For instance, if the file_contexts file is missing, the selabel_open() call sets errno to ENOENT. It would be better to change matchpathcon() itself (and possibly it's underlying functions like matchpathcon_init()) to report back errors depending on what failed.

Quoted 8 lines

Thanks,
Chad

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Patches accepted.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.