Skip to contentSkip to conversation

policycoreutils: fixfiles: tidy up usage(), manpage synopsis

PATCH In review Alan Jenkins 2 participants 13 messages May 7, 2017 – May 9, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/10 policycoreutils: fixfiles: tidy up usage(), manpage synopsis

Make sure usage() in fixfiles shows all the current options. It's printed when there's a user error, so it needs to be helpful! (Excluding the deprecated option - see below).

manpage:

Remove the deprecated option -l logfile.

Add missing space in restore|[-f] relabel.

It's not clear why -R rpmpackagename was considered optional in the second invocation. (If the user omits it, they are just performing the first invocation). It desn't match usage() in fixfiles either.

Clean up bolding for fixfiles onboot.

Disable justification (troff "adjustment") in the synopsis. We want the common options in the different invocations to line up consistently.

---
 policycoreutils/scripts/fixfiles   |  2 +-
 policycoreutils/scripts/fixfiles.8 | 18 +++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)
policycoreutils/scripts/fixfiles +1 -1
index c876432..e416dfc 100755
@@ -311,7 +311,7 @@ esac
 }
 usage() {
 	echo $"""
-Usage: $0 [-v] [-F] [-N time ] { check | restore| [-f] relabel | verify } [[dir/file] ... ]
+Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | [-f] relabel | verify } [[dir/file] ... ]
 or
 Usage: $0 [-v] [-F] -R rpmpackage[,rpmpackage...] { check | restore | verify }
 or
policycoreutils/scripts/fixfiles.8 +9 -9
index 0099b9b..c58cb7d 100644
@@ -3,18 +3,21 @@
 fixfiles \- fix file SELinux security contexts.
 
 .SH "SYNOPSIS"
+.na
 
 .B fixfiles 
-.I [\-v] [\-F] [-B] [ -N time ] [\-l logfile ] { check | restore|[\-f] relabel | verify } [[dir/file] ... ]
+.I [\-v] [\-F] [\-B | \-N time ] { check | restore | [\-f] relabel | verify } [[dir/file] ... ]
 
 .B fixfiles 
-.I [\-v] [\-F] [ \-R rpmpackagename[,rpmpackagename...] ] [\-l logfile ] { check | restore | verify }
+.I [\-v] [\-F] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify }
 
-.B fixfiles 
-.I [\-v] [\-F] \-C PREVIOUS_FILECONTEXT [\-l logfile ] { check | restore | verify }
+.B fixfiles
+.I [\-v] [\-F] \-C PREVIOUS_FILECONTEXT  { check | restore | verify }
+
+.B fixfiles
+.I [-F] [-B] onboot
 
-.B fixfiles [-F] [-B]
-.I onboot
+.ad
 
 .SH "DESCRIPTION"
 This manual page describes the
@@ -40,9 +43,6 @@ will setup the machine to relabel on the next reboot.
 .B \-B
 If specified with onboot, this fixfiles will record the current date in the /.autorelabel file, so that it can be used later to speed up labeling. If used with restore, the restore will only affect files that were modified today.
 .TP
-.B \-l logfile
-Save the output to the specified logfile
-.TP 
 .B \-F
 Force reset of context to match file_context for customizable files
 
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/10 policycoreutils: fixfiles: remove two unused variables

DIRS was suspicious because you can't store file names in a normal variable, and it's not that common to use arrays in bash. It's not actually used.

While we're here, there's another variable which is never used and should just be removed. (Pointed out by shellcheck. It makes a couple of other points too, but I have more specific patches I want to put those in).

---
 policycoreutils/scripts/fixfiles | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
policycoreutils/scripts/fixfiles +1 -3
index e416dfc..da79f47 100755
@@ -107,13 +107,11 @@ fullFlag=0
 BOOTTIME=""
 VERBOSE="-p"
 FORCEFLAG=""
-DIRS=""
 RPMILES=""
 SETFILES=/sbin/setfiles
 RESTORECON=/sbin/restorecon
 FILESYSTEMSRW=`get_rw_labeled_mounts`
 FILESYSTEMSRO=`get_ro_labeled_mounts`
-FILESYSTEMS="$FILESYSTEMSRW $FILESYSTEMSRO"
 SELINUXTYPE="targeted"
 if [ -e /etc/selinux/config ]; then
     . /etc/selinux/config
@@ -373,7 +371,7 @@ fi
 shift
 
 #
-# check if they specified both DIRS and RPMFILES
+# check if they specified both RPMFILES and FILEPATHs
 #
 
 if [ ! -z "$RPMFILES" ]; then
Signature · 1 line
2.9.3
#2 lore raw

PATCH 3/10 policycoreutils: fixfiles: syntax error

In reply to Alan Jenkins
$ shellcheck fixfiles
...
In fixfiles line 94:
	  [[ "${i}" =~ "^[[:blank:]]*#" ]] && continue
                       ^-- SC2076: Don't quote rhs of =~, it'll match
                                   literally rather than as a regex.
---
 policycoreutils/scripts/fixfiles | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
policycoreutils/scripts/fixfiles +1 -1
index da79f47..29982e2 100755
@@ -91,7 +91,7 @@ exclude_dirs_from_relabelling() {
 	  # skip not absolute path
 	  # skip not directory
 	  [ -z "${i}" ] && continue
-	  [[ "${i}" =~ "^[[:blank:]]*#" ]] && continue
+	  [[ "${i}" =~ ^[[:blank:]]*# ]] && continue
 	  [[ ! "${i}" =~ ^/.* ]] && continue
 	  [[ ! -d "${i}" ]] && continue
 	  exclude_from_relabelling="$exclude_from_relabelling -e $i"
Signature · 1 line
2.9.3
#3 lore raw

PATCH 4/10 policycoreutils: fixfiles: usage errors are fatal

In reply to Alan Jenkins

The idea is to print a usage error, then terminate with EXIT_FAILURE.

Don't print the usage error twice when run with no command.

Don't try to check for bogus extra arguments _after_ performing a long-running operation... particularly
if that operation terminates the script with EXIT_SUCCESS first.

---
 policycoreutils/scripts/fixfiles | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
policycoreutils/scripts/fixfiles +4 -2
index 29982e2..014ab04 100755
@@ -365,6 +365,7 @@ shift $(( OPTIND - 1 ))
 command="$1"
 if [ -z "$command" ]; then
     usage
+    exit 1
 fi
 
 # Move out command from arguments
@@ -375,10 +376,11 @@ shift
 #
 
 if [ ! -z "$RPMFILES" ]; then
-    process "$command"
     if [ $# -gt 0 ]; then
-	    usage
+	usage
+	exit 1
     fi
+    process "$command"
 else
     if [ -z "$1" ]; then
 	process "$command"
Signature · 1 line
2.9.3
#4 lore raw

PATCH 5/10 policycoreutils: fixfiles: if restorecon aborts, we should too

In reply to Alan Jenkins

New users may try something like fixfiles restore -v /dir/file - not realizing they are required to use fixfiles -v restore /dir/file.

Detect that restorecon aborts due to being run on the non-existent file -v, and stop immediately. This will show the error much more clearly, instead of continuing to restore /dir/file *without* verbose messages.

---
 policycoreutils/scripts/fixfiles | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
policycoreutils/scripts/fixfiles +1 -1
index 014ab04..1b173e6 100755
@@ -387,7 +387,7 @@ else
     else
 	while [ -n "$1" ]; do
 	    FILEPATH="$1"
-	    process "$command"
+	    process "$command" || exit $?
 	    shift
 	done
     fi
Signature · 1 line
2.9.3
#5 lore raw

PATCH 6/10 policycoreutils: fixfiles: refactor into the `set -u` dialect

In reply to Alan Jenkins

This commit allows the use of set -u to detect reads of unset variables. But what I really liked was making the code more explicit about these modes. I hope that this is easier for a new reader to reason about.

fixfiles restore has accumulated five different modes it can run in. Now use a single variable to indicate the mode, out-of-band of the variables used for the individual modes.

Apparently set -u / set -o nounset doesn't work correctly with arrays. If we ever need bash arrays, we can simply remove set -u. The set -u dialect is a strict subset. See http://mywiki.wooledge.org/BashFAQ/112

Extra notes:

RESTORE_MODE was created because I couldn't bring myself to use an empty FILEPATH, as a special case to indicate the default mode. Arguments to the script (paths) could be empty already, so it would mean I had to work out how we behaved in that case and decide whether it was reasonable.

It turns out the -B | -N time mode is distinct and does not respect paths. So we can tell the user we're not going to do anything with the paths they passed. Make sure this distinction is shown in the usage error message.

We already rejected the combination of -R rpmpackage,... dir/file.... Being aware of the different modes just causes more bogus combinations to be rejected.

---
 policycoreutils/scripts/fixfiles   | 164 ++++++++++++++++++++-----------------
 policycoreutils/scripts/fixfiles.8 |   7 +-
 2 files changed, 95 insertions(+), 76 deletions(-)
policycoreutils/scripts/fixfiles +90 -74
index 1b173e6..df70b27 100755
@@ -20,6 +20,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+set -o nounset
+
 #
 # seclabel support was added in 2.6.30.  This function will return a positive
 # number if the current kernel version is greater than 2.6.30, a negative
@@ -107,7 +109,9 @@ fullFlag=0
 BOOTTIME=""
 VERBOSE="-p"
 FORCEFLAG=""
-RPMILES=""
+RPMFILES=""
+PREFC=""
+RESTORE_MODE="DEFAULT"
 SETFILES=/sbin/setfiles
 RESTORECON=/sbin/restorecon
 FILESYSTEMSRW=`get_rw_labeled_mounts`
@@ -209,50 +213,57 @@ restore () {
 OPTION=$1
 shift
 
-if [ ! -z "$PREFC" ]; then
-    diff_filecontext $*
-    exit $?
-fi
-if [ ! -z "$BOOTTIME" ]; then
-    newer $BOOTTIME $*
-    exit $?
-fi
+case "$RESTORE_MODE" in
+    PREFC)
+	diff_filecontext $*
+	exit $?
+    ;;
+    BOOTTIME)
+	newer $BOOTTIME $*
+	exit $?
+    ;;
+esac
+
 [ -x /usr/sbin/genhomedircon ] && /usr/sbin/genhomedircon
 
 EXCLUDEDIRS="`exclude_dirs_from_relabelling`"
 LogExcluded
 
-if [ ! -z "$RPMFILES" ]; then
-    for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
-	rpmlist $i | ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} $* -R -i -f -
-    done
-    exit $?
-fi
-if [ ! -z "$FILEPATH" ]; then
-    ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH"
-    return
-fi
-if [  -n "${FILESYSTEMSRW}" ]; then
-    LogReadOnly
-    echo "${OPTION}ing `echo ${FILESYSTEMSRW}`"
-    ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} -q ${FORCEFLAG} $* ${FC} ${FILESYSTEMSRW}
-else
-    echo >&2 "fixfiles: No suitable file systems found"
-fi
-if [ ${OPTION} != "Relabel" ]; then
-    return
-fi
-echo "Cleaning up labels on /tmp"
-rm -rf /tmp/gconfd-* /tmp/pulse-* /tmp/orbit-*
-
-UNDEFINED=`get_undefined_type` || exit $?
-UNLABELED=`get_unlabeled_type` || exit $?
-find /tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) \( -type s -o -type p \) -delete
-find /tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /tmp {} \;
-find /var/tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/tmp {} \;
-find /var/run \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/run {} \;
-[ ! -e /var/lib/debug ] || find /var/lib/debug \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /lib {} \;
-exit 0
+case "$RESTORE_MODE" in
+    RPMFILES)
+	for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
+	    rpmlist $i | ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} $* -R -i -f -
+	done
+	exit $?
+    ;;
+    FILEPATH)
+	${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH"
+	return  # to loop over each FILEPATH
+    ;;
+    DEFAULT)
+	if [ -n "${FILESYSTEMSRW}" ]; then
+	    LogReadOnly
+	    echo "${OPTION}ing `echo ${FILESYSTEMSRW}`"
+	    ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} -q ${FORCEFLAG} $* ${FC} ${FILESYSTEMSRW}
+	else
+	    echo >&2 "fixfiles: No suitable file systems found"
+	fi
+	if [ ${OPTION} != "Relabel" ]; then
+	    return
+	fi
+	echo "Cleaning up labels on /tmp"
+	rm -rf /tmp/gconfd-* /tmp/pulse-* /tmp/orbit-*
+
+	UNDEFINED=`get_undefined_type` || exit $?
+	UNLABELED=`get_unlabeled_type` || exit $?
+	find /tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) \( -type s -o -type p \) -delete
+	find /tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /tmp {} \;
+	find /var/tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/tmp {} \;
+	find /var/run \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/run {} \;
+	[ ! -e /var/lib/debug ] || find /var/lib/debug \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /lib {} \;
+	exit 0
+    ;;
+esac
 }
 
 fullrelabel() {
@@ -263,7 +274,7 @@ fullrelabel() {
 }
 
 relabel() {
-    if [ ! -z "$RPMFILES" ]; then
+    if [ "$RESTORE_MODE" == RPMFILES ]; then
 	restore Relabel
     fi
 
@@ -309,7 +320,9 @@ esac
 }
 usage() {
 	echo $"""
-Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | [-f] relabel | verify } [[dir/file] ... ]
+Usage: $0 [-v] [-F] { check | restore | [-f] relabel | verify } dir/file ...
+or
+Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | [-f] relabel | verify }
 or
 Usage: $0 [-v] [-F] -R rpmpackage[,rpmpackage...] { check | restore | verify }
 or
