1 /* add.c - ldap backend add function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2005 The OpenLDAP Foundation.
6 * Portions Copyright 2000-2003 Pierangelo Masarati.
7 * Portions Copyright 1999-2003 Howard Chu.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/string.h>
29 #include <ac/socket.h>
32 #include "back-ldap.h"
43 LDAPMod **attrs = NULL,
48 LDAPControl **ctrls = NULL;
50 rs->sr_err = LDAP_SUCCESS;
52 Debug( LDAP_DEBUG_ARGS, "==> ldap_back_add(\"%s\")\n",
53 op->o_req_dn.bv_val, 0, 0 );
55 lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
56 if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
61 /* Count number of attributes in entry */
62 for ( i = 1, a = op->oq_add.rs_e->e_attrs; a; i++, a = a->a_next )
63 /* just count attrs */ ;
65 /* Create array of LDAPMods for ldap_add() */
66 attrs = (LDAPMod **)ch_malloc( sizeof( LDAPMod * )*i
67 + sizeof( LDAPMod )*( i - 1 ) );
68 attrs2 = ( LDAPMod * )&attrs[ i ];
70 isupdate = be_shadow_update( op );
71 for ( i = 0, a = op->oq_add.rs_e->e_attrs; a; a = a->a_next ) {
72 if ( !isupdate && !get_manageDIT( op ) && a->a_desc->ad_type->sat_no_user_mod )
77 attrs[ i ] = &attrs2[ i ];
78 attrs[ i ]->mod_op = LDAP_MOD_BVALUES;
79 attrs[ i ]->mod_type = a->a_desc->ad_cname.bv_val;
81 for ( j = 0; a->a_vals[ j ].bv_val; j++ )
82 /* just count vals */ ;
83 attrs[i]->mod_vals.modv_bvals =
84 ch_malloc( ( j + 1 )*sizeof( struct berval * ) );
85 for ( j = 0; a->a_vals[ j ].bv_val; j++ ) {
86 attrs[ i ]->mod_vals.modv_bvals[ j ] = &a->a_vals[ j ];
88 attrs[ i ]->mod_vals.modv_bvals[ j ] = NULL;
94 rs->sr_err = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
95 if ( rs->sr_err != LDAP_SUCCESS ) {
96 send_ldap_result( op, rs );
101 rs->sr_err = ldap_add_ext( lc->lc_ld, op->o_req_dn.bv_val, attrs,
102 ctrls, NULL, &msgid );
103 rs->sr_err = ldap_back_op_result( lc, op, rs, msgid, LDAP_BACK_SENDRESULT );
104 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
106 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) ) {
112 (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
115 for ( --i; i >= 0; --i ) {
116 ch_free( attrs[ i ]->mod_vals.modv_bvals );
122 ldap_back_release_conn( op, rs, lc );
125 Debug( LDAP_DEBUG_ARGS, "<== ldap_back_add(\"%s\"): %d\n",
126 op->o_req_dn.bv_val, rs->sr_err, 0 );