selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libselinux: Ignore missing directories when -i is used
@ 2022-10-31 16:46 Vit Mojzis
  2022-11-07 19:34 ` James Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Vit Mojzis @ 2022-10-31 16:46 UTC (permalink / raw)
  To: selinux

Currently "-i" only ignores a file whose parent directory exists. Start also
ignoring paths with missing components.

Fixes:
  # restorecon -i -v -R /var/log/missingdir/missingfile; echo $?
  255
  restorecon: SELinux: Could not get canonical path for /var/log/missingdir/missingfile restorecon: No such file or directory.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
---
 libselinux/src/selinux_restorecon.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
index 2d24559f..6b5f6921 100644
--- a/libselinux/src/selinux_restorecon.c
+++ b/libselinux/src/selinux_restorecon.c
@@ -1108,6 +1108,10 @@ static int selinux_restorecon_common(const char *pathname_orig,
 			pathname = realpath(pathname_orig, NULL);
 			if (!pathname) {
 				free(basename_cpy);
+				/* missing parent directory */
+				if (state.flags.ignore_noent && errno == ENOENT) {
+					return 0;
+				}
 				goto realpatherr;
 			}
 		} else {
@@ -1121,6 +1125,9 @@ static int selinux_restorecon_common(const char *pathname_orig,
 			free(dirname_cpy);
 			if (!pathdnamer) {
 				free(basename_cpy);
+				if (state.flags.ignore_noent && errno == ENOENT) {
+					return 0;
+				}
 				goto realpatherr;
 			}
 			if (!strcmp(pathdnamer, "/"))
-- 
2.37.3


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

* Re: [PATCH] libselinux: Ignore missing directories when -i is used
  2022-10-31 16:46 [PATCH] libselinux: Ignore missing directories when -i is used Vit Mojzis
@ 2022-11-07 19:34 ` James Carter
  2022-11-09 13:48   ` James Carter
  0 siblings, 1 reply; 3+ messages in thread
From: James Carter @ 2022-11-07 19:34 UTC (permalink / raw)
  To: Vit Mojzis; +Cc: selinux

On Mon, Oct 31, 2022 at 12:51 PM Vit Mojzis <vmojzis@redhat.com> wrote:
>
> Currently "-i" only ignores a file whose parent directory exists. Start also
> ignoring paths with missing components.
>
> Fixes:
>   # restorecon -i -v -R /var/log/missingdir/missingfile; echo $?
>   255
>   restorecon: SELinux: Could not get canonical path for /var/log/missingdir/missingfile restorecon: No such file or directory.
>
> Signed-off-by: Vit Mojzis <vmojzis@redhat.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  libselinux/src/selinux_restorecon.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> index 2d24559f..6b5f6921 100644
> --- a/libselinux/src/selinux_restorecon.c
> +++ b/libselinux/src/selinux_restorecon.c
> @@ -1108,6 +1108,10 @@ static int selinux_restorecon_common(const char *pathname_orig,
>                         pathname = realpath(pathname_orig, NULL);
>                         if (!pathname) {
>                                 free(basename_cpy);
> +                               /* missing parent directory */
> +                               if (state.flags.ignore_noent && errno == ENOENT) {
> +                                       return 0;
> +                               }
>                                 goto realpatherr;
>                         }
>                 } else {
> @@ -1121,6 +1125,9 @@ static int selinux_restorecon_common(const char *pathname_orig,
>                         free(dirname_cpy);
>                         if (!pathdnamer) {
>                                 free(basename_cpy);
> +                               if (state.flags.ignore_noent && errno == ENOENT) {
> +                                       return 0;
> +                               }
>                                 goto realpatherr;
>                         }
>                         if (!strcmp(pathdnamer, "/"))
> --
> 2.37.3
>

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

* Re: [PATCH] libselinux: Ignore missing directories when -i is used
  2022-11-07 19:34 ` James Carter
@ 2022-11-09 13:48   ` James Carter
  0 siblings, 0 replies; 3+ messages in thread
From: James Carter @ 2022-11-09 13:48 UTC (permalink / raw)
  To: Vit Mojzis; +Cc: selinux

On Mon, Nov 7, 2022 at 2:34 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Mon, Oct 31, 2022 at 12:51 PM Vit Mojzis <vmojzis@redhat.com> wrote:
> >
> > Currently "-i" only ignores a file whose parent directory exists. Start also
> > ignoring paths with missing components.
> >
> > Fixes:
> >   # restorecon -i -v -R /var/log/missingdir/missingfile; echo $?
> >   255
> >   restorecon: SELinux: Could not get canonical path for /var/log/missingdir/missingfile restorecon: No such file or directory.
> >
> > Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>

Merged.
Thanks,
Jim

> > ---
> >  libselinux/src/selinux_restorecon.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> > index 2d24559f..6b5f6921 100644
> > --- a/libselinux/src/selinux_restorecon.c
> > +++ b/libselinux/src/selinux_restorecon.c
> > @@ -1108,6 +1108,10 @@ static int selinux_restorecon_common(const char *pathname_orig,
> >                         pathname = realpath(pathname_orig, NULL);
> >                         if (!pathname) {
> >                                 free(basename_cpy);
> > +                               /* missing parent directory */
> > +                               if (state.flags.ignore_noent && errno == ENOENT) {
> > +                                       return 0;
> > +                               }
> >                                 goto realpatherr;
> >                         }
> >                 } else {
> > @@ -1121,6 +1125,9 @@ static int selinux_restorecon_common(const char *pathname_orig,
> >                         free(dirname_cpy);
> >                         if (!pathdnamer) {
> >                                 free(basename_cpy);
> > +                               if (state.flags.ignore_noent && errno == ENOENT) {
> > +                                       return 0;
> > +                               }
> >                                 goto realpatherr;
> >                         }
> >                         if (!strcmp(pathdnamer, "/"))
> > --
> > 2.37.3
> >

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

end of thread, other threads:[~2022-11-09 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-31 16:46 [PATCH] libselinux: Ignore missing directories when -i is used Vit Mojzis
2022-11-07 19:34 ` James Carter
2022-11-09 13:48   ` James Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).