summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin Ouyang <Xin.Ouyang@windriver.com>2012-09-11 15:34:24 +0800
committerXin Ouyang <Xin.Ouyang@windriver.com>2012-10-18 11:07:44 +0800
commit0674df16fbee26d269af0552eb11a5110f43b40f (patch)
tree65696b90bbd006ea5dd6607a270900e967d393fb
parent154da76033edc352fb7848d827c51b8f592250f8 (diff)
downloadmeta-selinux-0674df16fbee26d269af0552eb11a5110f43b40f.tar.gz
initscripts: restorecon after populate-volatile
populate-volatile.sh creates new directories in /var/volatile/ while booting, so we should restore the security contexts in it. Also touch /var/log/lastlog to set correct security contexts. populate-volatile.sh is imported for oe-core, and add these two lines at the end. touch /var/log/lastlog test ! -x /sbin/restorecon || /sbin/restorecon -R /var/volatile/ Signed-off-by: Xin Ouyang <Xin.Ouyang@windriver.com>
-rwxr-xr-xrecipes-core/initscripts/files/populate-volatile.sh202
-rw-r--r--recipes-core/initscripts/initscripts_1.0.bbappend3
2 files changed, 205 insertions, 0 deletions
diff --git a/recipes-core/initscripts/files/populate-volatile.sh b/recipes-core/initscripts/files/populate-volatile.sh
new file mode 100755
index 0000000..6931b37
--- /dev/null
+++ b/recipes-core/initscripts/files/populate-volatile.sh
@@ -0,0 +1,202 @@
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: volatile
4# Required-Start: $local_fs
5# Required-Stop: $local_fs
6# Default-Start: S
7# Default-Stop:
8# Short-Description: Populate the volatile filesystem
9### END INIT INFO
10
11. /etc/default/rcS
12
13CFGDIR="/etc/default/volatiles"
14TMPROOT="/var/tmp"
15COREDEF="00_core"
16
17[ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems."
18
19create_file() {
20 EXEC="
21 touch \"$1\";
22 chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/tty0 2>&1;
23 chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/tty0 2>&1 "
24
25 test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache.build
26
27 [ -e "$1" ] && {
28 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
29 } || {
30 eval $EXEC &
31 }
32}
33
34mk_dir() {
35 EXEC="
36 mkdir -p \"$1\";
37 chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/tty0 2>&1;
38 chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/tty0 2>&1 "
39
40 test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache.build
41
42 [ -e "$1" ] && {
43 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
44 } || {
45 eval $EXEC
46 }
47}
48
49link_file() {
50 EXEC="test -e \"$2\" -o -L $2 || ln -s \"$1\" \"$2\" >/dev/tty0 2>&1"
51
52 test "$VOLATILE_ENABLE_CACHE" = yes && echo " $EXEC" >> /etc/volatile.cache.build
53
54 [ -e "$2" ] && {
55 echo "Cannot create link over existing -${TNAME}-." >&2
56 } || {
57 eval $EXEC &
58 }
59}
60
61check_requirements() {
62
63 cleanup() {
64 rm "${TMP_INTERMED}"
65 rm "${TMP_DEFINED}"
66 rm "${TMP_COMBINED}"
67 }
68
69 CFGFILE="$1"
70
71 [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0
72
73 TMP_INTERMED="${TMPROOT}/tmp.$$"
74 TMP_DEFINED="${TMPROOT}/tmpdefined.$$"
75 TMP_COMBINED="${TMPROOT}/tmpcombined.$$"
76
77
78 cat /etc/passwd | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
79 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 2 > "${TMP_INTERMED}"
80 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
81
82 NR_DEFINED_USERS="`cat "${TMP_DEFINED}" | wc -l`"
83 NR_COMBINED_USERS="`cat "${TMP_COMBINED}" | wc -l`"
84
85 [ "${NR_DEFINED_USERS}" -ne "${NR_COMBINED_USERS}" ] && {
86 echo "Undefined users:"
87 diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
88 cleanup
89 return 1
90 }
91
92
93 cat /etc/group | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
94 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 3 > "${TMP_INTERMED}"
95 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
96
97 NR_DEFINED_GROUPS="`cat "${TMP_DEFINED}" | wc -l`"
98 NR_COMBINED_GROUPS="`cat "${TMP_COMBINED}" | wc -l`"
99
100 [ "${NR_DEFINED_GROUPS}" -ne "${NR_COMBINED_GROUPS}" ] && {
101 echo "Undefined groups:"
102 diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
103 cleanup
104 return 1
105 }
106
107 # Add checks for required directories here
108
109 cleanup
110 return 0
111 }
112
113apply_cfgfile() {
114
115 CFGFILE="$1"
116
117 check_requirements "${CFGFILE}" || {
118 echo "Skipping ${CFGFILE}"
119 return 1
120 }
121
122 cat ${CFGFILE} | grep -v "^#" | \
123 while read LINE; do
124
125 eval `echo "$LINE" | sed -n "s/\(.*\)\ \(.*\) \(.*\)\ \(.*\)\ \(.*\)\ \(.*\)/TTYPE=\1 ; TUSER=\2; TGROUP=\3; TMODE=\4; TNAME=\5 TLTARGET=\6/p"`
126
127 [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-."
128
129
130 [ "${TTYPE}" = "l" ] && {
131 TSOURCE="$TLTARGET"
132 [ -L "${TNAME}" ] || {
133 [ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
134 link_file "${TSOURCE}" "${TNAME}" &
135 }
136 continue
137 }
138
139 [ -L "${TNAME}" ] && {
140 [ "${VERBOSE}" != "no" ] && echo "Found link."
141 NEWNAME=`ls -l "${TNAME}" | sed -e 's/^.*-> \(.*\)$/\1/'`
142 echo ${NEWNAME} | grep -v "^/" >/dev/null && {
143 TNAME="`echo ${TNAME} | sed -e 's@\(.*\)/.*@\1@'`/${NEWNAME}"
144 [ "${VERBOSE}" != "no" ] && echo "Converted relative linktarget to absolute path -${TNAME}-."
145 } || {
146 TNAME="${NEWNAME}"
147 [ "${VERBOSE}" != "no" ] && echo "Using absolute link target -${TNAME}-."
148 }
149 }
150
151 case "${TTYPE}" in
152 "f") [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-."
153 create_file "${TNAME}" &
154 ;;
155 "d") [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-."
156 mk_dir "${TNAME}"
157 # Add check to see if there's an entry in fstab to mount.
158 ;;
159 *) [ "${VERBOSE}" != "no" ] && echo "Invalid type -${TTYPE}-."
160 continue
161 ;;
162 esac
163
164
165 done
166
167 return 0
168
169 }
170
171clearcache=0
172exec 9</proc/cmdline
173while read line <&9
174do
175 case "$line" in
176 *clearcache*) clearcache=1
177 ;;
178 *) continue
179 ;;
180 esac
181done
182exec 9>&-
183
184if test -e /etc/volatile.cache -a "$VOLATILE_ENABLE_CACHE" = "yes" -a "x$1" != "xupdate" -a "x$clearcache" = "x0"
185then
186 sh /etc/volatile.cache
187else
188 rm -f /etc/volatile.cache /etc/volatile.cache.build
189 for file in `ls -1 "${CFGDIR}" | sort`; do
190 apply_cfgfile "${CFGDIR}/${file}"
191 done
192
193 [ -e /etc/volatile.cache.build ] && sync && mv /etc/volatile.cache.build /etc/volatile.cache
194fi
195
196if test -f /etc/ld.so.cache -a ! -f /var/run/ld.so.cache
197then
198 ln -s /etc/ld.so.cache /var/run/ld.so.cache
199fi
200
201touch /var/log/lastlog
202test ! -x /sbin/restorecon || /sbin/restorecon -R /var/volatile/
diff --git a/recipes-core/initscripts/initscripts_1.0.bbappend b/recipes-core/initscripts/initscripts_1.0.bbappend
new file mode 100644
index 0000000..fd0bc32
--- /dev/null
+++ b/recipes-core/initscripts/initscripts_1.0.bbappend
@@ -0,0 +1,3 @@
1PR .= ".1"
2
3FILESEXTRAPATHS_prepend := "${THISDIR}/files:"