Fixes for libselinux/matchpathcon
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;
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.
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_contextsfile is missing, theselabel_open()call sets errno to ENOENT. It would be better to changematchpathcon()itself (and possibly it's underlying functions likematchpathcon_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.