3 * Copyright (c) 1990 Regents of the University of Michigan.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that this notice is preserved and that due credit is given
8 * to the University of Michigan at Ann Arbor. The name of the University
9 * may not be used to endorse or promote products derived from this
10 * software without specific prior written permission. This software
11 * is provided ``as is'' without express or implied warranty.
18 #include <ac/socket.h>
20 #include <quipu/commonarg.h>
21 #include <quipu/attrvalue.h>
22 #include <quipu/ds_error.h>
23 #include <quipu/add.h>
24 #include <quipu/dap2.h>
25 #include <quipu/dua.h>
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;
51 Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
54 * Parse the add request. It looks like this:
55 * AddRequest := [APPLICATION 14] SEQUENCE {
56 * name DistinguishedName,
57 * attrs SEQUENCE OF SEQUENCE {
59 * values SET OF AttributeValue
64 #if ISODEPACKAGE == IC
66 DAS_AddEntryArgument_INIT ( &aa );
70 if ( ber_scanf( ber, "{a", &dn ) == LBER_ERROR ) {
71 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
72 send_ldap_msgresult( clientsb, ADDTAG, m,
73 LDAP_PROTOCOL_ERROR, NULL, "" );
77 Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", dn, 0, 0 );
79 aa.ada_object = ldap_str2dn( dn );
81 if ( aa.ada_object == NULLDN ) {
82 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
83 send_ldap_msgresult( clientsb, ADDTAG, m,
84 LDAP_INVALID_DN_SYNTAX, NULL, "" );
88 /* break out once we read them all, or return out on error */
89 aa.ada_entry = NULLATTR;
90 for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
91 tag = ber_next_element( ber, &len, last ) ) {
94 if ( ber_scanf( ber, "{a{V}}", &type, &bvals ) == LBER_ERROR )
97 if ( (as = get_as( clientsb, LDAP_RES_ADD, m, type,
98 bvals )) == NULLATTR )
101 aa.ada_entry = as_merge( aa.ada_entry, as );
104 aa.ada_common = common; /* struct copy */
106 rc = initiate_dap_operation( OP_ADDENTRY, m, &aa );
108 dn_free( aa.ada_object );
109 as_free( aa.ada_entry );
112 send_ldap_msgresult( clientsb, ADDTAG, m, rc, NULL, "" );
125 send_ldap_msgresult( sb, ADDTAG, m, LDAP_SUCCESS, NULL, "" );