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

Re: Protocol Error (2) on LDAP Add C API



I figured this out on my own.  I post the answer to the
list for Google to find in the archives.

The problem was my assignment of the mod_bvalues to NULL.
The NULL value was causing the protocol error.  What I
needed to do was leave the mod_bvalues undefined in my
program.  Doing this resulted in code that worked 
against openLDAP v1.x and v2.x servers when using 
protocol version 2.


	- VAB

On Fri, 6 Sep 2002, V. Alex Brennen wrote:

> I'm hoping that someone can help me.  I'm trying to use the
> LDAP C API to add an entry to an openLDAP directory, but my
> attempts are failing with a Protocol Error.  I can't seem 
> to figure out the problem.  I've been working on this for
> several days with no luck. I've tried setting the 
> protocol version to 2 and 3 and using all the different
> ldap_add and ldap_modify functions with the same (2)
> results.
> 
> I'm working on a stock RedHat 7.3 install with RedHat's
> copy of openLDAP.  I've also tested on RedHat 7.2, and 
> 6.2.  I'm able to add entries to the directory using the
> ldapadd and ldapmodify utilities, as well as with the 
> perl api. 
> 
> Command I'm using to compile:
> gcc -L/usr/local/lib -lldap -llber -lresolv test.c -o test
> 
> ldap lib:
> libldap.so.2.0.16
> 
> Any help that anyone can provide would be greatly appreciated.
> 
> I'll include some test source code I've been working with in
> line below.  Please ignore memory leaks and other problems
> such as that, I've greatly simplified the code to try and 
> find the LDAP error.
> 
> 
> Thanks,
> 
> 	 - Alex
> 
> ---
> code
> ---
> #include <stdio.h>
> #include <stdlib.h>
> #include <ldap.h>
> 
> 
> int main(void)
> {
> 	LDAP *ld;
> 	int rslt = 0;
> 	LDAPMod *list_of_attrs[4];
> 	LDAPMod attribute1, attribute2, attribute3;
> 
> 	char *dn = "ou=classes,dc=univ,dc=edu";
> 
> 	char *object_values[] = { "top", "organizationalUnit", NULL };
> 	char *ou_values[] = { "classes", NULL };
> 	char *des_values[] = { "Classes Students Can Take", NULL };
> 
> 	/* Build the LDAPMod datastructure */
> 	attribute1.mod_op = LDAP_MOD_ADD;
> 	attribute1.mod_type = "objectClass";
> 	attribute1.mod_values = object_values;
> 	attribute1.mod_bvalues = NULL;
> 
> 	attribute2.mod_op = LDAP_MOD_ADD;
> 	attribute2.mod_type = "ou";
> 	attribute2.mod_values = object_values;
> 	attribute2.mod_bvalues = NULL;
> 
> 	attribute3.mod_op = LDAP_MOD_ADD;
> 	attribute3.mod_type = "description";
> 	attribute3.mod_values = des_values;
> 	attribute3.mod_bvalues = NULL;
> 
> 	list_of_attrs[0] = &attribute2;
> 	list_of_attrs[1] = &attribute1;
> 	list_of_attrs[2] = &attribute3;
> 	list_of_attrs[3] = NULL;
> 
> 	ld = ldap_init("test.mycompany.com",389);
> 	if(ld == NULL)
> 	{
> 		printf("Failed to init\n");
> 	}
> 
> 	rslt = ldap_simple_bind_s(ld,"cn=root,dc=univ,dc=edu","password");
> 	if(rslt != LDAP_SUCCESS)
> 	{
> 		printf("Failed to bind. %d\n",rslt);
> 		printf("%s\n",ldap_err2string( rslt ));
> 	}
> 
> 	rslt = ldap_add_ext_s(ld,dn,list_of_attrs,NULL,NULL);
> 	if(rslt != LDAP_SUCCESS)
> 	{
> 		printf("Failed to add %d.\n",rslt);
> 		printf("%s\n",ldap_err2string( rslt ));
> 	}
> 
> 	/* Close connection to the LDAP Server */
> 	ldap_unbind(ld);
> }
> 
> 
> 

-- 
V. Alex Brennen
Senior Systems Engineer
IBM Certified Specialist
e-TechServices.com
IBM Business Partner
Bus: 352.246.8553
Fax: 770.216.1877
vab@e-techservices.com