better text for the button. thanks celeste
[kdebase.git] / workspace / mkpamserv
blobf7393305e8c2298234cdba8530b54f0abcf51506
1 #! /bin/sh
3 permit=false
4 if test "x$1" = x-P; then
5 permit=true
6 shift
7 fi
9 if test $# != 1; then
10 echo "Usage: $0 [-P] <service>" >&2
11 exit 1
14 if test -r /etc/pam.d/$1 || grep "^[ ]*$1[ ]" /etc/pam.conf >/dev/null 2>&1; then
15 echo "PAM service \"$1\" already configured."
16 exit 0
19 oi_mods="pam_(access|env|group|limits|listfile|mkhomedir|nologin|shells|tally|time)"
20 oo_mods="pam_(securetty|mail|motd|issue|lastlog)"
22 if test -d /etc/pam.d; then
23 if test ! -w /etc/pam.d; then
24 echo "Error: need write access to /etc/pam.d/ to install PAM service definition!" >&2
25 exit 1
27 for sv in kde login; do
28 if test -r /etc/pam.d/$sv; then
29 echo "Copying PAM service definition file \"$sv\" to \"$1\"."
30 if $permit; then
31 echo "auth required pam_permit.so" > /etc/pam.d/$1
32 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 |
33 perl -p -e "s/^([ \\t]*auth[ \\t]+[a-z]+[ \\t]+([^ \\t]+\\/)?(?!$oi_mods)\\w+\\.so)/#\$1/" >> /etc/pam.d/$1
34 else
35 perl -p -e "s/^([ \\t]*[^#].*[ \\t\\/]$oo_mods\\.so)/#\\1/" < /etc/pam.d/$sv > /etc/pam.d/$1
37 exit 0
39 done
40 echo "Error: no template PAM service file for \"$1\" found!" >&2
41 exit 1
42 elif test -f /etc/pam.conf; then
43 if test ! -w /etc/pam.conf; then
44 echo "Error: need write access to /etc/pam.conf to install PAM service definition!" >&2
45 exit 1
47 for sv in kde login; do
48 serv=`grep "^[ ]*$sv[ ]" /etc/pam.conf`
49 if test -n "$serv"; then
50 echo "Copying service definition entry \"$sv\" to \"$1\"."
51 echo >>/etc/pam.conf
52 sb="s/^[ \\t]*$sv([ \\t])/$1\$1/"
53 if $permit; then
54 echo "$1 auth required pam_permit.so" >>/etc/pam.conf
55 echo "$serv" | perl -p -e "$sb;s/^($1[ \\t]+auth[ \\t]+[a-z]+[ \\t]+([^ \\t]+\\/)?(?!$oi_mods)\\w+\\.so)/#\$1/" >>/etc/pam.conf
56 else
57 echo "$serv" | perl -p -e "$sb;s/^(.*[ \\t\\/]$oo_mods\\.so)/#\$1/" >>/etc/pam.conf
59 exit 0
61 done
62 echo "Error: no template PAM service entry for \"$1\" found!" >&2
63 exit 1
64 else
65 if test "`whoami`" != root; then
66 echo "Error: need root priviledges to install PAM service definitions!" >&2
67 else
68 echo "Error: don't know where to store the PAM service definition for \"$1\"!" >&2
70 exit 1