openafs-tools-cmd-20020115
[openafs.git] / src / tools / install / write_pam.pl
1 #!/usr/bin/perl
2 #
3 # A perl script that will enable or disable
4 # AFS login on a machine, depending on the
5 # first argument to the script.
6 #
7 # openafs-tools, Version 1.2.2
8
9 # Copyright 2001, International Business Machines Corporation and others.
10 # All Rights Reserved.
11
12 # This software has been released under the terms of the IBM Public
13 # License.  For details, see the LICENSE file in the top-level source
14 # directory or online at http://www.openafs.org/dl/license10.html
15 #
16
17 open( LOGIN, "</etc/pam.d/login");
18 @login = <LOGIN>;
19 close(LOGIN);
20
21 open( LOGIN, ">/etc/pam.d/login");
22
23 if( $ARGV[0] eq "enable" ) {
24
25     $enabled == 0;
26     
27     foreach $line (@login) {
28         @splitline = split( /\s+/, $line);
29         # only enable if: it's directly before the pwdb line (without the "shadow nullock",
30         #                 it hasn't been enabled yet in this script
31         if( $splitline[2] eq "/lib/security/pam_pwdb.so" && $splitline[3] eq ""  && $enabled == 0 ) {
32             print LOGIN "auth\t   sufficient\t/lib/security/pam_afs.so try_first_pass ignore_root\n";
33             $enabled = 1;
34         } 
35         # If you encounter the line, turn enabled on
36         if( $splitline[2] eq "/lib/scurity/pam_afs.so" ) {
37             $enabled = 1;
38         }    
39         print LOGIN $line;
40     }
41
42 } else {
43
44     foreach $line (@login) {
45         @splitline = split( /\s+/, $line);
46         if( $splitline[2] ne "/lib/security/pam_afs.so" ) {
47             print LOGIN $line;
48         }
49         
50     }
51
52 }
53
54