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(LDAPMod *mods);
34 unsigned long tag, len;
39 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
42 * Parse the modify request. It looks like this:
44 * ModifyRequest := [APPLICATION 6] SEQUENCE {
45 * name DistinguishedName,
46 * mods SEQUENCE OF SEQUENCE {
47 * operation ENUMERATED {
52 * modification SEQUENCE {
54 * values SET OF AttributeValue
60 if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) {
61 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
62 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
66 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
68 (void) dn_normalize_case( ndn );
70 /* collect modifications & save for later */
73 for ( tag = ber_first_element( op->o_ber, &len, &last );
75 tag = ber_next_element( op->o_ber, &len, last ) )
77 (*modtail) = (LDAPMod *) ch_calloc( 1, sizeof(LDAPMod) );
79 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &(*modtail)->mod_op,
80 &(*modtail)->mod_type, &(*modtail)->mod_bvalues )
83 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
92 if ( (*modtail)->mod_op != LDAP_MOD_ADD &&
93 (*modtail)->mod_op != LDAP_MOD_DELETE &&
94 (*modtail)->mod_op != LDAP_MOD_REPLACE )
96 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
97 "unrecognized modify operation" );
103 if ( (*modtail)->mod_bvalues == NULL && (*modtail)->mod_op
104 != LDAP_MOD_DELETE ) {
105 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
108 modlist_free( mods );
111 attr_normalize( (*modtail)->mod_type );
113 modtail = &(*modtail)->mod_next;
118 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
119 for ( tmp = mods; tmp != NULL; tmp = tmp->mod_next ) {
120 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n", tmp->mod_op
121 == LDAP_MOD_ADD ? "add" : (tmp->mod_op == LDAP_MOD_DELETE ?
122 "delete" : "replace"), tmp->mod_type, 0 );
126 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
127 conn->c_connid, op->o_opid, ndn, 0, 0 );
130 * We could be serving multiple database backends. Select the
131 * appropriate one, or send a referral to our "referral server"
132 * if we don't hold it.
134 if ( (be = select_backend( ndn )) == NULL ) {
136 modlist_free( mods );
137 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
142 /* alias suffix if approp */
143 ndn = suffixAlias ( ndn, op, be );
146 * do the modify if 1 && (2 || 3)
147 * 1) there is a modify function implemented in this backend;
148 * 2) this backend is master for what it holds;
149 * 3) it's a replica and the dn supplied is the update_ndn.
151 if ( be->be_modify != NULL ) {
152 /* do the update here */
153 if ( be->be_update_ndn == NULL ||
154 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
157 if ( (*be->be_modify)( be, conn, op, ndn, mods ) == 0 ) {
158 replog( be, LDAP_REQ_MODIFY, ndn, mods, 0 );
161 /* send a referral */
163 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
167 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
168 "Function not implemented" );
172 modlist_free( mods );
182 for ( ; mods != NULL; mods = next ) {
183 next = mods->mod_next;
184 free( mods->mod_type );
185 if ( mods->mod_bvalues != NULL )
186 ber_bvecfree( mods->mod_bvalues );