2 * Copyright (c) 1990 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
17 #include <ac/socket.h>
19 #include <quipu/commonarg.h>
20 #include <quipu/attrvalue.h>
21 #include <quipu/ds_error.h>
22 #include <quipu/add.h>
23 #include <quipu/dap2.h>
24 #include <quipu/dua.h>
30 extern int ldap_compat;
31 #define ADDTAG (ldap_compat == 20 ? OLD_LDAP_RES_ADD : LDAP_RES_ADD)
33 #define ADDTAG LDAP_RES_ADD
45 struct berval **bvals;
47 unsigned long tag, len;
48 struct ds_addentry_arg aa;
49 static CommonArgs common = default_common_args;
50 extern DN ldap_str2dn();
52 Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
55 * Parse the add request. It looks like this:
56 * AddRequest := [APPLICATION 14] SEQUENCE {
57 * name DistinguishedName,
58 * attrs SEQUENCE OF SEQUENCE {
60 * values SET OF AttributeValue
65 #if ISODEPACKAGE == IC
67 DAS_AddEntryArgument_INIT ( &aa );
71 if ( ber_scanf( ber, "{a", &dn ) == LBER_ERROR ) {
72 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
73 send_ldap_msgresult( clientsb, ADDTAG, m,
74 LDAP_PROTOCOL_ERROR, NULL, "" );
78 Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", dn, 0, 0 );
80 aa.ada_object = ldap_str2dn( dn );
82 if ( aa.ada_object == NULLDN ) {
83 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
84 send_ldap_msgresult( clientsb, ADDTAG, m,
85 LDAP_INVALID_DN_SYNTAX, NULL, "" );
89 /* break out once we read them all, or return out on error */
90 aa.ada_entry = NULLATTR;
91 for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
92 tag = ber_next_element( ber, &len, last ) ) {
93 Attr_Sequence as, get_as();
95 if ( ber_scanf( ber, "{a{V}}", &type, &bvals ) == LBER_ERROR )
98 if ( (as = get_as( clientsb, LDAP_RES_ADD, m, type,
99 bvals )) == NULLATTR )
102 aa.ada_entry = as_merge( aa.ada_entry, as );
105 aa.ada_common = common; /* struct copy */
107 rc = initiate_dap_operation( OP_ADDENTRY, m, &aa );
109 dn_free( aa.ada_object );
110 as_free( aa.ada_entry );
113 send_ldap_msgresult( clientsb, ADDTAG, m, rc, NULL, "" );
126 send_ldap_msgresult( sb, ADDTAG, m, LDAP_SUCCESS, NULL, "" );