@@ -319,39 +332,52 @@ Usage: $0 [-F] [-B] onboot
 """
 }
 
-if [ $# = 0 ]; then
+if [ $# -eq 0 ]; then
 	usage
 	exit 1
 fi
 
+set_restore_mode() {
+	if [ "$RESTORE_MODE" != DEFAULT ]; then
+		# can't specify two different modes
+		usage
+		exit 1
+	fi
+	RESTORE_MODE="$1"
+}
+
 # See how we were called.
 while getopts "N:BC:FfR:l:v" i; do
     case "$i" in
 	B)
 		BOOTTIME=`/bin/who -b | awk '{print $3}'`
+		set_restore_mode BOOTTIME
 		;;
-	f)
-		fullFlag=1
-		;;
-	v)
-		VERBOSE="-v"
+	N)
+		BOOTTIME=$OPTARG
+		set_restore_mode BOOTTIME
 		;;
 	R)
 		RPMFILES=$OPTARG
+		set_restore_mode RPMFILES
+		;;
+	C)
+		PREFC=$OPTARG
+		set_restore_mode PREFC
+		;;
+	v)
+		VERBOSE="-v"
 		;;
 	l)
 		# Old scripts use obsolete option `-l logfile`
 		echo "Redirecting output to $OPTARG"
 		exec >>"$OPTARG" 2>&1
 		;;
-	C)
-		PREFC=$OPTARG
-		;;
 	F)
 		FORCEFLAG="-F"
 		;;
-	N)
-		BOOTTIME=$OPTARG
+	f)
+		fullFlag=1
 		;;
 	*)
 	    usage
@@ -362,34 +388,24 @@ done
 shift $(( OPTIND - 1 ))
 
 # Check for the command
-command="$1"
-if [ -z "$command" ]; then
+if [ $# -eq 0 ]; then
     usage
     exit 1
 fi
+command="$1"
 
 # Move out command from arguments
 shift
 
-#
-# check if they specified both RPMFILES and FILEPATHs
-#
-
-if [ ! -z "$RPMFILES" ]; then
-    if [ $# -gt 0 ]; then
-	usage
-	exit 1
-    fi
-    process "$command"
+if [ $# -gt 0 ]; then
+    set_restore_mode FILEPATH
+    while [ $# -gt 0 ]; do
+	FILEPATH="$1"
+	process "$command" || exit $?
+	shift
+    done
 else
-    if [ -z "$1" ]; then
-	process "$command"
-    else
-	while [ -n "$1" ]; do
-	    FILEPATH="$1"
-	    process "$command" || exit $?
-	    shift
-	done
-    fi
+    process "$command"
 fi
+
 exit $?
policycoreutils/scripts/fixfiles.8 +5 -2
index c58cb7d..0ec18a8 100644
@@ -5,8 +5,11 @@ fixfiles \- fix file SELinux security contexts.
 .SH "SYNOPSIS"
 .na
 
-.B fixfiles 
-.I [\-v] [\-F] [\-B | \-N time ] { check | restore | [\-f] relabel | verify } [[dir/file] ... ]
+.B fixfiles
+.I [\-v] [\-F] { check | restore | [\-f] relabel | verify } dir/file ...
+
+.B fixfiles
+.I [\-v] [\-F] [\-B | \-N time ] { check | restore | [\-f] relabel | verify }
 
 .B fixfiles 
 .I [\-v] [\-F] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify }
Signature · 1 line
2.9.3
#6 lore raw

PATCH 7/10 policycoreutils: fixfiles: un-document `-R -a` option

In reply to Alan Jenkins

fixfiles -R -a is much less useful than it was made to sound, because -R now works recursively. Therefore fixfiles -R -a relabels every file on the system, multiple times. On my system it took over 5 times as long as plain fixfiles (which takes about a minute).

---
 policycoreutils/scripts/fixfiles.8 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
policycoreutils/scripts/fixfiles.8 +1 -1
index 0ec18a8..7a00bc3 100644
@@ -55,7 +55,7 @@ Clear /tmp directory with out prompt for removal.
 
 .TP 
 .B \-R rpmpackagename[,rpmpackagename...]
-Use the rpm database to discover all files within the specified packages and restore the file contexts.  (\-a will get all files in the RPM database).
+Use the rpm database to discover all files within the specified packages and restore the file contexts.
 .TP
 .B \-C PREVIOUS_FILECONTEXT
 Run a diff on  the PREVIOUS_FILECONTEXT file to the currently installed one, and restore the context of all affected files.
Signature · 1 line
2.9.3
#7 lore raw

PATCH 8/10 policycoreutils: fixfiles: remove bad modes of "relabel" command

In reply to Alan Jenkins

* fixfiles -B relabel or fixfiles -C previouscontext relabel would skip the code that handles e.g. /var/tmp, which would be run by fixfiles relabel. It would still remove all files in /tmp (subject to user confirmation). This is confusing, undocumented, and unlikely to be intentional.

* fixfiles relabel path1 path2 is the same, except it would only relabel the first path.

* fixfiles -R ... relabel was equivalent to fixfiles -R ... restore, again contradicting the man page.

Also fixfiles onboot would ignore paths, -C, or -R.

fixfiles is mostly for users, where it should be acceptable to remove these non-sensical combinations.

fixfiles -C is used in selinux-policy rpm install scripts. However I believe the rpms used fixfiles -C previouscontext restore, and did not either require user interaction or blow away /tmp without prompting. So they should still work fine.

With these combinations removed, we can remove the exit calls which were seen in some of the (non-error) code paths in restore().

---
 policycoreutils/scripts/fixfiles   | 26 +++++++++++++++-----------
 policycoreutils/scripts/fixfiles.8 |  7 +++++--
 2 files changed, 20 insertions(+), 13 deletions(-)
policycoreutils/scripts/fixfiles +15 -11
index df70b27..ce4a01a 100755
@@ -216,11 +216,11 @@ shift
 case "$RESTORE_MODE" in
     PREFC)
 	diff_filecontext $*
-	exit $?
+	return
     ;;
     BOOTTIME)
 	newer $BOOTTIME $*
-	exit $?
+	return
     ;;
 esac
 
@@ -234,11 +234,9 @@ case "$RESTORE_MODE" in
 	for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
 	    rpmlist $i | ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} $* -R -i -f -
 	done
-	exit $?
     ;;
     FILEPATH)
 	${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH"
-	return  # to loop over each FILEPATH
     ;;
     DEFAULT)
 	if [ -n "${FILESYSTEMSRW}" ]; then
@@ -261,7 +259,6 @@ case "$RESTORE_MODE" in
 	find /var/tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/tmp {} \;
 	find /var/run \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/run {} \;
 	[ ! -e /var/lib/debug ] || find /var/lib/debug \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /lib {} \;
-	exit 0
     ;;
 esac
 }
@@ -269,17 +266,19 @@ esac
 fullrelabel() {
     echo "Cleaning out /tmp"
     find /tmp/ -mindepth 1 -delete
-    LogReadOnly
     restore Relabel
 }
 
+
 relabel() {
-    if [ "$RESTORE_MODE" == RPMFILES ]; then
-	restore Relabel
+    if [ "$RESTORE_MODE" != DEFAULT ]; then
+	usage
+	exit 1
     fi
 
     if [ $fullFlag == 1  ]; then
 	fullrelabel
+	return
     fi
 
     echo -n "
@@ -306,6 +305,10 @@ case "$1" in
     verify) restore Verify -n;;
     relabel) relabel;;
     onboot)
+	if [ "$RESTORE_MODE" != DEFAULT ]; then
+	    usage
+	    exit 1
+	fi
 	> /.autorelabel
 	[ -z "$FORCEFLAG" ] || echo -n "$FORCEFLAG " >> /.autorelabel
 	[ -z "$BOOTTIME" ] || echo -N $BOOTTIME >> /.autorelabel
@@ -320,9 +323,11 @@ esac
 }
 usage() {
 	echo $"""
