如何在匿名连接到服务器后获取有关人员的信息。
我正在搜索uid = barbara到匿名绑定的ldap服务器,如下所示,
我收到错误,
LDAP initialize successful.
Set LDAPv3 client version.
LDAP connection successful.
ldap_search_ext_s: No such object
如果我是chnage char * FIND_DN =“ou = Users,dc = example,dc = com”;
rc = ldap_simple_bind_s(ld,root_dn,root_pw); 它工作正常 代码如下:
int main(int argc, char**argv)
{
LDAP *ld;
int desired_version = LDAP_VERSION3;
char *ldap_host = "localhost";
char *root_dn = "cn=Manager, dc=example,dc=com";
char *root_pw = "secret";
char *FIND_DN = "dc=example, dc=com";
LDAPMessage *result, *e;
BerElement *ber;
char *a;
char **vals;
int i, rc;
ldap_initialize( &ld, ldap_host );
printf("LDAP initialize successful.\n");
rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &desired_version);
if ( rc != LDAP_SUCCESS ) {
perror( "ldap_set_option failed" );
exit(EXIT_FAILURE);
} else {
printf("Set LDAPv3 client version.\n");
}
rc = ldap_simple_bind_s(ld,NULL ,NULL);
if ( rc != LDAP_SUCCESS ) {
fprintf(stderr, "ldap_simple_bind_s: %s\n", ldap_err2string(rc));
exit(EXIT_FAILURE);
} else {
printf("LDAP connection successful.\n");
}
if ( ( rc = ldap_search_ext_s( ld, FIND_DN, LDAP_SCOPE_SUBTREE,
"(uid=barbara)",NULL,0,NULL,NULL,NULL,
LDAP_NO_LIMIT, &result ) ) != LDAP_SUCCESS ) {
fprintf(stderr, "ldap_search_ext_s: %s\n", ldap_err2string(rc));
ldap_unbind( ld );
return( 1 );
}
ldap_msgfree( result );
ldap_unbind( ld );
return( 0 );
}
在ldapsearch命令中,我得到了
Enter LDAP Password: # Users, example.com dn: ou=Users,dc=example,dc=com ou: Users description: Example.Com Users objectClass: organizationalUnit # matt, Users, example.com dn: uid=matt,ou=Users,dc=example,dc=com ou: Users uid: matt cn: Matt Butcher sn: Butcher givenName: Matt givenName: Matthew displayName: Matt Butcher title: Systems Integrator description: Systems Integration and IT for Example.Com employeeType: Employee departmentNumber: 001 employeeNumber: 001-08-98 mail: mbutcher@example.com mail: matt@example.com roomNumber: 301 telephoneNumber: +1 555 555 4321 mobile: +1 555 555 6789 st: Illinois l: Chicago street: 1234 Cicero Ave. homePhone: +1 555 555 9876 homePostalAddress: 1234 home street $ Chicago, IL $ 60699-1234 userPassword:: c2VjcmV0 preferredLanguage: en-us,en-gb objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson # barbara, Users, example.com dn: uid=barbara,ou=Users,dc=example,dc=com ou: Users uid: barbara sn: Jensen cn: Barbara Jensen givenName: Barbara displayName: Barbara Jensen mail: barbara@example.com userPassword:: c2VjcmV0 objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson # search result search: 2 result: 0 Success # numResponses: 4 # numEntries: 3