blob: af781611ae85c294edc8a26fcedf72416bfe0760 [file] [log] [blame]
robbiew3f9a8802001-10-12 20:39:17 +00001#!/bin/sh
2
robbiew599ddd72001-11-28 21:31:41 +00003# Copyright (c) International Business Machines Corp., 2001
4#
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.
9#
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.
14#
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
18
19# FILE : IDcheck.sh
20# DESCRIPTION : checks for req'd users/groups and will create them if requested.
21# HISTORY :
22# 11/28/2001 Robbie Williamson (robbiew@austin.ibm.com)
23# written
robbiew631a9f52002-03-05 22:42:55 +000024# 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
robbiew599ddd72001-11-28 21:31:41 +000028
29
30
robbiewd23f7242001-11-21 17:33:40 +000031# Prompt user if ids/groups should be created
robbiewc0f37e62001-11-27 19:14:19 +000032clear
33echo "Checking for required user/group ids"
34echo ""
robbiewd23f7242001-11-21 17:33:40 +000035
36# Check ids and create if needed.
37NOBODY_ID=0
38BIN_ID=0
39DAEMON_ID=0
40NOBODY_GRP=0
41BIN_GRP=0
42DAEMON_GRP=0
robbiew06e3bdf2003-04-08 15:23:33 +000043USERS_GRP=0
44SYS_GRP=0
robbiewcefffa72003-03-03 17:06:24 +000045I_AM_ROOT=0
robbiewd23f7242001-11-21 17:33:40 +000046
47id nobody > /dev/null
48if [ $? != "0" ]; then
49 NOBODY_ID=1
50fi
51
52id bin > /dev/null
53if [ $? != "0" ]; then
54 BIN_ID=1
55fi
56
57id daemon > /dev/null
58if [ $? != "0" ]; then
59 DAEMON_ID=1
60fi
61
robbiew90fc94c2002-04-08 14:55:37 +000062id -g nobody > /dev/null
robbiewd23f7242001-11-21 17:33:40 +000063if [ $? != "0" ]; then
64 NOBODY_GRP=1
65fi
66
67id -g bin > /dev/null
68if [ $? != "0" ]; then
69 BIN_GRP=1
70fi
71
72id -g daemon > /dev/null
73if [ $? != "0" ]; then
74 DAEMON_GRP=1
75fi
76
robbiew06e3bdf2003-04-08 15:23:33 +000077grep users /etc/group | cut -d: -f1 | grep users > /dev/null
78if [ $? != "0" ]; then
79 USERS_GRP=1
80fi
81
82grep sys /etc/group | cut -d: -f1 | grep sys > /dev/null
83if [ $? != "0" ]; then
84 SYS_GRP=1
85fi
86
robbiewcefffa72003-03-03 17:06:24 +000087whoami | grep root > /dev/null
88if [ $? == "0" ]; then
89 I_AM_ROOT=1
90fi
91
robbiew06e3bdf2003-04-08 15:23:33 +000092if [ $NOBODY_ID != "0" ] || [ $BIN_ID != "0" ] || [ $DAEMON_ID != "0" ] || [ $NOBODY_GRP != "0" ] || [ $BIN_GRP != "0" ] || [ $DAEMON_GRP != "0" ] || [ $USERS_GRP != "0" ] || [ $SYS_GRP != "0" ] && [ $I_AM_ROOT != "0" ];
robbiew631a9f52002-03-05 22:42:55 +000093then
94 echo -n "If any required user ids and/or groups are missing, would you like these created? Y/N "
95 read ans
96 case $ans in
97 Y*|y*)
98 CREATE=1
99 ;;
100 *)
101 CREATE=0
102 ;;
103 esac
104fi
105
robbiewd23f7242001-11-21 17:33:40 +0000106if [ $NOBODY_ID != "1" ] && [ $NOBODY_GRP != "1" ]; then
107 echo "Nobody user id and group exist."
108else
109 if [ $NOBODY_ID -eq "1" ] && [ $CREATE -eq "1" ]; then
110 echo nobody:x:99:99:Nobody:: >> /etc/passwd
111 fi
112 if [ $NOBODY_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then
113 echo nobody:x:`id -u nobody`: >> /etc/group
114 fi
115fi
116
117if [ $BIN_ID != "1" ] && [ $BIN_GRP != "1" ]; then
118 echo "Bin user id and group exist."
119else
nstrazf9598e42001-12-19 15:45:24 +0000120 if [ $BIN_ID -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000121 echo bin:x:1:1:bin:: >> /etc/passwd
122 fi
nstrazf9598e42001-12-19 15:45:24 +0000123 if [ $BIN_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000124 echo bin:x:`id -u bin`:bin >> /etc/group
125 fi
126fi
127
nstrazf9598e42001-12-19 15:45:24 +0000128if [ $DAEMON_ID -ne "1" ] && [ $DAEMON_GRP -ne "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000129 echo "Daemon user id and group exist."
130else
nstrazf9598e42001-12-19 15:45:24 +0000131 if [ $DAEMON_ID -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000132 echo daemon:x:2:2:daemon:: >> /etc/passwd
133 fi
nstrazf9598e42001-12-19 15:45:24 +0000134 if [ $DAEMON_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000135 echo daemon:x:`id -u daemon`:daemon >> /etc/group
136 fi
137fi
138
robbiew06e3bdf2003-04-08 15:23:33 +0000139if [ $USERS_GRP -ne "1" ]; then
140 echo "Users group exists."
141else
142 if [ $CREATE -eq "1" ]; then
143 echo users:x:100: >> /etc/group
144 fi
145fi
146
147if [ $SYS_GRP -ne "1" ]; then
148 echo "Sys group exists."
149else
150 if [ $CREATE -eq "1" ]; then
151 echo sys:x:3: >> /etc/group
152 fi
153fi
154
robbiewd23f7242001-11-21 17:33:40 +0000155id nobody > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000156if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000157 id bin > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000158 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000159 id daemon > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000160 if [ $? -eq "0" ]; then
robbiew90fc94c2002-04-08 14:55:37 +0000161 id -g nobody > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000162 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000163 id -g bin > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000164 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000165 id -g daemon > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000166 if [ $? -eq "0" ]; then
robbiew06e3bdf2003-04-08 15:23:33 +0000167 grep users /etc/group | cut -d: -f1 | grep users > /dev/null
168 if [ $? -eq "0" ]; then
169 grep sys /etc/group | cut -d: -f1 | grep sys > /dev/null
170 if [ $? -eq "0" ]; then
171 echo "Required users/groups exist."
172 exit 0
173 fi
174 fi
robbiew3f9a8802001-10-12 20:39:17 +0000175 fi
176 fi
177 fi
178 fi
179 fi
180fi
robbiewd23f7242001-11-21 17:33:40 +0000181echo "*****************************************"
182echo "* Required users/groups do NOT exist!!! *"
183echo "* *"
184echo "* Some kernel/syscall tests will FAIL! *"
185echo "*****************************************"
186exit 1