]> git.sur5r.net Git - openldap/blob - servers/slapd/back-relay/config.c
previous commit contradicts man page; see comment in code
[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                 switch ( argc ) {
52                 case 3:
53                         if ( strcmp( argv[ 2 ], "massage" ) != 0 ) {
54                                 Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
55                                         "%s: line %d: "
56                                         "unknown arg[#2]=\"%s\" "
57                                         "in \"relay <dn> [massage]\" line\n",
58                                         fname, lineno, argv[ 2 ] );
59                                 return 1;
60                         }
61
62                         if ( be->be_nsuffix == NULL ) {
63                                 Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
64                                         "%s: line %d: "
65                                         "\"relay\" directive "
66                                         "must appear after \"suffix\".\n",
67                                         fname, lineno );
68                                 return 1;
69                         }
70
71                         if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
72                                 Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
73                                         "%s: line %d: "
74                                         "relayng of multiple suffix "
75                                         "database not supported.\n",
76                                         fname, lineno );
77                                 return 1;
78                         }
79                         /* fallthru */
80
81                 case 2:
82                         break;
83
84                 case 1:
85                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
86                                 "%s: line %d: missing relay suffix "
87                                 "in \"relay <dn> [massage]\" line.\n",
88                                 fname, lineno );
89                         return 1;
90
91                 default:
92                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
93                                 "%s: line %d: extra cruft "
94                                 "in \"relay <dn> [massage]\" line.\n",
95                                 fname, lineno );
96                         return 1;
97                 }
98
99                 if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
100                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
101                                 "%s: line %d: "
102                                 "relay dn already specified.\n",
103                                 fname, lineno );
104                         return 1;
105                 }
106
107                 /* The man page says that the "relay" directive
108                  * automatically instantiates slapo-rwm; I don't
109                  * like this very much any more, I'd prefer to
110                  * have automatic instantiation only when "massage"
111                  * is specified, so one has better control on
112                  * where the overlay gets instantiated, but this
113                  * would break compatibility.  One can still control
114                  * where the overlay is instantiated by moving
115                  * around the "relay" directive, although this could
116                  * make slapd.conf a bit confusing. */
117                 if ( overlay_config( be, "rwm" ) ) {
118                         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
119                                 "%s: line %d: unable to install "
120                                 "rwm overlay "
121                                 "in \"relay <dn> [massage]\" line\n",
122                                 fname, lineno );
123                         return 1;
124                 }
125
126                 dn.bv_val = argv[ 1 ];
127                 dn.bv_len = strlen( argv[ 1 ] );
128                 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
129                 if ( rc != LDAP_SUCCESS ) {
130                         Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
131                                 "%s: line %d: "
132                                 "relay dn \"%s\" is invalid "
133                                 "in \"relay <dn> [massage]\" line\n",
134                                 fname, lineno, argv[ 1 ] );
135                         return 1;
136                 }
137
138                 bd = select_backend( &ndn, 0, 1 );
139                 if ( bd == NULL ) {
140                         Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
141                                 "%s: line %d: "
142                                 "cannot find database "
143                                 "of relay dn \"%s\" "
144                                 "in \"relay <dn> [massage]\" line\n",
145                                 fname, lineno, argv[ 1 ] );
146                         rc = 1;
147                         goto relay_done;
148
149                 } else if ( bd->be_private == be->be_private ) {
150                         Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
151                                 "%s: line %d: "
152                                 "relay dn \"%s\" would call self "
153                                 "in \"relay <dn> [massage]\" line\n",
154                                 fname, lineno, pdn.bv_val );
155                         rc = 1;
156                         goto relay_done;
157                 }
158
159                 ri->ri_realsuffix = ndn;
160
161                 if ( argc == 3 ) {
162                         char    *cargv[ 4 ];
163
164                         cargv[ 0 ] = "rwm-suffixmassage";
165                         cargv[ 1 ] = be->be_suffix[0].bv_val;
166                         cargv[ 2 ] = pdn.bv_val;
167                         cargv[ 3 ] = NULL;
168
169                         rc = be->be_config( be, fname, lineno, 3, cargv );
170                 }
171
172 relay_done:;
173                 ch_free( pdn.bv_val );
174
175                 return rc;
176         }
177
178         /* anything else */
179         return SLAP_CONF_UNKNOWN;
180 }
181