]> git.sur5r.net Git - openldap/blob - servers/ldapd/add.c
merged with autoconf branch
[openldap] / servers / ldapd / add.c
1 /*
2  * Copyright (c) 1990 Regents of the University of Michigan.
3  * All rights reserved.
4  *
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.
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/socket.h>
18
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>
25 #include "lber.h"
26 #include "ldap.h"
27 #include "common.h"
28
29 #ifdef LDAP_COMPAT20
30 extern int      ldap_compat;
31 #define ADDTAG  (ldap_compat == 20 ? OLD_LDAP_RES_ADD : LDAP_RES_ADD)
32 #else
33 #define ADDTAG  LDAP_RES_ADD
34 #endif
35
36 int
37 do_add(
38     Sockbuf     *clientsb,
39     struct msg  *m,
40     BerElement  *ber
41 )
42 {
43         char                            *dn;
44         char                            *type, *last;
45         struct berval                   **bvals;
46         int                             rc;
47         unsigned long                   tag, len;
48         struct ds_addentry_arg          aa;
49         static CommonArgs               common = default_common_args;
50         extern DN                       ldap_str2dn();
51
52         Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
53
54         /*
55          * Parse the add request.  It looks like this:
56          *      AddRequest := [APPLICATION 14] SEQUENCE {
57          *              name    DistinguishedName,
58          *              attrs   SEQUENCE OF SEQUENCE {
59          *                      type    AttributeType,
60          *                      values  SET OF AttributeValue
61          *              }
62          *      }
63          */
64
65 #if ISODEPACKAGE == IC
66 #if ICRELEASE > 2
67         DAS_AddEntryArgument_INIT ( &aa );
68 #endif
69 #endif
70
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, "" );
75                 return( 0 );
76         }
77
78         Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", dn, 0, 0 );
79
80         aa.ada_object = ldap_str2dn( dn );
81         free( 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, "" );
86                 return( 0 );
87         }
88
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();
94
95                 if ( ber_scanf( ber, "{a{V}}", &type, &bvals ) == LBER_ERROR )
96                         break;
97
98                 if ( (as = get_as( clientsb, LDAP_RES_ADD, m, type,
99                     bvals )) == NULLATTR )
100                         return( 0 );
101
102                 aa.ada_entry = as_merge( aa.ada_entry, as );
103         }
104
105         aa.ada_common = common; /* struct copy */
106
107         rc = initiate_dap_operation( OP_ADDENTRY, m, &aa );
108
109         dn_free( aa.ada_object );
110         as_free( aa.ada_entry );
111
112         if ( rc != 0 ) {
113                 send_ldap_msgresult( clientsb, ADDTAG, m, rc, NULL, "" );
114                 return( 0 );
115         }
116
117         return( 1 );
118 }
119
120 void
121 add_result(
122     Sockbuf     *sb,
123     struct msg  *m
124 )
125 {
126         send_ldap_msgresult( sb, ADDTAG, m, LDAP_SUCCESS, NULL, "" );
127
128         return;
129 }