Handle hostnames with upper-case letters
[webmin.git] / pam / pam_env.so.pl
1 # display args for pam_env.so
2
3 # display_args(&service, &module, &args)
4 sub display_module_args
5 {
6 local $file = $_[2]->{'conffile'} ? $_[2]->{'conffile'}
7                                   : "/etc/security/pam_env.conf";
8 open(FILE, $file);
9 while(<FILE>) {
10         s/#.*$//;
11         s/\r|\n//g;
12         if (/^\s*(\S+)/) {
13                 local $var = $1;
14                 local ($def, $over);
15                 if (/DEFAULT="([^"]+)"/i || /DEFAULT=(\S+)/i) {
16                         $def = $1;
17                         }
18                 if (/OVERRIDE="([^"]+)"/i || /OVERRIDE=(\S+)/i) {
19                         $over = $1;
20                         }
21                 push(@env, [ $var, $def, $over ]);
22                 }
23         }
24 close(FILE);
25 local $et;
26 $et .= &ui_columns_start([ $text{'env_var'},
27                           $text{'env_def'},
28                           $text{'env_over'} ]);
29 local $i = 0;
30 foreach $e (@env, [ ]) {
31         $et .= &ui_columns_row([
32                 &ui_textbox("var_$i", $e->[0], 20),
33                 &ui_textbox("def_$i", $e->[1], 30),
34                 &ui_textbox("over_$i", $e->[2], 30),
35                 ]);
36         $i++;
37         }
38 $et .= &ui_columns_end();
39 print &ui_table_row(undef, $et, 4);
40 }
41
42 # parse_module_args(&service, &module, &args)
43 sub parse_module_args
44 {
45 local $file = $_[2]->{'conffile'} ? $_[2]->{'conffile'}
46                                   : "/etc/security/pam_env.conf";
47 local ($i, @lines);
48 for($i=0; defined($in{"var_$i"}); $i++) {
49         next if (!$in{"var_$i"});
50         $in{"var_$i"} =~ /^\S+$/ || &error($text{'env_evar'});
51         local $line = $in{"var_$i"};
52         $line .= "\tDEFAULT=\"".$in{"def_$i"}."\"" if ($in{"def_$i"});
53         $line .= "\tOVERRIDE=\"".$in{"over_$i"}."\"" if ($in{"over_$i"});
54         push(@lines, $line,"\n");
55         }
56 &lock_file($file);
57 &open_tempfile(FILE, ">$file");
58 &print_tempfile(FILE, @lines);
59 &close_tempfile(FILE);
60 &unlock_file($file);
61 }
62