Skip to contentSkip to conversation

policycoreutils/scripts/fixfiles: pass -I/-D through to setfiles/restorecon

PATCH In review Stephen Smalley 1 participant 2 messages Sep 18 – Sep 21 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH v2 1/1 policycoreutils/scripts/fixfiles: pass -I/-D through to setfiles/restorecon

setfiles/restorecon -D enables per-directory security.sehash digest tracking (skip a subtree whose stored digest matches the current file_contexts) and -I forces the walk anyway while refreshing the digests. As noted by issue #44, fixfiles has no way to reach either.

Add -I and -D to fixfiles and pass whichever is set as ${DIGESTFLAG} to every setfiles/restorecon invocation, export it into the unshare -m subshell used with -M, and record it in /.autorelabel for onboot. -I wins over -D (setfiles -I already implies -D).

---
v2 fixes a typo in the description.

 policycoreutils/scripts/fixfiles   | 36 ++++++++++++++++++------------
 policycoreutils/scripts/fixfiles.8 | 28 ++++++++++++++++++-----
 2 files changed, 44 insertions(+), 20 deletions(-)
policycoreutils/scripts/fixfiles +22 -14
index 493c86f9..6e93d2ba 100755
@@ -92,6 +92,7 @@ fullFlag=0
 BOOTTIME=""
 VERBOSE="-p"
 FORCEFLAG=""
+DIGESTFLAG=""
 THREADS=""
 RPMFILES=""
 PREFC=""
@@ -136,7 +137,7 @@ newer() {
     shift
     LogReadOnly
     for m in `echo $FILESYSTEMSRW`; do
-	find $m -mount -newermt $DATE -print0 2>/dev/null | ${RESTORECON} ${FORCEFLAG} ${VERBOSE} ${THREADS} $* -i -0 -f -
+	find $m -mount -newermt $DATE -print0 2>/dev/null | ${RESTORECON} ${FORCEFLAG} ${DIGESTFLAG} ${VERBOSE} ${THREADS} $* -i -0 -f -
     done;
 }
 
@@ -180,7 +181,7 @@ if [ -f ${PREFC} -a -x /usr/bin/diff ]; then
 		  esac;
 	       fi;
 	    done |
-	${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${THREADS} $* -i -R -f -;
+	${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${DIGESTFLAG} ${THREADS} $* -i -R -f -;
 	rm -f ${TEMPFILE} ${PREFCTEMPFILE}
 fi
 }
@@ -203,7 +204,7 @@ fix_labels_on_mountpoint() {
 	test -z ${TMP_MOUNT+x} && echo "Unable to find temporary directory!" && exit 1
 	mkdir -p "${TMP_MOUNT}${m}" || exit 1
 	mount --bind "${m}" "${TMP_MOUNT}${m}" || exit 1
-	${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${THREADS} $* -q ${FC} -r "${TMP_MOUNT}" "${TMP_MOUNT}${m}"
+	${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${DIGESTFLAG} ${THREADS} $* -q ${FC} -r "${TMP_MOUNT}" "${TMP_MOUNT}${m}"
 	umount "${TMP_MOUNT}${m}" || exit 1
 	rm -rf "${TMP_MOUNT}" || echo "Error cleaning up."
 }
@@ -237,11 +238,11 @@ LogExcluded
 case "$RESTORE_MODE" in
     RPMFILES)
 	for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
-	    rpmlist $i | ${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${THREADS} $* -i -R -f -
+	    rpmlist $i | ${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${DIGESTFLAG} ${THREADS} $* -i -R -f -
 	done
     ;;
     FILEPATH)
-	${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${THREADS} $* -R -- "$FILEPATH"
+	${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${DIGESTFLAG} ${THREADS} $* -R -- "$FILEPATH"
     ;;
     *)
 	if [ -n "${FILESYSTEMSRW}" ]; then
@@ -249,13 +250,13 @@ case "$RESTORE_MODE" in
 	    echo "${OPTION}ing `echo ${FILESYSTEMSRW}`"
 
 	    if [ -z "$BIND_MOUNT_FILESYSTEMS" ]; then
-	        ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} $* -q ${THREADS} ${FC} ${FILESYSTEMSRW}
+	        ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} ${DIGESTFLAG} $* -q ${THREADS} ${FC} ${FILESYSTEMSRW}
 	    else
 	        # we bind mount so we can fix the labels of files that have already been
 	        # mounted over
 	        for m in `echo $FILESYSTEMSRW`; do
 	            TMP_MOUNT="$(mktemp -p /run -d fixfiles.XXXXXXXXXX)"
-	            export SETFILES VERBOSE EXCLUDEDIRS FORCEFLAG THREADS FC TMP_MOUNT m
+	            export SETFILES VERBOSE EXCLUDEDIRS FORCEFLAG DIGESTFLAG THREADS FC TMP_MOUNT m
 	            if type unshare &> /dev/null; then
 	                unshare -m bash -c "fix_labels_on_mountpoint $*" || exit $?
 	            else
@@ -323,6 +324,7 @@ case "$1" in
 	fi
 	> /.autorelabel || exit $?
 	[ -z "$FORCEFLAG" ] || echo -n "$FORCEFLAG " >> /.autorelabel
+	[ -z "$DIGESTFLAG" ] || echo -n "$DIGESTFLAG " >> /.autorelabel
 	[ -z "$BOOTTIME" ] || echo -n "-N $BOOTTIME " >> /.autorelabel
 	[ -z "$BIND_MOUNT_FILESYSTEMS" ] || echo -n "-M " >> /.autorelabel
 	[ -z "$THREADS" ] || echo -n "$THREADS " >> /.autorelabel
@@ -337,17 +339,17 @@ esac
 }
 usage() {
 	echo $"""
-Usage: $0 [-v] [-F] [-M] [-f] [-T nthreads] relabel
+Usage: $0 [-v] [-F] [-I|-D] [-M] [-f] [-T nthreads] relabel
 or
-Usage: $0 [-v] [-F] [-B | -N time ] [-T nthreads] { check | restore | verify }
+Usage: $0 [-v] [-F] [-I|-D] [-B | -N time ] [-T nthreads] { check | restore | verify }
 or
-Usage: $0 [-v] [-F] [-T nthreads] { check | restore | verify } dir/file ...
+Usage: $0 [-v] [-F] [-I|-D] [-T nthreads] { check | restore | verify } dir/file ...
 or
-Usage: $0 [-v] [-F] [-T nthreads] -R rpmpackage[,rpmpackage...] { check | restore | verify }
+Usage: $0 [-v] [-F] [-I|-D] [-T nthreads] -R rpmpackage[,rpmpackage...] { check | restore | verify }
 or
-Usage: $0 [-v] [-F] [-T nthreads] -C PREVIOUS_FILECONTEXT { check | restore | verify }
+Usage: $0 [-v] [-F] [-I|-D] [-T nthreads] -C PREVIOUS_FILECONTEXT { check | restore | verify }
 or
-Usage: $0 [-F] [-M] [-B] [-T nthreads] onboot
+Usage: $0 [-F] [-I|-D] [-M] [-B] [-T nthreads] onboot
 """
 }
 
@@ -366,7 +368,7 @@ set_restore_mode() {
 }
 
 # See how we were called.
-while getopts "N:BC:FfR:l:vMT:" i; do
+while getopts "N:BC:FIDfR:l:vMT:" i; do
     case "$i" in
 	B)
 		BOOTTIME=`/bin/who -b | awk '{print $3}'`
