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/d.$$"
     30 
     31 while read src dest
     32 do
     33 	if [ ! -f $dest ] ; then
     34 		cp $src $dest
     35 	else
     36 		#
     37 		# 2.1 version of this file had a trailing blank
     38 		# in the nobody entry.  Remove it.
     39 		#
     40 		# 2.6 & earlier versions had an smtp entry; remove it.
     41 		#
     42 		# The NFS nobody users get better GECOS entries.
     43 		sed -e 's/^\(nobody:.*:\) $/\1/' \
     44 		    -e '/^smtp:/d' \
     45 		    -e '/^nobody:/s/:Nobody:/:NFS Anonymous Access User:/' \
     46 		    -e '/^nobody4:/s/:SunOS\ 4\.x\ Nobody:/:SunOS 4.x NFS Anonymous Access User:/;' \
     47 		    $dest > $TEMPF
     48 		cp $TEMPF $dest
     49 		rm -f $TEMPF
     50 
     51 		#
     52 		# s10 is changing root's group back to 0:
     53 		#
     54 		sed -e 's/^root:\([^:]*\):0:1:/root:\1:0:0:/' \
     55 			$dest > $TEMPF
     56 		cp $TEMPF $dest
     57 		rm -f $TEMPF
     58 
     59 		#
     60 		# Add the 'nobody' user from 4.x so that people don't
     61 		# assign it to a regular user and confuse themselves
     62 		#
     63 		NOBODY4_LINE="nobody4:x:65534:65534:SunOS 4.x NFS Anoymous Access User:/:"
     64 		if grep "^nobody4:" $dest >/dev/null 2>&1; then
     65 			:
     66 		else
     67 			sed '/^noaccess:x/ a\
     68 '"$NOBODY4_LINE"'' $dest > $TEMPF
     69 			mv -f $TEMPF $dest
     70 		fi
     71 
     72 		#
     73 		# Add the 'smmsp' user for sendmail 8.12
     74 		#
     75 		SMMSP_LIN="smmsp:x:25:25:SendMail Message Submission Program:/:"
     76 		if grep "$SMMSP_LIN" $dest >/dev/null 2>&1; then
     77 			:
     78 		else
     79 			sed '/^nobody4:x/ a\
     80 '"$SMMSP_LIN"'' $dest > $TEMPF
     81 			mv -f $TEMPF $dest
     82 		fi
     83 		
     84 		#
     85 		# Add the 'gdm' user if it doesn't exist.
     86 		#
     87 		GDM_LINE="gdm:x:50:50:GDM Reserved UID:/var/lib/gdm:"
     88 		OLD_GDM_LINE="gdm:x:50:50:GDM Reserved UID:/:"
     89 		cur_name=`awk -F: '$3 == 50 { print $1 }' $dest`
     90 		if [ ! -z "$cur_name" -a "$cur_name" != "gdm" ]; then
     91 			echo "ERROR: Reserved UID 50 already assigned" \
     92 				"to '$cur_name'" >> /tmp/CLEANUP
     93 		elif grep "$GDM_LINE" $dest >/dev/null 2>&1; then
     94 			:
     95 		elif grep "$OLD_GDM_LINE" $dest > /dev/null 2>&1; then
     96 			sed '/^gdm:/s/:\/:/:\/var\/lib\/gdm:/' $dest > $TEMPF
     97 			mv -f $TEMPF $dest
     98 		else
     99 			sed '/^listen:x/ a\
    100 '"$GDM_LINE"'' $dest > $TEMPF
    101 			mv -f $TEMPF $dest
    102 		fi
    103 
    104 		#
    105 		# Add the 'webservd' user if it doesn't exist.
    106 		#
    107 		WEBSERVD_LIN="webservd:x:80:80:WebServer Reserved UID:/:"
    108 		cur_name=`awk -F: '$3 == 80 { print $1 }' $dest`
    109 		if [ ! -z "$cur_name" -a "$cur_name" != "webservd" ]; then
    110 			echo "ERROR: Reserved UID 80 already assigned" \
    111 				"to '$cur_name'" >> /tmp/CLEANUP
    112 		elif grep "$WEBSERVD_LIN" $dest > /dev/null 2>&1; then
    113 			:
    114 		else
    115 			sed '/^gdm:x/ a\
    116 '"$WEBSERVD_LIN"'' $dest > $TEMPF
    117 			mv -f $TEMPF $dest
    118 		fi
    119 
    120 		#
    121 		# Add the 'postgres' user if it doesn't exist.
    122 		#
    123 		POSTGRES_LIN="postgres:x:90:90:PostgreSQL Reserved UID:/:/usr/bin/pfksh"
    124 		cur_name=`awk -F: '$3 == 90 { print $1 }' $dest`
    125 		cur_id=`awk -F: '$1 == "postgres" { print $3 }' $dest`
    126 		if [ ! -z "$cur_name" -a "$cur_name" != "postgres" ]; then
    127 			echo "ERROR: Reserved UID 90 already assigned" \
    128 			    "to '$cur_name'" >> /tmp/CLEANUP
    129 		elif [ ! -z "$cur_id" -a "$cur_id" != "90" ]; then
    130 			echo "NOTE: postgres username already assigned" \
    131 			    "to id '$cur_id'" >> /tmp/CLEANUP
    132 		elif grep "$POSTGRES_LIN" $dest > /dev/null 2>&1; then
    133 			:
    134 		else
    135 			sed '/^webservd:x/ a\
    136 '"$POSTGRES_LIN"'' $dest > $TEMPF
    137 			mv -f $TEMPF $dest
    138 		fi
    139 
    140                 #
    141                 # Add the 'mysql' user if it doesn't exist.
    142                 #
    143                 MYSQL_LIN="mysql:x:70:70:MySQL Reserved UID:/:"
    144                 cur_name=`awk -F: '$3 == 70 { print $1 }' $dest`
    145                 cur_id=`awk -F: '$1 == "mysql" { print $3 }' $dest`
    146                 if [ ! -z "$cur_name" -a "$cur_name" != "mysql" ]; then
    147                         echo "ERROR: Reserved UID 70 already assigned" \
    148                             "to '$cur_name'" >> /tmp/CLEANUP
    149                 elif [ ! -z "$cur_id" -a "$cur_id" != "70" ]; then
    150                         echo "NOTE: mysql username already assigned" \
    151                             "to id '$cur_id'" >> /tmp/CLEANUP
    152                 elif grep "$MYSQL_LIN" $dest > /dev/null 2>&1; then
    153                         :
    154                 else
    155                         sed '/^postgres:x/ a\
    156 '"$MYSQL_LIN"'' $dest > $TEMPF
    157 			mv -f $TEMPF $dest
    158                 fi
    159 
    160 		#
    161 		# Add the 'svctag' user if it doesn't exist.
    162 		#
    163 		SVCTAG_LIN="svctag:x:95:12:Service Tag UID:/:"
    164 		cur_name=`awk -F: '$3 == 95 { print $1 }' $dest`
    165 		cur_id=`awk -F: '$1 == "svctag" { print $3 }' $dest`
    166 		if [ ! -z "$cur_name" -a "$cur_name" != "svctag" ]; then
    167 			echo "ERROR: Reserved UID 95 already assigned" \
    168 			    "to '$cur_name'" >> /tmp/CLEANUP
    169 		elif [ ! -z "$cur_id" -a "$cur_id" != "95" ]; then
    170 			echo "NOTE: svctag username already assigned" \
    171 			    "to id '$cur_id'" >> /tmp/CLEANUP
    172 		elif grep "$SVCTAG_LIN" $dest > /dev/null 2>&1; then
    173 			:
    174 		else
    175 			sed '/^postgres:x/ a\
    176 '"$SVCTAG_LIN"'' $dest > $TEMPF
    177 			mv -f $TEMPF $dest
    178 		fi
    179 
    180 		#
    181 		# Add the 'dladm' user if it doesn't exist.
    182 		#
    183 		DLADM_LIN="dladm:x:15:3:Datalink Admin:/:"
    184 		cur_name=`awk -F: '$3 == 15 { print $1 }' $dest`
    185 		if [ ! -z "$cur_name" -a "$cur_name" != "dladm" ]; then
    186 			echo "ERROR: Reserved UID 15 already assigned" \
    187 				"to '$cur_name'" >> /tmp/CLEANUP
    188 		elif grep "$DLADM_LIN" $dest > /dev/null 2>&1; then
    189 			:
    190 		else
    191 			sed '/^nuucp:x/ a\
    192 '"$DLADM_LIN"'' $dest > $TEMPF
    193 			mv -f $TEMPF $dest
    194 		fi
    195 
    196 		#
    197 		# Add the 'xvm' user if it doesn't exist.
    198 		#
    199 		XVM_LIN="xvm:x:60:60:xVM User:/:"
    200 		cur_name=`awk -F: '$3 == 60 { print $1 }' $dest`
    201 		cur_id=`awk -F: '$1 == "xvm" { print $3 }' $dest`
    202 		if [ ! -z "$cur_name" -a "$cur_name" != "xvm" ]; then
    203 			echo "ERROR: Reserved UID 60 already assigned" \
    204 			    "to '$cur_name'" >> /tmp/CLEANUP
    205 		elif [ ! -z "$cur_id" -a "$cur_id" != "60" ]; then
    206 			echo "NOTE: xvm username already assigned" \
    207 			    "to id '$cur_id'" >> /tmp/CLEANUP
    208 		elif grep "$XVM_LIN" $dest > /dev/null 2>&1; then
    209 			:
    210 		else
    211 			sed '/^gdm:x/ a\
    212 '"$XVM_LIN"'' $dest > $TEMPF
    213 			mv -f $TEMPF $dest
    214 		fi
    215 		#
    216 		# Add the 'openldap' user if it doesn't exist.
    217 		#
    218 		OPENLDAP_LIN="openldap:x:75:75:OpenLDAP User:/:"
    219 		cur_name=`awk -F: '$3 == 75 { print $1 }' $dest`
    220 		cur_id=`awk -F: '$1 == "openldap" { print $3 }' $dest`
    221 		if [ ! -z "$cur_name" -a "$cur_name" != "openldap" ]; then
    222 			echo "ERROR: Reserved UID 75 already assigned" \
    223 			    "to '$cur_name'" >> /tmp/CLEANUP
    224 		elif [ ! -z "$cur_id" -a "$cur_id" != "75" ]; then
    225 			echo "NOTE: openldap username already assigned" \
    226 			    "to id '$cur_id'" >> /tmp/CLEANUP
    227 		elif grep "$OPENLDAP_LIN" $dest > /dev/null 2>&1; then
    228 			:
    229 		else
    230 			sed '/^mysql:x/ a\
    231 '"$OPENLDAP_LIN"'' $dest > $TEMPF
    232 			mv -f $TEMPF $dest
    233 		fi
    234 
    235 		#
    236 		# Add the 'zfssnap' user if it doesn't exist.
    237 		#
    238 		ZSNAP_LIN="zfssnap:x:51:12:ZFS Automatic Snapshots Reserved UID:/:/usr/bin/pfsh"
    239 		cur_name=`awk -F: '$3 == 51 { print $1 }' $dest`
    240 		cur_id=`awk -F: '$1 == "zfssnap" { print $3 }' $dest`
    241 		if [ ! -z "$cur_name" -a "$cur_name" != "zfssnap" ]; then
    242 			echo "ERROR: Reserved UID 51 already assigned" \
    243 			    "to '$cur_name'" >> /tmp/CLEANUP
    244 		elif [ ! -z "$cur_id" -a "$cur_id" != "51" ]; then
    245 			echo "NOTE: zfssnap username already assigned" \
    246 			    "to id '$cur_id'" >> /tmp/CLEANUP
    247 		elif grep "$ZSNAP_LIN" $dest > /dev/null 2>&1; then
    248 			:
    249 		else
    250 			sed '/^gdm:x/ a\
    251 '"$ZSNAP_LIN"'' $dest > $TEMPF
    252 			mv -f $TEMPF $dest
    253 		fi
    254 
    255 		#
    256 		# Add the 'upnp' user if it doesn't exist.
    257 		#
    258 		UPNP_LIN="upnp:x:52:52:UPnP Server Reserved UID:/var/coherence:/bin/ksh"
    259 		cur_name=`awk -F: '$3 == 52 { print $1 }' $dest`
    260 		cur_id=`awk -F: '$1 == "upnp" { print $3 }' $dest`
    261 		if [ ! -z "$cur_name" -a "$cur_name" != "upnp" ]; then
    262 			echo "ERROR: Reserved UID 52 already assigned" \
    263 			    "to '$cur_name'" >> /tmp/CLEANUP
    264 		elif [ ! -z "$cur_id" -a "$cur_id" != "52" ]; then
    265 			echo "NOTE: upnp username already assigned" \
    266 			    "to id '$cur_id'" >> /tmp/CLEANUP
    267 		elif grep "$UPNP_LIN" $dest > /dev/null 2>&1; then
    268 			:
    269 		else
    270 			sed '/^zfssnap:x/ a\
    271 '"$UPNP_LIN"'' $dest > $TEMPF
    272 			mv -f $TEMPF $dest
    273 		fi
    274 	fi
    275 done
    276 
    277 exit 0
    278