X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fadd.c;h=afe4d873b066d831cfc36142dcf226742bba420c;hb=205b5ce587d7ef4dce695501250342be36202852;hp=3a9397e1f9a1dea6832c1b688108b029f1c918bf;hpb=a9f13553a7dc4b618d3521c938a216c0bc64822d;p=openldap diff --git a/libraries/libldap/add.c b/libraries/libldap/add.c index 3a9397e1f9..afe4d873b0 100644 --- a/libraries/libldap/add.c +++ b/libraries/libldap/add.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2014 The OpenLDAP Foundation. + * Copyright 1998-2015 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -85,65 +85,31 @@ ldap_add( LDAP *ld, LDAP_CONST char *dn, LDAPMod **attrs ) } -/* - * ldap_add_ext - initiate an ldap extended add operation. Parameters: - * - * ld LDAP descriptor - * dn DN of the entry to add - * mods List of attributes for the entry. This is a null- - * terminated array of pointers to LDAPMod structures. - * only the type and values in the structures need be - * filled in. - * sctrl Server Controls - * cctrl Client Controls - * msgidp Message ID pointer - * - * Example: - * LDAPMod *attrs[] = { - * { 0, "cn", { "babs jensen", "babs", 0 } }, - * { 0, "sn", { "jensen", 0 } }, - * { 0, "objectClass", { "person", 0 } }, - * 0 - * } - * rc = ldap_add_ext( ld, dn, attrs, NULL, NULL, &msgid ); - */ -int -ldap_add_ext( +BerElement * +ldap_build_add_req( LDAP *ld, - LDAP_CONST char *dn, + const char *dn, LDAPMod **attrs, LDAPControl **sctrls, LDAPControl **cctrls, - int *msgidp ) + ber_int_t *msgidp ) { - BerElement *ber; - int i, rc; - ber_int_t id; - - Debug( LDAP_DEBUG_TRACE, "ldap_add_ext\n", 0, 0, 0 ); - assert( ld != NULL ); - assert( LDAP_VALID( ld ) ); - assert( dn != NULL ); - assert( msgidp != NULL ); - - /* check client controls */ - rc = ldap_int_client_controls( ld, cctrls ); - if( rc != LDAP_SUCCESS ) return rc; + BerElement *ber; + int i, 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; + return( NULL ); } - LDAP_NEXT_MSGID(ld, id); + LDAP_NEXT_MSGID(ld, *msgidp); rc = ber_printf( ber, "{it{s{", /* '}}}' */ - id, LDAP_REQ_ADD, dn ); + *msgidp, LDAP_REQ_ADD, dn ); if ( rc == -1 ) { ld->ld_errno = LDAP_ENCODING_ERROR; ber_free( ber, 1 ); - return ld->ld_errno; + return( NULL ); } /* allow attrs to be NULL ("touch"; should fail...) */ @@ -156,14 +122,14 @@ ldap_add_ext( if ( attrs[i]->mod_bvalues == NULL ) { ld->ld_errno = LDAP_PARAM_ERROR; ber_free( ber, 1 ); - return ld->ld_errno; + 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 ld->ld_errno; + return( NULL ); } } @@ -174,7 +140,7 @@ ldap_add_ext( if ( attrs[i]->mod_values == NULL ) { ld->ld_errno = LDAP_PARAM_ERROR; ber_free( ber, 1 ); - return ld->ld_errno; + return( NULL ); } rc = ber_printf( ber, "{s[v]N}", attrs[i]->mod_type, @@ -183,7 +149,7 @@ ldap_add_ext( if ( rc == -1 ) { ld->ld_errno = LDAP_ENCODING_ERROR; ber_free( ber, 1 ); - return ld->ld_errno; + return( NULL ); } } } @@ -191,21 +157,73 @@ ldap_add_ext( 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_add_ext - initiate an ldap extended add operation. Parameters: + * + * ld LDAP descriptor + * dn DN of the entry to add + * mods List of attributes for the entry. This is a null- + * terminated array of pointers to LDAPMod structures. + * only the type and values in the structures need be + * filled in. + * sctrl Server Controls + * cctrl Client Controls + * msgidp Message ID pointer + * + * Example: + * LDAPMod *attrs[] = { + * { 0, "cn", { "babs jensen", "babs", 0 } }, + * { 0, "sn", { "jensen", 0 } }, + * { 0, "objectClass", { "person", 0 } }, + * 0 + * } + * rc = ldap_add_ext( ld, dn, attrs, NULL, NULL, &msgid ); + */ +int +ldap_add_ext( + LDAP *ld, + LDAP_CONST char *dn, + LDAPMod **attrs, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp ) +{ + BerElement *ber; + int i, rc; + ber_int_t id; + + Debug( LDAP_DEBUG_TRACE, "ldap_add_ext\n", 0, 0, 0 ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( dn != NULL ); + assert( msgidp != NULL ); + + /* check client controls */ + rc = ldap_int_client_controls( ld, cctrls ); + if( rc != LDAP_SUCCESS ) return rc; + + ber = ldap_build_add_req( ld, dn, attrs, sctrls, cctrls, &id ); + if( !ber ) + return ld->ld_errno; + /* send the message */ *msgidp = ldap_send_initial_request( ld, LDAP_REQ_ADD, dn, ber, id );