@@ -398,6 +400,12 @@ while getopts "N:BC:FfR:l:vMT:" i; do
 	F)
 		FORCEFLAG="-F"
 		;;
+	I)
+		DIGESTFLAG="-I"
+		;;
+	D)
+		[ -z "$DIGESTFLAG" ] && DIGESTFLAG="-D"
+		;;
 	f)
 		fullFlag=1
 		;;
policycoreutils/scripts/fixfiles.8 +22 -6
index 928b8200..f5b5d9ac 100644
@@ -6,22 +6,22 @@ fixfiles \- fix file SELinux security contexts.
 .na
 
 .B fixfiles
-.I [\-v] [\-F] [-M] [\-f] [\-T nthreads] relabel
+.I [\-v] [\-F] [\-I|\-D] [-M] [\-f] [\-T nthreads] relabel
 
 .B fixfiles
-.I [\-v] [\-F] [\-T nthreads] { check | restore | verify } dir/file ...
+.I [\-v] [\-F] [\-I|\-D] [\-T nthreads] { check | restore | verify } dir/file ...
 
 .B fixfiles
-.I [\-v] [\-F] [\-B | \-N time ] [\-T nthreads] { check | restore | verify }
+.I [\-v] [\-F] [\-I|\-D] [\-B | \-N time ] [\-T nthreads] { check | restore | verify }
 
 .B fixfiles
-.I [\-v] [\-F] [\-T nthreads] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify }
+.I [\-v] [\-F] [\-I|\-D] [\-T nthreads] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify }
 
 .B fixfiles
-.I [\-v] [\-F] [\-T nthreads] \-C PREVIOUS_FILECONTEXT  { check | restore | verify }
+.I [\-v] [\-F] [\-I|\-D] [\-T nthreads] \-C PREVIOUS_FILECONTEXT  { check | restore | verify }
 
 .B fixfiles
-.I [-F] [-M] [-B] [\-T nthreads] onboot
+.I [-F] [\-I|\-D] [-M] [-B] [\-T nthreads] onboot
 
 .ad
 
@@ -52,6 +52,22 @@ If specified with onboot, this fixfiles will record the current date in the /.au
 .B \-F
 Force reset of context to match file_context for customizable files
 
+.TP
+.B \-D
+Set or update per-directory
+.I security.sehash
+digests. On subsequent runs, directories whose stored digest still
+matches the current file_contexts are skipped. See
+.BR setfiles (8).
+
+.TP
+.B \-I
+Ignore existing per-directory
+.I security.sehash
+digests, so all directories are checked and their
+digests refreshed. See
+.BR setfiles (8).
+
 .TP
 .B \-f
 Clear /tmp directory with out prompt for removal.
Signature · 1 line
2.55.0
author maintainer
#1 lore raw
Quoted 11 lines · Stephen Smalley

setfiles/restorecon -D enables per-directory security.sehash digest tracking (skip a subtree whose stored digest matches the current file_contexts) and -I forces the walk anyway while refreshing the digests. As noted by issue #44, fixfiles has no way to reach either.

Add -I and -D to fixfiles and pass whichever is set as ${DIGESTFLAG} to every setfiles/restorecon invocation, export it into the unshare -m subshell used with -M, and record it in /.autorelabel for onboot. -I wins over -D (setfiles -I already implies -D).

Quoted 4 lines

---
v2 fixes a typo in the description.

This patch has been merged.