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 | cefffa7 | 2003-03-03 17:06:24 +0000 | [diff] [blame] | 43 | I_AM_ROOT=0 |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 44 | |
| 45 | id nobody > /dev/null |
| 46 | if [ $? != "0" ]; then |
| 47 | NOBODY_ID=1 |
| 48 | fi |
| 49 | |
| 50 | id bin > /dev/null |
| 51 | if [ $? != "0" ]; then |
| 52 | BIN_ID=1 |
| 53 | fi |
| 54 | |
| 55 | id daemon > /dev/null |
| 56 | if [ $? != "0" ]; then |
| 57 | DAEMON_ID=1 |
| 58 | fi |
| 59 | |
robbiew | 90fc94c | 2002-04-08 14:55:37 +0000 | [diff] [blame] | 60 | id -g nobody > /dev/null |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 61 | if [ $? != "0" ]; then |
| 62 | NOBODY_GRP=1 |
| 63 | fi |
| 64 | |
| 65 | id -g bin > /dev/null |
| 66 | if [ $? != "0" ]; then |
| 67 | BIN_GRP=1 |
| 68 | fi |
| 69 | |
| 70 | id -g daemon > /dev/null |
| 71 | if [ $? != "0" ]; then |
| 72 | DAEMON_GRP=1 |
| 73 | fi |
| 74 | |
robbiew | cefffa7 | 2003-03-03 17:06:24 +0000 | [diff] [blame] | 75 | whoami | grep root > /dev/null |
| 76 | if [ $? == "0" ]; then |
| 77 | I_AM_ROOT=1 |
| 78 | fi |
| 79 | |
| 80 | if [ $NOBODY_ID != "0" ] || [ $BIN_ID != "0" ] || [ $DAEMON_ID != "0" ] || [ $NOBODY_GRP != "0" ] || [ $BIN_GRP != "0" ] || [ $DAEMON_GRP != "0" ] && [ $I_AM_ROOT != "0" ]; |
robbiew | 631a9f5 | 2002-03-05 22:42:55 +0000 | [diff] [blame] | 81 | then |
| 82 | echo -n "If any required user ids and/or groups are missing, would you like these created? Y/N " |
| 83 | read ans |
| 84 | case $ans in |
| 85 | Y*|y*) |
| 86 | CREATE=1 |
| 87 | ;; |
| 88 | *) |
| 89 | CREATE=0 |
| 90 | ;; |
| 91 | esac |
| 92 | fi |
| 93 | |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 94 | if [ $NOBODY_ID != "1" ] && [ $NOBODY_GRP != "1" ]; then |
| 95 | echo "Nobody user id and group exist." |
| 96 | else |
| 97 | if [ $NOBODY_ID -eq "1" ] && [ $CREATE -eq "1" ]; then |
| 98 | echo nobody:x:99:99:Nobody:: >> /etc/passwd |
| 99 | fi |
| 100 | if [ $NOBODY_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then |
| 101 | echo nobody:x:`id -u nobody`: >> /etc/group |
| 102 | fi |
| 103 | fi |
| 104 | |
| 105 | if [ $BIN_ID != "1" ] && [ $BIN_GRP != "1" ]; then |
| 106 | echo "Bin user id and group exist." |
| 107 | else |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 108 | if [ $BIN_ID -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 109 | echo bin:x:1:1:bin:: >> /etc/passwd |
| 110 | fi |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 111 | if [ $BIN_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 112 | echo bin:x:`id -u bin`:bin >> /etc/group |
| 113 | fi |
| 114 | fi |
| 115 | |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 116 | if [ $DAEMON_ID -ne "1" ] && [ $DAEMON_GRP -ne "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 117 | echo "Daemon user id and group exist." |
| 118 | else |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 119 | if [ $DAEMON_ID -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 120 | echo daemon:x:2:2:daemon:: >> /etc/passwd |
| 121 | fi |
nstraz | f9598e4 | 2001-12-19 15:45:24 +0000 | [diff] [blame] | 122 | if [ $DAEMON_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 123 | echo daemon:x:`id -u daemon`:daemon >> /etc/group |
| 124 | fi |
| 125 | fi |
| 126 | |
| 127 | id nobody > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 128 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 129 | id bin > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 130 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 131 | id daemon > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 132 | if [ $? -eq "0" ]; then |
robbiew | 90fc94c | 2002-04-08 14:55:37 +0000 | [diff] [blame] | 133 | id -g nobody > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 134 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 135 | id -g bin > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 136 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 137 | id -g daemon > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 138 | if [ $? -eq "0" ]; then |
| 139 | echo "Required users/groups exist." |
| 140 | exit 0 |
| 141 | fi |
| 142 | fi |
| 143 | fi |
| 144 | fi |
| 145 | fi |
| 146 | fi |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 147 | echo "*****************************************" |
| 148 | echo "* Required users/groups do NOT exist!!! *" |
| 149 | echo "* *" |
| 150 | echo "* Some kernel/syscall tests will FAIL! *" |
| 151 | echo "*****************************************" |
| 152 | exit 1 |