Use the smbpasswd command to create and delete users

This commit is contained in:
Jamie Cameron
2010-06-06 11:57:14 -07:00
parent ccb94b62e0
commit 10cd3915ef
2 changed files with 39 additions and 10 deletions

View File

@@ -24,3 +24,5 @@ Allow the server description to be set to explicitly nothing.
---- Changes since 1.500 ----
Show the real Samba version number on the main page.
Fix list of users for a share to show open files correctly, and not show the same file multiple times on different shares.
---- Changes since 1.510 ----
Try to use the smbpasswd command to create or delete users, if installed.

View File

@@ -584,12 +584,22 @@ if ($has_pdbedit) {
$? && &error("$config{'pdbedit'} failed : <pre>$out</pre>");
}
else {
# Add direct to Samba password file
&open_tempfile(PASS, ">>$config{'smb_passwd'}");
&print_tempfile(PASS, &user_string($_[0]));
&close_tempfile(PASS);
chown(0, 0, $config{'smb_passwd'});
chmod(0600, $config{'smb_passwd'});
# Try using smbpasswd -a
local $out = &backquote_logged(
"cd / && $config{'samba_password_program'} ".
"-s $config{'smb_conf'} -a ".
(&indexof("D", @{$_[0]->{'opts'}}) >= 0 ? "-d " : "").
(&indexof("N", @{$_[0]->{'opts'}}) >= 0 ? "-n " : "").
(&indexof("W", @{$_[0]->{'opts'}}) >= 0 ? "-m " : "").
quotemeta($_[0]->{'name'}));
if ($?) {
# Add direct to Samba password file
&open_tempfile(PASS, ">>$config{'smb_passwd'}");
&print_tempfile(PASS, &user_string($_[0]));
&close_tempfile(PASS);
chown(0, 0, $config{'smb_passwd'});
chmod(0600, $config{'smb_passwd'});
}
}
}
@@ -619,8 +629,19 @@ if ($has_pdbedit) {
}
}
else {
# Directly update the Samba password file
&replace_file_line($config{'smb_passwd'}, $_[0]->{'line'}, &user_string($_[0]));
if (!$_[0]->{'oldname'} || _[0]->{'oldname'} eq $_[0]->{'name'}) {
# Try using smbpasswd command
local $out = &backquote_logged(
"cd / && $config{'samba_password_program'} ".
"-s $config{'smb_conf'} ".
(&indexof("D", @{$_[0]->{'opts'}}) >= 0 ? "-d "
: "-e ").
quotemeta($_[0]->{'name'}));
}
# Also directly update the Samba password file
&replace_file_line($config{'smb_passwd'}, $_[0]->{'line'},
&user_string($_[0]));
}
}
@@ -636,8 +657,14 @@ if ($has_pdbedit) {
$? && &error("$config{'pdbedit'} failed : <pre>$out</pre>");
}
else {
# Just remove from the Samba password file
&replace_file_line($config{'smb_passwd'}, $_[0]->{'line'});
# Try the smbpasswd command
local $out = &backquote_logged(
"cd / && $config{'samba_password_program'} ".
"-s $config{'smb_conf'} -x ".quotemeta($_[0]->{'name'}));
if ($?) {
# Just remove from the Samba password file
&replace_file_line($config{'smb_passwd'}, $_[0]->{'line'});
}
}
}