/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2012 The OpenLDAP Foundation.
+ * Copyright 1998-2016 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* (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") */
if ( rc == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
}
}
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 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;
+
+ 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 );
* 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 },