-Usage: $0 [-v] [-F] { check | restore | [-f] relabel | verify } dir/file ...
+Usage: $0 [-v] [-F] [-f] relabel
+or
+Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | verify }
 or
-Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | [-f] relabel | verify }
+Usage: $0 [-v] [-F] { check | restore | verify } dir/file ...
 or
 Usage: $0 [-v] [-F] -R rpmpackage[,rpmpackage...] { check | restore | verify }
 or
@@ -408,4 +413,3 @@ else
     process "$command"
 fi
 
-exit $?
policycoreutils/scripts/fixfiles.8 +5 -2
index 7a00bc3..9f447f0 100644
@@ -6,10 +6,13 @@ fixfiles \- fix file SELinux security contexts.
 .na
 
 .B fixfiles
-.I [\-v] [\-F] { check | restore | [\-f] relabel | verify } dir/file ...
+.I [\-v] [\-F] [\-f] relabel
 
 .B fixfiles
-.I [\-v] [\-F] [\-B | \-N time ] { check | restore | [\-f] relabel | verify }
+.I [\-v] [\-F] { check | restore | verify } dir/file ...
+
+.B fixfiles
+.I [\-v] [\-F] [\-B | \-N time ] { check | restore | verify }
 
 .B fixfiles 
 .I [\-v] [\-F] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify }
