[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
CLDAP request - Netlogon attribute
Hi,
I am having openldap-2.3.11 compiled with -DLDAP_CONNECTIONLESS to enable CLDAP/LDAP-UDP.
I am using openldap apis to connect to MS AD and sending a CLDAP request to DC
to get the Netlogon attribute, but i am getting error as
"io.c:81: ber_write: Assertion `buf != ((void *)0)' failed."
I didn't find any sampe code to send a LDAP UDP request using openldap apis. And i don't know
the openldap api to use for sending LDAP UDP request. But, i managed to write some code.
Can anyone send me a sample LDAP UDP request/response program?
Can anyone please let me know where my code is wrong?
Thanks in Advance,
Srini
Below is my code...
CODE STARTS ****
#include <stdio.h>
#include <ldap.h>
#include <lber.h>
#define LDAP_HOSTNAME "xxxhost.domain.local"
#define LDAP_PORT 389
#define SAMPLE_USER "sample_user"
int find_netlogon(
LDAP *ld,
LDAPMessage **res,
char *domain,
char *host,
char *attr
)
{
char *Attr[] = {
attr,
NULL
};
char search_exp[1024];
sprintf (search_exp, "(&(DnsDomain=%s)(Host=%s)(Ntver=\006))", domain, host);
return ldap_search_s (ld, NULL, LDAP_SCOPE_BASE,
search_exp, Attr, 0, res);
}
int main(int argc, char *argv[])
{
LDAPURLDesc url;
char *ldapuri = NULL;
LDAP *ld = NULL;
int rc;
int ldap_debug = LDAP_DEBUG_TRACE
LDAPMessage *res;
memset( &url, 0, sizeof(url));
url.lud_scheme = "cldap";
url.lud_host = LDAP_HOSTNAME;
url.lud_port = LDAP_PORT;
url.lud_scope = LDAP_SCOPE_DEFAULT;
(void) ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &ldap_debug);
ldapuri = ldap_url_desc2str( &url );
rc = ldap_initialize( &ld, ldapuri );
if( rc != LDAP_SUCCESS ) {
fprintf( stderr, "ldap_initialize( %s ) failed with error (%d): %s\n",
ldapuri != NULL ? ldapuri : "<DEFAULT>", rc, ldap_err2string(rc) );
}else
printf("LDAP initialize successful\n");
rc = LDAP_VERSION3;
(void)ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &rc);
(void)ldap_set_option(ld, LDAP_OPT_REFERRALS , 0);
printf("calling find_netlogon...\n");
rc = find_netlogon(ld, &res, "domain.local", "xxxhost", "Netlogon");
if (rc != LDAP_SUCCESS) {
printf("Error occured while find_netlogon\n");
goto clean_exit;
} else if (rc == LDAP_SUCCESS && ldap_count_entries(ld, res) == 0)
{
printf("No records found\n");
}else
printf("No of records found: %d\n", ldap_count_entries(ld, res));
clean_exit:
if(ld) ldap_unbind(ld);
}
CODE ENDS ****