- 論壇徽章:
- 0
|
linux下的client訪問windows的AD,程序如下:
- #include <stdio.h>
- #include <stdlib.h>
- #include <ldap.h>
-
- main()
- {
- LDAP *ld;
- LDAPMessage *res, *e;
- int i;
- char *a, *dn;
- void *ptr;
- char **vals;
- char *server = "192.168.1.161";
- int group = 0, user = 0;
- char *gname[256];
- int gcount = 0, ucount = 0;
- int j;
- const char *attr[]={
- "name",
- "member",
- NULL
- };
-
- if ( (ld = ldap_open( server, LDAP_PORT )) == NULL )
- exit( 1 );
- if ( ldap_simple_bind_s( ld, "test", "111222333") != LDAP_SUCCESS )
- {
- ldap_perror( ld, "ldap_simple_bind_s" );
- exit( 1 );
- }
- if (ldap_search_s(ld, "ou=test,dc=cu,dc=com", LDAP_SCOPE_SUBTREE, NULL, NULL, 0, &res) != LDAP_SU
- CCESS)
- {
- ldap_perror( ld, "ldap_search_s" );
- exit( 1 );
- }
- for ( e = ldap_first_entry( ld, res ); e != NULL; e = ldap_next_entry( ld, e ) )
- {
- dn = ldap_get_dn( ld, e );
- printf( "dn: %s\n", dn );
- free( dn );
- for ( a = ldap_first_attribute( ld, e, (BerElement **)&ptr ); a != NULL; a = ldap_next_attribute( ld, e, (BerElement *)ptr )
- )
- {
- printf("attribute[%s]:", a);
- vals = ldap_get_values( ld, e, a );
- for ( i = 0; vals[i] != NULL; i++ )
- {
- printf("%s\n",vals[i]);
- }
- ldap_value_free( vals );
- }
- }
- ldap_msgfree( res );
- ldap_unbind( ld );
- }
復(fù)制代碼
可以得到所有在ou=test中的用戶,但是我想得到所有ou里面的用戶,我把程序改為:
- if (ldap_search_s(ld, "ou=test,dc=cu,dc=com", LDAP_SCOPE_SUBTREE, NULL, NULL, 0, &res) != LDAP_SU
- CCESS)
復(fù)制代碼
改為:
- if (ldap_search_s(ld, "dc=cu,dc=com", LDAP_SCOPE_SUBTREE, NULL, NULL, 0, &res) != LDAP_SU
- CCESS)
復(fù)制代碼
會一直在這里阻塞,但是利用tcpdump抓包看到AD已經(jīng)把所有的ou信息發(fā)送給了client,這是為什么呢? |
|