[Date Prev][Date Next] [Chronological] [Thread] [Top]

ldap_search returning protocol error?



Hello,

I'm working on a program that utilizes the ldap_search function and it
appears that it is returning a protocol error. All of the functions
leading up to the search work fine.

Any help would be great.

Thanks,
Hank 

options_str =
ldap://server.domain.com/dc=domain,dc=com?attribute?sub?(username=%25s)
key_str = username

static LDAPURLDesc *ludp;



int dbserver_get(
				const char *key_str, 
				const char *options_str,
				char **str_return, 
				int  *len_return
				){
	LDAP *connection = NULL;
	LDAPMessage *res = NULL;
	LDAPMessage *mptr = NULL;
	BerElement *ber = NULL;
	int count;
	int attrcount = 0;
	int status = -1;
	int ret_val;
	char *pstr;
	char **bv_val = NULL;
	char *filter = NULL;
	char **ldap_returns = NULL;
	char critical;
	char *binddn=NULL;
	char *bindpw=NULL;
	char *cLdapReturnVal;

	extern options_t opt;

	*len_return = 0;

	if (ldap_is_ldap_url(options_str) == 0) {
		return(-1);
	}
	if (ldap_url_parse(options_str, &ludp) != 0) {
		return(-1);
	}
	/* Open LDAP connection */
	if ((connection = ldap_init(ludp->lud_host, ludp->lud_port)) ==
NULL) {
		return(-1);
	}
	if (ldap_bind_s(connection, binddn, bindpw, LDAP_AUTH_SIMPLE) 
		!= LDAP_SUCCESS) {
		goto leave;
	}
	/* Build a filter string */
	if ((filter = (char *)malloc(strlen(key_str) +
	
strlen(ludp->lud_filter))) == NULL) {
		PERDITION_DEBUG_ERRNO("filter malloc");
		status = -3;
		goto leave;
	}
	sprintf(filter, ludp->lud_filter, key_str);

	/* Perform the search */
	ret_val = ldap_search(connection, ludp->lud_dn, ludp->lud_scope,
filter, ludp->lud_attrs, 0);


	if (ret_val != LDAP_SUCCESS) {
		cLdapReturnVal = ldap_err2string(ret_val);
		openlog("myLittleProgram", LOG_PID, LOG_LOCAL0);
		syslog(LOG_NOTICE, "Performed the search and it died
%d", ret_val);
		syslog(LOG_NOTICE, "Function ldap_search() failed:
%s\n", cLdapReturnVal);
		closelog();
		goto leave;
	}
	free(filter);
	filter = NULL;

	etc.