]> git.sur5r.net Git - openldap/blob - servers/slapd/back-relay/config.c
c893be6d5315c3343895d676987298af1ed8c584
[openldap] / servers / slapd / back-relay / config.c
1 /* config.c - relay backend configuration file routine */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2004-2006 The OpenLDAP Foundation.
5  * Portions Copyright 2004 Pierangelo Masarati.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Pierangelo Masaratifor inclusion
18  * in OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24
25 #include "slap.h"
26 #include "back-relay.h"
27
28 int
29 relay_back_db_config(
30         BackendDB       *be,
31         const char      *fname,
32         int             lineno,
33         int             argc,
34         char            **argv )
35 {
36         relay_back_info *ri = (struct relay_back_info *)be->be_private;
37
38         if ( ri == NULL ) {
39                 Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
40                         "%s: line %d: relay backend info is null.\n",
41                         fname, lineno );
42                 return 1;
43         }
44
45         /* real naming context */
46         if ( strcasecmp( argv[0], "relay" ) == 0 ) {
47                 struct berval   dn, ndn, pdn;
48                 int             rc;
49                 BackendDB       *bd;
50
51                 if ( argc < 2 ) {
52                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
53                                 "%s: line %d: missing relay suffix "
54                                 "in \"relay <dn> [massage]\" line.\n",
55                                 fname, lineno );
56                         return 1;
57
58                 } else if ( argc > 3 ) {
59                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
60                                 "%s: line %d: extra cruft in \"relay <dn> [massage]\" line.\n",
61                                 fname, lineno );
62                         return 1;
63                 }
64
65                 if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
66                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
67                                 "%s: line %d: "
68                                 "relay dn already specified.\n",
69                                 fname, lineno );
70                         return 1;
71                 }
72
73                 dn.bv_val = argv[ 1 ];
74                 dn.bv_len = strlen( argv[ 1 ] );
75                 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
76                 if ( rc != LDAP_SUCCESS ) {
77                         Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
78                                 "%s: line %d: "
79                                 "relay dn \"%s\" is invalid "
80                                 "in \"relay <dn> [massage]\" line\n",
81                                 fname, lineno, argv[ 1 ] );
82                         return 1;
83                 }
84
85                 bd = select_backend( &ndn, 0, 1 );
86                 if ( bd == NULL ) {
87                         Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
88                                 "%s: line %d: "
89                                 "cannot find database "
90                                 "of relay dn \"%s\" "
91                                 "in \"relay <dn> [massage]\" line\n",
92                                 fname, lineno, argv[ 1 ] );
93                         return 1;
94
95                 } else if ( bd == be ) {
96                         Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
97                                 "%s: line %d: "
98                                 "relay dn \"%s\" would call self "
99                                 "in \"relay <dn> [massage]\" line\n",
100                                 fname, lineno, pdn.bv_val );
101                         return 1;
102                 }
103
104                 ri->ri_realsuffix = ndn;
105
106                 if ( overlay_config( be, "rwm" ) ) {
107                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
108                                 "%s: line %d: unable to install "
109                                 "rwm overlay "
110                                 "in \"relay <dn> [massage]\" line\n",
111                                 fname, lineno );
112                         return 1;
113                 }
114
115                 if ( argc == 3 ) {
116                         char    *cargv[ 4 ];
117
118                         if ( strcmp( argv[2], "massage" ) != 0 ) {
119                                 Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
120                                         "%s: line %d: "
121                                         "unknown directive \"%s\" "
122                                         "in \"relay <dn> [massage]\" line\n",
123                                         fname, lineno, argv[ 2 ] );
124                                 return 1;
125                         }
126
127                         cargv[ 0 ] = "rwm-suffixmassage";
128                         cargv[ 1 ] = be->be_suffix[0].bv_val;
129                         cargv[ 2 ] = pdn.bv_val;
130                         cargv[ 3 ] = NULL;
131
132                         if ( be->be_config( be, fname, lineno, 3, cargv ) ) {
133                                 return 1;
134                         }
135                 }
136
137                 ch_free( pdn.bv_val );
138
139         /* anything else */
140         } else {
141                 return SLAP_CONF_UNKNOWN;
142         }
143
144         return 0;
145 }
146