updated passdb backend parameter
[Samba.git] / examples / LDAP / import_smbpasswd.pl
blob14aeff967f187a426e1c56173f817f4b8021d338
1 #!/usr/bin/perl
2 ##
3 ## Example script of how you could import and smbpasswd file into an LDAP
4 ## directory using the Mozilla PerLDAP module.
5 ##
6 ## writen by jerry@samba.org
7 ##
9 use Mozilla::LDAP::Conn;
10 use Mozilla::LDAP::Entry;
12 #################################################
13 ## set these to a value appropriate for your site
16 $DN="ou=people,dc=plainjoe,dc=org";
17 $ROOTDN="cn=Manager,dc=plainjoe,dc=org";
18 $rootpw = "secret";
19 $LDAPSERVER="localhost";
22 ## end local site variables
23 #################################################
25 $conn = new Mozilla::LDAP::Conn ("$LDAPSERVER", "389", $ROOTDN, $rootpw );
26 die "Unable to connect to LDAP server $LDAPSERVER" unless $conn;
29 while ( $string = <STDIN> ) {
30 chop ($string);
32 ## get the account information
33 @smbentry = split (/:/, $string);
35 ## check for the existence of the posixAccount first
37 ## FIXME!! Should do a getownam() and let the NSS modules lookup the account
38 ## This way you can have a UNIX account in /etc/passwd and the smbpasswd i
39 ## entry in LDAP.
40 $result = $conn->search ("$DN", "sub", "(&(uid=$smbentry[0])(objectclass=posixAccount))");
41 if ( ! $result ) {
42 print STDERR "uid=$smbentry[0] does not have a posixAccount entry in the directory!\n";
43 next;
46 print "Updating [" . $result->getDN() . "]\n";
48 ## Do we need to add the 'objectclass: smbPasswordEntry' attribute?
49 if (! $result->hasValue("objectclass", "smbPasswordEntry")) {
50 $result->addValue("objectclass", "smbPasswordEntry");
53 ## Set other attribute values
54 $result->setValues ("lmPassword", $smbentry[2]);
55 $result->setValues ("ntPassword", $smbentry[3]);
56 $result->setValues ("acctFlags", $smbentry[4]);
57 $result->setValues ("pwdLastSet", substr($smbentry[5],4));
59 if (! $conn->update($result)) {
60 print "Error updating!\n";
64 $conn->close();
65 exit 0;