Signature · 1 line
2.9.3
#8 lore raw

PATCH 9/10 policycoreutils: fixfiles: don't ignore `-F` when run in `-C` mode

In reply to Alan Jenkins

This was supposedly fixed in 2009.
http://selinux.fedoraproject.narkive.com/ZskMsNrx/fixfiles-f-option

-F was mentioned again in 2013 (commit 2910ca21).

It doesn't look like -F -C was fixed though.

---
 policycoreutils/scripts/fixfiles | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
policycoreutils/scripts/fixfiles +1 -1
index ce4a01a..cff1111 100755
@@ -195,7 +195,7 @@ if [ -f ${PREFC} -a -x /usr/bin/diff ]; then
 		  esac; \
 	       fi; \
 	    done | \
-	${RESTORECON} ${VERBOSE} -i -f - -R $* ${EXCLUDEDIRS}; \
+	${RESTORECON} ${VERBOSE} -i -f - -R $* ${EXCLUDEDIRS} ${FORCEFLAG}; \
 	rm -f ${TEMPFILE} ${PREFCTEMPFILE}
 fi
 }
Signature · 1 line
2.9.3
#9 lore raw

PATCH 10/10 policycoreutils: fixfiles: use a consistent order for options to restorecon

In reply to Alan Jenkins

