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.
22 # 11/28/2001 Robbie Williamson (robbiew@austin.ibm.com)
24 # 03/05/2002 Jay Huie (wjh@us.ibm.com)
25 # Changed script to only ask regarding creation of IDs if
26 # necessary. Cleaner automation of the script and
27 # most distos now have IDs already added
28 # HISTORY : see the cvs log
31 # debian is good enough
35 # Prompt user if ids/groups should be created
37 echo "Checking for required user/group ids"
40 # Check ids and create if needed.
66 if [ -n "$CREATE_ENTRIES" ] ; then
68 if [ $I_AM_ROOT -eq 0 ] ; then
69 echo "Not root; can't create user / group entries on local machine".
72 echo "CREATE_ENTRIES variable set to $CREATE_ENTRIES ..."
77 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 -a $I_AM_ROOT -ne 0 ] ; then
78 echo -n "If any required user ids and/or groups are missing, would you like these created? [y/N]"
81 Y
*|y
*) CREATE_ENTRIES
=1 ;;
82 *) CREATE_ENTRIES
=0 ;;
91 if [ -z ${EUID} ] ; then
95 if [ -e /etc
/passwd
-a ! -r /etc
/passwd
] ; then
96 echo "/etc/passwd not readable by uid $EUID"
98 elif [ -e /etc
/group
-a ! -r /etc
/group
] ; then
99 echo "/etc/group not readable by uid $EUID"
103 ife bin
; NO_BIN_ID
=$?
104 ife daemon
; NO_DAEMON_ID
=$?
105 ife nobody
; NO_NOBODY_ID
=$?
107 gfe
'^bin:' /etc
/group
; NO_BIN_GRP
=$?
108 gfe
'^daemon:' /etc
/group
; NO_DAEMON_GRP
=$?
109 gfe
'^nobody:' /etc
/group
; NO_NOBODY_GRP
=$?
110 gfe
'^sys:' /etc
/group
; NO_SYS_GRP
=$?
111 gfe
'^users:' /etc
/group
; NO_USERS_GRP
=$?
113 if [ $EUID -eq 0 ] ; then
121 echo "Missing the following group / user entries:"
122 echo "nobody: $NO_NOBODY_ID"
123 echo "bin: $NO_BIN_ID"
124 echo "daemon: $NO_DAEMON_ID"
125 echo "nobody grp: $NO_NOBODY_GRP"
126 echo "bin grp: $NO_BIN_GRP"
127 echo "daemon grp: $NO_DAEMON_GRP"
128 echo "sys grp: $NO_SYS_GRP"
129 echo "users grp: $NO_USERS_GRP"
131 echo "i am root: $I_AM_ROOT"
138 if [ $CREATE_ENTRIES -ne 0 ] ; then
139 if ! touch /etc
/group
; then
140 echo "Couldn't touch /etc/group"
146 local name
=$1 id
=$2 no_id
=$3 no_grp
=$4
148 if [ $no_id -eq 0 -a $no_grp -eq 0 ] ; then
149 echo "'$name' user id and group found."
150 elif [ $CREATE_ENTRIES -ne 0 ] ; then
151 echo "Creating entries for $name"
153 # Avoid chicken and egg issue with id(1) call
154 # made above and below.
155 if ! gfe
"^${name}:" /etc
/passwd
&& [ $no_id -ne 0 ] ; then
156 echo "${name}:x:${id}:${id}:${name}::" >> /etc
/passwd
158 if [ $no_grp -ne 0 ] ; then
159 echo "${name}:x:$(id -u ${name}):" >> /etc
/group
163 make_user_group nobody
99 $NO_NOBODY_ID $NO_NOBODY_GRP
164 make_user_group bin
1 $NO_BIN_ID $NO_BIN_GRP
165 make_user_group daemon
2 $NO_DAEMON_ID $NO_DAEMON_GRP
167 if [ $NO_USERS_GRP -eq 0 ] ; then
168 echo "Users group found."
169 elif [ $CREATE_ENTRIES -ne 0 ] ; then
170 echo 'users:x:100:' >> /etc
/group
173 if [ $NO_SYS_GRP -eq 0 ] ; then
174 echo "Sys group found."
175 elif [ $CREATE_ENTRIES -ne 0 ] ; then
176 echo 'sys:x:3:' >> /etc
/group
179 if ife nobody
&& ife bin
&& ife daemon
&&
180 ife
-g nobody
&& ife
-g bin
&& ife
-g daemon
&&
181 gfe
'^users:' /etc
/group
&& gfe
'^sys:' /etc
/group
&&
182 gfe
'^nobody:' /etc
/group
185 echo "Required users/groups exist."
190 echo "*****************************************"
191 echo "* Required users/groups do NOT exist!!! *"
193 echo "* Some kernel/syscall tests will FAIL! *"
194 echo "*****************************************"