summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Durnev <mikhail_durnev@mentor.com>2013-06-25 21:54:36 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-06-28 09:14:07 +0100
commitc62b1a33386439d0b4b51585fbc5b9198fd07068 (patch)
treedc37b5192588fd3960f9b6bdaeaac09549248742
parent1f7647c197929f5a8c633a93a02ac9f04b94b3ae (diff)
downloadpoky-c62b1a33386439d0b4b51585fbc5b9198fd07068.tar.gz
useradd.bbclass: Add members to a group
useradd.bbclass supports adding new users and new groups. But it does not support adding existing users to existing groups. There is a need of adding users to some groups (e.g. audio). The class was extended to call groupmems utility with arguments passed via GROUPMEMS_PARAM. (From OE-Core rev: 6b3bd34bf8c5e511bccfbb64bdd1236e1e7576e3) Signed-off-by: Mikhail Durnev <mikhail_durnev@mentor.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/useradd.bbclass68
1 files changed, 63 insertions, 5 deletions
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
index e50c889da8..3fe011d976 100644
--- a/meta/classes/useradd.bbclass
+++ b/meta/classes/useradd.bbclass
@@ -24,13 +24,15 @@ if test "x$D" != "x"; then
24 OPT="--root $D" 24 OPT="--root $D"
25 25
26 # Add groups and users defined for all recipe packages 26 # Add groups and users defined for all recipe packages
27 GROUPADD_PARAM="${@get_all_cmd_params(d, 'group')}" 27 GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
28 USERADD_PARAM="${@get_all_cmd_params(d, 'user')}" 28 USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
29 GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
29else 30else
30 # Installing onto a target 31 # Installing onto a target
31 # Add groups and users defined only for this package 32 # Add groups and users defined only for this package
32 GROUPADD_PARAM="${GROUPADD_PARAM}" 33 GROUPADD_PARAM="${GROUPADD_PARAM}"
33 USERADD_PARAM="${USERADD_PARAM}" 34 USERADD_PARAM="${USERADD_PARAM}"
35 GROUPMEMS_PARAM="${GROUPMEMS_PARAM}"
34fi 36fi
35 37
36# Perform group additions first, since user additions may depend 38# Perform group additions first, since user additions may depend
@@ -114,6 +116,62 @@ if test "x$USERADD_PARAM" != "x"; then
114 remaining=`echo "$remaining" | cut -d ';' -f 2-` 116 remaining=`echo "$remaining" | cut -d ';' -f 2-`
115 done 117 done
116fi 118fi
119
120if test "x$GROUPMEMS_PARAM" != "x"; then
121 echo "Running groupmems commands..."
122 # groupmems fails if /etc/gshadow does not exist
123 if [ -f $SYSROOT${sysconfdir}/gshadow ]; then
124 gshadow="yes"
125 else
126 gshadow="no"
127 touch $SYSROOT${sysconfdir}/gshadow
128 fi
129 # Invoke multiple instances of groupmems for parameter lists
130 # separated by ';'
131 opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1`
132 remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2-`
133 while test "x$opts" != "x"; do
134 groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'`
135 username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'`
136 echo "$groupname $username"
137 mem_exists=`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $SYSROOT/etc/group || true`
138 if test "x$mem_exists" = "x"; then
139 count=1
140 while true; do
141 eval $PSEUDO groupmems $OPT $opts || true
142 mem_exists=`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $SYSROOT/etc/group || true`
143 if test "x$mem_exists" = "x"; then
144 # File locking issues can require us to retry the command
145 echo "WARNING: groupmems command did not succeed. Retrying..."
146 sleep 1
147 else
148 break
149 fi
150 count=`expr $count + 1`
151 if test $count = 11; then
152 echo "ERROR: tried running groupmems command 10 times without success, giving up"
153 if test "x$gshadow" = "xno"; then
154 rm -f $SYSROOT${sysconfdir}/gshadow
155 rm -f $SYSROOT${sysconfdir}/gshadow-
156 fi
157 exit 1
158 fi
159 done
160 else
161 echo "Note: group $groupname already contains $username, not re-adding it"
162 fi
163
164 if test "x$opts" = "x$remaining"; then
165 break
166 fi
167 opts=`echo "$remaining" | cut -d ';' -f 1`
168 remaining=`echo "$remaining" | cut -d ';' -f 2-`
169 done
170 if test "x$gshadow" = "xno"; then
171 rm -f $SYSROOT${sysconfdir}/gshadow
172 rm -f $SYSROOT${sysconfdir}/gshadow-
173 fi
174fi
117} 175}
118 176
119useradd_sysroot () { 177useradd_sysroot () {
@@ -160,8 +218,8 @@ def update_useradd_after_parse(d):
160 raise bb.build.FuncFailed("%s inherits useradd but doesn't set USERADD_PACKAGES" % d.getVar('FILE')) 218 raise bb.build.FuncFailed("%s inherits useradd but doesn't set USERADD_PACKAGES" % d.getVar('FILE'))
161 219
162 for pkg in useradd_packages.split(): 220 for pkg in useradd_packages.split():
163 if not d.getVar('USERADD_PARAM_%s' % pkg, True) and not d.getVar('GROUPADD_PARAM_%s' % pkg, True): 221 if not d.getVar('USERADD_PARAM_%s' % pkg, True) and not d.getVar('GROUPADD_PARAM_%s' % pkg, True) and not d.getVar('GROUPMEMS_PARAM_%s' % pkg, True):
164 raise bb.build.FuncFailed("%s inherits useradd but doesn't set USERADD_PARAM or GROUPADD_PARAM for package %s" % (d.getVar('FILE'), pkg)) 222 raise bb.build.FuncFailed("%s inherits useradd but doesn't set USERADD_PARAM, GROUPADD_PARAM or GROUPMEMS_PARAM for package %s" % (d.getVar('FILE'), pkg))
165 223
166python __anonymous() { 224python __anonymous() {
167 update_useradd_after_parse(d) 225 update_useradd_after_parse(d)
@@ -172,7 +230,7 @@ python __anonymous() {
172def get_all_cmd_params(d, cmd_type): 230def get_all_cmd_params(d, cmd_type):
173 import string 231 import string
174 232
175 param_type = cmd_type.upper() + "ADD_PARAM_%s" 233 param_type = cmd_type.upper() + "_PARAM_%s"
176 params = [] 234 params = []
177 235
178 useradd_packages = d.getVar('USERADD_PACKAGES', True) or "" 236 useradd_packages = d.getVar('USERADD_PACKAGES', True) or ""