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);
33 unsigned long tag, len;
34 LDAPModList *modlist, *tmp;
35 LDAPModList **modtail;
38 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
41 * Parse the modify request. It looks like this:
43 * ModifyRequest := [APPLICATION 6] SEQUENCE {
44 * name DistinguishedName,
45 * mods SEQUENCE OF SEQUENCE {
46 * operation ENUMERATED {
51 * modification SEQUENCE {
53 * values SET OF AttributeValue
59 if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) {
60 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
61 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
65 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
67 (void) dn_normalize_case( ndn );
69 /* 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) = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) );
79 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &(*modtail)->ml_op,
80 &(*modtail)->ml_type, &(*modtail)->ml_bvalues )
83 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
88 modlist_free( modlist );
92 if ( (*modtail)->ml_op != LDAP_MOD_ADD &&
93 (*modtail)->ml_op != LDAP_MOD_DELETE &&
94 (*modtail)->ml_op != LDAP_MOD_REPLACE )
96 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
97 "unrecognized modify operation" );
99 modlist_free( modlist );
103 if ( (*modtail)->ml_bvalues == NULL
104 && (*modtail)->ml_op != LDAP_MOD_DELETE )
106 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
109 modlist_free( modlist );
112 attr_normalize( (*modtail)->ml_type );
114 modtail = &(*modtail)->ml_next;
119 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
120 for ( tmp = modlist; tmp != NULL; tmp = tmp->ml_next ) {
121 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
122 tmp->ml_op == LDAP_MOD_ADD
123 ? "add" : (tmp->ml_op == LDAP_MOD_DELETE
124 ? "delete" : "replace"), tmp->ml_type, 0 );
128 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
129 conn->c_connid, op->o_opid, ndn, 0, 0 );
132 * We could be serving multiple database backends. Select the
133 * appropriate one, or send a referral to our "referral server"
134 * if we don't hold it.
136 if ( (be = select_backend( ndn )) == NULL ) {
138 modlist_free( modlist );
139 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
144 /* alias suffix if approp */
145 ndn = suffixAlias ( ndn, op, be );
148 * do the modify if 1 && (2 || 3)
149 * 1) there is a modify function implemented in this backend;
150 * 2) this backend is master for what it holds;
151 * 3) it's a replica and the dn supplied is the update_ndn.
153 if ( be->be_modify ) {
154 /* do the update here */
155 if ( be->be_update_ndn == NULL ||
156 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
158 if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
159 replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
162 /* send a referral */
164 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
168 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
169 "Function not implemented" );
173 modlist_free( modlist );
183 for ( ; ml != NULL; ml = next ) {
187 if ( ml->ml_bvalues != NULL )
188 ber_bvecfree( ml->ml_bvalues );