Handle hostnames with upper-case letters
[webmin.git] / samba / save_pass.cgi
1 #!/usr/local/bin/perl
2 # save_pass.cgi
3 # Save inputs from conf_pass.cgi
4
5 require './samba-lib.pl';
6 &ReadParse();
7 &lock_file($config{'smb_conf'});
8 $global = &get_share("global");
9
10 # check acls
11
12 &error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
13 &error("$text{'eacl_np'} $text{'eacl_pcp'}") unless $access{'conf_pass'};
14
15 &error_setup($text{'savepass_fail'});
16 $nopass = (`$config{samba_password_program} 2>&1 </dev/null` =~ /encryption not selected/);
17 if ($in{encrypt_passwords} eq "yes" && $nopass) {
18         &error($text{'savepass_nopass'});
19         }
20 &setval("encrypt passwords", $in{encrypt_passwords}, "no");
21
22 &setval("null passwords", $in{null_passwords}, "no");
23
24 if (!$in{passwd_program_def} && !$in{passwd_program}) {
25         &error($text{'savepass_passwd'});
26         }
27 &setval("passwd program", $in{passwd_program_def}?"":$in{passwd_program}, "");
28
29 &setval("unix password sync", $in{'unix_password_sync'}, "no");
30
31 if ($in{passwd_chat_def}) { &delval("passwd chat"); }
32 else {
33         for($i=0; defined($in{"chat_recv_$i"}); $i++) {
34                 push(@chat, $in{"chat_recv_$i"});
35                 push(@chat, $in{"chat_send_$i"});
36                 }
37         $clast = -1;
38         for($i=0; $i<@chat; $i++) {
39                 if ($chat[$i] =~ /\S/) { $clast = $i; }
40                 }
41         if ($clast < 0) {
42                 &error($text{'savepass_chat'});
43                 }
44         @chat = @chat[0 .. $clast];
45         @chat = map { /^$/ ? "." : /^\S+$/ ? $_ : "\"$_\""; } @chat;
46         &setval("passwd chat", join(' ', @chat));
47         }
48
49 $mapfile = &getval("username map");
50 if ($in{username_map_def}) { &delval("username map"); }
51 else {
52         if (!$mapfile) {
53                 $config{smb_conf} =~ /^(.*)\/[^\/]+$/;
54                 $mapfile = "$1/user.map";
55                 }
56         &setval("username map", $mapfile);
57         for($i=0; defined($in{"umap_unix_$i"}); $i++) {
58                 if ($in{"umap_unix_$i"} =~ /\S/ && $in{"umap_win_$i"} =~ /\S/) {
59                         if ($in{"umap_win_$i"} =~ /\s/) {
60                                 push(@umap, $in{"umap_unix_$i"}."=\"".
61                                             $in{"umap_win_$i"}."\"");
62                                 }
63                         else {
64                                 push(@umap, $in{"umap_unix_$i"}."=".
65                                             $in{"umap_win_$i"});
66                                 }
67                         }
68                 }
69         &open_lock_tempfile(UMAP, "> $mapfile");
70         foreach $line (@umap) {
71                 &print_tempfile(UMAP, "$line\n");
72                 }
73         &close_tempfile(UMAP);
74         }
75
76 if ($global) { &modify_share("global", "global"); }
77 else { &create_share("global"); }
78 &unlock_file($config{'smb_conf'});
79 &webmin_log("pass", undef, undef, \%in);
80 &redirect("");
81