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