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, "do_modify: 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 if( dn_normalize_case( ndn ) == NULL ) {
82 Debug( LDAP_DEBUG_ANY, "do_modify: invalid dn (%s)\n", ndn, 0, 0 );
83 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
84 "invalid DN", NULL, NULL );
89 /* collect modifications & save for later */
93 for ( tag = ber_first_element( op->o_ber, &len, &last );
95 tag = ber_next_element( op->o_ber, &len, last ) )
99 (*modtail) = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) );
101 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &mop,
102 &(*modtail)->ml_type, &(*modtail)->ml_bvalues )
105 send_ldap_disconnect( conn, op,
106 LDAP_PROTOCOL_ERROR, "decoding modlist error" );
110 modlist_free( modlist );
114 (*modtail)->ml_op = mop;
116 if ( (*modtail)->ml_op != LDAP_MOD_ADD &&
117 (*modtail)->ml_op != LDAP_MOD_DELETE &&
118 (*modtail)->ml_op != LDAP_MOD_REPLACE )
120 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
121 NULL, "unrecognized modify operation", NULL, NULL );
123 modlist_free( modlist );
124 return LDAP_PROTOCOL_ERROR;
127 if ( (*modtail)->ml_bvalues == NULL
128 && (*modtail)->ml_op != LDAP_MOD_DELETE )
130 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
131 NULL, "unrecognized modify operation", NULL, NULL );
133 modlist_free( modlist );
134 return LDAP_PROTOCOL_ERROR;
136 attr_normalize( (*modtail)->ml_type );
138 modtail = &(*modtail)->ml_next;
143 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
144 for ( tmp = modlist; tmp != NULL; tmp = tmp->ml_next ) {
145 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
146 tmp->ml_op == LDAP_MOD_ADD
147 ? "add" : (tmp->ml_op == LDAP_MOD_DELETE
148 ? "delete" : "replace"), tmp->ml_type, 0 );
152 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
154 modlist_free( modlist );
155 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
159 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
160 op->o_connid, op->o_opid, ndn, 0, 0 );
163 * We could be serving multiple database backends. Select the
164 * appropriate one, or send a referral to our "referral server"
165 * if we don't hold it.
167 if ( (be = select_backend( ndn )) == NULL ) {
169 modlist_free( modlist );
170 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
171 NULL, NULL, default_referral, NULL );
175 /* deref suffix alias if appropriate */
176 ndn = suffix_alias( be, ndn );
179 * do the modify if 1 && (2 || 3)
180 * 1) there is a modify function implemented in this backend;
181 * 2) this backend is master for what it holds;
182 * 3) it's a replica and the dn supplied is the update_ndn.
184 if ( be->be_modify ) {
185 /* do the update here */
186 if ( be->be_update_ndn == NULL ||
187 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
189 if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
190 replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
193 /* send a referral */
195 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
196 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
199 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
200 NULL, "Function not implemented", NULL, NULL );
204 modlist_free( modlist );
215 for ( ; ml != NULL; ml = next ) {
219 if ( ml->ml_bvalues != NULL )
220 ber_bvecfree( ml->ml_bvalues );