3 # Copyright (c) International Business Machines Corp., 2001
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 # the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # DESCRIPTION : checks for req'd users/groups and will create them if requested.
21 # HISTORY : see the cvs log
24 # debian is good enough
28 # Prompt user if ids/groups should be created
29 echo "Checking for required user/group ids"
32 # Check ids and create if needed.
42 group
="$DESTDIR/etc/group"
43 passwd
="$DESTDIR/etc/passwd"
49 [ -e "$FILE" ] ||
return $?
50 grep -q "^$ID:" "$FILE"
54 if [ -z "$CREATE_ENTRIES" ] ; then
56 if [ $NO_NOBODY_ID -ne 0 -o $NO_BIN_ID -ne 0 -o $NO_DAEMON_ID -ne 0 -o $NO_NOBODY_GRP -ne 0 -o $NO_BIN_GRP -ne 0 -o $NO_DAEMON_GRP -ne 0 -o $NO_USERS_GRP -ne 0 -o $NO_SYS_GRP -ne 0 ] ; then
57 echo -n "If any required user ids and/or groups are missing, would you like these created? [y/N]"
60 Y
*|y
*) CREATE_ENTRIES
=1 ;;
61 *) CREATE_ENTRIES
=0 ;;
70 if [ -z ${EUID} ] ; then
74 for i
in "$passwd" "$group"; do
75 if [ -e "$i" -a ! -r "$i" ] ; then
76 echo "$i not readable by uid $EUID"
81 fe bin
"$passwd"; NO_BIN_ID
=$?
82 fe daemon
"$passwd"; NO_DAEMON_ID
=$?
83 fe nobody
"$passwd"; NO_NOBODY_ID
=$?
85 fe bin
"$group"; NO_BIN_GRP
=$?
86 fe daemon
"$group"; NO_DAEMON_GRP
=$?
87 fe nobody
"$group"; NO_NOBODY_GRP
=$?
88 fe sys
"$group"; NO_SYS_GRP
=$?
89 fe users
"$group"; NO_USERS_GRP
=$?
95 echo "Missing the following group / user entries:"
96 echo "Group file: $group"
97 echo "Password file: $passwd"
98 echo "nobody: $NO_NOBODY_ID"
99 echo "bin: $NO_BIN_ID"
100 echo "daemon: $NO_DAEMON_ID"
101 echo "nobody grp: $NO_NOBODY_GRP"
102 echo "bin grp: $NO_BIN_GRP"
103 echo "daemon grp: $NO_DAEMON_GRP"
104 echo "sys grp: $NO_SYS_GRP"
105 echo "users grp: $NO_USERS_GRP"
112 if [ $CREATE_ENTRIES -ne 0 ] ; then
113 if ! touch "$group" "$passwd" 2>/dev
/null
; then
114 echo "Failed to touch $group or $passwd"
120 local name
=$1 id
=$2 no_id
=$3 no_grp
=$4
122 if [ $no_id -eq 0 -a $no_grp -eq 0 ] ; then
123 echo "'$name' user id and group found."
124 elif [ $CREATE_ENTRIES -ne 0 ] ; then
125 echo "Creating entries for $name"
127 # Avoid chicken and egg issue with id(1) call
128 # made above and below.
129 if ! fe
"$name" "$passwd" && [ $no_id -ne 0 ] ; then
130 echo "${name}:x:${id}:${id}:${name}::" >> "$passwd"
132 if [ $no_grp -ne 0 ] ; then
133 echo "${name}:x:$(id -u ${name}):" >> "$group"
137 make_user_group nobody
99 $NO_NOBODY_ID $NO_NOBODY_GRP
138 make_user_group bin
1 $NO_BIN_ID $NO_BIN_GRP
139 make_user_group daemon
2 $NO_DAEMON_ID $NO_DAEMON_GRP
141 if [ $NO_USERS_GRP -eq 0 ] ; then
142 echo "Users group found."
143 elif [ $CREATE_ENTRIES -ne 0 ] ; then
144 echo 'users:x:100:' >> "$group"
147 if [ $NO_SYS_GRP -eq 0 ] ; then
148 echo "Sys group found."
149 elif [ $CREATE_ENTRIES -ne 0 ] ; then
150 echo 'sys:x:3:' >> "$group"
155 # For entries that exist in both $group and $passwd.
156 for i
in nobody bin daemon
; do
157 for file in "$group" "$passwd"; do
158 if ! fe
"$i" "$file"; then
163 if [ $MISSING_ENTRY -ne 0 ]; then
168 # For entries that only exist in $group.
169 for i
in users sys
; do
170 if ! fe
"$i" "$group" ; then
175 if [ $MISSING_ENTRY -eq 0 ] ; then
176 echo "Required users/groups exist."
181 echo "*****************************************"
182 echo "* Required users/groups do NOT exist!!! *"
184 echo "* Some kernel/syscall tests will FAIL! *"
185 echo "*****************************************"