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,
49 NULL, "SASL bind in progress", NULL, NULL );
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_disconnect( conn, op,
75 LDAP_PROTOCOL_ERROR, "decoding error" );
79 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
81 (void) dn_normalize_case( ndn );
83 /* collect modifications & save for later */
87 for ( tag = ber_first_element( op->o_ber, &len, &last );
89 tag = ber_next_element( op->o_ber, &len, last ) )
93 (*modtail) = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) );
95 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &mop,
96 &(*modtail)->ml_type, &(*modtail)->ml_bvalues )
99 send_ldap_disconnect( conn, op,
100 LDAP_PROTOCOL_ERROR, "decoding modlist error" );
104 modlist_free( modlist );
108 (*modtail)->ml_op = mop;
110 if ( (*modtail)->ml_op != LDAP_MOD_ADD &&
111 (*modtail)->ml_op != LDAP_MOD_DELETE &&
112 (*modtail)->ml_op != LDAP_MOD_REPLACE )
114 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
115 NULL, "unrecognized modify operation", NULL, NULL );
117 modlist_free( modlist );
118 return LDAP_PROTOCOL_ERROR;
121 if ( (*modtail)->ml_bvalues == NULL
122 && (*modtail)->ml_op != LDAP_MOD_DELETE )
124 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
125 NULL, "unrecognized modify operation", NULL, NULL );
127 modlist_free( modlist );
128 return LDAP_PROTOCOL_ERROR;
130 attr_normalize( (*modtail)->ml_type );
132 modtail = &(*modtail)->ml_next;
137 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
138 for ( tmp = modlist; tmp != NULL; tmp = tmp->ml_next ) {
139 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
140 tmp->ml_op == LDAP_MOD_ADD
141 ? "add" : (tmp->ml_op == LDAP_MOD_DELETE
142 ? "delete" : "replace"), tmp->ml_type, 0 );
146 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
148 modlist_free( modlist );
149 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
153 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
154 op->o_connid, op->o_opid, ndn, 0, 0 );
157 * We could be serving multiple database backends. Select the
158 * appropriate one, or send a referral to our "referral server"
159 * if we don't hold it.
161 if ( (be = select_backend( ndn )) == NULL ) {
163 modlist_free( modlist );
164 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
165 NULL, NULL, default_referral, NULL );
170 * do the modify if 1 && (2 || 3)
171 * 1) there is a modify function implemented in this backend;
172 * 2) this backend is master for what it holds;
173 * 3) it's a replica and the dn supplied is the update_ndn.
175 if ( be->be_modify ) {
176 /* do the update here */
177 if ( be->be_update_ndn == NULL ||
178 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
180 if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
181 replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
184 /* send a referral */
186 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
187 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
190 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
191 NULL, "Function not implemented", NULL, NULL );
195 modlist_free( modlist );
206 for ( ; ml != NULL; ml = next ) {
210 if ( ml->ml_bvalues != NULL )
211 ber_bvecfree( ml->ml_bvalues );