TDE base libraries and programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mkpamserv 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #! /bin/sh
  2. permit=false
  3. if test "x$1" = x-P; then
  4. permit=true
  5. shift
  6. fi
  7. if test $# != 1; then
  8. echo "Usage: $0 [-P] <service>" >&2
  9. exit 1
  10. fi
  11. if test -r /etc/pam.d/$1 || grep "^[ ]*$1[ ]" /etc/pam.conf >/dev/null 2>&1; then
  12. echo "PAM service \"$1\" already configured."
  13. exit 0
  14. fi
  15. oi_mods="pam_(access|env|group|issue|lastlog|limits|listfile|mkhomedir|motd|nologin|shells|tally|time)"
  16. oo_mods="pam_securetty"
  17. if test -d /etc/pam.d; then
  18. if test ! -w /etc/pam.d; then
  19. echo "Error: need write access to /etc/pam.d/ to install PAM service definition!" >&2
  20. exit 1
  21. fi
  22. for sv in kde login; do
  23. if test -r /etc/pam.d/$sv; then
  24. echo "Copying PAM service definition file \"$sv\" to \"$1\"."
  25. if $permit; then
  26. echo "auth required pam_permit.so" > /etc/pam.d/$1
  27. perl -p -e "if (/^([ \\t]*\\@include[ \\t]+([^ \\t]+)[ \\t]*)\\n/) { \$l=\$1; \$p=\$2; \$p=~m,^/, || (\$p='/etc/pam.d/'.\$p); print \"#\$l -- start\\n\"; system \"cat \$p\"; \$_ = \"#\$l -- end\\n\"; }" < /etc/pam.d/$sv |
  28. perl -p -e "s/^([ \\t]*auth[ \\t]+[a-z]+[ \\t]+([^ \\t]+\\/)?(?!$oi_mods)\\w+\\.so)/#\$1/" >> /etc/pam.d/$1
  29. else
  30. perl -p -e "s/^([ \\t]*[^#].*[ \\t\\/]$oo_mods\\.so)/#\\1/" < /etc/pam.d/$sv > /etc/pam.d/$1
  31. fi
  32. exit 0
  33. fi
  34. done
  35. echo "Error: no template PAM service file for \"$1\" found!" >&2
  36. exit 1
  37. elif test -f /etc/pam.conf; then
  38. if test ! -w /etc/pam.conf; then
  39. echo "Error: need write access to /etc/pam.conf to install PAM service definition!" >&2
  40. exit 1
  41. fi
  42. for sv in kde login; do
  43. serv=`grep "^[ ]*$sv[ ]" /etc/pam.conf`
  44. if test -n "$serv"; then
  45. echo "Copying service definition entry \"$sv\" to \"$1\"."
  46. echo >>/etc/pam.conf
  47. sb="s/^[ \\t]*$sv([ \\t])/$1\$1/"
  48. if $permit; then
  49. echo "$1 auth required pam_permit.so" >>/etc/pam.conf
  50. echo "$serv" | perl -p -e "$sb;s/^($1[ \\t]+auth[ \\t]+[a-z]+[ \\t]+([^ \\t]+\\/)?(?!$oi_mods)\\w+\\.so)/#\$1/" >>/etc/pam.conf
  51. else
  52. echo "$serv" | perl -p -e "$sb;s/^(.*[ \\t\\/]$oo_mods\\.so)/#\$1/" >>/etc/pam.conf
  53. fi
  54. exit 0
  55. fi
  56. done
  57. echo "Error: no template PAM service entry for \"$1\" found!" >&2
  58. exit 1
  59. else
  60. if test "`whoami`" != root; then
  61. echo "Error: need root priviledges to install PAM service definitions!" >&2
  62. else
  63. echo "Error: don't know where to store the PAM service definition for \"$1\"!" >&2
  64. fi
  65. exit 1
  66. fi