88e8c2c0184b5177b610261e1fa5644aec74f9a3
[debian/sudo] / debian / sudo-ldap.postinst
1 #!/usr/bin/perl
2
3 # remove old link
4
5 unlink ("/etc/alternatives/sudo") if ( -l "/etc/alternatives/sudo");
6
7 # complain if no sudoers file is present
8 if ( ! -f "/etc/sudoers") {
9         print "WARNING:  /etc/sudoers not present!\n";
10 }
11
12 # handle state directory transition from /var/run/sudo to /var/lib/sudo,
13 # moving any existing content over to avoid re-lecturing existing users
14 if ( -d "/var/run/sudo") {
15     system ('mkdir -p /var/lib/sudo');
16     system ('(cd /var/run/sudo ; tar cf - .) | (cd /var/lib/sudo ; tar xf -)');
17     system ('rm -rf /var/run/sudo');
18 }
19
20 # make sure sudoers has the correct permissions and owner/group
21 system ('chown root:root /etc/sudoers');
22 system ('chmod 440 /etc/sudoers');
23
24 # must do a remove first to un-do the "bad" links created by previous version
25 system ('update-rc.d -f sudo remove >/dev/null 2>&1');
26
27 system ('update-rc.d sudo start 75 2 3 4 5 . >/dev/null');
28
29 # create symlink to ease transition to new path for ldap config
30 # if old config file exists and new one doesn't
31 if (-e "/etc/ldap/ldap.conf" && ! -e "/etc/sudo-ldap.conf") {
32   system("ln -s ldap/ldap.conf /etc/sudo-ldap.conf");
33 }
34
35 # make sure we have a sudo group
36
37 exit 0 if getgrnam("sudo"); # we're finished if there is a group sudo
38
39 $gid = 27;                 # start searcg with gid 27
40 setgrent;
41 while (getgrgid($gid)) {
42         ++$gid;
43 }
44 endgrent;
45
46 if ($gid != 27) {
47         print "On Debian we normally use gid 27 for 'sudo'.\n";
48         $gname = getgrgid(27);
49         print "However, on your system gid 27 is group '$gname'.\n\n";
50         print "Would you like me to stop configuring sudo so that you can change this? [n] "; 
51         $ans = <STDIN>;
52         if ($ans =~ m/^[yY].*/) {
53                 print "'dpkg --pending --configure' will restart the configuration.\n\n\n";
54                 exit 1;
55         }
56 }
57
58 print "Creating group 'sudo' with gid = $gid\n";
59 system("groupadd -g $gid sudo");
60
61 print "";