]> git.sur5r.net Git - openldap/blob - servers/slapd/back-relay/config.c
791cd0801f0e97d615e305d8c65eb089ce644c89
[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 2003-2004 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 <ac/string.h>
26 #include <ac/socket.h>
27
28 #include "slap.h"
29 #include "back-relay.h"
30 #include "lutil.h"
31
32 int
33 relay_back_db_config(
34     BackendDB   *be,
35     const char  *fname,
36     int         lineno,
37     int         argc,
38     char        **argv
39 )
40 {
41         relay_back_info *ri = (struct relay_back_info *)be->be_private;
42
43         if ( ri == NULL ) {
44                 fprintf( stderr, "%s: line %d: relay backend info is null!\n",
45                     fname, lineno );
46                 return( 1 );
47         }
48
49         /* real naming context */
50         if ( strcasecmp( argv[0], "relay" ) == 0 ) {
51                 struct berval   dn, ndn, pdn;
52                 int             rc;
53
54                 if (argc != 2) {
55                         fprintf( stderr,
56         "%s: line %d: missing relay suffix in \"relay <dn>\" line\n",
57                             fname, lineno );
58                         return( 1 );
59                 }
60
61                 dn.bv_val = argv[ 1 ];
62                 dn.bv_len = strlen( argv[ 1 ] );
63                 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
64                 if ( rc != LDAP_SUCCESS ) {
65                         fprintf( stderr, "%s: line %d: "
66                                         "relay dn '%s' is invalid\n",
67                                         fname, lineno, argv[ 1 ] );
68                         return 1;
69                 }
70
71                 ri->ri_bd = select_backend( &ndn, 0, 1 );
72                 if ( ri->ri_bd == NULL ) {
73                         fprintf( stderr, "%s: line %d: "
74                                         "cannot find database "
75                                         "of relay dn '%s'\n",
76                                         fname, lineno, argv[ 1 ] );
77                         return 1;
78                 }
79                 
80                 if ( overlay_config( be, "rewrite-remap" ) ) {
81                         fprintf( stderr, "unable to install "
82                                         "rewrite-remap overlay "
83                                         "in back-relay \"%s\" => \"%s\"\n",
84                                         be->be_suffix[0].bv_val,
85                                         ri->ri_bd->be_suffix[0].bv_val ? 
86                                         ri->ri_bd->be_suffix[0].bv_val : "<unknown>" );
87                 }
88
89         /* anything else */
90         } else {
91                 return SLAP_CONF_UNKNOWN;
92         }
93
94         return 0;
95 }
96