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.
14 #include <quipu/commonarg.h>
15 #include <quipu/attrvalue.h>
16 #include <quipu/ds_error.h>
17 #include <quipu/add.h>
18 #include <quipu/dap2.h>
19 #include <quipu/dua.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
27 extern int ldap_compat;
28 #define ADDTAG (ldap_compat == 20 ? OLD_LDAP_RES_ADD : LDAP_RES_ADD)
30 #define ADDTAG LDAP_RES_ADD
42 struct berval **bvals;
44 unsigned long tag, len;
45 struct ds_addentry_arg aa;
46 static CommonArgs common = default_common_args;
47 extern DN ldap_str2dn();
49 Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
52 * Parse the add request. It looks like this:
53 * AddRequest := [APPLICATION 14] SEQUENCE {
54 * name DistinguishedName,
55 * attrs SEQUENCE OF SEQUENCE {
57 * values SET OF AttributeValue
62 #if ISODEPACKAGE == IC
64 DAS_AddEntryArgument_INIT ( &aa );
68 if ( ber_scanf( ber, "{a", &dn ) == LBER_ERROR ) {
69 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
70 send_ldap_msgresult( clientsb, ADDTAG, m,
71 LDAP_PROTOCOL_ERROR, NULL, "" );
75 Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", dn, 0, 0 );
77 aa.ada_object = ldap_str2dn( dn );
79 if ( aa.ada_object == NULLDN ) {
80 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
81 send_ldap_msgresult( clientsb, ADDTAG, m,
82 LDAP_INVALID_DN_SYNTAX, NULL, "" );
86 /* break out once we read them all, or return out on error */
87 aa.ada_entry = NULLATTR;
88 for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
89 tag = ber_next_element( ber, &len, last ) ) {
90 Attr_Sequence as, get_as();
92 if ( ber_scanf( ber, "{a{V}}", &type, &bvals ) == LBER_ERROR )
95 if ( (as = get_as( clientsb, LDAP_RES_ADD, m, type,
96 bvals )) == NULLATTR )
99 aa.ada_entry = as_merge( aa.ada_entry, as );
102 aa.ada_common = common; /* struct copy */
104 rc = initiate_dap_operation( OP_ADDENTRY, m, &aa );
106 dn_free( aa.ada_object );
107 as_free( aa.ada_entry );
110 send_ldap_msgresult( clientsb, ADDTAG, m, rc, NULL, "" );
123 send_ldap_msgresult( sb, ADDTAG, m, LDAP_SUCCESS, NULL, "" );