[Samba] smbpasswd via cgi

Chris McKeever cgmckeever at prupref.com
Sun Apr 27 20:49:00 GMT 2003


using samba and ldap - redhat 7.3

trying to work on a short cgi to update samba password (it is a url with
attributes username and password).  I am not very good at all with perl, so
if someone can take a quick ponder and help me out, that would be great.

I think that it fails in theory however, because to change other users
password, you need to be root ... So I was wondering if anyone knows what
the encryption the smbpasswd uses to write the 2 passwords to the LDAP
directory and then how to call them via a command line..then I can use the
ldapmodify to do the change .. however, that line fails as well in the code
below.

If anyone has ideas or solutions, that would be absolutely brillant.


--------
#!/usr/bin/perl

use CGI;
use strict;

my $app = new CGI;


my $username = $app->param('username');
my $password = $app->param('password');

use CGI;
use strict;

my $app = new CGI;


my $username = $app->param('username');
my $password = $app->param('password');

if ($username ne "" && $password ne "") {

        my $md5 = `/usr/sbin/slappasswd -s $password -h {MD5}`;

        my $temp_ldif = "dn: uid=USERNAME,ou=People,dc=prupref,dc=com
changetype: modify
replace: userPassword
userPassword: PASSWORD";

        $temp_ldif =~ s/USERNAME/$username/;
        $temp_ldif =~ s/PASSWORD/$md5/;

        my $ldap_update = `echo "$temp_ldif\n" | /usr/bin/ldapmodify -x -D
"cn=root,dc=prupref,dc=com" -w ROOTPASSWORD 2>&1`;

        my $samba_update = `echo "$password\n$password\n" |
/usr/bin/smbpasswd -s $username 2>&1`;

        print $app->header();
        print $app->start_html();
        print $app->h1({align=>'center'}, "Password Changed");
        print $app->h1("$md5");
        print $app->h1("LDAP RESPONSE: $ldap_update");
        print $app->h1("SAMBA RESPONSE: $samba_update");
        print $app->end_html();
}
else {
        print $app->header();
        print $app->start_html();
        print $app->h1({align=>'center'}, "Change Password Utility");
        print $app->end_html();
}


More information about the samba mailing list