Skip to content

Commit

Permalink
libselinux: Ignore missing directories when -i is used
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
vmojzis authored and jwcart2 committed Nov 9, 2022
1 parent 4860237 commit 2f71384
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libselinux/src/selinux_restorecon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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, "/"))
Expand Down

0 comments on commit 2f71384

Please sign in to comment.