home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 4.ddi / sbin / adduser next >
Encoding:
Text File  |  1990-12-08  |  3.4 KB  |  184 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11.  
  12.  
  13.  
  14. #ident    "@(#)/sbin/adduser.sl 1.1 4.0 12/08/90 49603 AT&T-USL"
  15.  
  16. # add a user to the system
  17. rm -f /usr/tmp/addcfm
  18.  
  19. # Do all validations first
  20.  
  21. loginid=$1       #  login ID
  22. fullname=$2      #  Users full name
  23. userid=$3        #  User ID
  24. logdir=$4        #  Home directory
  25.  
  26. if [ $# -eq 5 ]
  27. then
  28.     sysadm=$5     #  System admin privileges ( Yes or No )
  29. else
  30.     sysadm=No
  31. fi
  32.  
  33. USAGE="USAGE: $0 <login id> <name> <user id> <home directory>"
  34.  
  35. if [ $# -lt 4 ]
  36. then
  37.     echo $USAGE
  38.     exit 1
  39. fi
  40.  
  41. #    check if the length of input is longer than 8
  42.  
  43. length=`echo $loginid | wc -c`
  44. if [ "$length" -gt "9" ]
  45. then 
  46.     echo "Login name can not be longer than eight characters."
  47.     exit 1
  48. fi
  49.  
  50. #check for illegal character (s)
  51.  
  52. if echo "$loginid" | grep "[^0-9a-z]" > /dev/null
  53. then 
  54.     echo "Only numbers & lower case letters are permitted in login name." 
  55.     exit 1
  56. fi
  57.  
  58. #    check if login name already exists
  59.  
  60. grep "^$loginid:" /etc/passwd >/dev/null
  61. rc=$?
  62. if [ $rc -eq 0 ]
  63. then
  64.     echo "$loginid already exists on your system. Choose another login name." 
  65.     exit 1
  66. fi
  67.  
  68. # Verify Full name doesn't contain illegal characters
  69.  
  70. echo "$fullname" | grep "[^[0-9]a-z A-Z.]" > /dev/null
  71. if [ "$?" -eq "0" ]
  72. then 
  73.     echo "The full name can only be letters, numbers, and periods." 
  74.     exit 1
  75. fi
  76.  
  77. #check for input string length
  78.  
  79. length=`echo $fullname | wc -c`
  80. if [ "$length" -gt "26" -o "$length" -lt "2" ]
  81. then 
  82.     echo "The full name has to be 1 to 25 characters." 
  83.     exit 1
  84. fi
  85.  
  86. #    Check for illegal range
  87.  
  88. if [ "$userid" -gt 50000 -o "$userid" -lt 100 ]
  89.     then 
  90.     echo "User ID number out of legal range (100-50000)."
  91.     exit 1
  92. fi
  93.  
  94. #    Check if input userid exists already
  95.  
  96. if grep "^[^:]*:[^:]*:0*$userid:" /etc/passwd > /dev/null
  97. then
  98.     echo "User Id already used on system, please choose another."
  99.     exit 1
  100. fi
  101.  
  102. if test -f "$logdir" -o -d "$logdir"
  103. then
  104.     echo "$logdir directory already exists. Choose another HOME directory."
  105.     exit 1
  106. fi
  107.  
  108. echo "$logdir" | grep "[^0-9_/.a-zA-Z]" >/dev/null
  109. rc=$?
  110. if [ "$rc" = "0" ]
  111. then
  112.     echo "Directory name contains illegal characters." 
  113.     exit 1
  114. fi
  115.  
  116. dir=$logdir
  117. while [ "$dir" != "/" -a "$dir" != "." ]
  118. do
  119.     path=`basename $dir`
  120.     dir=`dirname $dir`
  121.     length=`echo "$path" | wc -c`
  122.     if [ "$length" -gt "15" ]
  123.     then
  124.         echo "More than 14 characters in directory name." 
  125.         exit 1
  126.     fi
  127. done
  128.  
  129. #
  130. #    Set default group id to 1. (for now)
  131. #
  132.  
  133. groupid=1
  134.  
  135. #
  136. #    Echo entry into /etc/passwd
  137. #
  138.  
  139. /usr/bin/passmgmt -a -c "$fullname" -h $logdir -g $groupid -u $userid $loginid
  140.  
  141. #
  142. #    Make home directory 
  143. #
  144. umask 002
  145. mkdir ${logdir}
  146. if [ $? -ne 0 ]
  147. then
  148.     echo "Creation of ${logdir} failed."
  149.     /usr/bin/passmgmt -d $loginid
  150.     exit 1
  151. fi
  152. chgrp ${groupid} ${logdir}
  153. chown ${userid} ${logdir}
  154.  
  155. #    System administrative privileges
  156.  
  157. if [ "$sysadm" = "Yes" ]
  158. then
  159.     if test -r /etc/adm.lock
  160.     then
  161.         :
  162.     else
  163.         > /etc/adm.lock
  164.         echo "$loginid base-adm" >> /etc/.useradm
  165.         rm -f /etc/adm.lock
  166.     fi
  167. fi
  168.  
  169.  
  170. #
  171. #      Give user a default .profile if /etc/stdprofile exists.
  172. #
  173.  
  174. if [ -r /etc/stdprofile ]
  175. then
  176.         cp /etc/stdprofile ${logdir}/.profile
  177.         chmod 644 ${logdir}/.profile
  178.         chown ${userid} ${logdir}/.profile
  179. fi
  180.  
  181. echo "Enter a password for $loginid:"
  182. /bin/passwd $loginid
  183.