dealing with file SIDs in packages
In my Debian package "selinux" I have a sample policy for setfiles. This causes setfiles to be run in a different domain with appropriate permissions to read every directory on the system and change the context of every file.
The initial problem I had was that replacing the "selinux" package would replace a copy of the file with a new copy in the default context (which didn't work).
So here is my solution:
I put the following code in the preinst script of "selinux":
if [ ! -f /usr/sbin/setfiles.old ]; then
mv /usr/sbin/setfiles /usr/sbin/setfiles.old
fi
Then I put the following code in /etc/dpkg/postinst.d/selinux:
#!/bin/sh
SETFILES=/usr/sbin/setfiles
if [ -x /usr/sbin/setfiles.old ]; then
SETFILES=/usr/sbin/setfiles.old
fi
dpkg -L $1 | grep ... | $SETFILES -s /etc/selinux/file_contexts/file_contexts if [ -x /usr/sbin/setfiles.old -a "$1" = "selinux" ]; then
rm /usr/sbin/setfiles.old
fi
The /etc/dpkg/postinst.d/* scripts are run by my hacked version of dpkg after the package is installed, but before the postinst script from the package is run. $1 is the name of the package that is being installed.
The old file is only removed if we are installing the "selinux" package, so if the preinst scripts from several packages are run before the postinsts of them are run then we won't remove the old file until the new one has the correct context.
Hope this helps people doing RPM packages or other packaging...
Signature · 9 lines
If you send email to me or to a mailing list that I use which has >4 lines of legalistic junk at the end then you are specifically authorizing me to do whatever I wish with the message and all other messages from your domain, by posting the message you agree that your long legalistic sig is void. -- You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.