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( DOS ) || defined( _WIN32 )
24 #if !defined( MACOS ) && !defined( DOS )
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #endif /* !MACOS && !DOS */
34 * ldap_add - initiate an ldap (and X.500) add operation. Parameters:
37 * dn DN of the entry to add
38 * mods List of attributes for the entry. This is a null-
39 * terminated array of pointers to LDAPMod structures.
40 * only the type and values in the structures need be
44 * LDAPMod *attrs[] = {
45 * { 0, "cn", { "babs jensen", "babs", 0 } },
46 * { 0, "sn", { "jensen", 0 } },
47 * { 0, "objectClass", { "person", 0 } },
50 * msgid = ldap_add( ld, dn, attrs );
53 ldap_add( LDAP *ld, char *dn, LDAPMod **attrs )
59 * An add request looks like this:
60 * AddRequest ::= SEQUENCE {
61 * entry DistinguishedName,
62 * attrs SEQUENCE OF SEQUENCE {
64 * values SET OF AttributeValue
69 Debug( LDAP_DEBUG_TRACE, "ldap_add\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_ADD, dn )
78 ld->ld_errno = LDAP_ENCODING_ERROR;
83 /* for each attribute in the entry... */
84 for ( i = 0; attrs[i] != NULL; i++ ) {
85 if ( ( attrs[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
86 rc = ber_printf( ber, "{s[V]}", attrs[i]->mod_type,
87 attrs[i]->mod_values );
89 rc = ber_printf( ber, "{s[v]}", attrs[i]->mod_type,
90 attrs[i]->mod_values );
93 ld->ld_errno = LDAP_ENCODING_ERROR;
99 if ( ber_printf( ber, "}}}" ) == -1 ) {
100 ld->ld_errno = LDAP_ENCODING_ERROR;
105 /* send the message */
106 return( ldap_send_initial_request( ld, LDAP_REQ_ADD, dn, ber ));
110 ldap_add_s( LDAP *ld, char *dn, LDAPMod **attrs )
115 if ( (msgid = ldap_add( ld, dn, attrs )) == -1 )
116 return( ld->ld_errno );
118 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
119 return( ld->ld_errno );
121 return( ldap_result2error( ld, res, 1 ) );