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 #define ADDTAG (ldap_compat == 20 ? OLD_LDAP_RES_ADD : LDAP_RES_ADD)
32 #define ADDTAG LDAP_RES_ADD
44 struct berval **bvals;
46 unsigned long tag, len;
47 struct ds_addentry_arg aa;
48 static CommonArgs common = default_common_args;
50 Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
53 * Parse the add request. It looks like this:
54 * AddRequest := [APPLICATION 14] SEQUENCE {
55 * name DistinguishedName,
56 * attrs SEQUENCE OF SEQUENCE {
58 * values SET OF AttributeValue
63 #if ISODEPACKAGE == IC
65 DAS_AddEntryArgument_INIT ( &aa );
69 if ( ber_scanf( ber, "{a", &dn ) == LBER_ERROR ) {
70 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
71 send_ldap_msgresult( clientsb, ADDTAG, m,
72 LDAP_PROTOCOL_ERROR, NULL, "" );
76 Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", dn, 0, 0 );
78 aa.ada_object = ldap_str2dn( dn );
80 if ( aa.ada_object == NULLDN ) {
81 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
82 send_ldap_msgresult( clientsb, ADDTAG, m,
83 LDAP_INVALID_DN_SYNTAX, NULL, "" );
87 /* break out once we read them all, or return out on error */
88 aa.ada_entry = NULLATTR;
89 for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
90 tag = ber_next_element( ber, &len, last ) ) {
93 if ( ber_scanf( ber, "{a{V}}", &type, &bvals ) == LBER_ERROR )
96 if ( (as = get_as( clientsb, LDAP_RES_ADD, m, type,
97 bvals )) == NULLATTR )
100 aa.ada_entry = as_merge( aa.ada_entry, as );
103 aa.ada_common = common; /* struct copy */
105 rc = initiate_dap_operation( OP_ADDENTRY, m, &aa );
107 dn_free( aa.ada_object );
108 as_free( aa.ada_entry );
111 send_ldap_msgresult( clientsb, ADDTAG, m, rc, NULL, "" );
124 send_ldap_msgresult( sb, ADDTAG, m, LDAP_SUCCESS, NULL, "" );