1 /* config.c - ldap backend configuration file routine */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 /* This is an altered version */
9 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
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:
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.
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.
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.
26 * 4. This notice may not be removed or altered.
30 * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
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.
42 #include <ac/string.h>
43 #include <ac/socket.h>
46 #include "back-ldap.h"
57 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
60 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
65 /* server address to query (depricated, use "uri" directive) */
66 if ( strcasecmp( argv[0], "server" ) == 0 ) {
69 "%s: line %d: missing address in \"server <address>\" line\n",
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]);
82 /* URI of server to query (preferred over "server" directive) */
83 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
86 "%s: line %d: missing address in \"uri <address>\" line\n",
92 li->url = ch_strdup(argv[1]);
94 /* name to use for ldap_back_group */
95 } else if ( strcasecmp( argv[0], "binddn" ) == 0 ) {
98 "%s: line %d: missing name in \"binddn <name>\" line\n",
102 li->binddn = ch_strdup(argv[1]);
104 /* password to use for ldap_back_group */
105 } else if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
108 "%s: line %d: missing password in \"bindpw <password>\" line\n",
112 li->bindpw = ch_strdup(argv[1]);
115 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
116 char *dn, *massaged_dn;
121 "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
126 tmp_be = select_backend( argv[1], 0 );
127 if ( tmp_be != NULL && tmp_be != be ) {
129 "%s: line %d: suffix already in use by another backend in"
130 " \"suffixMassage <suffix> <massaged suffix>\"\n",
135 tmp_be = select_backend( argv[2], 0 );
136 if ( tmp_be != NULL ) {
138 "%s: line %d: massaged suffix already in use by another backend in"
139 " \"suffixMassage <suffix> <massaged suffix>\"\n",
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 );
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 );
157 /* objectclass/attribute mapping */
158 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
160 struct ldapmapping *mapping;
163 if ( argc < 3 || argc > 4 ) {
165 "%s: line %d: syntax is \"map {objectclass | attribute} {<source> | *} [<dest> | *]\"\n",
170 if ( strcasecmp( argv[1], "objectclass" ) == 0 ) {
172 } else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
176 "%s: line %d: syntax is \"map {objectclass | attribute} {<source> | *} [<dest> | *]\"\n",
181 if ( strcasecmp( argv[2], "*" ) != 0 ) {
185 else if ( strcasecmp( argv[3], "*" ) == 0 )
191 map->drop_missing = 1;
194 if ( strcasecmp( argv[3], "*" ) == 0 ) {
195 map->drop_missing = 0;
203 if ( ( map == &li->at_map )
204 && ( strcasecmp( src, "objectclass" ) == 0
205 || strcasecmp( dst, "objectclass" ) == 0 ) )
208 "%s: line %d: objectclass attribute cannot be mapped\n",
212 mapping = (struct ldapmapping *)ch_calloc( 2, sizeof(struct ldapmapping) );
213 if ( mapping == NULL ) {
215 "%s: line %d: out of memory\n",
219 mapping->src = ch_strdup(src);
220 mapping->dst = ch_strdup(dst);
222 mapping[1].src = mapping->dst;
223 mapping[1].dst = mapping->src;
225 mapping[1].src = mapping->src;
226 mapping[1].dst = mapping->dst;
229 if ( avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL
230 || avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
233 "%s: line %d: duplicate mapping found (ignored)\n",
238 avl_insert( &map->map, (caddr_t)mapping,
239 mapping_cmp, mapping_dup );
240 avl_insert( &map->remap, (caddr_t)&mapping[1],
241 mapping_cmp, mapping_dup );
246 "%s: line %d: unknown directive \"%s\" in ldap database definition (ignored)\n",
247 fname, lineno, argv[0] );
253 mapping_cmp ( const void *c1, const void *c2 )
255 struct ldapmapping *map1 = (struct ldapmapping *)c1;
256 struct ldapmapping *map2 = (struct ldapmapping *)c2;
258 return ( strcasecmp(map1->src, map2->src) );
262 mapping_dup ( void *c1, void *c2 )
264 struct ldapmapping *map1 = (struct ldapmapping *)c1;
265 struct ldapmapping *map2 = (struct ldapmapping *)c2;
267 return( ( strcasecmp(map1->src, map2->src) == 0 ) ? -1 : 0 );
271 ldap_back_map ( struct ldapmap *map, char *s, int remap )
274 struct ldapmapping *mapping, fmapping;
282 mapping = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping, mapping_cmp );
283 if (mapping != NULL) {
284 if ( *mapping->dst == 0 )
286 return(mapping->dst);
289 if (map->drop_missing)
296 ldap_back_map_filter ( struct ldapinfo *li, char *f, int remap )
298 char *nf, *m, *p, *q, *s, c;
299 int len, extra, plen, in_quote;
307 nf = ch_malloc( len + 1 );
311 /* this loop assumes the filter ends with one
312 * of the delimiter chars -- probably ')'.
318 for (p = f; c = *p; p++) {
320 in_quote = !in_quote;
328 } else if (in_quote) {
329 /* ignore everything in quotes --
330 * what about attrs in DNs?
333 } else if (c != '(' && c != ')'
334 && c != '=' && c != '>' && c != '<'
335 && c != '|' && c != '&')
342 m = ldap_back_map(&li->at_map, q, remap);
344 m = ldap_back_map(&li->oc_map, q, remap);
357 nf = ch_realloc(nf, len + 1);
377 ldap_back_map_attrs ( struct ldapinfo *li, char **a, int remap )
385 for (count = 0; a[count] != NULL; count++) {
389 na = (char **)ch_calloc( count + 1, sizeof(char *) );
393 for (i = 0, j = 0; i < count; i++) {
394 mapped = ldap_back_map(&li->at_map, a[i], remap);
395 if (mapped != NULL) {
396 mapped = ch_strdup(mapped);
397 if (mapped == NULL) {