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