From d597081324d5bcd91826e3aaa248cf157796ccea Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Tue, 1 Jul 2025 16:26:48 +0200 Subject: [PATCH] src/grpconv.c: chroot or prefix SELinux file context Do not process SELinux file context during file closure when chroot or prefix options are selected. Signed-off-by: Iker Pedrosa --- src/grpconv.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/grpconv.c b/src/grpconv.c index e36e0cef1..3804d3f05 100644 --- a/src/grpconv.c +++ b/src/grpconv.c @@ -40,6 +40,12 @@ #include "shadowlog.h" #include "sssd.h" +/* + * Structures + */ +struct option_flags { + bool chroot; +}; /* * Global variables @@ -52,7 +58,7 @@ static bool sgr_locked = false; /* local function prototypes */ static void fail_exit (int status); static void usage (int status); -static void process_flags (int argc, char **argv); +static void process_flags (int argc, char **argv, struct option_flags *flags); static void fail_exit (int status) { @@ -94,7 +100,7 @@ static void usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv) +static void process_flags (int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -113,6 +119,7 @@ static void process_flags (int argc, char **argv) usage (E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ + flags->chroot = true; break; default: usage (E_USAGE); @@ -130,6 +137,8 @@ int main (int argc, char **argv) struct group grent; const struct sgrp *sg; struct sgrp sgent; + struct option_flags flags; + bool process_selinux; log_set_progname(Prog); log_set_logfd(stderr); @@ -142,7 +151,8 @@ int main (int argc, char **argv) OPENLOG (Prog); - process_flags (argc, argv); + process_flags (argc, argv, &flags); + process_selinux = !flags.chroot; if (gr_lock () == 0) { fprintf (stderr, @@ -235,26 +245,26 @@ int main (int argc, char **argv) } } - if (sgr_close (true) == 0) { + if (sgr_close (process_selinux) == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ())); fail_exit (3); } - if (gr_close (true) == 0) { + if (gr_close (process_selinux) == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ())); fail_exit (3); } - if (sgr_unlock (true) == 0) { + if (sgr_unlock (process_selinux) == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ())); /* continue */ } - if (gr_unlock (true) == 0) { + if (gr_unlock (process_selinux) == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); /* continue */ -- 2.47.3