3 # Change a user's password
5 require './passwd-lib.pl';
6 &error_setup($text{'passwd_err'});
9 if ($config{'passwd_cmd'}) {
10 # Call the passwd program to do the change
11 @user = getpwnam($in{'user'});
12 @user || &error($text{'passwd_euser'});
13 &can_edit_passwd(\@user) || &error($text{'passwd_ecannot'});
14 if ($access{'repeat'}) {
15 $in{'new'} eq $in{'repeat'} || &error($text{'passwd_erepeat'});
17 &foreign_require("proc", "proc-lib.pl");
18 if ($access{'old'} == 1 ||
19 $access{'old'} == 2 && $in{'user'} ne $remote_user) {
20 @cmd = ( $config{'passwd_cmd'}, $user[2], $user[3] );
23 @cmd = ( "$config{'passwd_cmd'} '$in{'user'}'" );
25 &additional_log('exec', undef, $cmd[0]);
26 local ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", @cmd);
28 local $rv = &wait_for($fh, '(new|re-enter).*:',
29 '(old|current|login).*:',
31 $out .= $wait_for_input;
34 syswrite($fh, $in{'new'}."\n", length($in{'new'})+1);
37 syswrite($fh, $in{'old'}."\n", length($in{'old'})+1);
40 syswrite($fh, "1\n", 2);
45 last if (++$count > 10);
49 &error(&text('passwd_ecmd', "<tt>$config{'passwd_cmd'}</tt>", "<pre>$out</pre>")) if ($? || $count > 10);
50 &webmin_log("passwd", undef, $in{'user'});
53 # Update the config files directly via the useradmin module
54 &foreign_require("useradmin", "user-lib.pl");
56 # Find the user, either in local password file or LDAP
57 $user = &find_user($in{'user'});
61 if ($access{'old'} == 1 ||
62 $access{'old'} == 2 && $user->{'user'} ne $remote_user) {
63 &useradmin::validate_password(
64 $in{'old'}, $user->{'pass'}) ||
65 &error($text{'passwd_eold'});
67 if ($access{'repeat'}) {
68 $in{'new'} eq $in{'repeat'} || &error($text{'passwd_erepeat'});
70 $err = &useradmin::check_password_restrictions(
71 $in{'new'}, $in{'user'});
72 &error($err) if ($err);
74 &can_edit_passwd([ $user->{'user'}, $user->{'pass'},
75 $user->{'uid'}, $user->{'gid'} ]) ||
76 &error($text{'passwd_ecannot'});
78 # Actually do the change
79 &change_password($user, $in{'new'},
80 $access{'others'} == 1 ||
81 $access{'others'} == 2 && $in{'others'});
84 &error($text{'passwd_euser'});
86 delete($user->{'plainpass'});
87 delete($user->{'pass'});
88 &webmin_log("passwd", undef, $user->{'user'}, $user);
91 # Show a confirmation message
92 &ui_print_header(undef, $text{'passwd_title'}, "");
93 if (($user->{'user'} eq $remote_user || $user->{'user'} eq $base_remote_user) &&
95 print "<p>",&text('passwd_ok', "<tt>$user->{'user'}</tt>"),"<p>\n";
98 print "<p>",&text('passwd_ok2', "<tt>$user->{'user'}</tt>"),"<p>\n";
100 &ui_print_footer($in{'one'} ? ( "/", $text{'index'} )
101 : ( "", $text{'index_return'} ));