2008-08-19 19:30:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# fixfiles
|
|
|
|
#
|
|
|
|
# Script to restore labels on a SELinux box
|
|
|
|
#
|
2013-10-09 21:43:52 +00:00
|
|
|
# Copyright (C) 2004-2013 Red Hat, Inc.
|
2008-08-19 19:30:36 +00:00
|
|
|
# Authors: Dan Walsh <dwalsh@redhat.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2011-07-10 14:09:11 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# number if the current is less than 2.6.30 and 0 if they are the same.
|
|
|
|
#
|
|
|
|
function useseclabel {
|
2013-10-09 21:43:52 +00:00
|
|
|
VER=`uname -r`
|
|
|
|
SUP=2.6.30
|
|
|
|
expr '(' "$VER" : '\([^.]*\)' ')' '-' '(' "$SUP" : '\([^.]*\)' ')' '|' \
|
|
|
|
'(' "$VER.0" : '[^.]*[.]\([^.]*\)' ')' '-' '(' "$SUP.0" : '[^.]*[.]\([^.]*\)' ')' '|' \
|
|
|
|
'(' "$VER.0.0" : '[^.]*[.][^.]*[.]\([^.]*\)' ')' '-' '(' "$SUP.0.0" : '[^.]*[.][^.]*[.]\([^.]*\)' ')'
|
2011-07-10 14:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Get all mount points that support labeling. Use the 'seclabel' field if it
|
|
|
|
# is available. Else fall back to known fs types which likely support xattrs
|
|
|
|
# and we know were not context mounted.
|
|
|
|
#
|
|
|
|
get_all_labeled_mounts() {
|
|
|
|
FS="`cat /proc/self/mounts | sort | uniq | awk '{print $2}'`"
|
|
|
|
for i in $FS; do
|
|
|
|
if [ `useseclabel` -ge 0 ]
|
|
|
|
then
|
|
|
|
grep " $i " /proc/self/mounts | awk '{print $4}' | egrep --silent '(^|,)seclabel(,|$)' && echo $i
|
|
|
|
else
|
|
|
|
grep " $i " /proc/self/mounts | grep -v "context=" | egrep --silent '(ext[234]| ext4dev | gfs2 | xfs | jfs | btrfs )' && echo $i
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
get_rw_labeled_mounts() {
|
|
|
|
FS=`get_all_labeled_mounts | sort | uniq`
|
|
|
|
for i in $FS; do
|
|
|
|
grep " $i " /proc/self/mounts | awk '{print $4}' | egrep --silent '(^|,)rw(,|$)' && echo $i
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
get_ro_labeled_mounts() {
|
|
|
|
FS=`get_all_labeled_mounts | sort | uniq`
|
|
|
|
for i in $FS; do
|
|
|
|
grep " $i " /proc/self/mounts | awk '{print $4}' | egrep --silent '(^|,)ro(,|$)' && echo $i
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2011-08-10 18:32:47 +00:00
|
|
|
#
|
2013-10-09 21:43:52 +00:00
|
|
|
# Get the default label returned from the kernel for a file with a lable the
|
2011-08-10 18:32:47 +00:00
|
|
|
# kernel does not understand
|
|
|
|
#
|
|
|
|
get_undefined_type() {
|
|
|
|
SELINUXMNT=`grep selinuxfs /proc/self/mountinfo | head -1 | awk '{ print $5 }'`
|
|
|
|
cat ${SELINUXMNT}/initial_contexts/unlabeled | secon -t
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Get the default label for a file without a label
|
|
|
|
#
|
|
|
|
get_unlabeled_type() {
|
|
|
|
SELINUXMNT=`grep selinuxfs /proc/self/mountinfo | head -1 | awk '{ print $5 }'`
|
2013-10-09 21:43:52 +00:00
|
|
|
cat $SELINUXMNT/initial_contexts/file | secon -t
|
2011-08-10 18:32:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-10 12:14:14 +00:00
|
|
|
exclude_dirs_from_relabelling() {
|
|
|
|
exclude_from_relabelling=
|
|
|
|
if [ -e /etc/selinux/fixfiles_exclude_dirs ]
|
|
|
|
then
|
2013-10-09 21:43:52 +00:00
|
|
|
while read i
|
|
|
|
do
|
|
|
|
# skip blank line and comment
|
|
|
|
# skip not absolute path
|
|
|
|
# skip not directory
|
|
|
|
[ -z "${i}" ] && continue
|
|
|
|
[[ "${i}" =~ "^[[:blank:]]*#" ]] && continue
|
|
|
|
[[ ! "${i}" =~ ^/.* ]] && continue
|
|
|
|
[[ ! -d "${i}" ]] && continue
|
|
|
|
exclude_from_relabelling="$exclude_from_relabelling -e $i"
|
|
|
|
logit "skipping the directory $i"
|
|
|
|
done < /etc/selinux/fixfiles_exclude_dirs
|
2011-07-10 12:14:14 +00:00
|
|
|
fi
|
|
|
|
echo "$exclude_from_relabelling"
|
|
|
|
}
|
|
|
|
|
|
|
|
exclude_dirs() {
|
|
|
|
exclude=
|
2013-01-25 22:30:06 +00:00
|
|
|
for i in /sys /proc /dev /run /mnt /var/tmp /var/lib/BackupPC /home /tmp /dev; do
|
2013-10-09 21:43:52 +00:00
|
|
|
[ -e $i ] && exclude="$exclude -e $i";
|
2011-07-10 12:14:14 +00:00
|
|
|
done
|
|
|
|
exclude="$exclude `exclude_dirs_from_relabelling`"
|
|
|
|
echo "$exclude"
|
|
|
|
}
|
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
#
|
|
|
|
# Set global Variables
|
|
|
|
#
|
|
|
|
fullFlag=0
|
2013-01-25 22:30:06 +00:00
|
|
|
BOOTTIME=""
|
2012-02-03 16:56:39 +00:00
|
|
|
VERBOSE="-p"
|
2008-08-19 19:30:36 +00:00
|
|
|
FORCEFLAG=""
|
|
|
|
DIRS=""
|
|
|
|
RPMILES=""
|
policycoreutils: let output of `fixfiles` be redirected (as normal)
fixfiles was redirecting log output to `tty`. This overrides user intent
e.g. when shell redirection is used.
Redirect it to stdout, using /proc. `tty` equally depended on /proc.
We do not depend on /dev/stdout: it might not be present, if a rescue
system is booted with devtmpfs (no udev daemon).
By default, log messages were redirected into the void when not run from a
tty. We consider this a bug, which is now fixed.
1. If calling scripts happen to require the old behaviour, they can easily
write the same code themselves.
2. When fixfiles is run from Fedora's selinux-autorelabel.service,
the calling script is specifically run from a tty.
Also Fedora's calling script chooses to redirect stdout and stderr to
/dev/null. This redirection will now suceed, improving the transparency
of the code. The previous behaviour may be obtained by choosing not
to redirect the progress messages of this long-running process to
/dev/null. A patch has been submitted to Fedora to suggest this novel
approach: https://bugzilla.redhat.com/show_bug.cgi?id=1415674
Complete disclosure:
* Remove unused variable LOGGER.
* Fix logfiles containing spaces.
Disclaimer:
1. "Log" output may contain escape sequences (backspace?) e.g. in
`fixfiles -l log.txt restore`. This is not the usual understanding
of a log file.
2. For some reason, not all informative messages are sent to `-l` e.g.
the list of filesystems, and "cleaning up labels on /tmp".
3. `function logit` is retained, but the logfile is also written to
outside this function. Implementing support for the system log
would require another function which accepts piped input.
Also see point 1.
Signed-off-by: Alan Jenkins <alan.christopher.jenkins@gmail.com>
2017-01-23 12:15:50 +00:00
|
|
|
LOGFILE=/proc/self/fd/1
|
2008-08-19 19:30:36 +00:00
|
|
|
SETFILES=/sbin/setfiles
|
|
|
|
RESTORECON=/sbin/restorecon
|
2011-07-10 14:09:11 +00:00
|
|
|
FILESYSTEMSRW=`get_rw_labeled_mounts`
|
|
|
|
FILESYSTEMSRO=`get_ro_labeled_mounts`
|
2008-08-19 19:30:36 +00:00
|
|
|
FILESYSTEMS="$FILESYSTEMSRW $FILESYSTEMSRO"
|
|
|
|
SELINUXTYPE="targeted"
|
|
|
|
if [ -e /etc/selinux/config ]; then
|
|
|
|
. /etc/selinux/config
|
2013-10-09 21:43:52 +00:00
|
|
|
FC=/etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts
|
2008-08-19 19:30:36 +00:00
|
|
|
else
|
|
|
|
FC=/etc/security/selinux/file_contexts
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
policycoreutils: let output of `fixfiles` be redirected (as normal)
fixfiles was redirecting log output to `tty`. This overrides user intent
e.g. when shell redirection is used.
Redirect it to stdout, using /proc. `tty` equally depended on /proc.
We do not depend on /dev/stdout: it might not be present, if a rescue
system is booted with devtmpfs (no udev daemon).
By default, log messages were redirected into the void when not run from a
tty. We consider this a bug, which is now fixed.
1. If calling scripts happen to require the old behaviour, they can easily
write the same code themselves.
2. When fixfiles is run from Fedora's selinux-autorelabel.service,
the calling script is specifically run from a tty.
Also Fedora's calling script chooses to redirect stdout and stderr to
/dev/null. This redirection will now suceed, improving the transparency
of the code. The previous behaviour may be obtained by choosing not
to redirect the progress messages of this long-running process to
/dev/null. A patch has been submitted to Fedora to suggest this novel
approach: https://bugzilla.redhat.com/show_bug.cgi?id=1415674
Complete disclosure:
* Remove unused variable LOGGER.
* Fix logfiles containing spaces.
Disclaimer:
1. "Log" output may contain escape sequences (backspace?) e.g. in
`fixfiles -l log.txt restore`. This is not the usual understanding
of a log file.
2. For some reason, not all informative messages are sent to `-l` e.g.
the list of filesystems, and "cleaning up labels on /tmp".
3. `function logit` is retained, but the logfile is also written to
outside this function. Implementing support for the system log
would require another function which accepts piped input.
Also see point 1.
Signed-off-by: Alan Jenkins <alan.christopher.jenkins@gmail.com>
2017-01-23 12:15:50 +00:00
|
|
|
# Write to LOGFILE
|
2008-08-19 19:30:36 +00:00
|
|
|
#
|
|
|
|
logit () {
|
|
|
|
if [ -n $LOGFILE ]; then
|
policycoreutils: let output of `fixfiles` be redirected (as normal)
fixfiles was redirecting log output to `tty`. This overrides user intent
e.g. when shell redirection is used.
Redirect it to stdout, using /proc. `tty` equally depended on /proc.
We do not depend on /dev/stdout: it might not be present, if a rescue
system is booted with devtmpfs (no udev daemon).
By default, log messages were redirected into the void when not run from a
tty. We consider this a bug, which is now fixed.
1. If calling scripts happen to require the old behaviour, they can easily
write the same code themselves.
2. When fixfiles is run from Fedora's selinux-autorelabel.service,
the calling script is specifically run from a tty.
Also Fedora's calling script chooses to redirect stdout and stderr to
/dev/null. This redirection will now suceed, improving the transparency
of the code. The previous behaviour may be obtained by choosing not
to redirect the progress messages of this long-running process to
/dev/null. A patch has been submitted to Fedora to suggest this novel
approach: https://bugzilla.redhat.com/show_bug.cgi?id=1415674
Complete disclosure:
* Remove unused variable LOGGER.
* Fix logfiles containing spaces.
Disclaimer:
1. "Log" output may contain escape sequences (backspace?) e.g. in
`fixfiles -l log.txt restore`. This is not the usual understanding
of a log file.
2. For some reason, not all informative messages are sent to `-l` e.g.
the list of filesystems, and "cleaning up labels on /tmp".
3. `function logit` is retained, but the logfile is also written to
outside this function. Implementing support for the system log
would require another function which accepts piped input.
Also see point 1.
Signed-off-by: Alan Jenkins <alan.christopher.jenkins@gmail.com>
2017-01-23 12:15:50 +00:00
|
|
|
echo $1 >> "$LOGFILE"
|
2008-08-19 19:30:36 +00:00
|
|
|
fi
|
|
|
|
}
|
2013-01-25 22:30:06 +00:00
|
|
|
#
|
|
|
|
# Find files newer then the passed in date and fix the label
|
|
|
|
#
|
|
|
|
newer() {
|
|
|
|
DATE=$1
|
2016-08-09 13:24:15 +00:00
|
|
|
shift
|
2013-01-25 22:30:06 +00:00
|
|
|
for m in `echo $FILESYSTEMSRW`; do
|
2016-08-09 13:24:15 +00:00
|
|
|
find $m -mount -newermt $DATE -print0 2>/dev/null | ${RESTORECON} ${FORCEFLAG} ${VERBOSE} $* -i -0 -f -
|
2013-01-25 22:30:06 +00:00
|
|
|
done;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
#
|
2013-10-09 21:43:52 +00:00
|
|
|
# Compare PREVious File Context to currently installed File Context and
|
2008-08-19 19:30:36 +00:00
|
|
|
# run restorecon on all files affected by the differences.
|
|
|
|
#
|
|
|
|
diff_filecontext() {
|
|
|
|
if [ -f ${PREFC} -a -x /usr/bin/diff ]; then
|
|
|
|
TEMPFILE=`mktemp ${FC}.XXXXXXXXXX`
|
|
|
|
test -z "$TEMPFILE" && exit
|
|
|
|
PREFCTEMPFILE=`mktemp ${PREFC}.XXXXXXXXXX`
|
|
|
|
sed -r -e 's,:s0, ,g' $PREFC | sort -u > ${PREFCTEMPFILE}
|
|
|
|
sed -r -e 's,:s0, ,g' $FC | sort -u | \
|
|
|
|
/usr/bin/diff -b ${PREFCTEMPFILE} - | \
|
|
|
|
grep '^[<>]'|cut -c3-| grep ^/ | \
|
|
|
|
egrep -v '(^/home|^/root|^/tmp|^/dev)' |\
|
|
|
|
sed -r -e 's,[[:blank:]].*,,g' \
|
2013-10-09 21:43:52 +00:00
|
|
|
-e 's|\(([/[:alnum:]]+)\)\?|{\1,}|g' \
|
2008-08-19 19:30:36 +00:00
|
|
|
-e 's|([/[:alnum:]])\?|{\1,}|g' \
|
2013-10-09 21:43:52 +00:00
|
|
|
-e 's|\?.*|*|g' \
|
|
|
|
-e 's|\{.*|*|g' \
|
2008-08-19 19:30:36 +00:00
|
|
|
-e 's|\(.*|*|g' \
|
|
|
|
-e 's|\[.*|*|g' \
|
2013-10-09 21:43:52 +00:00
|
|
|
-e 's|\.\*.*|*|g' \
|
|
|
|
-e 's|\.\+.*|*|g' | \
|
2008-08-19 19:30:36 +00:00
|
|
|
# These two sorts need to be separate commands \
|
|
|
|
sort -u | \
|
|
|
|
sort -d | \
|
2013-10-09 21:43:52 +00:00
|
|
|
while read pattern ; \
|
2008-08-19 19:30:36 +00:00
|
|
|
do if ! echo "$pattern" | grep -q -f ${TEMPFILE} 2>/dev/null; then \
|
2013-10-09 21:43:52 +00:00
|
|
|
echo "$pattern"; \
|
|
|
|
case "$pattern" in *"*") \
|
|
|
|
echo "$pattern" | sed -e 's,^,^,' -e 's,\*$,,g' >> ${TEMPFILE};;
|
|
|
|
esac; \
|
|
|
|
fi; \
|
|
|
|
done | \
|
2016-08-09 13:24:15 +00:00
|
|
|
${RESTORECON} ${VERBOSE} -i -f - -R $* `exclude_dirs`; \
|
2008-08-19 19:30:36 +00:00
|
|
|
rm -f ${TEMPFILE} ${PREFCTEMPFILE}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
#
|
2013-10-09 21:43:52 +00:00
|
|
|
# Log all Read Only file systems
|
2008-08-19 19:30:36 +00:00
|
|
|
#
|
|
|
|
LogReadOnly() {
|
|
|
|
if [ ! -z "$FILESYSTEMSRO" ]; then
|
|
|
|
logit "Warning: Skipping the following R/O filesystems:"
|
|
|
|
logit "$FILESYSTEMSRO"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmlist() {
|
|
|
|
rpm -q --qf '[%{FILESTATES} %{FILENAMES}\n]' "$1" | grep '^0 ' | cut -f2- -d ' '
|
|
|
|
[ ${PIPESTATUS[0]} != 0 ] && echo "$1 not found" >/dev/stderr
|
|
|
|
}
|
|
|
|
|
2013-10-09 21:43:52 +00:00
|
|
|
#
|
2008-08-19 19:30:36 +00:00
|
|
|
# restore
|
|
|
|
# if called with -n will only check file context
|
|
|
|
#
|
|
|
|
restore () {
|
2013-10-09 21:43:52 +00:00
|
|
|
OPTION=$1
|
|
|
|
shift
|
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
if [ ! -z "$PREFC" ]; then
|
|
|
|
diff_filecontext $*
|
|
|
|
exit $?
|
|
|
|
fi
|
2013-01-25 22:30:06 +00:00
|
|
|
if [ ! -z "$BOOTTIME" ]; then
|
2016-08-09 13:24:15 +00:00
|
|
|
newer $BOOTTIME $*
|
2013-01-25 22:30:06 +00:00
|
|
|
exit $?
|
|
|
|
fi
|
2009-11-03 15:37:13 +00:00
|
|
|
[ -x /usr/sbin/genhomedircon ] && /usr/sbin/genhomedircon
|
2008-08-19 19:30:36 +00:00
|
|
|
LogReadOnly
|
2011-07-10 12:14:14 +00:00
|
|
|
#
|
2013-10-09 21:43:52 +00:00
|
|
|
exclude_dirs="`exclude_dirs_from_relabelling $OPTION`"
|
2011-07-10 12:14:14 +00:00
|
|
|
if [ -n "${exclude_dirs}" ]
|
|
|
|
then
|
|
|
|
TEMPFCFILE=`mktemp ${FC}.XXXXXXXXXX`
|
|
|
|
test -z "$TEMPFCFILE" && exit
|
|
|
|
/bin/cp -p ${FC} ${TEMPFCFILE} &>/dev/null || exit
|
2013-10-09 21:43:52 +00:00
|
|
|
tmpdirs=${tempdirs//-e/}
|
|
|
|
for p in ${tmpdirs}
|
2011-07-10 12:14:14 +00:00
|
|
|
do
|
|
|
|
p="${p%/}"
|
|
|
|
p1="${p}(/.*)? -- <<none>>"
|
|
|
|
echo "${p1}" >> $TEMPFCFILE
|
2013-10-09 21:43:52 +00:00
|
|
|
logit "skipping the directory ${p}"
|
2011-07-10 12:14:14 +00:00
|
|
|
done
|
|
|
|
FC=$TEMPFCFILE
|
|
|
|
fi
|
2013-10-09 21:43:52 +00:00
|
|
|
if [ ! -z "$RPMFILES" ]; then
|
|
|
|
for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
|
|
|
|
rpmlist $i | ${RESTORECON} $exclude_dirs ${FORCEFLAG} ${VERBOSE} $* -R -i -f - 2>&1 | cat >> $LOGFILE
|
|
|
|
done
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
if [ ! -z "$FILEPATH" ]; then
|
|
|
|
${RESTORECON} $exclude_dirs ${FORCEFLAG} ${VERBOSE} -R $* $FILEPATH 2>&1 | cat >> $LOGFILE
|
|
|
|
return
|
|
|
|
fi
|
2012-03-26 15:33:17 +00:00
|
|
|
if [ -n "${FILESYSTEMSRW}" ]; then
|
2013-10-09 21:43:52 +00:00
|
|
|
echo "${OPTION}ing `echo ${FILESYSTEMSRW}`"
|
|
|
|
${SETFILES} ${VERBOSE} $exclude_dirs -q ${FORCEFLAG} $* ${FC} ${FILESYSTEMSRW} 2>&1 | cat >> $LOGFILE
|
2012-03-26 15:33:17 +00:00
|
|
|
else
|
|
|
|
echo >&2 "fixfiles: No suitable file systems found"
|
|
|
|
fi
|
2013-10-09 21:43:52 +00:00
|
|
|
if [ ${OPTION} != "Relabel" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "Cleaning up labels on /tmp"
|
2011-07-10 12:14:14 +00:00
|
|
|
rm -rf /tmp/gconfd-* /tmp/pulse-* /tmp/orbit-* $TEMPFCFILE
|
|
|
|
|
2011-08-10 18:32:47 +00:00
|
|
|
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 {} \;
|
2013-10-09 21:43:52 +00:00
|
|
|
[ ! -e /var/lib/debug ] || find /var/lib/debug \( -context "*:${UNLABELED}*" -o -context "*:${UNDEFINED}*" \) -exec chcon --reference /lib {} \;
|
|
|
|
exit 0
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fullrelabel() {
|
|
|
|
logit "Cleaning out /tmp"
|
2011-07-10 11:27:11 +00:00
|
|
|
find /tmp/ -mindepth 1 -delete
|
2008-08-19 19:30:36 +00:00
|
|
|
LogReadOnly
|
2013-10-09 21:43:52 +00:00
|
|
|
restore Relabel
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
relabel() {
|
|
|
|
if [ ! -z "$RPMFILES" ]; then
|
2013-10-09 21:43:52 +00:00
|
|
|
restore Relabel
|
2008-08-19 19:30:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $fullFlag == 1 ]; then
|
|
|
|
fullrelabel
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n "
|
2013-10-09 21:43:52 +00:00
|
|
|
Files in the /tmp directory may be labeled incorrectly, this command
|
|
|
|
can remove all files in /tmp. If you choose to remove files from /tmp,
|
2008-08-19 19:30:36 +00:00
|
|
|
a reboot will be required after completion.
|
2013-10-09 21:43:52 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
Do you wish to clean out the /tmp directory [N]? "
|
|
|
|
read answer
|
2013-10-09 21:43:52 +00:00
|
|
|
if [ "$answer" = y -o "$answer" = Y ]; then
|
2008-08-19 19:30:36 +00:00
|
|
|
fullrelabel
|
|
|
|
else
|
2013-10-09 21:43:52 +00:00
|
|
|
restore Relabel
|
2008-08-19 19:30:36 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
process() {
|
|
|
|
#
|
|
|
|
# Make sure they specified one of the three valid commands
|
|
|
|
#
|
|
|
|
case "$1" in
|
2013-10-09 21:43:52 +00:00
|
|
|
restore) restore Relabel;;
|
|
|
|
check) VERBOSE="-v"; restore Check -n;;
|
|
|
|
verify) restore Verify -n -o -;;
|
2008-08-19 19:30:36 +00:00
|
|
|
relabel) relabel;;
|
|
|
|
onboot)
|
2013-01-25 22:30:06 +00:00
|
|
|
> /.autorelabel
|
|
|
|
[ -z "$FORCEFLAG" ] || echo -n "$FORCEFLAG " >> /.autorelabel
|
|
|
|
[ -z "$BOOTTIME" ] || echo -N $BOOTTIME >> /.autorelabel
|
|
|
|
# Force full relabel if / does not have a label on it
|
|
|
|
getfilecon / > /dev/null 2>&1 || echo -F >/.autorelabel
|
2008-08-19 19:30:36 +00:00
|
|
|
echo "System will relabel on next boot"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
usage() {
|
2013-10-09 21:43:52 +00:00
|
|
|
echo $"""
|
|
|
|
Usage: $0 [-v] [-F] [-N time ] [-l logfile ] { check | restore| [-f] relabel | verify } [[dir/file] ... ]
|
2009-11-03 15:37:13 +00:00
|
|
|
or
|
2013-10-09 21:43:52 +00:00
|
|
|
Usage: $0 [-v] [-F] -R rpmpackage[,rpmpackage...] [-l logfile ] { check | restore | verify }
|
2009-11-03 15:37:13 +00:00
|
|
|
or
|
2013-10-09 21:43:52 +00:00
|
|
|
Usage: $0 [-v] [-F] -C PREVIOUS_FILECONTEXT { check | restore | verify }
|
2009-11-03 15:37:13 +00:00
|
|
|
or
|
2013-10-09 21:43:52 +00:00
|
|
|
Usage: $0 [-F] [-B] onboot
|
2009-11-03 15:37:13 +00:00
|
|
|
"""
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# = 0 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# See how we were called.
|
2013-01-25 22:30:06 +00:00
|
|
|
while getopts "N:BC:FfR:l:v" i; do
|
2008-08-19 19:30:36 +00:00
|
|
|
case "$i" in
|
2013-01-25 22:30:06 +00:00
|
|
|
B)
|
|
|
|
BOOTTIME=`/bin/who -b | awk '{print $3}'`
|
|
|
|
;;
|
2008-08-19 19:30:36 +00:00
|
|
|
f)
|
|
|
|
fullFlag=1
|
|
|
|
;;
|
2012-02-03 16:56:39 +00:00
|
|
|
v)
|
|
|
|
VERBOSE="-v"
|
|
|
|
;;
|
2013-10-09 21:43:52 +00:00
|
|
|
R)
|
2008-08-19 19:30:36 +00:00
|
|
|
RPMFILES=$OPTARG
|
|
|
|
;;
|
2013-10-09 21:43:52 +00:00
|
|
|
l)
|
2008-08-19 19:30:36 +00:00
|
|
|
LOGFILE=$OPTARG
|
|
|
|
;;
|
2013-10-09 21:43:52 +00:00
|
|
|
C)
|
2008-08-19 19:30:36 +00:00
|
|
|
PREFC=$OPTARG
|
|
|
|
;;
|
|
|
|
F)
|
|
|
|
FORCEFLAG="-F"
|
|
|
|
;;
|
2013-01-25 22:30:06 +00:00
|
|
|
N)
|
|
|
|
BOOTTIME=$OPTARG
|
|
|
|
;;
|
2008-08-19 19:30:36 +00:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
# Move out processed options from arguments
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
|
|
|
# Check for the command
|
|
|
|
command=$1
|
|
|
|
if [ -z $command ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Move out command from arguments
|
|
|
|
shift
|
|
|
|
|
|
|
|
#
|
|
|
|
# check if they specified both DIRS and RPMFILES
|
|
|
|
#
|
|
|
|
|
|
|
|
if [ ! -z "$RPMFILES" ]; then
|
|
|
|
process $command
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
process $command
|
|
|
|
else
|
2013-10-09 21:43:52 +00:00
|
|
|
while [ -n "$1" ]; do
|
2008-08-19 19:30:36 +00:00
|
|
|
FILEPATH=$1
|
2013-10-09 21:43:52 +00:00
|
|
|
process $command
|
2008-08-19 19:30:36 +00:00
|
|
|
shift
|
2013-10-09 21:43:52 +00:00
|
|
|
done
|
2008-08-19 19:30:36 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exit $?
|