Handle hostnames with upper-case letters
[webmin.git] / pam / save_mod.cgi
1 #!/usr/local/bin/perl
2 # save_mod.cgi
3 # Update a module line in a service
4
5 require './pam-lib.pl';
6 &ReadParse();
7 &error_setup($text{'mod_err'});
8 @pam = &get_pam_config();
9 $pam = $pam[$in{'idx'}];
10
11 &lock_file($pam->{'file'});
12 if ($in{'delete'}) {
13         # Deleting a module
14         $mod = $pam->{'mods'}->[$in{'midx'}];
15         &delete_module($pam->{'name'}, $mod);
16         }
17 else {
18         if ($in{'_module'}) {
19                 # Adding a new module
20                 $mod = { 'type' => $in{'_type'},
21                          'module' => $in{'_module'} };
22                 $module = $in{'_module'};
23                 }
24         else {
25                 # Existing module entry
26                 $mod = $pam->{'mods'}->[$in{'midx'}];
27                 $module = $mod->{'module'};
28                 $module =~ s/^.*\///;
29                 }
30         $mod->{'control'} = $in{'control'};
31
32         if (-r "./$module.pl") {
33                 # Args selected by UI
34                 do "./$module.pl";
35                 if (!$module_has_no_args) {
36                         foreach $a (split(/\s+/, $mod->{'args'})) {
37                                 if ($a =~ /^([^\s=]+)=(\S*)$/) {
38                                         $args{$1} = $2;
39                                         }
40                                 else {
41                                         $args{$a} = "";
42                                         }
43                                 }
44                         &parse_module_args($pam, $mod, \%args);
45                         foreach $a (keys %args) {
46                                 if ($args{$a} eq "") {
47                                         push(@args, $a);
48                                         }
49                                 else {
50                                         push(@args, "$a=$args{$a}");
51                                         }
52                                 }
53                         $mod->{'args'} = join(" ", @args);
54                         }
55                 }
56         else {
57                 # Args entered manually
58                 $mod->{'args'} = $in{'args'};
59                 }
60
61         if ($in{'_module'}) {
62                 # Add the PAM module entry
63                 &create_module($pam->{'name'}, $mod);
64                 }
65         else {
66                 # Update the existing entry
67                 &modify_module($pam->{'name'}, $mod);
68                 }
69         }
70 &unlock_file($pam->{'file'});
71 &webmin_log($in{'delete'} ? "delete" : $in{'_module'} ? "create" : "modify",
72             "mod", $pam->{'name'}, $mod);
73 &redirect("edit_pam.cgi?idx=$in{'idx'}");
74
75