X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fmodify.c;h=eb37afbaa4b2a306b44d4cb2946c60f72e462a8b;hb=59e9ff6243465640956b58ad1756a3ede53eca7c;hp=f95c6f4ab7802d5cf1ef54ac0008f7a1f094e8bf;hpb=36b9c2a33962d698e1cf9c76702c6fdd5a962bc9;p=openldap diff --git a/libraries/libldap/modify.c b/libraries/libldap/modify.c index f95c6f4ab7..eb37afbaa4 100644 --- a/libraries/libldap/modify.c +++ b/libraries/libldap/modify.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2013 The OpenLDAP Foundation. + * Copyright 1998-2018 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -51,60 +51,29 @@ * (Source: RFC 4511) */ - -/* - * ldap_modify_ext - initiate an ldap extended modify operation. - * - * Parameters: - * - * ld LDAP descriptor - * dn DN of the object to modify - * mods List of modifications to make. This is null-terminated - * array of struct ldapmod's, specifying the modifications - * to perform. - * sctrls Server Controls - * cctrls Client Controls - * msgidp Message ID pointer - * - * Example: - * LDAPMod *mods[] = { - * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } }, - * { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } }, - * { LDAP_MOD_DELETE, "ou", 0 }, - * { LDAP_MOD_INCREMENT, "uidNumber, { "1", 0 } } - * 0 - * } - * rc= ldap_modify_ext( ld, dn, mods, sctrls, cctrls, &msgid ); - */ -int -ldap_modify_ext( LDAP *ld, +BerElement * +ldap_build_modify_req( + LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods, LDAPControl **sctrls, LDAPControl **cctrls, - int *msgidp ) + ber_int_t *msgidp ) { BerElement *ber; int i, rc; - ber_int_t id; - - Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 ); - - /* check client controls */ - 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 ); + return( NULL ); } - LDAP_NEXT_MSGID( ld, id ); - rc = ber_printf( ber, "{it{s{" /*}}}*/, id, LDAP_REQ_MODIFY, dn ); + 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( ld->ld_errno ); + return( NULL ); } /* allow mods to be NULL ("touch") */ @@ -124,7 +93,7 @@ ldap_modify_ext( LDAP *ld, if ( rc == -1 ) { ld->ld_errno = LDAP_ENCODING_ERROR; ber_free( ber, 1 ); - return( ld->ld_errno ); + return( NULL ); } } } @@ -132,21 +101,70 @@ ldap_modify_ext( LDAP *ld, if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) { ld->ld_errno = LDAP_ENCODING_ERROR; ber_free( ber, 1 ); - return( ld->ld_errno ); + return( NULL ); } /* Put Server Controls */ if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) { ber_free( ber, 1 ); - return ld->ld_errno; + return( NULL ); } if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) { ld->ld_errno = LDAP_ENCODING_ERROR; ber_free( ber, 1 ); - return( ld->ld_errno ); + return( NULL ); } + return( ber ); +} + +/* + * ldap_modify_ext - initiate an ldap extended modify operation. + * + * Parameters: + * + * ld LDAP descriptor + * dn DN of the object to modify + * mods List of modifications to make. This is null-terminated + * array of struct ldapmod's, specifying the modifications + * to perform. + * sctrls Server Controls + * cctrls Client Controls + * msgidp Message ID pointer + * + * Example: + * LDAPMod *mods[] = { + * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } }, + * { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } }, + * { LDAP_MOD_DELETE, "ou", 0 }, + * { LDAP_MOD_INCREMENT, "uidNumber, { "1", 0 } } + * 0 + * } + * rc= ldap_modify_ext( ld, dn, mods, sctrls, cctrls, &msgid ); + */ +int +ldap_modify_ext( LDAP *ld, + LDAP_CONST char *dn, + LDAPMod **mods, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp ) +{ + BerElement *ber; + int rc; + ber_int_t id; + + Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 ); + + /* check client controls */ + rc = ldap_int_client_controls( ld, cctrls ); + if( rc != LDAP_SUCCESS ) return rc; + + ber = ldap_build_modify_req( ld, dn, mods, sctrls, cctrls, &id ); + if( !ber ) + return ld->ld_errno; + /* send the message */ *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber, id ); return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS ); @@ -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 },