Is the data encoded in UTF8? Cart wrote:
> Hi everyone, > > I am having trouble writing extended ASCII characters (for example: french > accent characters: é, ê, ç, etc...) to the iPlanet Directory Server. The > add function (ldap_add_ext_s()) doesn't give me error (it returns > LDAP_SUCCESS), however if I try updating the entry later, I doesn't work. > In addition, if I go into the iPlanet Console, the entry is there but all > characters before the extended ASCII character (including the extended > ASCII char itself) is truncated. For example: if uid = Helloébye, the > console would show Hello. > > Has anyone experienced the same problem? Should I be using the berval > element in the LDAPMod structure? > > I would really apprepriate it if someone could help me here... > > Thanks, > Cart. > > /* CODE BEGINS HERE */ > > If you're interested, here is my code: > > #include <fl_ldap.h> > #include <string.h> > > /* number of attributes to be added */ > /* userID, given, surname, common name */ > #define NMODS 9 > #define MAX_TRIES 5 > > extern char * add_uid(char LDAP_host[255], int LDAP_port, char > people_dn[255], char mangr_dn[255], char mangr_pwd[255], char > new_user_id[255], char given[255], char surname[255], char sslyesno[3]); > > char * > add_uid(char LDAP_host[255], int LDAP_port, char people_dn[255], char > mangr_dn[255], char mangr_pwd[255], char new_user_id[255], char given[255], > char surname[255], char sslyesno[3]) > { > LDAP *ld; > char dn[255]; > LDAPMod **mods; > int i; > int msgid; > struct timeval zerotime; > char ldap_error[255]; > > /* object classes to add (object class is actually an attribute that > determines what attributes will be available to this entry) */ > char *objectclass_values[] = { "top", "person", "organizationalPerson", > "inetorgperson", "inetsubscriber", NULL }; > char *passRetryCnt_values[] = { "0", NULL }; > /* true indicates that the account is InActive */ > char *acctLock_values[] = { "true", NULL }; > char *cn_values[] = { given, NULL }; > char *sn_values[] = { surname, NULL }; > char *givenname_values[] = { given, NULL }; > char *uid_values[] = { new_user_id, NULL }; > char *chall_values[] = { "", NULL }; > char *response_values[] = { " ", NULL }; > > zerotime.tv_sec = zerotime.tv_usec = 0L; > > /* specify the dn we're adding... */ > strcpy(dn, "uid="); > strcat(dn, new_user_id); > strcat(dn, ", "); > strcat(dn, people_dn); > > /* check for ssl */ > if ( strncmp(sslyesno, "No", 2) == 0 ) { > if ( (ld = ldap_init( LDAP_host, LDAP_port )) == NULL ) { > return "LDAP init failed"; > } > } > else { > if ( ldapssl_client_init( CERT_DB, NULL ) < 0) { > return "Failed to initialize SSL client..."; > } > > /* Initialize LDAP session */ > if ( (ld = ldap_init( LDAP_host, LDAP_port )) == NULL ) { > perror( "ldap_init" ); > return "LDAP init failed"; > } > > /* Load SSL routines */ > if ( ldapssl_install_routines( ld ) != 0 ) { > ldap_perror( ld, "ldapssl_install_routines" ); > return "LDAP SSL install routines failed"; > } > /* Set up option in LDAP struct for using SSL */ > if ( ldap_set_option( ld, 0x0A, ((void *)1) ) != 0 ) { > ldap_perror( ld, "ldap_set_option" ); > return "LDAP set option failed"; > } > } > > /* authenticate to the directory as the Directory Manager */ > if ( ( msgid = ldap_simple_bind_s( ld, mangr_dn, mangr_pwd ) ) != > LDAP_SUCCESS ) { > printf("Error Message ID = %d\n", msgid); > > return "Could not authenticate directory manager"; > } > > /* construct the array of values to add */ > mods = ( LDAPMod ** ) malloc (( NMODS + 1 ) * sizeof( LDAPMod * )); > if ( mods == NULL ) { > return "Could not allocate memory for mods array"; > } > > /* allocate memory for mods elements */ > for ( i = 0; i < NMODS; i++) { > if (( mods[i] = ( LDAPMod * ) malloc( sizeof( LDAPMod * ))) == NULL) >{ > return "Could not allocate memory for mods element"; > } > } > > /* fill the mods array */ > /* each mods array element is a particular attribute of our directory > element */ > (mods[0]->mod_op) = 0; > (mods[0]->mod_type) = "objectclass"; > (mods[0]->mod_values) = objectclass_values; > > (mods[1]->mod_op) = 0; > (mods[1]->mod_type) = "passwordretrycount"; > (mods[1]->mod_values) = passRetryCnt_values; > > (mods[2]->mod_op) = 0; > (mods[2]->mod_type) = "nsAccountLock"; > (mods[2]->mod_values) = acctLock_values; > > (mods[3]->mod_op) = 0; > (mods[3]->mod_type) = "cn"; > (mods[3]->mod_values) = cn_values; > > (mods[4]->mod_op) = 0; > (mods[4]->mod_type) = "sn"; > (mods[4]->mod_values) = sn_values; > > (mods[5]->mod_op) = 0; > (mods[5]->mod_type) = "givenname"; > (mods[5]->mod_values) = givenname_values; > > (mods[6]->mod_op) = 0; > (mods[6]->mod_type) = "uid"; > (mods[6]->mod_values) = uid_values; > > (mods[7]->mod_op) = 0; > (mods[7]->mod_type) = "inetsubscriberchallenge"; > (mods[7]->mod_values) = chall_values; > > (mods[8]->mod_op) = 0; > (mods[8]->mod_type) = "inetsubscriberresponse"; > (mods[8]->mod_values) = response_values; > > (mods[9] = NULL); > > /* initiate the add op */ > if (( msgid = ldap_add_ext_s( ld, dn, mods, NULL, NULL )) < 0 ) { > ldap_mods_free ( mods, 1 ); > printf("Error Message ID = %d\n", msgid); > > return "Add failed"; > } > > ldap_mods_free( mods, 1 ); > > ldap_unbind( ld ); > > /* return empty string to indicate everyone went ok */ > return ""; > }