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>
25 * ldap_add - initiate an ldap (and X.500) add operation. Parameters:
28 * dn DN of the entry to add
29 * mods List of attributes for the entry. This is a null-
30 * terminated array of pointers to LDAPMod structures.
31 * only the type and values in the structures need be
35 * LDAPMod *attrs[] = {
36 * { 0, "cn", { "babs jensen", "babs", 0 } },
37 * { 0, "sn", { "jensen", 0 } },
38 * { 0, "objectClass", { "person", 0 } },
41 * msgid = ldap_add( ld, dn, attrs );
44 ldap_add( LDAP *ld, char *dn, LDAPMod **attrs )
50 * An add request looks like this:
51 * AddRequest ::= SEQUENCE {
52 * entry DistinguishedName,
53 * attrs SEQUENCE OF SEQUENCE {
55 * values SET OF AttributeValue
60 Debug( LDAP_DEBUG_TRACE, "ldap_add\n", 0, 0, 0 );
62 /* create a message to send */
63 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
67 if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_ADD, dn )
69 ld->ld_errno = LDAP_ENCODING_ERROR;
74 /* for each attribute in the entry... */
75 for ( i = 0; attrs[i] != NULL; i++ ) {
76 if ( ( attrs[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
77 rc = ber_printf( ber, "{s[V]}", attrs[i]->mod_type,
78 attrs[i]->mod_values );
80 rc = ber_printf( ber, "{s[v]}", attrs[i]->mod_type,
81 attrs[i]->mod_values );
84 ld->ld_errno = LDAP_ENCODING_ERROR;
90 if ( ber_printf( ber, "}}}" ) == -1 ) {
91 ld->ld_errno = LDAP_ENCODING_ERROR;
96 /* send the message */
97 return( ldap_send_initial_request( ld, LDAP_REQ_ADD, dn, ber ));
101 ldap_add_s( LDAP *ld, char *dn, LDAPMod **attrs )
106 if ( (msgid = ldap_add( ld, dn, attrs )) == -1 )
107 return( ld->ld_errno );
109 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
110 return( ld->ld_errno );
112 return( ldap_result2error( ld, res, 1 ) );