diff mbox series

[RFC,3/4] libselinux: restorecon: forward error if not ENOENT

Message ID 20220511184225.218062-2-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit aaa49acac9c5
Headers show
Series [RFC] libselinux: emulate O_PATH support in fgetfilecon/fsetfilecon | expand

Commit Message

Christian Göttsche May 11, 2022, 6:42 p.m. UTC
selabel_lookup_raw(3) can fail for other reasons than no corresponding
context found, e.g. ENOMEM or EINVAL for invalid key or type.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/src/selinux_restorecon.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

James Carter May 12, 2022, 5:39 p.m. UTC | #1
On Thu, May 12, 2022 at 5:54 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> selabel_lookup_raw(3) can fail for other reasons than no corresponding
> context found, e.g. ENOMEM or EINVAL for invalid key or type.
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

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

> ---
>  libselinux/src/selinux_restorecon.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> index c158ead8..42ef30cb 100644
> --- a/libselinux/src/selinux_restorecon.c
> +++ b/libselinux/src/selinux_restorecon.c
> @@ -651,12 +651,16 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
>                                                     sb->st_mode);
>
>         if (rc < 0) {
> -               if (errno == ENOENT && flags->warnonnomatch && first)
> -                       selinux_log(SELINUX_INFO,
> -                                   "Warning no default label for %s\n",
> -                                   lookup_path);
> +               if (errno == ENOENT) {
> +                       if (flags->warnonnomatch && first)
> +                               selinux_log(SELINUX_INFO,
> +                                           "Warning no default label for %s\n",
> +                                           lookup_path);
>
> -               return 0; /* no match, but not an error */
> +                       return 0; /* no match, but not an error */
> +               }
> +
> +               return -1;
>         }
>
>         if (flags->progress) {
> --
> 2.36.1
>
James Carter May 16, 2022, 5:10 p.m. UTC | #2
On Thu, May 12, 2022 at 1:39 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Thu, May 12, 2022 at 5:54 AM Christian Göttsche
> <cgzones@googlemail.com> wrote:
> >
> > selabel_lookup_raw(3) can fail for other reasons than no corresponding
> > context found, e.g. ENOMEM or EINVAL for invalid key or type.
> >
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>

Merged.
Thanks,
Jim


> > ---
> >  libselinux/src/selinux_restorecon.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> > index c158ead8..42ef30cb 100644
> > --- a/libselinux/src/selinux_restorecon.c
> > +++ b/libselinux/src/selinux_restorecon.c
> > @@ -651,12 +651,16 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
> >                                                     sb->st_mode);
> >
> >         if (rc < 0) {
> > -               if (errno == ENOENT && flags->warnonnomatch && first)
> > -                       selinux_log(SELINUX_INFO,
> > -                                   "Warning no default label for %s\n",
> > -                                   lookup_path);
> > +               if (errno == ENOENT) {
> > +                       if (flags->warnonnomatch && first)
> > +                               selinux_log(SELINUX_INFO,
> > +                                           "Warning no default label for %s\n",
> > +                                           lookup_path);
> >
> > -               return 0; /* no match, but not an error */
> > +                       return 0; /* no match, but not an error */
> > +               }
> > +
> > +               return -1;
> >         }
> >
> >         if (flags->progress) {
> > --
> > 2.36.1
> >
diff mbox series

Patch

diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
index c158ead8..42ef30cb 100644
--- a/libselinux/src/selinux_restorecon.c
+++ b/libselinux/src/selinux_restorecon.c
@@ -651,12 +651,16 @@  static int restorecon_sb(const char *pathname, const struct stat *sb,
 						    sb->st_mode);
 
 	if (rc < 0) {
-		if (errno == ENOENT && flags->warnonnomatch && first)
-			selinux_log(SELINUX_INFO,
-				    "Warning no default label for %s\n",
-				    lookup_path);
+		if (errno == ENOENT) {
+			if (flags->warnonnomatch && first)
+				selinux_log(SELINUX_INFO,
+					    "Warning no default label for %s\n",
+					    lookup_path);
 
-		return 0; /* no match, but not an error */
+			return 0; /* no match, but not an error */
+		}
+
+		return -1;
 	}
 
 	if (flags->progress) {