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>
24 * ldap_modify - initiate an ldap (and X.500) modify operation. Parameters:
27 * dn DN of the object to modify
28 * mods List of modifications to make. This is null-terminated
29 * array of struct ldapmod's, specifying the modifications
34 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
35 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
38 * msgid = ldap_modify( ld, dn, mods );
41 ldap_modify( LDAP *ld, char *dn, LDAPMod **mods )
47 * A modify request looks like this:
48 * ModifyRequet ::= SEQUENCE {
49 * object DistinguishedName,
50 * modifications SEQUENCE OF SEQUENCE {
51 * operation ENUMERATED {
56 * modification SEQUENCE {
58 * values SET OF AttributeValue
64 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
66 /* create a message to send */
67 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
71 if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_MODIFY, dn )
73 ld->ld_errno = LDAP_ENCODING_ERROR;
78 /* for each modification to be performed... */
79 for ( i = 0; mods[i] != NULL; i++ ) {
80 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
81 rc = ber_printf( ber, "{e{s[V]}}",
82 mods[i]->mod_op & ~LDAP_MOD_BVALUES,
83 mods[i]->mod_type, mods[i]->mod_bvalues );
85 rc = ber_printf( ber, "{e{s[v]}}", mods[i]->mod_op,
86 mods[i]->mod_type, mods[i]->mod_values );
90 ld->ld_errno = LDAP_ENCODING_ERROR;
96 if ( ber_printf( ber, "}}}" ) == -1 ) {
97 ld->ld_errno = LDAP_ENCODING_ERROR;
102 /* send the message */
103 return( ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber ));
107 ldap_modify_s( LDAP *ld, char *dn, LDAPMod **mods )
112 if ( (msgid = ldap_modify( ld, dn, mods )) == -1 )
113 return( ld->ld_errno );
115 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
116 return( ld->ld_errno );
118 return( ldap_result2error( ld, res, 1 ) );