Friday, January 8, 2010

Import SambaSamAccount Attribute to existing LDAP

Import SambaSamAccount Attribute to existing LDAP

---------------------------------------------------------



// Connecting to LDAP
$ldapconn = ldap_connect ($ldaphost, $ldapport)
or die("Could not connect to $ldaphost");

$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

$dn="ou=Student,dc=newera,dc=edu,dc=my";
$filter="uid=testuser";
$justthese=array("description","uidnumber");
$sr=ldap_search($ldapconn,$dn,$filter,$justthese);
$info=ldap_get_entries($ldapconn,$sr);
print $info["count"]." entries returned

";

for($i=0; $i<$info["count"]; $i++)
{

//$aaa=$info[$i]["uid"][0];
//ldap_mod_add($ldapconn,"uid=" . $aaa .",ou=Student,dc=test3,dc=test2,dc=test1",$entry);
//echo $info[$i]["uid"][0]."
";

//$uuu = $info[$i]["uid"][0];
$kkk = $info[$i]["description"][0];
$mmm = $info[$i]["uidnumber"][0]*2+1000;
$nnn = "S-1-5-21-3242087124-4121386262-3365014982-";
$ppp = $nnn.$mmm;
echo $kkk;

//-------------------
$con = mysql_connect("$hostname","$username","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("studentemail", $con);

$result = mysql_query("SELECT * FROM student
WHERE student_id='$kkk'");

while($row = mysql_fetch_array($result))
{
$yyy = $row['student_ic'];
$zzz = rtrim(shell_exec("/usr/local/bin/mkntpwd -N $yyy"));
echo $row['student_ic'];
echo "
";
}
//--------------------

//add new attribute
$entry["objectClass"]="sambaSamAccount";
$entry["sambaSID"]=$ppp;
$entry["sambaDomainName"]="lab";
$entry["sambaAcctFlags"]="[U]";
$entry["sambaPwdLastSet"]="1262395503";
$entry["sambaNTPassword"]=$zzz;
ldap_mod_del($ldapconn,"uid=testuser,ou=Student,dc=test3,dc=test2,dc=test1",$entry);

}

?>
---------------------------------------------------------------------------------------------

3 comments:

  1. Samba Attributes in LDAP

    ObjectClass : SambaSamAccount
    SambaAcctFlags
    SambaDomainName
    SambaNTPassword
    SambaPwdLastSet
    SambaSID (SambaSID = uidNumber*2+1000)

    ReplyDelete
  2. Import Chinese Simplified And Traditional Conversation

    1. Go to Left corner's function icon
    2. Select "Word Options"
    3. Select "Customize"
    4. Go to "Choose commands from" and select "Review Tab"
    5. Add "Simplified", "Traditional" and "Translate With Options" to "Customize Quick Access Toolbar"
    6. Finished

    ReplyDelete
  3. How to install mkntpwd package
    ------------
    $ tar -zxf mkntpwd.tar.gz
    $ cd mkntpwd
    $ make
    $ cp mkntpwd /usr/local/bin
    $ mkntpwd

    ReplyDelete