Handle hostnames with upper-case letters
[webmin.git] / acl / save_unix.cgi
1 #!/usr/local/bin/perl
2 # edit_unix.cgi
3 # Save automatic unix user authentication options
4
5 require './acl-lib.pl';
6 &ReadParse();
7 &error_setup($text{'unix_err'});
8 $access{'unix'} && $access{'create'} && $access{'delete'} ||
9         &error($text{'unix_ecannot'});
10
11 # Parse Unix auth table
12 if (!$in{'unix_def'}) {
13         for($i=0; defined($mode = $in{"mode_$i"}); $i++) {
14                 next if (!$mode);
15                 $who = $in{"who_$i"};
16                 if ($mode == 2 && !$who) {
17                         &error(&text('unix_ewhogroup', $i+1));
18                         }
19                 elsif ($mode == 3 && !$who) {
20                         &error(&text('unix_ewhouser', $i+1));
21                         }
22                 $to = $in{"to_$i"};
23                 push(@unix, [ $mode == 1 ? "*" :
24                               $mode == 2 ? "\@$who" : $who, $to ]);
25                 }
26         @unix || &error($text{'unix_enone'});
27         }
28
29 # Parse list of allowed users
30 @users = split(/\s+/, $in{"users"});
31 if ($in{"access"}) {
32         foreach $u (@users) {
33                 if ($u =~ /^\@(\S+)$/) {
34                         defined(getgrnam($1)) ||
35                                 &error(&text('unix_egroup', "$1"));
36                         }
37                 elsif ($u =~ /^(\d*)-(\d*)$/ && ($1 || $2)) {
38                         # Assume UIDs are ok
39                         }
40                 else {
41                         defined(getpwnam($u)) ||
42                                 &error(&text('unix_euser', $u));
43                         }
44                 }
45         }
46 if ($in{'shells_deny'}) {
47         -r $in{'shells'} || &error($text{'unix_eshell'});
48         }
49
50 &lock_file($ENV{'MINISERV_CONFIG'});
51 &get_miniserv_config(\%miniserv);
52 &save_unixauth(\%miniserv, \@unix);
53 delete($miniserv{"allowusers"});
54 delete($miniserv{"denyusers"});
55 if ($in{"access"} == 1) { $miniserv{"allowusers"} = join(' ', @users); }
56 elsif ($in{"access"} == 2) { $miniserv{"denyusers"} = join(' ', @users); }
57 if ($in{'shells_deny'}) {
58         $miniserv{'shells_deny'} = $in{'shells'};
59         }
60 else {
61         delete($miniserv{'shells_deny'});
62         }
63 if ($in{'sudo'}) {
64         &has_command("sudo") || &error(&text('unix_esudo', "<tt>sudo</tt>"));
65         eval "use IO::Pty";
66         $@ && &error(&text('unix_esudomod', "<tt>IO::Pty</tt>"));
67         }
68 $miniserv{'sudo'} = $in{'sudo'};
69 $miniserv{'pamany'} = $in{'pamany'} ? $in{'pamany_user'} : undef;
70 &put_miniserv_config(\%miniserv);
71 &unlock_file($ENV{'MINISERV_CONFIG'});
72 if ($oldsudo != $in{'sudo'}) {
73         &restart_miniserv();
74         }
75 else {
76         &reload_miniserv();
77         }
78 &webmin_log("unix");
79 &redirect("");
80