Merge commit 'upstream/1.7.2p1'
[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 # make sure we have a sudoers file
8 if ( ! -f "/etc/sudoers") {
9
10         print "No /etc/sudoers found... creating one for you.\n";
11
12         open (SUDOERS, "> /etc/sudoers");
13         print SUDOERS "# /etc/sudoers\n",
14           "#\n",
15           "# This file MUST be edited with the 'visudo' command as root.\n",
16           "#\n",
17           "# See the man page for details on how to write a sudoers file.\n",
18           "#\n\nDefaults\tenv_reset\n\n",
19           "# Host alias specification\n\n",
20           "# User alias specification\n\n",
21           "# Cmnd alias specification\n\n",
22           "# User privilege specification\nroot\tALL=(ALL) ALL\n\n",
23           "# Allow members of group sudo to not need a password\n",
24           "# (Note that later entries override this, so you might need to move\n",
25           "# it further down)\n",
26           "%sudo ALL=(ALL) ALL\n",
27           "#\n",
28           "#includedir /etc/sudoers.d\n";
29         close SUDOERS;
30
31 }
32
33 # make sure sudoers has the correct permissions and owner/group
34 system ('chown root:root /etc/sudoers');
35 system ('chmod 440 /etc/sudoers');
36
37 # must do a remove first to un-do the "bad" links created by previous version
38 system ('update-rc.d -f sudo remove >/dev/null 2>&1');
39
40 system ('update-rc.d sudo start 75 S . >/dev/null');
41
42 # make sure we have a sudo group
43
44 exit 0 if getgrnam("sudo"); # we're finished if there is a group sudo
45
46 $gid = 27;                 # start searcg with gid 27
47 setgrent;
48 while (getgrgid($gid)) {
49         ++$gid;
50 }
51 endgrent;
52
53 if ($gid != 27) {
54         print "On Debian we normally use gid 27 for 'sudo'.\n";
55         $gname = getgrgid(27);
56         print "However, on your system gid 27 is group '$gname'.\n\n";
57         print "Would you like me to stop configuring sudo so that you can change this? [n] "; 
58         $ans = <STDIN>;
59         if ($ans =~ m/^[yY].*/) {
60                 print "'dpkg --pending --configure' will restart the configuration.\n\n\n";
61                 exit 1;
62         }
63 }
64
65 print "Creating group 'sudo' with gid = $gid\n";
66 system("groupadd -g $gid sudo");
67
68 # create symlink to ease transition to new path for ldap config
69 # if old config file exists and new one doesn't
70 if (-e "/etc/ldap/ldap.conf" && ! -e "/etc/sudo-ldap.conf") {
71   system("ln -s ldap/ldap.conf /etc/sudo-ldap.conf");
72 }
73
74 print "";