robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
robbiew | 599ddd7 | 2001-11-28 21:31:41 +0000 | [diff] [blame] | 3 | # 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 |
robbiew | 631a9f5 | 2002-03-05 22:42:55 +0000 | [diff] [blame] | 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 |
robbiew | 599ddd7 | 2001-11-28 21:31:41 +0000 | [diff] [blame] | 28 | |
| 29 | |
| 30 | |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 31 | # Prompt user if ids/groups should be created |
robbiew | c0f37e6 | 2001-11-27 19:14:19 +0000 | [diff] [blame] | 32 | clear |
| 33 | echo "Checking for required user/group ids" |
| 34 | echo "" |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 35 | |
| 36 | # Check ids and create if needed. |
| 37 | NOBODY_ID=0 |
| 38 | BIN_ID=0 |
| 39 | DAEMON_ID=0 |
| 40 | NOBODY_GRP=0 |
| 41 | BIN_GRP=0 |
| 42 | DAEMON_GRP=0 |
robbiew | 06e3bdf | 2003-04-08 15:23:33 +0000 | [diff] [blame] | 43 | USERS_GRP=0 |
| 44 | SYS_GRP=0 |
robbiew | cefffa7 | 2003-03-03 17:06:24 +0000 | [diff] [blame] | 45 | I_AM_ROOT=0 |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 46 | |
| 47 | id nobody > /dev/null |
| 48 | if [ $? != "0" ]; then |
| 49 | NOBODY_ID=1 |
| 50 | fi |
| 51 | |
| 52 | id bin > /dev/null |
| 53 | if [ $? != "0" ]; then |
| 54 | BIN_ID=1 |
| 55 | fi |
| 56 | |
| 57 | id daemon > /dev/null |
| 58 | if [ $? != "0" ]; then |
| 59 | DAEMON_ID=1 |
| 60 | fi |
| 61 | |
plars | a040c12 | 2003-07-17 15:59:36 +0000 | [diff] [blame] | 62 | grep -q ^nobody: /etc/group |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 63 | if [ $? != "0" ]; then |
| 64 | NOBODY_GRP=1 |
| 65 | fi |
| 66 | |
plars | a040c12 | 2003-07-17 15:59:36 +0000 | [diff] [blame] | 67 | grep -q ^bin: /etc/group |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 68 | if [ $? != "0" ]; then |
| 69 | BIN_GRP=1 |
| 70 | fi |
| 71 | |
plars | a040c12 | 2003-07-17 15:59:36 +0000 | [diff] [blame] | 72 | grep -q ^daemon: /etc/group |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 73 | if [ $? != "0" ]; then |
| 74 | DAEMON_GRP=1 |
| 75 | fi |
| 76 | |
plars | a040c12 | 2003-07-17 15:59:36 +0000 | [diff] [blame] | 77 | grep -q ^users: /etc/group |
robbiew | 06e3bdf | 2003-04-08 15:23:33 +0000 | [diff] [blame] | 78 | if [ $? != "0" ]; then |
| 79 | USERS_GRP=1 |
| 80 | fi |
| 81 | |
plars | a040c12 | 2003-07-17 15:59:36 +0000 | [diff] [blame] | 82 | grep -q ^sys: /etc/group |
robbiew | 06e3bdf | 2003-04-08 15:23:33 +0000 | [diff] [blame] | 83 | if [ $? != "0" ]; then |
| 84 | SYS_GRP=1 |
| 85 | fi |
| 86 | |
robbiew | cefffa7 | 2003-03-03 17:06:24 +0000 | [diff] [blame] | 87 | whoami | grep root > /dev/null |
| 88 | if [ $? == "0" ]; then |
| 89 | I_AM_ROOT=1 |
| 90 | fi |
| 91 | |
robbiew | 539fd46 | 2006-02-08 21:21:09 +0000 | [diff] [blame] | 92 | if [ -n "$CREATE" ]; then |
| 93 | echo "CREATE variable set to $CREATE ..." |
| 94 | else |
| 95 | if [ $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" ]; |
| 96 | then |
| 97 | echo -n "If any required user ids and/or groups are missing, would you like these created? Y/N " |
| 98 | read ans |
| 99 | case $ans in |
| 100 | Y*|y*) |
| 101 | CREATE=1 |
| 102 | ;; |
| 103 | *) |
| 104 | CREATE=0 |
| 105 | ;; |
| 106 | esac |
| 107 | fi |
robbiew | 631a9f5 | 2002-03-05 22:42:55 +0000 | [diff] [blame] | 108 | fi |
| 109 | |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 110 | if [ $NOBODY_ID != "1" ] && [ $NOBODY_GRP != "1" ]; then |
| 111 | echo "Nobody user id and group exist." |
| 112 | else |
| 113 | if [ $NOBODY_ID -eq "1" ] && [ $CREATE -eq "1" ]; then |
| 114 | echo nobody:x:99:99:Nobody:: >> /etc/passwd |
| 115 | fi |
| 116 | if [ $NOBODY_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then |
| 117 | echo nobody:x:`id -u nobody`: >> /etc/group |
| 118 | fi |
| 119 | fi |
| 120 | |
| 121 | if [ $BIN_ID != "1" ] && [ $BIN_GRP != "1" ]; then |
| 122 | echo "Bin user id and group exist." |
| 123 | else |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 124 | if [ $BIN_ID -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 125 | echo bin:x:1:1:bin:: >> /etc/passwd |
| 126 | fi |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 127 | if [ $BIN_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 128 | echo bin:x:`id -u bin`:bin >> /etc/group |
| 129 | fi |
| 130 | fi |
| 131 | |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 132 | if [ $DAEMON_ID -ne "1" ] && [ $DAEMON_GRP -ne "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 133 | echo "Daemon user id and group exist." |
| 134 | else |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 135 | if [ $DAEMON_ID -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 136 | echo daemon:x:2:2:daemon:: >> /etc/passwd |
| 137 | fi |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 138 | if [ $DAEMON_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 139 | echo daemon:x:`id -u daemon`:daemon >> /etc/group |
| 140 | fi |
| 141 | fi |
| 142 | |
robbiew | 06e3bdf | 2003-04-08 15:23:33 +0000 | [diff] [blame] | 143 | if [ $USERS_GRP -ne "1" ]; then |
| 144 | echo "Users group exists." |
| 145 | else |
| 146 | if [ $CREATE -eq "1" ]; then |
| 147 | echo users:x:100: >> /etc/group |
| 148 | fi |
| 149 | fi |
| 150 | |
| 151 | if [ $SYS_GRP -ne "1" ]; then |
| 152 | echo "Sys group exists." |
| 153 | else |
| 154 | if [ $CREATE -eq "1" ]; then |
| 155 | echo sys:x:3: >> /etc/group |
| 156 | fi |
| 157 | fi |
| 158 | |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 159 | id nobody > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 160 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 161 | id bin > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 162 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 163 | id daemon > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 164 | if [ $? -eq "0" ]; then |
robbiew | 90fc94c | 2002-04-08 14:55:37 +0000 | [diff] [blame] | 165 | id -g nobody > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 166 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 167 | id -g bin > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 168 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 169 | id -g daemon > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 170 | if [ $? -eq "0" ]; then |
robbiew | 06e3bdf | 2003-04-08 15:23:33 +0000 | [diff] [blame] | 171 | grep users /etc/group | cut -d: -f1 | grep users > /dev/null |
| 172 | if [ $? -eq "0" ]; then |
| 173 | grep sys /etc/group | cut -d: -f1 | grep sys > /dev/null |
| 174 | if [ $? -eq "0" ]; then |
| 175 | echo "Required users/groups exist." |
| 176 | exit 0 |
| 177 | fi |
| 178 | fi |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 179 | fi |
| 180 | fi |
| 181 | fi |
| 182 | fi |
| 183 | fi |
| 184 | fi |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 185 | echo "*****************************************" |
| 186 | echo "* Required users/groups do NOT exist!!! *" |
| 187 | echo "* *" |
| 188 | echo "* Some kernel/syscall tests will FAIL! *" |
| 189 | echo "*****************************************" |
| 190 | exit 1 |