Home | History | Annotate | Download | only in common_files
      1 #!/bin/sh
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     23 # Use is subject to license terms.
     24 #
     25 
     26 PATH="/usr/bin:/usr/sbin:${PATH}"
     27 export PATH
     28 
     29 while read src dest
     30 do
     31 	if [ ! -f $dest ] ; then
     32 		cp $src $dest
     33 	else
     34 		#
     35 		# Strip off any leading "/a"
     36 		#
     37 		dest_file=`echo $dest | sed "s=^/a/=/="`
     38 
     39 		#
     40 		# Add the sysadmin group (gid 14) to support admintool
     41 		#
     42 		grep '^sysadmin:.*:14:.*' $dest 2>&1 >/dev/null
     43 		if [ $? = 0 ] ; then
     44 			/usr/bin/true
     45 		elif grep '^sysadmin:' $dest 2>&1 >/dev/null; then
     46 			cur_name="sysadmin"
     47 			echo "SYSADMIN_NOT_14 $dest_file none" >> /tmp/CLEANUP
     48 			echo "sysadmin::14:" >> $dest
     49 
     50 		elif grep ':14:' $dest 2>&1 >/dev/null; then
     51 			cur_name=`grep ':14:' $dest | awk -F: '{print $1}'`
     52 			echo "GROUP14_IN_USE $dest_file none" >> /tmp/CLEANUP
     53 			echo "sysadmin::14:" >> $dest
     54 
     55 		else		# add the group
     56 			echo "sysadmin::14:" >> $dest
     57 		fi
     58 
     59 		#
     60 		# Add the 'nogroup' group from 4.x so that people don't
     61 		# assign it to a regular user and confuse themselves
     62 		#
     63 		NOGROUP_LINE="nogroup::65534:"
     64 		if grep "$NOGROUP_LINE" $dest 2>&1 >/dev/null; then
     65 			:
     66 		else
     67 			printf '/^noaccess::60002:\na\n%s\n.\nw\nq\n' \
     68 				"$NOGROUP_LINE" | ed -s $dest > /dev/null
     69 		fi
     70 
     71 		# Remove redundant /etc/group entries that overlap with
     72 		# primary groups from /etc/passwd
     73 		sed  '
     74 			/^root:/s/\([:,]\)root,/\1/;
     75 			/^root:/s/,root$//;
     76 			/^root:/s/:root$/:/;
     77 			/^bin:/s/\([:,]\)bin,/\1/;
     78 			/^bin:/s/,bin$//;
     79 			/^bin:/s/:bin$/:/;
     80 			/^sys:/s/\([:,]\)sys,/\1/;
     81 			/^sys:/s/,sys$//;
     82 			/^sys:/s/:sys$/:/;
     83 			/^adm:/s/\([:,]\)adm,/\1/;
     84 			/^adm:/s/,adm$//;
     85 			/^adm:/s/:adm$/:/;
     86 			/^tty:/s/\([:,]\)tty,/\1/;
     87 			/^tty:/s/,tty$//;
     88 			/^tty:/s/:tty$/:/;
     89 			/^uucp:/s/\([:,]\)uucp,/\1/;
     90 			/^uucp:/s/,uucp$//;
     91 			/^uucp:/s/:uucp$/:/;
     92 			/^nuucp:/s/\([:,]\)nuucp,/\1/;
     93 			/^nuucp:/s/,nuucp$//;
     94 			/^nuucp:/s/:nuucp$/:/;
     95 			/^daemon:/s/\([:,]\)daemon,/\1/;
     96 			/^daemon:/s/,daemon$//;
     97 			/^daemon:/s/:daemon$/:/;
     98 			/^smmsp:/s/\([:,]\)smmsp,/\1/;
     99 			/^smmsp:/s/,smmsp$//;
    100 			/^smmsp:/s/:smmsp$/:/;
    101 			/^lp:/s/\([:,]\)lp,/\1/;
    102 			/^lp:/s/,lp$//;
    103 			/^lp:/s/:lp$/:/' $dest > /tmp/g.$$ && 
    104 		cp /tmp/g.$$ $dest
    105 		rm -f /tmp/g.$$
    106 
    107 		#add 'root' to user-list of group1
    108 		# line 1,2: skip any line with root in the user field
    109 		# line 3:   users already in list, add "root,"
    110 		# line 4:   no users in list, add "root"
    111 
    112 		sed '
    113 			/[:,]root,/b
    114 			/[:,]root$/b
    115 			s/:1:\([^:][^:]*\)$/:1:root,\1/;
    116 			s/:1:$/:1:root/;
    117 		' $dest > /tmp/g.$$ &&
    118 
    119 		cp /tmp/g.$$ $dest
    120 		rm -f /tmp/g.$$
    121 
    122 		#
    123 		# Add the 'smmsp' group for sendmail 8.12
    124 		#
    125 		SMMSPGROUP_LINE="smmsp::25:"
    126 		if grep "$SMMSPGROUP_LINE" $dest 2>&1 >/dev/null; then
    127 			:
    128 		else
    129 			printf '/^nogroup::65534:\na\n%s\n.\nw\nq\n' \
    130 				"$SMMSPGROUP_LINE" | ed -s $dest > /dev/null
    131 		fi
    132 		#
    133 		# Add the 'gdm' group if it doesn't already exist.
    134 		#
    135 		GDMGROUP_LINE="gdm::50:"
    136 		cur_name=`awk -F: '$3 == 50 {print $1}' $dest`
    137 		if [ ! -z "$cur_name" -a "$cur_name" != "gdm" ]; then
    138 			echo "ERROR: Reserved GID 50 already assigned" \
    139 				"to '$cur_name'" >> /tmp/CLEANUP
    140 		elif grep "$GDMGROUP_LINE" $dest 2>&1 >/dev/null; then
    141 			:
    142 		else
    143 			printf '/^smmsp::25:\na\n%s\n.\nw\nq\n' \
    144 				"$GDMGROUP_LINE" | ed -s $dest > /dev/null
    145 		fi
    146 		#
    147 		# Add the 'webservd' group if it doesn't already exist.
    148 		#
    149 		WEBSERVDGROUP_LINE="webservd::80:"
    150 		cur_name=`awk -F: '$3 == 80 {print $1}' $dest`
    151 		if [ ! -z "$cur_name" -a "$cur_name" != "webservd" ]; then
    152 			echo "ERROR: Reserved GID 80 already assigned" \
    153 				"to '$cur_name'" >> /tmp/CLEANUP
    154 		elif grep "$WEBSERVDGROUP_LINE" $dest 2>&1 >/dev/null; then
    155 			:
    156 		else
    157 			printf '/^gdm::50:\na\n%s\n.\nw\nq\n' \
    158 				"$WEBSERVDGROUP_LINE" | ed -s $dest > /dev/null
    159 		fi
    160 
    161 		#
    162 		# Add the 'postgres' group if it doesn't already exist.
    163 		#
    164 		POSTGRESGROUP_LINE="postgres::90:"
    165 		cur_name=`awk -F: '$3 == 90 {print $1}' $dest`
    166 		cur_id=`awk -F: '$1 == "postgres" {print $3}' $dest`
    167 		if [ ! -z "$cur_name" -a "$cur_name" != "postgres" ]; then
    168 			echo "ERROR: Reserved GID 90 already assigned" \
    169 			    "to '$cur_name'" >> /tmp/CLEANUP
    170 		elif [ ! -z "$cur_id" -a "$cur_id" != "90" ]; then
    171 			echo "NOTE: postgres group already assigned" \
    172 			    "to id '$cur_id'" >> /tmp/CLEANUP
    173 		elif grep "$POSTGRESGROUP_LINE" $dest 2>&1 >/dev/null; then
    174 			:
    175 		else
    176 			printf '/^webservd::80:\na\n%s\n.\nw\nq\n' \
    177 			    "$POSTGRESGROUP_LINE" | ed -s $dest > /dev/null
    178 		fi
    179    	        #	
    180 		# Add the 'mysql' group if it doesn't already exist.
    181                 #
    182 		MYSQLGROUP_LINE="mysql::70:"
    183                 cur_name=`awk -F: '$3 == 70 {print $1}' $dest`
    184                 cur_id=`awk -F: '$1 == "mysql" {print $3}' $dest`
    185                 if [ ! -z "$cur_name" -a "$cur_name" != "mysql" ]; then
    186                         echo "ERROR: Reserved GID 70 already assigned" \
    187                             "to '$cur_name'" >> /tmp/CLEANUP
    188                 elif [ ! -z "$cur_id" -a "$cur_id" != "70" ]; then
    189                         echo "NOTE: mysql group already assigned" \
    190                             "to id '$cur_id'" >> /tmp/CLEANUP
    191                 elif grep "$MYSQLGROUP_LINE" $dest 2>&1 >/dev/null; then
    192                         :
    193                 else
    194                         printf '/^postgres::90:\na\n%s\n.\nw\nq\n' \
    195                             "$MYSQLGROUP_LINE" | ed -s $dest > /dev/null
    196                 fi
    197                 #
    198 		# Add the 'games' group if it doesn't already exist.
    199 		#
    200 		GAMESGROUP_LINE="games::20:"
    201 		cur_name=`awk -F: '$3 == 20 {print $1}' $dest`
    202 		cur_id=`awk -F: '$1 == "games" {print $3}' $dest`
    203 		if [ ! -z "$cur_name" -a "$cur_name" != "games" ]; then
    204 			echo "ERROR: Reserved GID 20 already assigned" \
    205 			"to '$cur_name'" >> /tmp/CLEANUP
    206 		elif [ ! -z "$cur_id" -a "$cur_id" != "20" ]; then
    207 			echo "NOTE: games group already assigned" \
    208 			"to id '$cur_id'" >> /tmp/CLEANUP
    209 		elif grep "$GAMESGROUP_LINE" $dest 2>&1 >/dev/null; then
    210 			:
    211 		else
    212 			printf '/^smmsp::25:\ni\n%s\n.\nw\nq\n' \
    213 			"$GAMESGROUP_LINE" | ed -s $dest > /dev/null
    214 		fi
    215 		#
    216 		# Add the 'xvm' group if it doesn't already exist.
    217 		#
    218 		XVMGROUP_LINE="xvm::60:"
    219 		cur_name=`awk -F: '$3 == 60 {print $1}' $dest`
    220 		cur_id=`awk -F: '$1 == "xvm" {print $3}' $dest`
    221 		if [ ! -z "$cur_name" -a "$cur_name" != "xvm" ]; then
    222 			echo "ERROR: Reserved GID 60 already assigned" \
    223 			"to '$cur_name'" >> /tmp/CLEANUP
    224 		elif [ ! -z "$cur_id" -a "$cur_id" != "60" ]; then
    225 			echo "NOTE: xvm group already assigned" \
    226 			"to id '$cur_id'" >> /tmp/CLEANUP
    227 		elif grep "$XVMGROUP_LINE" $dest 2>&1 >/dev/null; then
    228 			:
    229 		else
    230 			printf '/^mysql::70:\ni\n%s\n.\nw\nq\n' \
    231                             "$XVMGROUP_LINE" | ed -s $dest > /dev/null
    232 		fi
    233                 #
    234                 # Add the 'slocate' group if it doesn't already exist.
    235                 #
    236                 SLOCATEGROUP_LINE="slocate::95:"
    237                 cur_name=`awk -F: '$3 == 95 {print $1}' $dest`
    238                 cur_id=`awk -F: '$1 == "slocate" {print $3}' $dest`
    239                 if [ ! -z "$cur_name" -a "$cur_name" != "slocate" ]; then
    240                         echo "ERROR: Reserved GID 95 already assigned" \
    241                             "to '$cur_name'" >> /tmp/CLEANUP
    242                 elif [ ! -z "$cur_id" -a "$cur_id" != "95" ]; then
    243                         echo "NOTE: slocate group already assigned" \
    244                             "to id '$cur_id'" >> /tmp/CLEANUP
    245                 elif grep "$SLOCATEGROUP_LINE" $dest 2>&1 >/dev/null; then
    246                         :
    247                 else
    248                         printf '/^postgres::90:\na\n%s\n.\nw\nq\n' \
    249                             "$SLOCATEGROUP_LINE" | ed -s $dest > /dev/null
    250                 fi
    251    	        #	
    252 		# Add the 'openldap' group if it doesn't already exist.
    253                 #
    254 		OPENLDAPGROUP_LINE="openldap::75:"
    255                 cur_name=`awk -F: '$3 == 75 {print $1}' $dest`
    256                 cur_id=`awk -F: '$1 == "openldap" {print $3}' $dest`
    257                 if [ ! -z "$cur_name" -a "$cur_name" != "openldap" ]; then
    258                         echo "ERROR: Reserved GID 75 already assigned" \
    259                             "to '$cur_name'" >> /tmp/CLEANUP
    260                 elif [ ! -z "$cur_id" -a "$cur_id" != "75" ]; then
    261                         echo "NOTE: openldap group already assigned" \
    262                             "to id '$cur_id'" >> /tmp/CLEANUP
    263                 elif grep "$OPENLDAPGROUP_LINE" $dest 2>&1 >/dev/null; then
    264                         :
    265                 else
    266                         printf '/^mysql::70:\na\n%s\n.\nw\nq\n' \
    267                             "$OPENLDAPGROUP_LINE" | ed -s $dest > /dev/null
    268                 fi
    269 	fi
    270 done
    271 exit 0
    272