mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-18 11:05:48 +08:00
ITS#8262 add ldap_build_*_req functions
Basic ops except abandon and unbind; since they get no reply it's not important for the caller to know their msgID.
This commit is contained in:
parent
756a6b8683
commit
34ccd14f3e
@ -85,6 +85,96 @@ ldap_add( LDAP *ld, LDAP_CONST char *dn, LDAPMod **attrs )
|
||||
}
|
||||
|
||||
|
||||
BerElement *
|
||||
ldap_build_add_req(
|
||||
LDAP *ld,
|
||||
const char *dn,
|
||||
LDAPMod **attrs,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp )
|
||||
{
|
||||
BerElement *ber;
|
||||
int i, rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID(ld, *msgidp);
|
||||
rc = ber_printf( ber, "{it{s{", /* '}}}' */
|
||||
*msgidp, LDAP_REQ_ADD, dn );
|
||||
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* allow attrs to be NULL ("touch"; should fail...) */
|
||||
if ( attrs ) {
|
||||
/* for each attribute in the entry... */
|
||||
for ( i = 0; attrs[i] != NULL; i++ ) {
|
||||
if ( ( attrs[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
|
||||
int j;
|
||||
|
||||
if ( attrs[i]->mod_bvalues == NULL ) {
|
||||
ld->ld_errno = LDAP_PARAM_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
for ( j = 0; attrs[i]->mod_bvalues[ j ] != NULL; j++ ) {
|
||||
if ( attrs[i]->mod_bvalues[ j ]->bv_val == NULL ) {
|
||||
ld->ld_errno = LDAP_PARAM_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
rc = ber_printf( ber, "{s[V]N}", attrs[i]->mod_type,
|
||||
attrs[i]->mod_bvalues );
|
||||
|
||||
} else {
|
||||
if ( attrs[i]->mod_values == NULL ) {
|
||||
ld->ld_errno = LDAP_PARAM_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
rc = ber_printf( ber, "{s[v]N}", attrs[i]->mod_type,
|
||||
attrs[i]->mod_values );
|
||||
}
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( ber );
|
||||
}
|
||||
|
||||
/*
|
||||
* ldap_add_ext - initiate an ldap extended add operation. Parameters:
|
||||
*
|
||||
@ -99,7 +189,7 @@ ldap_add( LDAP *ld, LDAP_CONST char *dn, LDAPMod **attrs )
|
||||
* msgidp Message ID pointer
|
||||
*
|
||||
* Example:
|
||||
* LDAPMod *attrs[] = {
|
||||
* LDAPMod *attrs[] = {
|
||||
* { 0, "cn", { "babs jensen", "babs", 0 } },
|
||||
* { 0, "sn", { "jensen", 0 } },
|
||||
* { 0, "objectClass", { "person", 0 } },
|
||||
@ -130,81 +220,9 @@ ldap_add_ext(
|
||||
rc = ldap_int_client_controls( ld, cctrls );
|
||||
if( rc != LDAP_SUCCESS ) return rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
ld->ld_errno = LDAP_NO_MEMORY;
|
||||
ber = ldap_build_add_req( ld, dn, attrs, sctrls, cctrls, &id );
|
||||
if( !ber )
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID(ld, id);
|
||||
rc = ber_printf( ber, "{it{s{", /* '}}}' */
|
||||
id, LDAP_REQ_ADD, dn );
|
||||
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
/* allow attrs to be NULL ("touch"; should fail...) */
|
||||
if ( attrs ) {
|
||||
/* for each attribute in the entry... */
|
||||
for ( i = 0; attrs[i] != NULL; i++ ) {
|
||||
if ( ( attrs[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
|
||||
int j;
|
||||
|
||||
if ( attrs[i]->mod_bvalues == NULL ) {
|
||||
ld->ld_errno = LDAP_PARAM_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
for ( j = 0; attrs[i]->mod_bvalues[ j ] != NULL; j++ ) {
|
||||
if ( attrs[i]->mod_bvalues[ j ]->bv_val == NULL ) {
|
||||
ld->ld_errno = LDAP_PARAM_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
}
|
||||
|
||||
rc = ber_printf( ber, "{s[V]N}", attrs[i]->mod_type,
|
||||
attrs[i]->mod_bvalues );
|
||||
|
||||
} else {
|
||||
if ( attrs[i]->mod_values == NULL ) {
|
||||
ld->ld_errno = LDAP_PARAM_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
rc = ber_printf( ber, "{s[v]N}", attrs[i]->mod_type,
|
||||
attrs[i]->mod_values );
|
||||
}
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
/* send the message */
|
||||
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_ADD, dn, ber, id );
|
||||
|
@ -37,6 +37,48 @@
|
||||
* }
|
||||
*/
|
||||
|
||||
BerElement *
|
||||
ldap_build_compare_req(
|
||||
LDAP *ld,
|
||||
LDAP_CONST char *dn,
|
||||
LDAP_CONST char *attr,
|
||||
struct berval *bvalue,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
int *msgidp )
|
||||
{
|
||||
BerElement *ber;
|
||||
int rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID(ld, *msgidp);
|
||||
rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
|
||||
*msgidp,
|
||||
LDAP_REQ_COMPARE, dn, attr, bvalue );
|
||||
if ( rc == -1 )
|
||||
{
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ldap_compare_ext - perform an ldap extended compare operation. The dn
|
||||
* of the entry to compare to and the attribute and value to compare (in
|
||||
@ -74,34 +116,10 @@ ldap_compare_ext(
|
||||
rc = ldap_int_client_controls( ld, cctrls );
|
||||
if( rc != LDAP_SUCCESS ) return rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( LDAP_NO_MEMORY );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID(ld, id);
|
||||
rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
|
||||
id,
|
||||
LDAP_REQ_COMPARE, dn, attr, bvalue );
|
||||
if ( rc == -1 )
|
||||
{
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
ber = ldap_build_compare_req(
|
||||
ld, dn, attr, bvalue, sctrls, cctrls, &id );
|
||||
if( !ber )
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
|
||||
/* send the message */
|
||||
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber, id );
|
||||
|
@ -31,6 +31,46 @@
|
||||
* DelRequet ::= DistinguishedName,
|
||||
*/
|
||||
|
||||
BerElement *
|
||||
ldap_build_delete_req(
|
||||
LDAP *ld,
|
||||
LDAP_CONST char *dn,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
int *msgidp )
|
||||
{
|
||||
BerElement *ber;
|
||||
int rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID( ld, *msgidp );
|
||||
rc = ber_printf( ber, "{its", /* '}' */
|
||||
*msgidp, LDAP_REQ_DELETE, dn );
|
||||
if ( rc == -1 )
|
||||
{
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( ber );
|
||||
}
|
||||
|
||||
/*
|
||||
* ldap_delete_ext - initiate an ldap extended delete operation. Parameters:
|
||||
@ -67,33 +107,9 @@ ldap_delete_ext(
|
||||
rc = ldap_int_client_controls( ld, cctrls );
|
||||
if( rc != LDAP_SUCCESS ) return rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
ld->ld_errno = LDAP_NO_MEMORY;
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID( ld, id );
|
||||
rc = ber_printf( ber, "{its", /* '}' */
|
||||
id, LDAP_REQ_DELETE, dn );
|
||||
if ( rc == -1 )
|
||||
{
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
ber = ldap_build_delete_req( ld, dn, sctrls, cctrls, &id );
|
||||
if( !ber )
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* send the message */
|
||||
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_DELETE, dn, ber, id );
|
||||
|
@ -530,6 +530,42 @@ ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx );
|
||||
LDAP_F (int)
|
||||
ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx );
|
||||
|
||||
/*
|
||||
* in add.c
|
||||
*/
|
||||
|
||||
LDAP_F (BerElement *) ldap_build_add_req LDAP_P((
|
||||
LDAP *ld,
|
||||
const char *dn,
|
||||
LDAPMod **attrs,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp ));
|
||||
|
||||
/*
|
||||
* in compare.c
|
||||
*/
|
||||
|
||||
LDAP_F (BerElement *) ldap_build_compare_req LDAP_P((
|
||||
LDAP *ld,
|
||||
const char *dn,
|
||||
const char *attr,
|
||||
struct berval *bvalue,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp ));
|
||||
|
||||
/*
|
||||
* in delete.c
|
||||
*/
|
||||
|
||||
LDAP_F (BerElement *) ldap_build_delete_req LDAP_P((
|
||||
LDAP *ld,
|
||||
const char *dn,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp ));
|
||||
|
||||
/*
|
||||
* in init.c
|
||||
*/
|
||||
@ -563,6 +599,32 @@ LDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
|
||||
*/
|
||||
LDAP_F (void) ldap_int_error_init( void );
|
||||
|
||||
/*
|
||||
* in modify.c
|
||||
*/
|
||||
|
||||
LDAP_F (BerElement *) ldap_build_modify_req LDAP_P((
|
||||
LDAP *ld,
|
||||
const char *dn,
|
||||
LDAPMod **mods,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp ));
|
||||
|
||||
/*
|
||||
* in modrdn.c
|
||||
*/
|
||||
|
||||
LDAP_F (BerElement *) ldap_build_moddn_req LDAP_P((
|
||||
LDAP *ld,
|
||||
const char *dn,
|
||||
const char *newrdn,
|
||||
const char *newSuperior,
|
||||
int deleteoldrdn,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp ));
|
||||
|
||||
/*
|
||||
* in unit-int.c
|
||||
*/
|
||||
@ -759,6 +821,17 @@ LDAP_F (int) ldap_int_sasl_bind LDAP_P((
|
||||
const char **rmech,
|
||||
int *msgid ));
|
||||
|
||||
/* in sasl.c */
|
||||
|
||||
LDAP_F (BerElement *) ldap_build_bind_req LDAP_P((
|
||||
LDAP *ld,
|
||||
const char *dn,
|
||||
const char *mech,
|
||||
struct berval *cred,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp ));
|
||||
|
||||
/* in schema.c */
|
||||
LDAP_F (char *) ldap_int_parse_numericoid LDAP_P((
|
||||
const char **sp,
|
||||
|
@ -51,6 +51,73 @@
|
||||
* (Source: RFC 4511)
|
||||
*/
|
||||
|
||||
BerElement *
|
||||
ldap_build_modify_req(
|
||||
LDAP *ld,
|
||||
LDAP_CONST char *dn,
|
||||
LDAPMod **mods,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp )
|
||||
{
|
||||
BerElement *ber;
|
||||
int i, rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID( ld, *msgidp );
|
||||
rc = ber_printf( ber, "{it{s{" /*}}}*/, *msgidp, LDAP_REQ_MODIFY, dn );
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* allow mods to be NULL ("touch") */
|
||||
if ( mods ) {
|
||||
/* for each modification to be performed... */
|
||||
for ( i = 0; mods[i] != NULL; i++ ) {
|
||||
if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
|
||||
rc = ber_printf( ber, "{e{s[V]N}N}",
|
||||
(ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ),
|
||||
mods[i]->mod_type, mods[i]->mod_bvalues );
|
||||
} else {
|
||||
rc = ber_printf( ber, "{e{s[v]N}N}",
|
||||
(ber_int_t) mods[i]->mod_op,
|
||||
mods[i]->mod_type, mods[i]->mod_values );
|
||||
}
|
||||
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( ber );
|
||||
}
|
||||
|
||||
/*
|
||||
* ldap_modify_ext - initiate an ldap extended modify operation.
|
||||
@ -67,7 +134,7 @@
|
||||
* msgidp Message ID pointer
|
||||
*
|
||||
* Example:
|
||||
* LDAPMod *mods[] = {
|
||||
* LDAPMod *mods[] = {
|
||||
* { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
|
||||
* { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } },
|
||||
* { LDAP_MOD_DELETE, "ou", 0 },
|
||||
@ -94,58 +161,9 @@ ldap_modify_ext( LDAP *ld,
|
||||
rc = ldap_int_client_controls( ld, cctrls );
|
||||
if( rc != LDAP_SUCCESS ) return rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( LDAP_NO_MEMORY );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID( ld, id );
|
||||
rc = ber_printf( ber, "{it{s{" /*}}}*/, id, LDAP_REQ_MODIFY, dn );
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* allow mods to be NULL ("touch") */
|
||||
if ( mods ) {
|
||||
/* for each modification to be performed... */
|
||||
for ( i = 0; mods[i] != NULL; i++ ) {
|
||||
if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
|
||||
rc = ber_printf( ber, "{e{s[V]N}N}",
|
||||
(ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ),
|
||||
mods[i]->mod_type, mods[i]->mod_bvalues );
|
||||
} else {
|
||||
rc = ber_printf( ber, "{e{s[v]N}N}",
|
||||
(ber_int_t) mods[i]->mod_op,
|
||||
mods[i]->mod_type, mods[i]->mod_values );
|
||||
}
|
||||
|
||||
if ( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
ber = ldap_build_modify_req( ld, dn, mods, sctrls, cctrls, &id );
|
||||
if( !ber )
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* send the message */
|
||||
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber, id );
|
||||
@ -164,7 +182,7 @@ ldap_modify_ext( LDAP *ld,
|
||||
* to perform.
|
||||
*
|
||||
* Example:
|
||||
* LDAPMod *mods[] = {
|
||||
* LDAPMod *mods[] = {
|
||||
* { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
|
||||
* { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } },
|
||||
* { LDAP_MOD_DELETE, "ou", 0 },
|
||||
|
@ -48,6 +48,65 @@
|
||||
* }
|
||||
*/
|
||||
|
||||
BerElement *
|
||||
ldap_build_moddn_req(
|
||||
LDAP *ld,
|
||||
LDAP_CONST char *dn,
|
||||
LDAP_CONST char *newrdn,
|
||||
LDAP_CONST char *newSuperior,
|
||||
int deleteoldrdn,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp )
|
||||
{
|
||||
BerElement *ber;
|
||||
int rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID( ld, *msgidp );
|
||||
if( newSuperior != NULL ) {
|
||||
/* must be version 3 (or greater) */
|
||||
if ( ld->ld_version < LDAP_VERSION3 ) {
|
||||
ld->ld_errno = LDAP_NOT_SUPPORTED;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
rc = ber_printf( ber, "{it{ssbtsN}", /* '}' */
|
||||
*msgidp, LDAP_REQ_MODDN,
|
||||
dn, newrdn, (ber_int_t) deleteoldrdn,
|
||||
LDAP_TAG_NEWSUPERIOR, newSuperior );
|
||||
|
||||
} else {
|
||||
rc = ber_printf( ber, "{it{ssbN}", /* '}' */
|
||||
*msgidp, LDAP_REQ_MODDN,
|
||||
dn, newrdn, (ber_int_t) deleteoldrdn );
|
||||
}
|
||||
|
||||
if ( rc < 0 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
rc = ber_printf( ber, /*{*/ "N}" );
|
||||
if ( rc < 0 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( ber );
|
||||
}
|
||||
|
||||
/*
|
||||
* ldap_rename - initiate an ldap extended modifyDN operation.
|
||||
@ -83,48 +142,10 @@ ldap_rename(
|
||||
rc = ldap_int_client_controls( ld, cctrls );
|
||||
if( rc != LDAP_SUCCESS ) return rc;
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( LDAP_NO_MEMORY );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID( ld, id );
|
||||
if( newSuperior != NULL ) {
|
||||
/* must be version 3 (or greater) */
|
||||
if ( ld->ld_version < LDAP_VERSION3 ) {
|
||||
ld->ld_errno = LDAP_NOT_SUPPORTED;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
rc = ber_printf( ber, "{it{ssbtsN}", /* '}' */
|
||||
id, LDAP_REQ_MODDN,
|
||||
dn, newrdn, (ber_int_t) deleteoldrdn,
|
||||
LDAP_TAG_NEWSUPERIOR, newSuperior );
|
||||
|
||||
} else {
|
||||
rc = ber_printf( ber, "{it{ssbN}", /* '}' */
|
||||
id, LDAP_REQ_MODDN,
|
||||
dn, newrdn, (ber_int_t) deleteoldrdn );
|
||||
}
|
||||
|
||||
if ( rc < 0 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
ber = ldap_build_moddn_req( ld, dn, newrdn, newSuperior,
|
||||
deleteoldrdn, sctrls, cctrls, &id );
|
||||
if( !ber )
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
rc = ber_printf( ber, /*{*/ "N}" );
|
||||
if ( rc < 0 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( ld->ld_errno );
|
||||
}
|
||||
|
||||
/* send the message */
|
||||
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber, id );
|
||||
|
@ -44,6 +44,83 @@
|
||||
|
||||
#include "ldap-int.h"
|
||||
|
||||
BerElement *
|
||||
ldap_build_bind_req(
|
||||
LDAP *ld,
|
||||
LDAP_CONST char *dn,
|
||||
LDAP_CONST char *mechanism,
|
||||
struct berval *cred,
|
||||
LDAPControl **sctrls,
|
||||
LDAPControl **cctrls,
|
||||
ber_int_t *msgidp )
|
||||
{
|
||||
BerElement *ber;
|
||||
int rc;
|
||||
|
||||
if( mechanism == LDAP_SASL_SIMPLE ) {
|
||||
if( dn == NULL && cred != NULL && cred->bv_len ) {
|
||||
/* use default binddn */
|
||||
dn = ld->ld_defbinddn;
|
||||
}
|
||||
|
||||
} else if( ld->ld_version < LDAP_VERSION3 ) {
|
||||
ld->ld_errno = LDAP_NOT_SUPPORTED;
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if ( dn == NULL ) {
|
||||
dn = "";
|
||||
}
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
LDAP_NEXT_MSGID( ld, *msgidp );
|
||||
if( mechanism == LDAP_SASL_SIMPLE ) {
|
||||
/* simple bind */
|
||||
rc = ber_printf( ber, "{it{istON}" /*}*/,
|
||||
*msgidp, LDAP_REQ_BIND,
|
||||
ld->ld_version, dn, LDAP_AUTH_SIMPLE,
|
||||
cred );
|
||||
|
||||
} else if ( cred == NULL || cred->bv_val == NULL ) {
|
||||
/* SASL bind w/o credentials */
|
||||
rc = ber_printf( ber, "{it{ist{sN}N}" /*}*/,
|
||||
*msgidp, LDAP_REQ_BIND,
|
||||
ld->ld_version, dn, LDAP_AUTH_SASL,
|
||||
mechanism );
|
||||
|
||||
} else {
|
||||
/* SASL bind w/ credentials */
|
||||
rc = ber_printf( ber, "{it{ist{sON}N}" /*}*/,
|
||||
*msgidp, LDAP_REQ_BIND,
|
||||
ld->ld_version, dn, LDAP_AUTH_SASL,
|
||||
mechanism, cred );
|
||||
}
|
||||
|
||||
if( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( ber );
|
||||
}
|
||||
|
||||
/*
|
||||
* ldap_sasl_bind - bind to the ldap server (and X.500).
|
||||
* The dn (usually NULL), mechanism, and credentials are provided.
|
||||
@ -79,70 +156,9 @@ ldap_sasl_bind(
|
||||
rc = ldap_int_client_controls( ld, cctrls );
|
||||
if( rc != LDAP_SUCCESS ) return rc;
|
||||
|
||||
if( mechanism == LDAP_SASL_SIMPLE ) {
|
||||
if( dn == NULL && cred != NULL && cred->bv_len ) {
|
||||
/* use default binddn */
|
||||
dn = ld->ld_defbinddn;
|
||||
}
|
||||
|
||||
} else if( ld->ld_version < LDAP_VERSION3 ) {
|
||||
ld->ld_errno = LDAP_NOT_SUPPORTED;
|
||||
ber = ldap_build_bind_req( ld, dn, mechanism, cred, sctrls, cctrls, &id );
|
||||
if( !ber )
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
if ( dn == NULL ) {
|
||||
dn = "";
|
||||
}
|
||||
|
||||
/* create a message to send */
|
||||
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
||||
ld->ld_errno = LDAP_NO_MEMORY;
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
assert( LBER_VALID( ber ) );
|
||||
|
||||
LDAP_NEXT_MSGID( ld, id );
|
||||
if( mechanism == LDAP_SASL_SIMPLE ) {
|
||||
/* simple bind */
|
||||
rc = ber_printf( ber, "{it{istON}" /*}*/,
|
||||
id, LDAP_REQ_BIND,
|
||||
ld->ld_version, dn, LDAP_AUTH_SIMPLE,
|
||||
cred );
|
||||
|
||||
} else if ( cred == NULL || cred->bv_val == NULL ) {
|
||||
/* SASL bind w/o credentials */
|
||||
rc = ber_printf( ber, "{it{ist{sN}N}" /*}*/,
|
||||
id, LDAP_REQ_BIND,
|
||||
ld->ld_version, dn, LDAP_AUTH_SASL,
|
||||
mechanism );
|
||||
|
||||
} else {
|
||||
/* SASL bind w/ credentials */
|
||||
rc = ber_printf( ber, "{it{ist{sON}N}" /*}*/,
|
||||
id, LDAP_REQ_BIND,
|
||||
ld->ld_version, dn, LDAP_AUTH_SASL,
|
||||
mechanism, cred );
|
||||
}
|
||||
|
||||
if( rc == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Put Server Controls */
|
||||
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
||||
ld->ld_errno = LDAP_ENCODING_ERROR;
|
||||
ber_free( ber, 1 );
|
||||
return ld->ld_errno;
|
||||
}
|
||||
|
||||
|
||||
/* send the message */
|
||||
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_BIND, dn, ber, id );
|
||||
|
Loading…
Reference in New Issue
Block a user