고수님들 코멘트 부탁드립니다.
--------------------------------------
소스상의
"ou=테스트, ou=resources, o=itnade,c=kr" 에 영문을 넣으면 되는데
한글은 안되네요
에러내용입니다.
ldap_add_ext_s: Invalid DN syntax
invalid DN
--------------------------------------
#include <stdio.h>
#include "ldap.h"
/* Change these as needed. */
#define HOSTNAME "localhost"
#define PORTNUMBER 50000
#define BIND_DN "cn=Manager,o=itnade,c=kr"
#define BIND_PW "secret"
#define NEW_DN "ou=테스트, ou=resources, o=itnade,c=kr"
#define NUM_MODS 3
int main( int argc, char **argv )
{
LDAP *ld;
LDAPMod **mods;
char *matched_msg = NULL, *error_msg = NULL;
int i, rc;
char *object_vals[] = { "top", "organizationalUnit", NULL };
char *attribute_vals[] = { "테스트",NULL };
int version = LDAP_VERSION3;
/* Get a handle to an LDAP connection. */
if ( (ld = ldap_init( HOSTNAME, PORTNUMBER )) == NULL ) {
perror( "ldap_init" );
return( 1 );
}
/* Bind to the server as the Directory Manager. */
(void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,&version
);
rc = ldap_simple_bind_s( ld, BIND_DN, BIND_PW );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, "ldap_simple_bind_s: %s\n", ldap_err2string( rc
) );
ldap_get_lderrno( ld, &matched_msg, &error_msg );
if ( error_msg != NULL && *error_msg != '\0' ) {
fprintf( stderr, "%s\n", error_msg );
}
if ( matched_msg != NULL && *matched_msg != '\0' )
{
fprintf( stderr,
"Part of the DN that matches an existing entry: %s\n",
matched_msg );
}
ldap_unbind_s( ld );
return( 1 );
}
printf("2\n");
/* Construct the array of LDAPMod structures representing the
attributes
of the new entry. */
mods = ( LDAPMod ** ) malloc(( NUM_MODS + 1 ) * sizeof( LDAPMod *
));
if ( mods == NULL ) {
fprintf( stderr, "Cannot allocate memory for mods array\n"
);
exit( 1 );
}
for ( i = 0; i < NUM_MODS; i++ ) {
if (( mods[ i ] = ( LDAPMod * ) malloc( sizeof( LDAPMod ))) ==
NULL ) {
fprintf( stderr, "Cannot allocate memory for mods element\n"
);
exit( 1 );
}
}
printf("3\n");
mods[0]->mod_op = 0;
mods[0]->mod_type = "objectclass";
mods[0]->mod_values = object_vals;
mods[1]->mod_op = 0;
mods[1]->mod_type = "ou";
mods[1]->mod_values = attribute_vals;
mods[2] = NULL ;
/* Perform the add operation. */
rc = ldap_add_ext_s( ld, NEW_DN, mods, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, "ldap_add_ext_s: %s\n", ldap_err2string( rc )
);
ldap_get_lderrno( ld, &matched_msg, &error_msg );
if ( error_msg != NULL & *error_msg != '\0' ) {
fprintf( stderr, "%s\n", error_msg );
}
if ( matched_msg != NULL && *matched_msg != '\0' )
{
fprintf( stderr,
"Part of the DN that matches an existing entry: %s\n",
matched_msg );
}
} else {
printf( "%s added successfully.\n", NEW_DN );
}
printf("4\n");
ldap_unbind_s( ld );
for ( i = 0; i < NUM_MODS; i++ ) {
free( mods[ i ] );
}
free( mods );
return 0;
}
|