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 );
46 * Parse the modify request. It looks like this:
48 * ModifyRequest := [APPLICATION 6] SEQUENCE {
49 * name DistinguishedName,
50 * mods SEQUENCE OF SEQUENCE {
51 * operation ENUMERATED {
56 * modification SEQUENCE {
58 * values SET OF AttributeValue
64 if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) {
65 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
66 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL, "" );
70 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
72 (void) dn_normalize_case( ndn );
74 /* collect modifications & save for later */
78 for ( tag = ber_first_element( op->o_ber, &len, &last );
80 tag = ber_next_element( op->o_ber, &len, last ) )
84 (*modtail) = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) );
86 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &mop,
87 &(*modtail)->ml_type, &(*modtail)->ml_bvalues )
90 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
95 modlist_free( modlist );
99 (*modtail)->ml_op = mop;
101 if ( (*modtail)->ml_op != LDAP_MOD_ADD &&
102 (*modtail)->ml_op != LDAP_MOD_DELETE &&
103 (*modtail)->ml_op != LDAP_MOD_REPLACE )
105 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
106 "unrecognized modify operation" );
108 modlist_free( modlist );
112 if ( (*modtail)->ml_bvalues == NULL
113 && (*modtail)->ml_op != LDAP_MOD_DELETE )
115 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
118 modlist_free( modlist );
121 attr_normalize( (*modtail)->ml_type );
123 modtail = &(*modtail)->ml_next;
128 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
129 for ( tmp = modlist; tmp != NULL; tmp = tmp->ml_next ) {
130 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
131 tmp->ml_op == LDAP_MOD_ADD
132 ? "add" : (tmp->ml_op == LDAP_MOD_DELETE
133 ? "delete" : "replace"), tmp->ml_type, 0 );
138 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
140 modlist_free( modlist );
141 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
146 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
147 conn->c_connid, op->o_opid, ndn, 0, 0 );
150 * We could be serving multiple database backends. Select the
151 * appropriate one, or send a referral to our "referral server"
152 * if we don't hold it.
154 if ( (be = select_backend( ndn )) == NULL ) {
156 modlist_free( modlist );
157 send_ldap_result( conn, op, rc = LDAP_PARTIAL_RESULTS, NULL,
162 /* alias suffix if approp */
163 ndn = suffixAlias ( ndn, op, be );
166 * do the modify if 1 && (2 || 3)
167 * 1) there is a modify function implemented in this backend;
168 * 2) this backend is master for what it holds;
169 * 3) it's a replica and the dn supplied is the update_ndn.
171 if ( be->be_modify ) {
172 /* do the update here */
173 if ( be->be_update_ndn == NULL ||
174 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
176 if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
177 replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
180 /* send a referral */
182 send_ldap_result( conn, op, rc = LDAP_PARTIAL_RESULTS, NULL,
186 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM, NULL,
187 "Function not implemented" );
191 modlist_free( modlist );
202 for ( ; ml != NULL; ml = next ) {
206 if ( ml->ml_bvalues != NULL )
207 ber_bvecfree( ml->ml_bvalues );