0

記入できるフォームを作成したいと思っています。フォームを送信すると、フォームの値が取り出され、その人が LDAP に作成されます。私は LDAP バインドの作業に取り組んだばかりなので、LDAP の経験があまりないので、助けが必要です。このフォームから新しいユーザーを LDAP に追加するにはどうすればよいですか? LDAP に Add コマンドがあることは知っていますが、どのように開始するか、LDAP で作成する人にどのような情報を渡す必要があるかについては特にわかりません。それが役立つ場合、以下は LDAP バインドの私のコードです。

<?php
$name=$_REQUEST['name'];
$x=1;
if($x==1)
{
    //LDAP stuff here.
    $username = "myusername";
    $password = "mypass";


    $ds = ldap_connect('ldap://ldap:389');

        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

    //Can't connect to LDAP.
    if( !ds )
    {
        echo "Error in contacting the LDAP server -- contact ";
        echo "technical services!  (Debug 1)";

        exit;
    }

    //Connection made -- bind anonymously and get dn for username.
    $bind = @ldap_bind($ds);

    //Check to make sure we're bound.
    if( !bind )
    {
        echo "Anonymous bind to LDAP FAILED.  Contact Tech Services! (Debug 2)";

        exit;
    }

    $search = ldap_search($ds, "ou=People,DC=sde,DC=goliat,DC=com", "uid=$username");

    //Make sure only ONE result was returned -- if not, they might've thrown a * into the username.  Bad user!
    if( ldap_count_entries($ds,$search) != 1 )
    {
        echo "Error processing username -- please try to login again. (Debug 3)";
        redirect(_WEBROOT_ . "/try1b.php");

        exit;
    }

    $info = ldap_get_entries($ds, $search);

    //Now, try to rebind with their full dn and password.
    $bind = @ldap_bind($ds, $info[0][dn], $password);
    if( !$bind || !isset($bind))
    {
        echo "Login failed -- please try again. (Debug 4)";
        redirect(_WEBROOT_ . "/try1b.php");

        exit;
    }

    //Now verify the previous search using their credentials.
    $search = ldap_search($ds, "ou=People,DC=sde,DC=goliat,DC=com", "cn=$name");

    $info = ldap_get_entries($ds, $search);
    if( $username == "myusername" )
    {

/*  
    very useful set of information to view the LDAP tree info from an array
    echo $username;
echo "<pre>".print_r($info[0],true)."</pre><br />";
*/
     echo $info[0][cn][0]; 
     echo ",";
     echo $info[0][mail][0];
     echo ",";
echo $info[0][telephonenumber][0];

        exit;
    }
    else
    {
        echo "Error. Access Denied";
        redirect(_WEBROOT_ . "/try1b.php");

        exit;
    }
    ldap_close($ds);
    exit;
}
?> 
4

2 に答える 2