ldap_mod_add或ldap_add不用于在LDAP服务器中添加新帐户

时间:2017-05-19 11:40:15

标签: php server ldap

有人知道用PHP脚本在LDAP服务器中添加新帐户吗? 如果我在谷歌搜索,答案总是这个函数ldap_add或ldap_mod_add,但我知道该函数只是添加像ldap_mod_add这样的属性。我只是搜索php函数而不是ad2ldap或者。

任何人都知道如何在LDAP服务器中添加新帐户?

这里是我的代码:

    Log.e("TAG", "Click on delete");
    ArrayList<ContentProviderOperation> mOperations = new ArrayList<ContentProviderOperation>();

    // Build the uri of your group with its id
    Uri uri = ContentUris.withAppendedId(ContactsContract.Groups.CONTENT_URI, Long.parseLong(groupModel.getGroup_id())).buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
            .build();
    ContentProviderOperation.Builder builder = ContentProviderOperation.newDelete(uri);
    mOperations.add(builder.build());

    // Then apply batch
    try {
        getContentResolver().applyBatch(ContactsContract.AUTHORITY, mOperations);

    } catch (Exception e) {
        Toast.makeText(ProspectsActivity.this, "Group is not delete.", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }

}

感谢 IK

2 个答案:

答案 0 :(得分:1)

  • ldap_mod_add允许您向已存在的条目添加属性
  • ldap_add允许您在目录中添加条目

ldap_add需要3个参数:

  • link_identifierldap_connect函数的结果
  • dn:要添加的条目的dn
  • entry:这是表示条目的数组。它需要具有执行ldapadd操作的所有属性(以LDAP方式),即,您必须设置:

您还可以在此处找到示例代码:https://community.spiceworks.com/topic/458770-adding-users-to-ad-using-php

答案 1 :(得分:0)

尝试这样的事情 - 适合我

            $ds = ldap_connect("ldaps://example.org");
            if ($ds) {
                $r = ldap_bind($ds, "userAdmin", "adminPSW");
                $dn = 'CN=username,CN=Users,DC=example,DC=org';
                $pwdtxt="password";
                ## Create Unicode password
                $newPassword = "\"" . $pwdtxt . "\"";
                $len = strlen($newPassword);
                $newPassw = "";
                for($i=0;$i<$len;$i++) {
                    $newPassw .= "{$newPassword{$i}}\000";
                }
                $ldaprecord['cn'] = "username";
                $ldaprecord['mail'] = "mail@example.org";
                $ldaprecord['ipphone'] = "0123456789";
                ldap_add($ds, $dn, $ldaprecord);
                $encodedPass = array('unicodepwd' => $newPassw);
                ldap_mod_replace ($ds, $dn, $encodedPass);
            }
            $res = ldap_error ($ds);
            if( $res=="Success"){
            ##Success
            }
            ldap_close($ds);