summaryrefslogtreecommitdiff
path: root/adduser.local
blob: 49aa47b1cc83e029f679da01772cec1193dd1ec7 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/sbin/adduser.local
  4. # Copyright 2001-2006 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: adduser.local,v 1.26 2006-08-25 04:39:27 jonas Exp $
  7. #
  8. # Adduser additions for Redpill networks
  9. #
  10. # TODO: Allow local overriding of using /etc/mailname
  11. # TODO: Only ask additional questions if real user
  12. # TODO: handle samba passwords in /var/lib/samba/passdb.tdb
  13. # TODO: Invent a way to flag for INTERACTIVE without abusing VERBOSE
  14. #
  15. set -e
  16. NEWUSERNAME=$1
  17. NEWUID=$2
  18. NEWGID=$3
  19. NEWHOMEDIR=$4
  20. fullname() { getent passwd $NEWUSERNAME | awk -F: '{print $5}' | awk -F, '{print $1}'; }
  21. maildomain() { if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; fi; }
  22. listlists() { if [ -x /usr/sbin/list_lists ]; then /usr/sbin/list_lists -ab -V "$1"; fi; }
  23. add2list() { /bin/echo "$1" | /usr/sbin/add_members -w y -a y -r - "$2"; }
  24. . /etc/adduser.conf
  25. # Ignore non-human accounts silently
  26. [ "$NEWUID" -ge "$FIRST_UID" -a "$NEWUID" -le "$LAST_UID" ] || exit 0
  27. [ -f /etc/local/users.conf ] && . /etc/local/users.conf
  28. # Samba password
  29. #FIXME: Check if enabled in samba.conf (or included files!)
  30. if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && ([ -x /usr/bin/pdbedit ] || [ -x /usr/bin/smbpasswd ]); then
  31. echo -n "Add samba access to the account (y/N)? "
  32. read sambaaccount
  33. case $sambaaccount in
  34. y|Y)
  35. if [ -x /usr/bin/pdbedit ]; then
  36. /usr/bin/pdbedit -a -u "$NEWUSERNAME"
  37. elif [ -x /usr/bin/smbpasswd ] && [ -f /etc/samba/smbpasswd ]; then
  38. /usr/bin/smbpasswd -a $NEWUSERNAME
  39. fi
  40. ;;
  41. esac
  42. fi
  43. # Mail forwarding
  44. if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -x /usr/local/sbin/userforward ]; then
  45. echo -n "Forward mail to an external account (y/N)? "
  46. read mailforward
  47. case $mailforward in
  48. y|Y)
  49. echo -n "Enter external email address: "
  50. read mail_address
  51. case $mail_address in
  52. ?*@?*.*)
  53. /usr/local/sbin/userforward $NEWUSERNAME $mail_address
  54. ;;
  55. ?*)
  56. echo "That wasn't a proper email address - skipping..."
  57. ;;
  58. esac
  59. ;;
  60. esac
  61. fi
  62. # Mailing lists
  63. maildomain="`maildomain`"
  64. if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$maildomain" ]; then
  65. echo -n "Subscribe $NEWUSERNAME@$maildomain to mailinglists (y/N)? "
  66. read subscribe
  67. case $subscribe in
  68. y|Y)
  69. if [ -n "$fullname" ]; then
  70. subscriber="`fullname` <$NEWUSERNAME@$maildomain>"
  71. else
  72. subscriber="$NEWUSERNAME@$maildomain"
  73. fi
  74. lists="`listlists "$maildomain"`"
  75. if [ -z "$lists" ]; then
  76. echo "No mailinglists found."
  77. fi
  78. for list in $lists; do
  79. echo -n "Subscribe to mailinglist $list (y/N)? "
  80. read subscribe
  81. case $subscribe in
  82. y|Y)
  83. add2list "$subscriber" "$list";;
  84. esac
  85. done
  86. esac
  87. fi
  88. if [ -f /etc/local/users.conf ]; then
  89. . /etc/local/users.conf
  90. if [ -n "$USERS_GROUPNAME" ]; then
  91. addgroup $NEWUSERNAME $USERS_GROUPNAME
  92. fi
  93. if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$REALUSERS_GROUPNAME" ]; then
  94. echo "This system has both dummy and real users:"
  95. echo " Dummy users have read access to specific files."
  96. echo " Real users have read/write access to personal files."
  97. echo -n "Is this a dummy user (Y/n)? "
  98. read realuser
  99. case $realuser in
  100. y|Y|"")
  101. ;;
  102. *)
  103. addgroup $NEWUSERNAME $REALUSERS_GROUPNAME
  104. ;;
  105. esac
  106. fi
  107. fi
  108. #if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$REALUSERS_GROUPNAME" ]; then
  109. # cat <<+
  110. #Is this a remote or local user (with need for physical
  111. #access to devices like CD-ROM, soundcard and modem needed)?
  112. #
  113. #+
  114. if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ]; then
  115. echo -n "Grant this user access to local utilities (y/N)?"
  116. read localuser
  117. case $localuser in
  118. y|Y)
  119. for group in floppy dialout cdrom audio video games; do
  120. addgroup $NEWUSERNAME $group
  121. done
  122. ;;
  123. *)
  124. ;;
  125. esac
  126. fi
  127. if [ -x /usr/local/sbin/user-init ]; then
  128. /usr/local/sbin/user-init $NEWUSERNAME
  129. fi