Back to index

php5  5.3.10
connect.inc
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004 Default values are "localhost", "root", database "test" and empty password.
00005 Change the LDAP_TEST_* environment values if you want to use another configuration.
00006 */
00007 
00008 $host                = getenv("LDAP_TEST_HOST")  ? getenv("LDAP_TEST_HOST")  : "localhost";
00009 $port                = getenv("LDAP_TEST_PORT")  ? getenv("LDAP_TEST_PORT")  : 389;
00010 $user                = getenv("LDAP_TEST_USER")  ? getenv("LDAP_TEST_USER")  : "cn=Manager,dc=my-domain,dc=com";
00011 $sasl_user           = getenv("LDAP_TEST_SASL_USER")    ? getenv("LDAP_TEST_SASL_USER")    : "Manager";
00012 $passwd                     = getenv("LDAP_TEST_PASSWD")       ? getenv("LDAP_TEST_PASSWD")       : "secret";
00013 $protocol_version    = getenv("LDAP_TEST_OPT_PROTOCOL_VERSION")       ? getenv("LDAP_TEST_OPT_PROTOCOL_VERSION")       : 3;
00014 $skip_on_bind_failure       = getenv("LDAP_TEST_SKIP_BIND_FAILURE") ? getenv("LDAP_TEST_SKIP_BIND_FAILURE") : true;
00015 
00016 function ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version) {
00017        $link = ldap_connect($host, $port);
00018        ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
00019        ldap_bind($link, $user, $passwd);
00020        return $link;
00021 }
00022 
00023 function insert_dummy_data($link) {
00024        ldap_add($link, "dc=my-domain,dc=com", array(
00025                "objectClass"   => array(
00026                        "top",
00027                        "dcObject",
00028                        "organization"),
00029                "dc"                    => "my-domain",
00030                "o"                             => "my-domain",
00031        ));
00032        ldap_add($link, "cn=userA,dc=my-domain,dc=com", array(
00033                "objectclass" => "person",
00034                "cn" => "userA",
00035                "sn" => "testSN1",
00036                "userPassword" => "oops",
00037                "telephoneNumber" => "xx-xx-xx-xx-xx",
00038                "description" => "user A",
00039        ));
00040        ldap_add($link, "cn=userB,dc=my-domain,dc=com", array(
00041                "objectclass" => "person",
00042                "cn" => "userB",
00043                "sn" => "testSN2",
00044                "userPassword" => "oopsIDitItAgain",
00045                "description" => "user B",
00046        ));
00047        ldap_add($link, "cn=userC,cn=userB,dc=my-domain,dc=com", array(
00048                "objectclass" => "person",
00049                "cn" => "userC",
00050                "sn" => "testSN3",
00051                "userPassword" => "0r1g1na1 passw0rd",
00052        ));
00053 }
00054 
00055 function remove_dummy_data($link) {
00056        ldap_delete($link, "cn=userC,cn=userB,dc=my-domain,dc=com");
00057        ldap_delete($link, "cn=userA,dc=my-domain,dc=com");
00058        ldap_delete($link, "cn=userB,dc=my-domain,dc=com");
00059        ldap_delete($link, "dc=my-domain,dc=com");
00060 }
00061 ?>