2 * Copyright (c) 1990 Regents of the University of Michigan.
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
16 #include <ac/socket.h>
17 #include <ac/string.h>
23 * ldap_modify - initiate an ldap (and X.500) modify operation. Parameters:
26 * dn DN of the object to modify
27 * mods List of modifications to make. This is null-terminated
28 * array of struct ldapmod's, specifying the modifications
33 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
34 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
37 * msgid = ldap_modify( ld, dn, mods );
40 ldap_modify( LDAP *ld, char *dn, LDAPMod **mods )
46 * A modify request looks like this:
47 * ModifyRequet ::= SEQUENCE {
48 * object DistinguishedName,
49 * modifications SEQUENCE OF SEQUENCE {
50 * operation ENUMERATED {
55 * modification SEQUENCE {
57 * values SET OF AttributeValue
63 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
65 /* create a message to send */
66 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
70 if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_MODIFY, dn )
72 ld->ld_errno = LDAP_ENCODING_ERROR;
77 /* for each modification to be performed... */
78 for ( i = 0; mods[i] != NULL; i++ ) {
79 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
80 rc = ber_printf( ber, "{e{s[V]}}",
81 mods[i]->mod_op & ~LDAP_MOD_BVALUES,
82 mods[i]->mod_type, mods[i]->mod_bvalues );
84 rc = ber_printf( ber, "{e{s[v]}}", mods[i]->mod_op,
85 mods[i]->mod_type, mods[i]->mod_values );
89 ld->ld_errno = LDAP_ENCODING_ERROR;
95 if ( ber_printf( ber, "}}}" ) == -1 ) {
96 ld->ld_errno = LDAP_ENCODING_ERROR;
101 /* send the message */
102 return( ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber ));
106 ldap_modify_s( LDAP *ld, char *dn, LDAPMod **mods )
111 if ( (msgid = ldap_modify( ld, dn, mods )) == -1 )
112 return( ld->ld_errno );
114 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
115 return( ld->ld_errno );
117 return( ldap_result2error( ld, res, 1 ) );