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 2009 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 TEMPF="/tmp/g.$$"
     30 
     31 while read src dest
     32 do
     33 	if [ ! -f $dest ] ; then
     34 		cp $src $dest
     35 	else
     36 		#
     37 		# Strip off any leading "/a"
     38 		#
     39 		dest_file=`echo $dest | sed "s=^/a/=/="`
     40 
     41 		#
     42 		# Add the sysadmin group (gid 14) to support admintool
     43 		#
     44 		grep '^sysadmin:.*:14:.*' $dest >/dev/null 2>&1
     45 		if [ $? = 0 ] ; then
     46 			/usr/bin/true
     47 		elif grep '^sysadmin:' $dest >/dev/null 2>&1; then
     48 			cur_name="sysadmin"
     49 			echo "SYSADMIN_NOT_14 $dest_file none" >> /tmp/CLEANUP
     50 			echo "sysadmin::14:" >> $dest
     51 
     52 		elif grep ':14:' $dest >/dev/null 2>&1; then
     53 			cur_name=`grep ':14:' $dest | awk -F: '{print $1}'`
     54 			echo "GROUP14_IN_USE $dest_file none" >> /tmp/CLEANUP
     55 			echo "sysadmin::14:" >> $dest
     56 
     57 		else		# add the group
     58 			echo "sysadmin::14:" >> $dest
     59 		fi
     60 
     61 		#
     62 		# Add the 'nogroup' group from 4.x so that people don't
     63 		# assign it to a regular user and confuse themselves
     64 		#
     65 		NOGROUP_LINE="nogroup::65534:"
     66 		if grep "$NOGROUP_LINE" $dest >/dev/null 2>&1; then
     67 			:
     68 		else
     69 			sed '/^noaccess::60002:/ a\
     70 '"$NOGROUP_LINE"'' $dest > $TEMPF
     71 			mv -f $TEMPF $dest
     72 				
     73 		fi
     74 
     75 		# Remove redundant /etc/group entries that overlap with
     76 		# primary groups from /etc/passwd
     77 		sed  '
     78 			/^root:/s/\([:,]\)root,/\1/;
     79 			/^root:/s/,root$//;
     80 			/^root:/s/:root$/:/;
     81 			/^bin:/s/\([:,]\)bin,/\1/;
     82 			/^bin:/s/,bin$//;
     83 			/^bin:/s/:bin$/:/;
     84 			/^sys:/s/\([:,]\)sys,/\1/;
     85 			/^sys:/s/,sys$//;
     86 			/^sys:/s/:sys$/:/;
     87 			/^adm:/s/\([:,]\)adm,/\1/;
     88 			/^adm:/s/,adm$//;
     89 			/^adm:/s/:adm$/:/;
     90 			/^tty:/s/\([:,]\)tty,/\1/;
     91 			/^tty:/s/,tty$//;
     92 			/^tty:/s/:tty$/:/;
     93 			/^uucp:/s/\([:,]\)uucp,/\1/;
     94 			/^uucp:/s/,uucp$//;
     95 			/^uucp:/s/:uucp$/:/;
     96 			/^nuucp:/s/\([:,]\)nuucp,/\1/;
     97 			/^nuucp:/s/,nuucp$//;
     98 			/^nuucp:/s/:nuucp$/:/;
     99 			/^daemon:/s/\([:,]\)daemon,/\1/;
    100 			/^daemon:/s/,daemon$//;
    101 			/^daemon:/s/:daemon$/:/;
    102 			/^smmsp:/s/\([:,]\)smmsp,/\1/;
    103 			/^smmsp:/s/,smmsp$//;
    104 			/^smmsp:/s/:smmsp$/:/;
    105 			/^lp:/s/\([:,]\)lp,/\1/;
    106 			/^lp:/s/,lp$//;
    107 			/^lp:/s/:lp$/:/' $dest > $TEMPF && 
    108 		cp $TEMPF $dest
    109 		rm -f $TEMPF
    110 
    111 		#add 'root' to user-list of group1
    112 		# line 1,2: skip any line with root in the user field
    113 		# line 3:   users already in list, add "root,"
    114 		# line 4:   no users in list, add "root"
    115 
    116 		sed '
    117 			/[:,]root,/b
    118 			/[:,]root$/b
    119 			s/:1:\([^:][^:]*\)$/:1:root,\1/;
    120 			s/:1:$/:1:root/;
    121 		' $dest > $TEMPF &&
    122 
    123 		cp $TEMPF $dest
    124 		rm -f $TEMPF
    125 
    126 		#
    127 		# Add the 'smmsp' group for sendmail 8.12
    128 		#
    129 		SMMSPGROUP_LINE="smmsp::25:"
    130 		if grep "$SMMSPGROUP_LINE" $dest >/dev/null 2>&1; then
    131 			:
    132 		else
    133 			sed '/^nogroup::65534:/ a\
    134 '"$SMMSPGROUP_LINE"'' $dest > $TEMPF
    135 			mv -f $TEMPF $dest
    136 		fi
    137 		#
    138 		# Add the 'gdm' group if it doesn't already exist.
    139 		#
    140 		GDMGROUP_LINE="gdm::50:"
    141 		cur_name=`awk -F: '$3 == 50 {print $1}' $dest`
    142 		if [ ! -z "$cur_name" -a "$cur_name" != "gdm" ]; then
    143 			echo "ERROR: Reserved GID 50 already assigned" \
    144 				"to '$cur_name'" >> /tmp/CLEANUP
    145 		elif grep "$GDMGROUP_LINE" $dest >/dev/null 2>&1; then
    146 			:
    147 		else
    148 			sed '/^smmsp::25:/ a\
    149 '"$GDMGROUP_LINE"'' $dest > $TEMPF
    150 			mv -f $TEMPF $dest
    151 		fi
    152 		#
    153 		# Add the 'upnp' group if it doesn't already exist.
    154 		#
    155 		UPNPGROUP_LINE="upnp::52:"
    156 		cur_name=`awk -F: '$3 == 52 {print $1}' $dest`
    157 		if [ ! -z "$cur_name" -a "$cur_name" != "upnp" ]; then
    158 			echo "ERROR: Reserved GID 52 already assigned" \
    159 				"to '$cur_name'" >> /tmp/CLEANUP
    160 		elif grep "$UPNPGROUP_LINE" $dest >/dev/null 2>&1; then
    161 			:
    162 		else
    163 			sed '/^gdm::50:/ a\
    164 '"$UPNPGROUP_LINE"'' $dest > $TEMPF
    165 			mv -f $TEMPF $dest
    166 		fi
    167 		#
    168 		# Add the 'webservd' group if it doesn't already exist.
    169 		#
    170 		WEBSERVDGROUP_LINE="webservd::80:"
    171 		cur_name=`awk -F: '$3 == 80 {print $1}' $dest`
    172 		if [ ! -z "$cur_name" -a "$cur_name" != "webservd" ]; then
    173 			echo "ERROR: Reserved GID 80 already assigned" \
    174 				"to '$cur_name'" >> /tmp/CLEANUP
    175 		elif grep "$WEBSERVDGROUP_LINE" $dest >/dev/null 2>&1; then
    176 			:
    177 		else
    178 			sed '/^upnp::50:/ a\
    179 '"$WEBSERVDGROUP_LINE"'' $dest > $TEMPF
    180 			mv -f $TEMPF $dest
    181 		fi
    182 
    183 		#
    184 		# Add the 'postgres' group if it doesn't already exist.
    185 		#
    186 		POSTGRESGROUP_LINE="postgres::90:"
    187 		cur_name=`awk -F: '$3 == 90 {print $1}' $dest`
    188 		cur_id=`awk -F: '$1 == "postgres" {print $3}' $dest`
    189 		if [ ! -z "$cur_name" -a "$cur_name" != "postgres" ]; then
    190 			echo "ERROR: Reserved GID 90 already assigned" \
    191 			    "to '$cur_name'" >> /tmp/CLEANUP
    192 		elif [ ! -z "$cur_id" -a "$cur_id" != "90" ]; then
    193 			echo "NOTE: postgres group already assigned" \
    194 			    "to id '$cur_id'" >> /tmp/CLEANUP
    195 		elif grep "$POSTGRESGROUP_LINE" $dest >/dev/null 2>&1; then
    196 			:
    197 		else
    198 			sed '/^webservd::80:/ a\
    199 '"$POSTGRESGROUP_LINE"'' $dest > $TEMPF
    200 			mv -f $TEMPF $dest
    201 		fi
    202    	        #	
    203 		# Add the 'mysql' group if it doesn't already exist.
    204                 #
    205 		MYSQLGROUP_LINE="mysql::70:"
    206                 cur_name=`awk -F: '$3 == 70 {print $1}' $dest`
    207                 cur_id=`awk -F: '$1 == "mysql" {print $3}' $dest`
    208                 if [ ! -z "$cur_name" -a "$cur_name" != "mysql" ]; then
    209                         echo "ERROR: Reserved GID 70 already assigned" \
    210                             "to '$cur_name'" >> /tmp/CLEANUP
    211                 elif [ ! -z "$cur_id" -a "$cur_id" != "70" ]; then
    212                         echo "NOTE: mysql group already assigned" \
    213                             "to id '$cur_id'" >> /tmp/CLEANUP
    214                 elif grep "$MYSQLGROUP_LINE" $dest >/dev/null 2>&1; then
    215                         :
    216                 else
    217                         sed '/^postgres::90:/ a\
    218 '"$MYSQLGROUP_LINE"'' $dest > $TEMPF
    219 			mv -f $TEMPF $dest
    220                 fi
    221                 #
    222 		# Add the 'games' group if it doesn't already exist.
    223 		#
    224 		GAMESGROUP_LINE="games::20:"
    225 		cur_name=`awk -F: '$3 == 20 {print $1}' $dest`
    226 		cur_id=`awk -F: '$1 == "games" {print $3}' $dest`
    227 		if [ ! -z "$cur_name" -a "$cur_name" != "games" ]; then
    228 			echo "ERROR: Reserved GID 20 already assigned" \
    229 			"to '$cur_name'" >> /tmp/CLEANUP
    230 		elif [ ! -z "$cur_id" -a "$cur_id" != "20" ]; then
    231 			echo "NOTE: games group already assigned" \
    232 			"to id '$cur_id'" >> /tmp/CLEANUP
    233 		elif grep "$GAMESGROUP_LINE" $dest >/dev/null 2>&1; then
    234 			:
    235 		else
    236 			sed '/^smmsp::25:/ a\
    237 '"$GAMESGROUP_LINE"'' $dest > $TEMPF
    238 			mv -f $TEMPF $dest
    239 		fi
    240 		#
    241 		# Add the 'xvm' group if it doesn't already exist.
    242 		#
    243 		XVMGROUP_LINE="xvm::60:"
    244 		cur_name=`awk -F: '$3 == 60 {print $1}' $dest`
    245 		cur_id=`awk -F: '$1 == "xvm" {print $3}' $dest`
    246 		if [ ! -z "$cur_name" -a "$cur_name" != "xvm" ]; then
    247 			echo "ERROR: Reserved GID 60 already assigned" \
    248 			"to '$cur_name'" >> /tmp/CLEANUP
    249 		elif [ ! -z "$cur_id" -a "$cur_id" != "60" ]; then
    250 			echo "NOTE: xvm group already assigned" \
    251 			"to id '$cur_id'" >> /tmp/CLEANUP
    252 		elif grep "$XVMGROUP_LINE" $dest >/dev/null 2>&1; then
    253 			:
    254 		else
    255 			sed '/^mysql::70:/ a\
    256 '"$XVMGROUP_LINE"'' $dest > $TEMPF
    257 			mv -f $TEMPF $dest
    258 		fi
    259                 #
    260                 # Add the 'slocate' group if it doesn't already exist.
    261                 #
    262                 SLOCATEGROUP_LINE="slocate::95:"
    263                 cur_name=`awk -F: '$3 == 95 {print $1}' $dest`
    264                 cur_id=`awk -F: '$1 == "slocate" {print $3}' $dest`
    265                 if [ ! -z "$cur_name" -a "$cur_name" != "slocate" ]; then
    266                         echo "ERROR: Reserved GID 95 already assigned" \
    267                             "to '$cur_name'" >> /tmp/CLEANUP
    268                 elif [ ! -z "$cur_id" -a "$cur_id" != "95" ]; then
    269                         echo "NOTE: slocate group already assigned" \
    270                             "to id '$cur_id'" >> /tmp/CLEANUP
    271                 elif grep "$SLOCATEGROUP_LINE" $dest >/dev/null 2>&1; then
    272                         :
    273                 else
    274                         sed '/^postgres::90:/ a\
    275 '"$SLOCATEGROUP_LINE"'' $dest > $TEMPF
    276 			mv -f $TEMPF $dest
    277                 fi
    278    	        #	
    279 		# Add the 'openldap' group if it doesn't already exist.
    280                 #
    281 		OPENLDAPGROUP_LINE="openldap::75:"
    282                 cur_name=`awk -F: '$3 == 75 {print $1}' $dest`
    283                 cur_id=`awk -F: '$1 == "openldap" {print $3}' $dest`
    284                 if [ ! -z "$cur_name" -a "$cur_name" != "openldap" ]; then
    285                         echo "ERROR: Reserved GID 75 already assigned" \
    286                             "to '$cur_name'" >> /tmp/CLEANUP
    287                 elif [ ! -z "$cur_id" -a "$cur_id" != "75" ]; then
    288                         echo "NOTE: openldap group already assigned" \
    289                             "to id '$cur_id'" >> /tmp/CLEANUP
    290                 elif grep "$OPENLDAPGROUP_LINE" $dest >/dev/null 2>&1; then
    291                         :
    292                 else
    293                         sed '/^mysql::70:/ a\
    294 '"$OPENLDAPGROUP_LINE"'' $dest > $TEMPF
    295 			mv -f $TEMPF $dest
    296                 fi
    297 	fi
    298 done
    299 exit 0
    300