It helps see the differences (hopefully there are only intended differences now!).

---
 policycoreutils/scripts/fixfiles | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
policycoreutils/scripts/fixfiles +4 -4
index cff1111..0eeeea4 100755
@@ -195,7 +195,7 @@ if [ -f ${PREFC} -a -x /usr/bin/diff ]; then
 		  esac; \
 	       fi; \
 	    done | \
-	${RESTORECON} ${VERBOSE} -i -f - -R $* ${EXCLUDEDIRS} ${FORCEFLAG}; \
+	${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} $* -i -R -f -; \
 	rm -f ${TEMPFILE} ${PREFCTEMPFILE}
 fi
 }
@@ -232,17 +232,17 @@ LogExcluded
 case "$RESTORE_MODE" in
     RPMFILES)
 	for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
-	    rpmlist $i | ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} $* -R -i -f -
+	    rpmlist $i | ${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} $* -i -R -f -
 	done
     ;;
     FILEPATH)
-	${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH"
+	${RESTORECON} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} $* -R -- "$FILEPATH"
     ;;
     DEFAULT)
 	if [ -n "${FILESYSTEMSRW}" ]; then
 	    LogReadOnly
 	    echo "${OPTION}ing `echo ${FILESYSTEMSRW}`"
-	    ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} -q ${FORCEFLAG} $* ${FC} ${FILESYSTEMSRW}
+	    ${SETFILES} ${VERBOSE} ${EXCLUDEDIRS} ${FORCEFLAG} $* -q ${FC} ${FILESYSTEMSRW}
 	else
 	    echo >&2 "fixfiles: No suitable file systems found"
 	fi
