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;
42 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
45 * Parse the modify request. It looks like this:
47 * ModifyRequest := [APPLICATION 6] SEQUENCE {
48 * name DistinguishedName,
49 * mods SEQUENCE OF SEQUENCE {
50 * operation ENUMERATED {
55 * modification SEQUENCE {
57 * values SET OF AttributeValue
63 if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) {
64 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
65 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
69 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
71 (void) dn_normalize_case( ndn );
73 /* collect modifications & save for later */
77 for ( tag = ber_first_element( op->o_ber, &len, &last );
79 tag = ber_next_element( op->o_ber, &len, last ) )
83 (*modtail) = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) );
85 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &mop,
86 &(*modtail)->ml_type, &(*modtail)->ml_bvalues )
89 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
94 modlist_free( modlist );
98 (*modtail)->ml_op = mop;
100 if ( (*modtail)->ml_op != LDAP_MOD_ADD &&
101 (*modtail)->ml_op != LDAP_MOD_DELETE &&
102 (*modtail)->ml_op != LDAP_MOD_REPLACE )
104 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
105 "unrecognized modify operation" );
107 modlist_free( modlist );
111 if ( (*modtail)->ml_bvalues == NULL
112 && (*modtail)->ml_op != LDAP_MOD_DELETE )
114 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
117 modlist_free( modlist );
120 attr_normalize( (*modtail)->ml_type );
122 modtail = &(*modtail)->ml_next;
127 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
128 for ( tmp = modlist; tmp != NULL; tmp = tmp->ml_next ) {
129 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
130 tmp->ml_op == LDAP_MOD_ADD
131 ? "add" : (tmp->ml_op == LDAP_MOD_DELETE
132 ? "delete" : "replace"), tmp->ml_type, 0 );
136 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
137 conn->c_connid, op->o_opid, ndn, 0, 0 );
140 * We could be serving multiple database backends. Select the
141 * appropriate one, or send a referral to our "referral server"
142 * if we don't hold it.
144 if ( (be = select_backend( ndn )) == NULL ) {
146 modlist_free( modlist );
147 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
152 /* alias suffix if approp */
153 ndn = suffixAlias ( ndn, op, be );
156 * do the modify if 1 && (2 || 3)
157 * 1) there is a modify function implemented in this backend;
158 * 2) this backend is master for what it holds;
159 * 3) it's a replica and the dn supplied is the update_ndn.
161 if ( be->be_modify ) {
162 /* do the update here */
163 if ( be->be_update_ndn == NULL ||
164 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
166 if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
167 replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
170 /* send a referral */
172 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
176 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
177 "Function not implemented" );
181 modlist_free( modlist );
191 for ( ; ml != NULL; ml = next ) {
195 if ( ml->ml_bvalues != NULL )
196 ber_bvecfree( ml->ml_bvalues );