]> git.sur5r.net Git - openldap/blob - servers/ldapd/add.c
Remove extern declarations of library functions from source.c.
[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 #define ADDTAG  (ldap_compat == 20 ? OLD_LDAP_RES_ADD : LDAP_RES_ADD)
31 #else
32 #define ADDTAG  LDAP_RES_ADD
33 #endif
34
35 int
36 do_add(
37     Sockbuf     *clientsb,
38     struct msg  *m,
39     BerElement  *ber
40 )
41 {
42         char                            *dn;
43         char                            *type, *last;
44         struct berval                   **bvals;
45         int                             rc;
46         unsigned long                   tag, len;
47         struct ds_addentry_arg          aa;
48         static CommonArgs               common = default_common_args;
49
50         Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
51
52         /*
53          * Parse the add request.  It looks like this:
54          *      AddRequest := [APPLICATION 14] SEQUENCE {
55          *              name    DistinguishedName,
56          *              attrs   SEQUENCE OF SEQUENCE {
57          *                      type    AttributeType,
58          *                      values  SET OF AttributeValue
59          *              }
60          *      }
61          */
62
63 #if ISODEPACKAGE == IC
64 #if ICRELEASE > 2
65         DAS_AddEntryArgument_INIT ( &aa );
66 #endif
67 #endif
68
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, "" );
73                 return( 0 );
74         }
75
76         Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", dn, 0, 0 );
77
78         aa.ada_object = ldap_str2dn( dn );
79         free( 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, "" );
84                 return( 0 );
85         }
86
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 ) ) {
91                 Attr_Sequence   as;
92
93                 if ( ber_scanf( ber, "{a{V}}", &type, &bvals ) == LBER_ERROR )
94                         break;
95
96                 if ( (as = get_as( clientsb, LDAP_RES_ADD, m, type,
97                     bvals )) == NULLATTR )
98                         return( 0 );
99
100                 aa.ada_entry = as_merge( aa.ada_entry, as );
101         }
102
103         aa.ada_common = common; /* struct copy */
104
105         rc = initiate_dap_operation( OP_ADDENTRY, m, &aa );
106
107         dn_free( aa.ada_object );
108         as_free( aa.ada_entry );
109
110         if ( rc != 0 ) {
111                 send_ldap_msgresult( clientsb, ADDTAG, m, rc, NULL, "" );
112                 return( 0 );
113         }
114
115         return( 1 );
116 }
117
118 void
119 add_result(
120     Sockbuf     *sb,
121     struct msg  *m
122 )
123 {
124         send_ldap_msgresult( sb, ADDTAG, m, LDAP_SUCCESS, NULL, "" );
125
126         return;
127 }