]> git.sur5r.net Git - openldap/blob - servers/ldapd/add.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / servers / ldapd / add.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright (c) 1990 Regents of the University of Michigan.
4  * All rights reserved.
5  *
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.
12  */
13
14 #include "portable.h"
15
16 #include <stdio.h>
17
18 #include <ac/socket.h>
19
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>
26 #include "lber.h"
27 #include "ldap.h"
28 #include "common.h"
29
30 #ifdef LDAP_COMPAT20
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
51         Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
52
53         /*
54          * Parse the add request.  It looks like this:
55          *      AddRequest := [APPLICATION 14] SEQUENCE {
56          *              name    DistinguishedName,
57          *              attrs   SEQUENCE OF SEQUENCE {
58          *                      type    AttributeType,
59          *                      values  SET OF AttributeValue
60          *              }
61          *      }
62          */
63
64 #if ISODEPACKAGE == IC
65 #if ICRELEASE > 2
66         DAS_AddEntryArgument_INIT ( &aa );
67 #endif
68 #endif
69
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, "" );
74                 return( 0 );
75         }
76
77         Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", dn, 0, 0 );
78
79         aa.ada_object = ldap_str2dn( dn );
80         free( 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, "" );
85                 return( 0 );
86         }
87
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 ) ) {
92                 Attr_Sequence   as;
93
94                 if ( ber_scanf( ber, "{a{V}}", &type, &bvals ) == LBER_ERROR )
95                         break;
96
97                 if ( (as = get_as( clientsb, LDAP_RES_ADD, m, type,
98                     bvals )) == NULLATTR )
99                         return( 0 );
100
101                 aa.ada_entry = as_merge( aa.ada_entry, as );
102         }
103
104         aa.ada_common = common; /* struct copy */
105
106         rc = initiate_dap_operation( OP_ADDENTRY, m, &aa );
107
108         dn_free( aa.ada_object );
109         as_free( aa.ada_entry );
110
111         if ( rc != 0 ) {
112                 send_ldap_msgresult( clientsb, ADDTAG, m, rc, NULL, "" );
113                 return( 0 );
114         }
115
116         return( 1 );
117 }
118
119 void
120 add_result(
121     Sockbuf     *sb,
122     struct msg  *m
123 )
124 {
125         send_ldap_msgresult( sb, ADDTAG, m, LDAP_SUCCESS, NULL, "" );
126
127         return;
128 }