2 * Copyright (c) 1995 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
17 #include <ac/socket.h>
18 #include <ac/string.h>
23 static void modlist_free(LDAPModList *ml);
36 LDAPModList **modtail;
43 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
45 if( op->o_bind_in_progress ) {
46 Debug( LDAP_DEBUG_ANY, "do_modify: SASL bind in progress.\n",
48 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS, NULL,
49 "SASL bind in progress" );
50 return LDAP_SASL_BIND_IN_PROGRESS;
54 * Parse the modify request. It looks like this:
56 * ModifyRequest := [APPLICATION 6] SEQUENCE {
57 * name DistinguishedName,
58 * mods SEQUENCE OF SEQUENCE {
59 * operation ENUMERATED {
64 * modification SEQUENCE {
66 * values SET OF AttributeValue
72 if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) {
73 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
74 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL, "" );
78 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
80 (void) dn_normalize_case( ndn );
82 /* collect modifications & save for later */
86 for ( tag = ber_first_element( op->o_ber, &len, &last );
88 tag = ber_next_element( op->o_ber, &len, last ) )
92 (*modtail) = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) );
94 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &mop,
95 &(*modtail)->ml_type, &(*modtail)->ml_bvalues )
98 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
103 modlist_free( modlist );
107 (*modtail)->ml_op = mop;
109 if ( (*modtail)->ml_op != LDAP_MOD_ADD &&
110 (*modtail)->ml_op != LDAP_MOD_DELETE &&
111 (*modtail)->ml_op != LDAP_MOD_REPLACE )
113 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
114 "unrecognized modify operation" );
116 modlist_free( modlist );
120 if ( (*modtail)->ml_bvalues == NULL
121 && (*modtail)->ml_op != LDAP_MOD_DELETE )
123 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
126 modlist_free( modlist );
129 attr_normalize( (*modtail)->ml_type );
131 modtail = &(*modtail)->ml_next;
136 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
137 for ( tmp = modlist; tmp != NULL; tmp = tmp->ml_next ) {
138 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
139 tmp->ml_op == LDAP_MOD_ADD
140 ? "add" : (tmp->ml_op == LDAP_MOD_DELETE
141 ? "delete" : "replace"), tmp->ml_type, 0 );
145 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
147 modlist_free( modlist );
148 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
152 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
153 conn->c_connid, op->o_opid, ndn, 0, 0 );
156 * We could be serving multiple database backends. Select the
157 * appropriate one, or send a referral to our "referral server"
158 * if we don't hold it.
160 if ( (be = select_backend( ndn )) == NULL ) {
162 modlist_free( modlist );
163 send_ldap_result( conn, op, rc = LDAP_PARTIAL_RESULTS, NULL,
168 /* alias suffix if approp */
169 ndn = suffixAlias ( ndn, op, be );
172 * do the modify if 1 && (2 || 3)
173 * 1) there is a modify function implemented in this backend;
174 * 2) this backend is master for what it holds;
175 * 3) it's a replica and the dn supplied is the update_ndn.
177 if ( be->be_modify ) {
178 /* do the update here */
179 if ( be->be_update_ndn == NULL ||
180 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
182 if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
183 replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
186 /* send a referral */
188 send_ldap_result( conn, op, rc = LDAP_PARTIAL_RESULTS, NULL,
192 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM, NULL,
193 "Function not implemented" );
197 modlist_free( modlist );
208 for ( ; ml != NULL; ml = next ) {
212 if ( ml->ml_bvalues != NULL )
213 ber_bvecfree( ml->ml_bvalues );