summaryrefslogtreecommitdiff
path: root/adduser.local
blob: a526ab2413761844e15ae10292689bcd8e405a46 (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2001-2006, 2010, Jonas Smedegaard <dr@jones.dk>
  4. # Description: Adduser extensions for Redpill <http://www.redpill.dk>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # TODO: Allow local overriding of using /etc/mailname
  20. # TODO: Only ask additional questions if real user
  21. # TODO: handle samba passwords in /var/lib/samba/passdb.tdb
  22. # TODO: Invent a way to flag for INTERACTIVE without abusing VERBOSE
  23. #
  24. set -e
  25. NEWUSERNAME=$1
  26. NEWUID=$2
  27. NEWGID=$3
  28. NEWHOMEDIR=$4
  29. fullname() { getent passwd $NEWUSERNAME | awk -F: '{print $5}' | awk -F, '{print $1}'; }
  30. maildomain() { if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; fi; }
  31. listlists() { if [ -x /usr/sbin/list_lists ]; then /usr/sbin/list_lists -ab -V "$1"; fi; }
  32. add2list() { /bin/echo "$1" | /usr/sbin/add_members -w y -a y -r - "$2"; }
  33. . /etc/adduser.conf
  34. # Ignore non-human accounts silently
  35. [ "$NEWUID" -ge "$FIRST_UID" -a "$NEWUID" -le "$LAST_UID" ] || exit 0
  36. [ -f /etc/local/users.conf ] && . /etc/local/users.conf
  37. # resolve account profiles
  38. case "$NEWUSERNAME" in
  39. *-*)
  40. profile_aux=1
  41. ;;
  42. *)
  43. ;;
  44. esac
  45. # Samba password
  46. #FIXME: Check if enabled in samba.conf (or included files!)
  47. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && ([ -x /usr/bin/pdbedit ] || [ -x /usr/bin/smbpasswd ]); then
  48. echo -n "Add samba access to the account (y/N)? "
  49. read sambaaccount
  50. case $sambaaccount in
  51. y|Y)
  52. if [ -x /usr/bin/pdbedit ]; then
  53. /usr/bin/pdbedit -a -u "$NEWUSERNAME"
  54. elif [ -x /usr/bin/smbpasswd ] && [ -f /etc/samba/smbpasswd ]; then
  55. /usr/bin/smbpasswd -a $NEWUSERNAME
  56. fi
  57. ;;
  58. esac
  59. fi
  60. # Mail forwarding
  61. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -x /usr/local/sbin/userforward ]; then
  62. echo -n "Forward mail to an external account (y/N)? "
  63. read mailforward
  64. case $mailforward in
  65. y|Y)
  66. echo -n "Enter external email address: "
  67. read mail_address
  68. case $mail_address in
  69. ?*@?*.*)
  70. /usr/local/sbin/userforward $NEWUSERNAME $mail_address
  71. ;;
  72. ?*)
  73. echo "That wasn't a proper email address - skipping..."
  74. ;;
  75. esac
  76. ;;
  77. esac
  78. fi
  79. # Mailing lists
  80. maildomain="`maildomain`"
  81. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$maildomain" ]; then
  82. echo -n "Subscribe $NEWUSERNAME@$maildomain to mailinglists (y/N)? "
  83. read subscribe
  84. case $subscribe in
  85. y|Y)
  86. if [ -n "$fullname" ]; then
  87. subscriber="`fullname` <$NEWUSERNAME@$maildomain>"
  88. else
  89. subscriber="$NEWUSERNAME@$maildomain"
  90. fi
  91. lists="`listlists "$maildomain"`"
  92. if [ -z "$lists" ]; then
  93. echo "No mailinglists found."
  94. fi
  95. for list in $lists; do
  96. echo -n "Subscribe to mailinglist $list (y/N)? "
  97. read subscribe
  98. case $subscribe in
  99. y|Y)
  100. add2list "$subscriber" "$list";;
  101. esac
  102. done
  103. esac
  104. fi
  105. if [ -z "$profile_aux" ] && [ -f /etc/local/users.conf ]; then
  106. . /etc/local/users.conf
  107. if [ -n "$USERS_GROUPNAME" ]; then
  108. addgroup $NEWUSERNAME $USERS_GROUPNAME
  109. fi
  110. if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$REALUSERS_GROUPNAME" ]; then
  111. echo "This system has both dummy and real users:"
  112. echo " Dummy users have read access to specific files."
  113. echo " Real users have read/write access to personal files."
  114. echo -n "Is this a dummy user (Y/n)? "
  115. read realuser
  116. case $realuser in
  117. y|Y|"")
  118. ;;
  119. *)
  120. addgroup $NEWUSERNAME $REALUSERS_GROUPNAME
  121. ;;
  122. esac
  123. fi
  124. fi
  125. #if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$REALUSERS_GROUPNAME" ]; then
  126. # cat <<+
  127. #Is this a remote or local user (with need for physical
  128. #access to devices like CD-ROM, soundcard and modem needed)?
  129. #
  130. #+
  131. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ]; then
  132. echo -n "Grant this user access to local utilities (y/N)?"
  133. read localuser
  134. case $localuser in
  135. y|Y)
  136. for group in floppy dialout cdrom audio video games; do
  137. addgroup $NEWUSERNAME $group
  138. done
  139. ;;
  140. *)
  141. ;;
  142. esac
  143. fi
  144. if [ -z "$profile_aux" ] && [ -x /usr/local/sbin/user-init ]; then
  145. /usr/local/sbin/user-init $NEWUSERNAME
  146. fi