Re: script wrapper for smbpasswd?



Davide Bianchi wrote:
On 2007-08-31, The Natural Philosopher <a@xxx> wrote:
Oh been ther, done that, just wondered if smbpasswd would work the same in a rooted script as it does in a root console session.

yes it does.

Now that IS a thought. I didn't know you could...

yes, samba 3 can use different 'password backend', including
SQL and LDAP.


MM... The question is where to find out how to set it all up...

I don't have MySQL users as such, since the only 'user' that accesses it is the apache server/php stuff, using a single 'login'

I've managed to set up .htpasswd files from within the php..that works well..

function htadduser($filename,$logname, $password)
{
$logname=rtrim($logname); //strip any trailing spaces
$password=rtrim($password);
$fp=fopen($filename,"r+"); // open reading AND writing
if($fp)
{
while (!feof($fp))
{
$buffer = fgets($fp, 4096);
$username=explode(":",$buffer); //extract the actual username
//echo($username[0]."<BR>");
if($logname==$username[0]) // can't add an existing user.
{
fclose($fp);
return -1;
}
}
// OK we are at the file end, and we haven't found an identical user.
// time to get an encrypted password
$salt.=chr(rand(64,126));
$salt.=chr(rand(64,126)); // two character salt to force DES
$hash=crypt($password,$salt);
echo("adding entry:".$logname.":".$hash."<BR>");
fseek($fp, 0, SEEK_END); // make sure we ARE at the file end..
// remove for now while testing !!
// fprintf($fp,"%s:%s\n", $logname,$hash);
fclose ($fp);
return 0;
}
return -1; // no password file!
}


What I want is a similar thing that does that for Samba, however its configured..and probably the Unix adduser stuff as well. Since Samba uses unix file perms to access the shares

Hmm. Maybe a set root id script IS the answer to run through the SMBpasswd AND the Linux system passwd and adduser stuff.


Davide

.