Skip to contentSkip to conversation

libselinux: Ignore missing directories when -i is used

PATCH In review Vit Mojzis 2 participants 3 messages Oct 31, 2022 – Nov 9, 2022 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 libselinux: Ignore missing directories when -i is used

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.
---
 libselinux/src/selinux_restorecon.c | 7 +++++++
 1 file changed, 7 insertions(+)
libselinux/src/selinux_restorecon.c +7 -0
index 2d24559f..6b5f6921 100644
@@ -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, "/"))
Signature · 1 line
2.37.3
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Vit Mojzis

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.
Quoted 32 lines
---
 libselinux/src/selinux_restorecon.c | 7 +++++++
 1 file changed, 7 insertions(+)
libselinux/src/selinux_restorecon.c +7 -1
index 2d24559f..6b5f6921 100644
@@ -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

#2 lore raw
Quoted 6 lines · James Carter
Quoted 4 lines · Vit Mojzis

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

Quoted 9 lines
Quoted 6 lines

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.

Merged.
Thanks,
Jim

Quoted 32 lines
Quoted 32 lines
---
 libselinux/src/selinux_restorecon.c | 7 +++++++
 1 file changed, 7 insertions(+)
libselinux/src/selinux_restorecon.c +7 -1
index 2d24559f..6b5f6921 100644
@@ -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