policycoreutils: fixfiles: remove bad modes of "relabel" command

* `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()`.

Signed-off-by: Alan Jenkins <alan.christopher.jenkins@gmail.com>
This commit is contained in:
Alan Jenkins 2017-05-07 12:05:54 +01:00 committed by James Carter
parent 96d11a281e
commit 6e289bb7bf
2 changed files with 20 additions and 13 deletions

View File

@ -216,11 +216,11 @@ shift
case "$RESTORE_MODE" in case "$RESTORE_MODE" in
PREFC) PREFC)
diff_filecontext $* diff_filecontext $*
exit $? return
;; ;;
BOOTTIME) BOOTTIME)
newer $BOOTTIME $* newer $BOOTTIME $*
exit $? return
;; ;;
esac esac
@ -234,11 +234,9 @@ case "$RESTORE_MODE" in
for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
rpmlist $i | ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} $* -R -i -f - rpmlist $i | ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} $* -R -i -f -
done done
exit $?
;; ;;
FILEPATH) FILEPATH)
${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH" ${RESTORECON} ${EXCLUDEDIRS} ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH"
return # to loop over each FILEPATH
;; ;;
DEFAULT) DEFAULT)
if [ -n "${FILESYSTEMSRW}" ]; then 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/tmp \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/tmp {} \;
find /var/run \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /var/run {} \; 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 {} \; [ ! -e /var/lib/debug ] || find /var/lib/debug \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /lib {} \;
exit 0
;; ;;
esac esac
} }
@ -269,17 +266,19 @@ esac
fullrelabel() { fullrelabel() {
echo "Cleaning out /tmp" echo "Cleaning out /tmp"
find /tmp/ -mindepth 1 -delete find /tmp/ -mindepth 1 -delete
LogReadOnly
restore Relabel restore Relabel
} }
relabel() { relabel() {
if [ "$RESTORE_MODE" == RPMFILES ]; then if [ "$RESTORE_MODE" != DEFAULT ]; then
restore Relabel usage
exit 1
fi fi
if [ $fullFlag == 1 ]; then if [ $fullFlag == 1 ]; then
fullrelabel fullrelabel
return
fi fi
echo -n " echo -n "
@ -306,6 +305,10 @@ case "$1" in
verify) restore Verify -n;; verify) restore Verify -n;;
relabel) relabel;; relabel) relabel;;
onboot) onboot)
if [ "$RESTORE_MODE" != DEFAULT ]; then
usage
exit 1
fi
> /.autorelabel > /.autorelabel
[ -z "$FORCEFLAG" ] || echo -n "$FORCEFLAG " >> /.autorelabel [ -z "$FORCEFLAG" ] || echo -n "$FORCEFLAG " >> /.autorelabel
[ -z "$BOOTTIME" ] || echo -N $BOOTTIME >> /.autorelabel [ -z "$BOOTTIME" ] || echo -N $BOOTTIME >> /.autorelabel
@ -320,9 +323,11 @@ esac
} }
usage() { usage() {
echo $""" echo $"""
Usage: $0 [-v] [-F] { check | restore | [-f] relabel | verify } dir/file ... Usage: $0 [-v] [-F] [-f] relabel
or or
Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | [-f] relabel | verify } Usage: $0 [-v] [-F] [-B | -N time ] { check | restore | verify }
or
Usage: $0 [-v] [-F] { check | restore | verify } dir/file ...
or or
Usage: $0 [-v] [-F] -R rpmpackage[,rpmpackage...] { check | restore | verify } Usage: $0 [-v] [-F] -R rpmpackage[,rpmpackage...] { check | restore | verify }
or or
@ -408,4 +413,3 @@ else
process "$command" process "$command"
fi fi
exit $?

View File

@ -6,10 +6,13 @@ fixfiles \- fix file SELinux security contexts.
.na .na
.B fixfiles .B fixfiles
.I [\-v] [\-F] { check | restore | [\-f] relabel | verify } dir/file ... .I [\-v] [\-F] [\-f] relabel
.B fixfiles .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 .B fixfiles
.I [\-v] [\-F] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify } .I [\-v] [\-F] \-R rpmpackagename[,rpmpackagename...] { check | restore | verify }