mirror of
https://github.com/webmin/webmin.git
synced 2025-07-20 16:48:46 +00:00
Set password at creation time if available https://sourceforge.net/p/webadmin/bugs/5314
This commit is contained in:
@ -100,7 +100,7 @@ while(@uinfo = getpwent()) {
|
||||
else {
|
||||
$nu->{'opts'} = \@flags;
|
||||
}
|
||||
&create_user($nu);
|
||||
&create_user($nu, $in{'newmode'} == 2 ? $in{'newpass'} : undef);
|
||||
$created++;
|
||||
}
|
||||
if ($m) {
|
||||
|
@ -629,21 +629,22 @@ return $config{'samba_password_program'}.
|
||||
$config{'smb_conf'}." ".$args;
|
||||
}
|
||||
|
||||
# create_user(&user)
|
||||
# create_user(&user, [plainpass])
|
||||
# Add a user to the samba password file
|
||||
sub create_user
|
||||
{
|
||||
local ($user, $plainpass) = @_;
|
||||
if ($has_pdbedit) {
|
||||
# Use the pdbedit command
|
||||
local $ws = &indexof("W", @{$_[0]->{'opts'}}) >= 0 ? "-m" : "";
|
||||
local @opts = grep { $_ ne "U" && $_ ne "W" } @{$_[0]->{'opts'}};
|
||||
local $ws = &indexof("W", @{$user->{'opts'}}) >= 0 ? "-m" : "";
|
||||
local @opts = grep { $_ ne "U" && $_ ne "W" } @{$user->{'opts'}};
|
||||
local $temp = &transname();
|
||||
&open_tempfile(TEMP, ">$temp", 0, 1);
|
||||
&print_tempfile(TEMP, "\n\n");
|
||||
&print_tempfile(TEMP, $plainpass."\n".$plainpass."\n");
|
||||
&close_tempfile(TEMP);
|
||||
local $out = &backquote_logged(
|
||||
"cd / && $config{'pdbedit'} -a -s $config{'smb_conf'} -t -u ".
|
||||
quotemeta($_[0]->{'name'}).
|
||||
quotemeta($user->{'name'}).
|
||||
($config{'sync_gid'} ? " -G $config{'sync_gid'}" : "").
|
||||
" -c '[".join("", @opts)."]' $ws <$temp 2>&1");
|
||||
$? && &error("$config{'pdbedit'} failed : <pre>$out</pre>");
|
||||
@ -653,14 +654,14 @@ else {
|
||||
local $out = &backquote_logged(
|
||||
"cd / && ".&smbpasswd_cmd(
|
||||
"-a ".
|
||||
(&indexof("D", @{$_[0]->{'opts'}}) >= 0 ? "-d " : "").
|
||||
(&indexof("N", @{$_[0]->{'opts'}}) >= 0 ? "-n " : "").
|
||||
(&indexof("W", @{$_[0]->{'opts'}}) >= 0 ? "-m " : "").
|
||||
quotemeta($_[0]->{'name'})));
|
||||
(&indexof("D", @{$user->{'opts'}}) >= 0 ? "-d " : "").
|
||||
(&indexof("N", @{$user->{'opts'}}) >= 0 ? "-n " : "").
|
||||
(&indexof("W", @{$user->{'opts'}}) >= 0 ? "-m " : "").
|
||||
quotemeta($user->{'name'})));
|
||||
if ($?) {
|
||||
# Add direct to Samba password file
|
||||
&open_tempfile(PASS, ">>$config{'smb_passwd'}");
|
||||
&print_tempfile(PASS, &user_string($_[0]));
|
||||
&print_tempfile(PASS, &user_string($user));
|
||||
&close_tempfile(PASS);
|
||||
chown(0, 0, $config{'smb_passwd'});
|
||||
chmod(0600, $config{'smb_passwd'});
|
||||
|
@ -5,32 +5,34 @@ do 'samba-lib.pl';
|
||||
# Create a new samba user if sync is enabled
|
||||
sub useradmin_create_user
|
||||
{
|
||||
local ($user) = @_;
|
||||
&get_share("global");
|
||||
if (&istrue("encrypt passwords") && ($config{'smb_passwd'} || $has_pdbedit) &&
|
||||
$config{'sync_add'} && !&get_user($_[0]->{'user'})) {
|
||||
$config{'sync_add'} && !&get_user($user->{'user'})) {
|
||||
# Add a user to smbpasswd
|
||||
&lock_file($config{'smb_passwd'});
|
||||
local $u = { 'name' => $_[0]->{'user'},
|
||||
'uid' => $_[0]->{'uid'} };
|
||||
local $u = { 'name' => $user->{'user'},
|
||||
'uid' => $user->{'uid'} };
|
||||
if ($samba_version >= 2) {
|
||||
local @opts = ("U");
|
||||
push(@opts, "N") if ($_[0]->{'passmode'} == 0);
|
||||
push(@opts, "D") if ($_[0]->{'passmode'} == 1);
|
||||
push(@opts, "N") if ($user->{'passmode'} == 0);
|
||||
push(@opts, "D") if ($user->{'passmode'} == 1);
|
||||
$u->{'opts'} = \@opts;
|
||||
}
|
||||
else {
|
||||
$u->{'real'} = $_[0]->{'real'};
|
||||
$u->{'home'} = $_[0]->{'home'};
|
||||
$u->{'shell'} = $_[0]->{'shell'};
|
||||
$u->{'real'} = $user->{'real'};
|
||||
$u->{'home'} = $user->{'home'};
|
||||
$u->{'shell'} = $user->{'shell'};
|
||||
}
|
||||
$u->{'pass1'} = $u->{'pass2'} = ("X" x 32);
|
||||
if ($_[0]->{'passmode'} == 0) {
|
||||
if ($user->{'passmode'} == 0) {
|
||||
$u->{'pass1'} = "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX";
|
||||
$u->{'pass2'} = $u->{'pass1'};
|
||||
}
|
||||
&create_user($u);
|
||||
if ($_[0]->{'passmode'} == 3) {
|
||||
&set_password($_[0]->{'user'}, $_[0]->{'plainpass'});
|
||||
&create_user($u, $user->{'passmode'} == 3 ? $user->{'plainpass'}
|
||||
: undef);
|
||||
if ($user->{'passmode'} == 3) {
|
||||
&set_password($user->{'user'}, $user->{'plainpass'});
|
||||
}
|
||||
&unlock_file($config{'smb_passwd'});
|
||||
}
|
||||
|
Reference in New Issue
Block a user