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;
35 LDAPModList **modtail;
41 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
44 * Parse the modify request. It looks like this:
46 * ModifyRequest := [APPLICATION 6] SEQUENCE {
47 * name DistinguishedName,
48 * mods SEQUENCE OF SEQUENCE {
49 * operation ENUMERATED {
54 * modification SEQUENCE {
56 * values SET OF AttributeValue
62 if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) {
63 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
64 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
68 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
70 (void) dn_normalize_case( ndn );
72 /* collect modifications & save for later */
76 for ( tag = ber_first_element( op->o_ber, &len, &last );
78 tag = ber_next_element( op->o_ber, &len, last ) )
80 (*modtail) = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) );
82 if ( ber_scanf( op->o_ber, "{i{a[V]}}", &(*modtail)->ml_op,
83 &(*modtail)->ml_type, &(*modtail)->ml_bvalues )
86 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
91 modlist_free( modlist );
95 if ( (*modtail)->ml_op != LDAP_MOD_ADD &&
96 (*modtail)->ml_op != LDAP_MOD_DELETE &&
97 (*modtail)->ml_op != LDAP_MOD_REPLACE )
99 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
100 "unrecognized modify operation" );
102 modlist_free( modlist );
106 if ( (*modtail)->ml_bvalues == NULL
107 && (*modtail)->ml_op != LDAP_MOD_DELETE )
109 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
112 modlist_free( modlist );
115 attr_normalize( (*modtail)->ml_type );
117 modtail = &(*modtail)->ml_next;
122 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
123 for ( tmp = modlist; tmp != NULL; tmp = tmp->ml_next ) {
124 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
125 tmp->ml_op == LDAP_MOD_ADD
126 ? "add" : (tmp->ml_op == LDAP_MOD_DELETE
127 ? "delete" : "replace"), tmp->ml_type, 0 );
131 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n",
132 conn->c_connid, op->o_opid, ndn, 0, 0 );
135 * We could be serving multiple database backends. Select the
136 * appropriate one, or send a referral to our "referral server"
137 * if we don't hold it.
139 if ( (be = select_backend( ndn )) == NULL ) {
141 modlist_free( modlist );
142 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
147 /* alias suffix if approp */
148 ndn = suffixAlias ( ndn, op, be );
151 * do the modify if 1 && (2 || 3)
152 * 1) there is a modify function implemented in this backend;
153 * 2) this backend is master for what it holds;
154 * 3) it's a replica and the dn supplied is the update_ndn.
156 if ( be->be_modify ) {
157 /* do the update here */
158 if ( be->be_update_ndn == NULL ||
159 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
161 if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
162 replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
165 /* send a referral */
167 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
171 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
172 "Function not implemented" );
176 modlist_free( modlist );
186 for ( ; ml != NULL; ml = next ) {
190 if ( ml->ml_bvalues != NULL )
191 ber_bvecfree( ml->ml_bvalues );