Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to add multiple SMB users with Windows access OS X Server
Sometimes it can be hard to add 140 users to the command line. So you write scripts for that. It's even more pesky to allow them all to login from Windows.

I ran accross a script which would generate the hash files, however, on OS X 10.2 Server, it would not let me log in from Windows still. The following script fixes that.

Read the rest of the article for the script...


#!/usr/bin/perl -w

use Term::ReadKey;
use Crypt::SmbHash;

if (@ARGV<1)
{
print "Error\nUsage: smbpasswd name password\n";
exit 1;
}
$username = $ARGV[0];
$password = $ARGV[1];
print "Adding or Creating the Password for $username\n";

# encrypt the new password
$password =~ /(.*)/;
#$salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64];
#$cpw = crypt($1, $salt);
$ENV{'PATH'} = '/bin:/usr/bin';

# Lets create the windows password hash
($lanManagePasword, $ntPassword) = ntlmgen $password;
$smbHashfile = "/private/var/db/samba/hash/" . $username;

delete $ENV{ENV};
delete $ENV{IFS};
delete $ENV{CDPATH};
delete $ENV{BASH_ENV};

# THE FOLLOWING IF STATEMENT SHOULD BE ONE LINE NOT TWO! #
# IT WAS BROKEN HERE FOR EASIER READABILITY ON THE WEB   #
if (system("/usr/bin/niutil", "-insertval", "/", "/users/$username", 
  "authentication_authority", ";basic;", "1") != 0)
{
print "Authentication values not added!  Failure at Insert Val 1\n";
exit 1;
}

# THE FOLLOWING IF STATEMENT SHOULD BE ONE LINE NOT TWO! #
# IT WAS BROKEN HERE FOR EASIER READABILITY ON THE WEB   #
if (system("/usr/bin/niutil", "-insertval", "/", "/users/$username", 
  "authentication_authority", ";LocalWindowsHash;", "2") != 0)
{
print "Authentication values not added! Failure at Insert Val 2\n";
exit 1;
}

# Check to see if the file already exists
if (stat($smbHashfile) ne NULL)
{
open(HASHFILE, ">" . $smbHashfile);
$newPasswordHash = $lanManagePasword . $ntPassword;
print HASHFILE $newPasswordHash;
close HASHFILE;
}
Hopefully this saves someone some time in the future...
    •    
  • Currently 1.67 / 5
  You rated: 1 / 5 (9 votes cast)
 
[10,539 views]  

A script to add multiple SMB users with Windows access | 4 comments | Create New Account
Click here to return to the 'A script to add multiple SMB users with Windows access' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to add multiple SMB users with Windows access
Authored by: gxw on Dec 22, '03 08:01:42PM

Cool! Thanks!
I was looking for an smbpasswd program on OS X - like the one on my Linux box. Put the search on hold when I found OS X does not include one.



[ Reply to This | # ]
A script to add multiple SMB users with Windows access
Authored by: seann on Dec 23, '03 12:13:29AM

That's exactly why I created it!
I felt your pain.

OS X has a smbpasswd utility, however, it does not work as it should for OS X.



[ Reply to This | # ]
A script to add multiple SMB users with Windows access
Authored by: ragengs on Dec 23, '03 04:03:11PM

Hi tested your script but got errors

smb.pl: line 3: use: command not found
smb.pl: line 4: use: command not found
smb.pl: line 16: syntax error near unexpected token `('
smb.pl: line 16: `$password =~ /(.*)/;'

can you tell me what to do
am i missing something?

Thanks



[ Reply to This | # ]
A script to add multiple SMB users with Windows access
Authored by: seann on Jan 06, '04 03:33:39AM

Did you save that as a file, then invoke it with perl?



[ Reply to This | # ]