]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/config.c
5113ed617d08e3e888d6cef3eb492aae7d12c137
[openldap] / servers / slapd / back-ldap / config.c
1 /* config.c - ldap backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7 /* This is an altered version */
8 /*
9  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
10  * 
11  * Permission is granted to anyone to use this software for any purpose
12  * on any computer system, and to alter it and redistribute it, subject
13  * to the following restrictions:
14  * 
15  * 1. The author is not responsible for the consequences of use of this
16  *    software, no matter how awful, even if they arise from flaws in it.
17  * 
18  * 2. The origin of this software must not be misrepresented, either by
19  *    explicit claim or by omission.  Since few users ever read sources,
20  *    credits should appear in the documentation.
21  * 
22  * 3. Altered versions must be plainly marked as such, and must not be
23  *    misrepresented as being the original software.  Since few users
24  *    ever read sources, credits should appear in the documentation.
25  * 
26  * 4. This notice may not be removed or altered.
27  *
28  *
29  *
30  * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
31  * 
32  * This software is being modified by Pierangelo Masarati.
33  * The previously reported conditions apply to the modified code as well.
34  * Changes in the original code are highlighted where required.
35  * Credits for the original code go to the author, Howard Chu.
36  */
37
38 #include "portable.h"
39
40 #include <stdio.h>
41
42 #include <ac/string.h>
43 #include <ac/socket.h>
44
45 #include "slap.h"
46 #include "back-ldap.h"
47
48 int
49 ldap_back_db_config(
50     BackendDB   *be,
51     const char  *fname,
52     int         lineno,
53     int         argc,
54     char        **argv
55 )
56 {
57         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
58
59         if ( li == NULL ) {
60                 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
61                     fname, lineno );
62                 return( 1 );
63         }
64
65         /* server address to query (depricated, use "uri" directive) */
66         if ( strcasecmp( argv[0], "server" ) == 0 ) {
67                 if (argc != 2) {
68                         fprintf( stderr,
69         "%s: line %d: missing address in \"server <address>\" line\n",
70                             fname, lineno );
71                         return( 1 );
72                 }
73                 if (li->url != NULL)
74                         ch_free(li->url);
75                 li->url = ch_calloc(strlen(argv[1]) + 9, sizeof(char));
76                 if (li->url != NULL) {
77                         strcpy(li->url, "ldap://");
78                         strcat(li->url, argv[1]);
79                         strcat(li->url, "/");
80                 }
81
82         /* URI of server to query (preferred over "server" directive) */
83         } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
84                 if (argc != 2) {
85                         fprintf( stderr,
86         "%s: line %d: missing address in \"uri <address>\" line\n",
87                             fname, lineno );
88                         return( 1 );
89                 }
90                 if (li->url != NULL)
91                         ch_free(li->url);
92                 li->url = ch_strdup(argv[1]);
93
94         /* name to use for ldap_back_group */
95         } else if ( strcasecmp( argv[0], "binddn" ) == 0 ) {
96                 if (argc != 2) {
97                         fprintf( stderr,
98         "%s: line %d: missing name in \"binddn <name>\" line\n",
99                             fname, lineno );
100                         return( 1 );
101                 }
102                 li->binddn = ch_strdup(argv[1]);
103
104         /* password to use for ldap_back_group */
105         } else if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
106                 if (argc != 2) {
107                         fprintf( stderr,
108         "%s: line %d: missing password in \"bindpw <password>\" line\n",
109                             fname, lineno );
110                         return( 1 );
111                 }
112                 li->bindpw = ch_strdup(argv[1]);
113         
114         /* dn massaging */
115         } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
116                 char *dn, *massaged_dn;
117                 BackendDB *tmp_be;
118                 
119                 if ( argc != 3 ) {
120                         fprintf( stderr,
121         "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
122                                 fname, lineno );
123                         return( 1 );
124                 }
125                 
126                 tmp_be = select_backend( argv[1], 0 );
127                 if ( tmp_be != NULL && tmp_be != be ) {
128                         fprintf( stderr,
129         "%s: line %d: suffix already in use by another backend in"
130         " \"suffixMassage <suffix> <massaged suffix>\"\n",
131                                 fname, lineno );
132                         return( 1 );                                            
133                 }
134
135                 tmp_be = select_backend( argv[2], 0 );
136                 if ( tmp_be != NULL ) {
137                         fprintf( stderr,
138         "%s: line %d: massaged suffix already in use by another backend in" 
139         " \"suffixMassage <suffix> <massaged suffix>\"\n",
140                                 fname, lineno );
141                         return( 1 );
142                 }
143                 
144                 dn = ch_strdup( argv[1] );
145                 charray_add( &li->suffix_massage, dn );
146                 (void) dn_normalize( dn );
147                 charray_add( &li->suffix_massage, dn );
148                 
149                 massaged_dn = ch_strdup( argv[2] );
150                 charray_add( &li->suffix_massage, massaged_dn );
151                 (void) dn_normalize( massaged_dn );
152                 charray_add( &li->suffix_massage, massaged_dn );
153                 
154                 free( dn );
155                 free( massaged_dn );
156
157         /* anything else */
158         } else {
159                 fprintf( stderr,
160 "%s: line %d: unknown directive \"%s\" in ldap database definition (ignored)\n",
161                     fname, lineno, argv[0] );
162         }
163         return 0;
164 }