Handle hostnames with upper-case letters
[webmin.git] / samba / save_euser.cgi
1 #!/usr/local/bin/perl
2 # save_euser.cgi
3 # Save an existing samba user
4
5 require './samba-lib.pl';
6 &ReadParse();
7 # check acls
8
9 &error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
10 &error("$text{'eacl_np'} $text{'eacl_pmusers'}")
11         unless $access{'maint_users'} && $access{'view_users'};
12 # save          
13 &error_setup($text{'saveuser_fail'});
14 &lock_file($config{'smb_passwd'});
15 @list = &list_users();
16 $u = $list[$in{'idx'}];
17
18 # check inputs
19 $in{'uid'} =~ /^\d+$/ || &error(&text('saveuser_uid', $in{'uid'}));
20 $u->{'uid'} = $in{'uid'};
21 if ($in{'new'}) {
22         $u->{'opts'} = [ split(/\0/, $in{'opts'}) ];
23         }
24 else {
25         $in{'realname'} !~ /:/ ||
26                 &error($text{'saveuser_colon'});
27         (-d $in{'homedir'}) ||
28                 &error(&text('saveuser_home', $in{'homedir'}));
29         (-x $in{'shell'}) || &error(&text('saveuser_shell', $in{'shell'}));
30         $u->{'home'} = $in{'homedir'};
31         $u->{'shell'} = $in{'shell'};
32         $u->{'real'} = $in{'realname'};
33         }
34
35 # apply changes
36 if ($in{ptype} == 0) {
37         $u->{'pass1'} = $u->{'$pass2'} = ("X" x 32);
38         }
39 elsif ($in{ptype} == 1) {
40         $u->{'pass1'} = "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX";
41         $u->{'pass2'} = $u->{'pass1'};
42         }
43 elsif ($in{ptype} == 3) {
44         # changing password.. need to set later with smbpasswd
45         $u->{'pass1'} = $u->{'$pass2'} = ("X" x 32);
46         $set_passwd = 1;
47         }
48 &modify_user($u);
49
50 # Call password change program if necessary
51 if ($set_passwd) {
52         &set_password($u->{'name'}, $in{'pass'}, \$err) ||
53                 &error(&text('saveuser_pass', $err));
54         }
55 &unlock_file($config{'smb_passwd'});
56 &webmin_log("save", "euser", $u->{'name'}, $u);
57
58 &redirect("edit_epass.cgi");
59