All of lore.kernel.org
 help / color / mirror / Atom feed
* Fixes for libselinux/matchpathcon
@ 2009-04-01 14:19 Daniel J Walsh
  2009-05-07 18:18 ` Chad Sellers
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel J Walsh @ 2009-04-01 14:19 UTC (permalink / raw)
  To: SE Linux

[-- Attachment #1: Type: text/plain, Size: 98 bytes --]

Removing trailing / if given to matchpathcon.

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

[-- Attachment #2: matchpathcon.patch --]
[-- Type: text/plain, Size: 825 bytes --]

--- nsalibselinux/utils/matchpathcon.c	2009-03-06 14:41:45.000000000 -0500
+++ libselinux-2.0.79/utils/matchpathcon.c	2009-03-27 10:09:31.000000000 -0400
@@ -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;
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Fixes for libselinux/matchpathcon
  2009-04-01 14:19 Fixes for libselinux/matchpathcon Daniel J Walsh
@ 2009-05-07 18:18 ` Chad Sellers
  2009-05-07 18:29   ` Daniel J Walsh
  0 siblings, 1 reply; 3+ messages in thread
From: Chad Sellers @ 2009-05-07 18:18 UTC (permalink / raw)
  To: Daniel J Walsh, SE Linux

On 4/1/09 10:19 AM, "Daniel J Walsh" <dwalsh@redhat.com> wrote:
<snip>
> 
> 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 majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Fixes for libselinux/matchpathcon
  2009-05-07 18:18 ` Chad Sellers
@ 2009-05-07 18:29   ` Daniel J Walsh
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel J Walsh @ 2009-05-07 18:29 UTC (permalink / raw)
  To: Chad Sellers; +Cc: SE Linux

On 05/07/2009 02:18 PM, Chad Sellers wrote:
> On 4/1/09 10:19 AM, "Daniel J Walsh"<dwalsh@redhat.com>  wrote:
> <snip>
>> 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 majordomo@tycho.nsa.gov 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 majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-05-07 18:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-01 14:19 Fixes for libselinux/matchpathcon Daniel J Walsh
2009-05-07 18:18 ` Chad Sellers
2009-05-07 18:29   ` Daniel J Walsh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.