2 * Copyright (c) 1990 Regents of the University of Michigan.
9 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
19 #if !defined( MACOS ) && !defined( DOS )
20 #include <sys/types.h>
21 #include <sys/socket.h>
29 * ldap_modify - initiate an ldap (and X.500) modify operation. Parameters:
32 * dn DN of the object to modify
33 * mods List of modifications to make. This is null-terminated
34 * array of struct ldapmod's, specifying the modifications
39 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
40 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
43 * msgid = ldap_modify( ld, dn, mods );
46 ldap_modify( LDAP *ld, char *dn, LDAPMod **mods )
52 * A modify request looks like this:
53 * ModifyRequet ::= SEQUENCE {
54 * object DistinguishedName,
55 * modifications SEQUENCE OF SEQUENCE {
56 * operation ENUMERATED {
61 * modification SEQUENCE {
63 * values SET OF AttributeValue
69 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
71 /* create a message to send */
72 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
76 if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_MODIFY, dn )
78 ld->ld_errno = LDAP_ENCODING_ERROR;
83 /* for each modification to be performed... */
84 for ( i = 0; mods[i] != NULL; i++ ) {
85 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
86 rc = ber_printf( ber, "{e{s[V]}}",
87 mods[i]->mod_op & ~LDAP_MOD_BVALUES,
88 mods[i]->mod_type, mods[i]->mod_bvalues );
90 rc = ber_printf( ber, "{e{s[v]}}", mods[i]->mod_op,
91 mods[i]->mod_type, mods[i]->mod_values );
95 ld->ld_errno = LDAP_ENCODING_ERROR;
101 if ( ber_printf( ber, "}}}" ) == -1 ) {
102 ld->ld_errno = LDAP_ENCODING_ERROR;
107 /* send the message */
108 return( ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber ));
112 ldap_modify_s( LDAP *ld, char *dn, LDAPMod **mods )
117 if ( (msgid = ldap_modify( ld, dn, mods )) == -1 )
118 return( ld->ld_errno );
120 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
121 return( ld->ld_errno );
123 return( ldap_result2error( ld, res, 1 ) );