Signature · 1 line
2.9.3
#10 lore raw
In reply to Alan Jenkins

We normally add a "signed-off-by" line to patches. Can I add "Signed-off-by: Alan Jenkins <[email protected]>" to your patches?

Jim

Quoted 79 lines · Alan Jenkins

Make sure usage() in fixfiles shows all the current options. It's printed when there's a user error, so it needs to be helpful! (Excluding the deprecated option - see below).

manpage:

Remove the deprecated option -l logfile.

Add missing space in restore|[-f] relabel.

It's not clear why -R rpmpackagename was considered optional in the second invocation. (If the user omits it, they are just performing the first invocation). It desn't match usage() in fixfiles either.

Clean up bolding for fixfiles onboot.

Disable justification (troff "adjustment") in the synopsis. We want the common options in the different invocations to line up consistently.

---
  policycoreutils/scripts/fixfiles   |  2 +-
  policycoreutils/scripts/fixfiles.8 | 18 +++++++++---------
  2 files changed, 10 insertions(+), 10 deletions(-)
policycoreutils/scripts/fixfiles +1 -1
index c876432..e416dfc 100755
@@ -311,7 +311,7 @@ esac
  }
  usage() {
  	echo $"""
-Usage: $0 [-v] [-F] [-N time ] { check | restore| [-f] relabel | verify } [[dir/file] ... ]
+Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | [-f] relabel | verify } [[dir/file] ... ]
  or
  Usage: $0 [-v] [-F] -R rpmpackage[,rpmpackage...] { check | restore | verify }
  or
policycoreutils/scripts/fixfiles.8 +9 -9
index 0099b9b..c58cb7d 100644
@@ -3,18 +3,21 @@
  fixfiles \- fix file SELinux security contexts.
 
  .SH "SYNOPSIS"
+.na
 
  .B fixfiles
-.I [\-v] [\-F] [-B] [ -N time ] [\-l logfile ] { check | restore|[\-f] relabel | verify } [[dir/file] ... ]
+.I [\-v] [\-F] [\-B | \-N time ] { check | restore | [\-f] relabel | verify } [[dir/file] ... ]
 
  .B fixfiles
-.I [\-v] [\-F] [ \-R rpmpackagename[,rpmpackagename...] ] [\-l logfile ] { check | restore | verify }
+.I [\-v] [\-F] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify }
 
-.B fixfiles
-.I [\-v] [\-F] \-C PREVIOUS_FILECONTEXT [\-l logfile ] { check | restore | verify }
+.B fixfiles
+.I [\-v] [\-F] \-C PREVIOUS_FILECONTEXT  { check | restore | verify }
+
+.B fixfiles
+.I [-F] [-B] onboot
 
-.B fixfiles [-F] [-B]
-.I onboot
+.ad
 
  .SH "DESCRIPTION"
  This manual page describes the
@@ -40,9 +43,6 @@ will setup the machine to relabel on the next reboot.
  .B \-B
  If specified with onboot, this fixfiles will record the current date in the /.autorelabel file, so that it can be used later to speed up labeling. If used with restore, the restore will only affect files that were modified today.
  .TP
-.B \-l logfile
-Save the output to the specified logfile
-.TP
  .B \-F
  Force reset of context to match file_context for customizable files
 
Signature · 2 lines
James Carter <[email protected]>
National Security Agency
#11 lore raw
Quoted 3 lines · James Carter

We normally add a "signed-off-by" line to patches. Can I add "Signed-off-by: Alan Jenkins <[email protected]>" to your patches?

Jim

Please do. Sorry, it looks like I forgot about that after the first few I sent here.

I hope that's the only problem with this last series :).

Regards
Alan

#12 lore raw
Quoted 11 lines · Alan Jenkins
Quoted 3 lines · James Carter

We normally add a "signed-off-by" line to patches. Can I add "Signed-off-by: Alan Jenkins <[email protected]>" to your patches?

Jim

Please do. Sorry, it looks like I forgot about that after the first few I sent here.

I hope that's the only problem with this last series :).

Regards
Alan

I have applied all of these.

Thanks,
Jim

Signature · 2 lines
James Carter <[email protected]>
National Security Agency