]> git.sur5r.net Git - openldap/blob - libraries/librewrite/map.c
minor cleanup
[openldap] / libraries / librewrite / map.c
1 /******************************************************************************
2  *
3  * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
4  * All rights reserved.
5  *
6  * Permission is granted to anyone to use this software for any purpose
7  * on any computer system, and to alter it and redistribute it, subject
8  * to the following restrictions:
9  *
10  * 1. The author is not responsible for the consequences of use of this
11  * software, no matter how awful, even if they arise from flaws in it.
12  *
13  * 2. The origin of this software must not be misrepresented, either by
14  * explicit claim or by omission.  Since few users ever read sources,
15  * credits should appear in the documentation.
16  *
17  * 3. Altered versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.  Since few users
19  * ever read sources, credits should appear in the documentation.
20  * 
21  * 4. This notice may not be removed or altered.
22  *
23  ******************************************************************************/
24
25 #include <portable.h>
26
27 #include <pwd.h>
28
29 #include "rewrite-int.h"
30 #include "rewrite-map.h"
31
32 /*
33  * Global data
34  */
35 #ifdef USE_REWRITE_LDAP_PVT_THREADS
36 ldap_pvt_thread_mutex_t xpasswd_mutex;
37 static int xpasswd_mutex_init = 0;
38 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
39
40 /*
41  * Map parsing
42  * NOTE: these are old-fashion maps; new maps will be parsed on separate
43  * config lines, and referred by name.
44  */
45 struct rewrite_map *
46 rewrite_xmap_parse(
47                 struct rewrite_info *info,
48                 const char *s,
49                 const char **currpos
50 )
51 {
52         struct rewrite_map *map;
53
54         assert( info != NULL );
55         assert( s != NULL );
56         assert( currpos != NULL );
57
58         Debug( LDAP_DEBUG_ARGS, "rewrite_xmap_parse: %s\n%s%s",
59                         s, "", "" );
60
61         *currpos = NULL;
62
63         map = calloc( sizeof( struct rewrite_map ), 1 );
64         if ( map == NULL ) {
65                 Debug( LDAP_DEBUG_ANY, "rewrite_xmap_parse:"
66                                 " calloc failed\n%s%s%s", "", "", "" );
67                 return NULL;
68         }
69
70         /*
71          * Experimental passwd map:
72          * replaces the uid with the matching gecos from /etc/passwd file 
73          */
74         if ( strncasecmp(s, "xpasswd", 7 ) == 0 ) {
75                 map->lm_type = REWRITE_MAP_XPWDMAP;
76                 map->lm_name = strdup( "xpasswd" );
77
78                 assert( s[7] == '}' );
79                 *currpos = s + 8;
80
81 #ifdef USE_REWRITE_LDAP_PVT_THREADS
82                 if ( !xpasswd_mutex_init ) {
83                         xpasswd_mutex_init = 1;
84                         if ( ldap_pvt_thread_mutex_init( &xpasswd_mutex ) ) {
85                                 free( map );
86                                 return NULL;
87                         }
88                 }
89 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
90
91                 /* Don't really care if fails */
92                 return map;
93         
94         /*
95          * Experimental file map:
96          * looks up key in a `key value' ascii file
97          */
98         } else if ( strncasecmp(s, "xfile", 5 ) == 0 ) {
99                 char *filename;
100                 const char *p;
101                 int l;
102                 int c = 5;
103                 
104                 map->lm_type = REWRITE_MAP_XFILEMAP;
105                 
106                 if ( s[ c ] != '(' ) {
107                         free( map );
108                         return NULL;
109                 }
110
111                 /* Must start with '/' for security concerns */
112                 c++;
113                 if ( s[ c ] != '/' ) {
114                         free( map );
115                         return NULL;
116                 }
117
118                 for ( p = s + c; p[ 0 ] != '\0' && p[ 0 ] != ')'; p++ );
119                 if ( p[ 0 ] != ')' ) {
120                         free( map );
121                         return NULL;
122                 }
123
124                 l = p - s - c;
125                 filename = calloc( sizeof( char ), l + 1 );
126                 AC_MEMCPY( filename, s + c, l );
127                 filename[ l ] = '\0';
128                 
129                 map->lm_args = ( void * )fopen( filename, "r" );
130                 free( filename );
131
132                 if ( map->lm_args == NULL ) {
133                         free( map );
134                         return NULL;
135                 }
136
137                 *currpos = p + 1;
138
139 #ifdef USE_REWRITE_LDAP_PVT_THREADS
140                 if ( ldap_pvt_thread_mutex_init( &map->lm_mutex ) ) {
141                         fclose( ( FILE * )map->lm_args );
142                         free( map );
143                         return NULL;
144                 }
145 #endif /* USE_REWRITE_LDAP_PVT_THREADS */       
146                 
147                 return map;
148
149         /*
150          * Experimental ldap map:
151          * looks up key on the fly (not implemented!)
152          */
153         } else if ( strncasecmp(s, "xldap", 5 ) == 0 ) {
154                 char *p;
155                 char *url;
156                 int l, rc;
157                 int c = 5;
158                 LDAPURLDesc *lud;
159
160                 if ( s[ c ] != '(' ) {
161                         free( map );
162                         return NULL;
163                 }
164                 c++;
165                 
166                 p = strchr( s, '}' );
167                 if ( p == NULL ) {
168                         free( map );
169                         return NULL;
170                 }
171                 p--;
172
173                 *currpos = p + 2;
174         
175                 /*
176                  * Add two bytes for urlencoding of '%s'
177                  */
178                 l = p - s - c;
179                 url = calloc( sizeof( char ), l + 3 );
180                 AC_MEMCPY( url, s + c, l );
181                 url[ l ] = '\0';
182
183                 /*
184                  * Urlencodes the '%s' for ldap_url_parse
185                  */
186                 p = strchr( url, '%' );
187                 if ( p != NULL ) {
188                         memmove( p + 3, p + 1, strlen( p + 1 ) + 1 );
189                         p[ 1 ] = '2';
190                         p[ 2 ] = '5';
191                 }
192
193                 rc =  ldap_url_parse( url, &lud );
194                 free( url );
195
196                 if ( rc != LDAP_SUCCESS ) {
197                         free( map );
198                         return NULL;
199                 }
200                 assert( lud != NULL );
201
202                 map->lm_args = ( void * )lud;
203                 map->lm_type = REWRITE_MAP_XLDAPMAP;
204
205 #ifdef USE_REWRITE_LDAP_PVT_THREADS
206                 if ( ldap_pvt_thread_mutex_init( &map->lm_mutex ) ) {
207                         ldap_free_urldesc( lud );
208                         free( map );
209                         return NULL;
210                 }
211 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
212
213                 return map;
214         
215         /* Unhandled map */
216         }
217         
218         return NULL;
219 }
220
221 struct rewrite_map *
222 rewrite_map_parse(
223                 struct rewrite_info *info,
224                 const char *string,
225                 const char **currpos
226 )
227 {
228         struct rewrite_map *map = NULL;
229         struct rewrite_subst *subst = NULL;
230         char *s, *begin = NULL, *end;
231         const char *p;
232         int l, cnt;
233
234         assert( info != NULL );
235         assert( string != NULL );
236         assert( currpos != NULL );
237
238         *currpos = NULL;
239
240         /*
241          * Go to the end of the map invocation (the right closing brace)
242          */
243         for ( p = string, cnt = 1; p[ 0 ] != '\0' && cnt > 0; p++ ) {
244                 if ( p[ 0 ] == REWRITE_SUBMATCH_ESCAPE ) {
245                         /*
246                          * '\' marks the beginning of a new map
247                          */
248                         if ( p[ 1 ] == '{' ) {
249                                 cnt++;
250                         /*
251                          * '\' followed by a digit may mark the beginning
252                          * of an old map
253                          */
254                         } else if ( isdigit( p[ 1 ] ) && p[ 2 ] == '{' ) {
255                                 cnt++;
256                                 p++;
257                         }
258                         p++;
259                 } else if ( p[ 0 ] == '}' ) {
260                         cnt--;
261                 }
262         }
263         if ( cnt != 0 ) {
264                 return NULL;
265         }
266         *currpos = p;
267         
268         /*
269          * Copy the map invocation
270          */
271         l = p - string - 1;
272         s = calloc( sizeof( char ), l + 1 );
273         AC_MEMCPY( s, string, l );
274         s[ l ] = 0;
275
276         /*
277          * Isolate the map name (except for variable deref)
278          */
279         switch ( s[ 0 ] ) {
280         case REWRITE_OPERATOR_VARIABLE_GET:
281         case REWRITE_OPERATOR_PARAM_GET:
282                 break;
283         default:
284                 begin = strchr( s, '(' );
285                 if ( begin == NULL ) {
286                         free( s );
287                         return NULL;
288                 }
289                 begin[ 0 ] = '\0';
290                 begin++;
291                 break;
292         }
293
294         /*
295          * Check for special map types
296          */
297         p = s;
298         switch ( p[ 0 ] ) {
299         case REWRITE_OPERATOR_SUBCONTEXT:
300         case REWRITE_OPERATOR_COMMAND:
301         case REWRITE_OPERATOR_VARIABLE_SET:
302         case REWRITE_OPERATOR_VARIABLE_GET:
303         case REWRITE_OPERATOR_PARAM_GET:
304                 p++;
305                 break;
306         }
307
308         /*
309          * Variable set and get may be repeated to indicate session-wide
310          * instead of operation-wide variables
311          */
312         switch ( p[ 0 ] ) {
313         case REWRITE_OPERATOR_VARIABLE_SET:
314         case REWRITE_OPERATOR_VARIABLE_GET:
315                 p++;
316                 break;
317         }
318
319         /*
320          * Variable get token can be appended to variable set to mean store
321          * AND rewrite
322          */
323         if ( p[ 0 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
324                 p++;
325         }
326         
327         /*
328          * Check the syntax of the variable name
329          */
330         if ( !isalpha( p[ 0 ] ) ) {
331                 free( s );
332                 return NULL;
333         }
334         for ( p++; p[ 0 ] != '\0'; p++ ) {
335                 if ( !isalnum( p[ 0 ] ) ) {
336                         free( s );
337                         return NULL;
338                 }
339         }
340
341         /*
342          * Isolate the argument of the map (except for variable deref)
343          */
344         switch ( s[ 0 ] ) {
345         case REWRITE_OPERATOR_VARIABLE_GET:
346         case REWRITE_OPERATOR_PARAM_GET:
347                 break;
348         default:
349                 end = strrchr( begin, ')' );
350                 if ( end == NULL ) {
351                         free( s );
352                         return NULL;
353                 }
354                 end[ 0 ] = '\0';
355
356                 /*
357                  * Compile the substitution pattern of the map argument
358                  */
359                 subst = rewrite_subst_compile( info, begin );
360                 if ( subst == NULL ) {
361                         free( s );
362                         return NULL;
363                 }
364                 break;
365         }
366
367         /*
368          * Create the map
369          */
370         map = calloc( sizeof( struct rewrite_map ), 1 );
371         if ( map == NULL ) {
372                 if ( subst != NULL ) {
373                         free( subst );
374                 }
375                 free( s );
376                 return NULL;
377         }
378         
379 #ifdef USE_REWRITE_LDAP_PVT_THREADS
380         if ( ldap_pvt_thread_mutex_init( &map->lm_mutex ) ) {
381                 if ( subst != NULL ) {
382                         free( subst );
383                 }
384                 free( s );
385                 free( map );
386                 return NULL;
387         }
388 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
389                         
390         /*
391          * No subst for variable deref
392          */
393         switch ( s[ 0 ] ) {
394         case REWRITE_OPERATOR_VARIABLE_GET:
395         case REWRITE_OPERATOR_PARAM_GET:
396                 break;
397         default:
398                 map->lm_subst = subst;
399                 break;
400         }
401
402         /*
403          * Parses special map types
404          */
405         switch ( s[ 0 ] ) {
406         
407         /*
408          * Subcontext
409          */
410         case REWRITE_OPERATOR_SUBCONTEXT:               /* '>' */
411
412                 /*
413                  * Fetch the rewrite context
414                  * it MUST have been defined previously
415                  */
416                 map->lm_type = REWRITE_MAP_SUBCONTEXT;
417                 map->lm_name = strdup( s + 1 );
418                 map->lm_data = rewrite_context_find( info, s + 1 );
419                 if ( map->lm_data == NULL ) {
420                         free( s );
421                         free( map );
422                         return NULL;
423                 }
424                 break;
425
426         /*
427          * External command
428          */
429         case REWRITE_OPERATOR_COMMAND:          /* '|' */
430                 free( map );
431                 map = NULL;
432                 break;
433         
434         /*
435          * Variable set
436          */
437         case REWRITE_OPERATOR_VARIABLE_SET:     /* '&' */
438                 if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_SET ) {
439                         if ( s[ 2 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
440                                 map->lm_type = REWRITE_MAP_SETW_SESN_VAR;
441                                 map->lm_name = strdup( s + 3 );
442                         } else {
443                                 map->lm_type = REWRITE_MAP_SET_SESN_VAR;
444                                 map->lm_name = strdup( s + 2 );
445                         }
446                 } else {
447                         if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
448                                 map->lm_type = REWRITE_MAP_SETW_OP_VAR;
449                                 map->lm_name = strdup( s + 2 );
450                         } else {
451                                 map->lm_type = REWRITE_MAP_SET_OP_VAR;
452                                 map->lm_name = strdup( s + 1 );
453                         }
454                 }
455                 break;
456         
457         /*
458          * Variable dereference
459          */
460         case REWRITE_OPERATOR_VARIABLE_GET:     /* '*' */
461                 if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
462                         map->lm_type = REWRITE_MAP_GET_SESN_VAR;
463                         map->lm_name = strdup( s + 2 );
464                 } else {
465                         map->lm_type = REWRITE_MAP_GET_OP_VAR;
466                         map->lm_name = strdup( s + 1 );
467                 }
468                 break;
469         
470         /*
471          * Parameter
472          */
473         case REWRITE_OPERATOR_PARAM_GET:                /* '$' */
474                 map->lm_type = REWRITE_MAP_GET_PARAM;
475                 map->lm_name = strdup( s + 1 );
476                 break;
477         
478         /*
479          * Built-in map
480          */
481         default:
482                 map->lm_type = REWRITE_MAP_BUILTIN;
483                 map->lm_name = strdup( s );
484                 map->lm_data = rewrite_builtin_map_find( info, s );
485                 if ( map->lm_data == NULL ) {
486                         return NULL;
487                 }
488                 break;
489
490         }
491         
492         free( s );
493         return map;
494 }
495
496 /*
497  * Map key -> value resolution
498  * NOTE: these are old-fashion maps; new maps will be parsed on separate
499  * config lines, and referred by name.
500  */
501 int
502 rewrite_xmap_apply(
503                 struct rewrite_info *info,
504                 struct rewrite_op *op,
505                 struct rewrite_map *map,
506                 struct berval *key,
507                 struct berval *val
508 )
509 {
510         int rc = REWRITE_SUCCESS;
511         
512         assert( info != NULL );
513         assert( op != NULL );
514         assert( map != NULL );
515         assert( key != NULL );
516         assert( val != NULL );
517         
518         val->bv_val = NULL;
519         val->bv_len = 0;
520         
521         switch ( map->lm_type ) {
522         case REWRITE_MAP_XPWDMAP: {
523                 struct passwd *pwd;
524
525 #ifdef USE_REWRITE_LDAP_PVT_THREADS
526                 ldap_pvt_thread_mutex_lock( &xpasswd_mutex );
527 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
528                 
529                 pwd = getpwnam( key->bv_val );
530                 if ( pwd == NULL ) {
531
532 #ifdef USE_REWRITE_LDAP_PVT_THREADS
533                         ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
534 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
535
536                         rc = REWRITE_NO_SUCH_OBJECT;
537                         break;
538                 }
539
540                 if ( pwd->pw_gecos != NULL && pwd->pw_gecos[0] != '\0' ) {
541                         int l = strlen( pwd->pw_gecos );
542                         
543                         val->bv_val = strdup( pwd->pw_gecos );
544                         if ( val->bv_val == NULL ) {
545
546 #ifdef USE_REWRITE_LDAP_PVT_THREADS
547                                 ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
548 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
549
550                                 rc = REWRITE_ERR;
551                                 break;
552                         }
553                         val->bv_len = l;
554                 } else {
555                         val->bv_val = strdup( key->bv_val );
556                         val->bv_len = key->bv_len;
557                 }
558
559 #ifdef USE_REWRITE_LDAP_PVT_THREADS
560                 ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
561 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
562                         
563                 break;
564         }
565         
566         case REWRITE_MAP_XFILEMAP: {
567                 char buf[1024];
568                 
569                 if ( map->lm_args == NULL ) {
570                         rc = REWRITE_ERR;
571                         break;
572                 }
573                 
574 #ifdef USE_REWRITE_LDAP_PVT_THREADS
575                 ldap_pvt_thread_mutex_lock( &map->lm_mutex );
576 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
577
578                 rewind( ( FILE * )map->lm_args );
579                 
580                 while ( fgets( buf, sizeof( buf ), ( FILE * )map->lm_args ) ) {
581                         char *p;
582                         int blen;
583                         
584                         blen = strlen( buf );
585                         if ( buf[ blen - 1 ] == '\n' ) {
586                                 buf[ blen - 1 ] = '\0';
587                         }
588                         
589                         p = strtok( buf, " " );
590                         if ( p == NULL ) {
591 #ifdef USE_REWRITE_LDAP_PVT_THREADS
592                                 ldap_pvt_thread_mutex_unlock( &map->lm_mutex );
593 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
594                                 rc = REWRITE_ERR;
595                                 goto rc_return;
596                         }
597                         if ( strcasecmp( p, key->bv_val ) == 0 
598                                         && ( p = strtok( NULL, "" ) ) ) {
599                                 val->bv_val = strdup( p );
600                                 if ( val->bv_val == NULL ) {
601                                         return REWRITE_ERR;
602                                 }
603
604                                 val->bv_len = strlen( p );
605                                 
606 #ifdef USE_REWRITE_LDAP_PVT_THREADS
607                                 ldap_pvt_thread_mutex_unlock( &map->lm_mutex );
608 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
609                                 
610                                 goto rc_return;
611                         }
612                 }
613
614 #ifdef USE_REWRITE_LDAP_PVT_THREADS
615                 ldap_pvt_thread_mutex_unlock( &map->lm_mutex );
616 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
617
618                 rc = REWRITE_ERR;
619                 
620                 break;
621         }
622
623         case REWRITE_MAP_XLDAPMAP: {
624                 LDAP *ld;
625                 char filter[ LDAP_FILT_MAXSIZ ];
626                 LDAPMessage *res = NULL, *entry;
627                 LDAPURLDesc *lud = ( LDAPURLDesc * )map->lm_args;
628                 int attrsonly = 0;
629                 char **values;
630
631                 assert( lud != NULL );
632
633                 /*
634                  * No mutex because there is no write on the map data
635                  */
636                 
637                 ld = ldap_init( lud->lud_host, lud->lud_port );
638                 if ( ld == NULL ) {
639                         rc = REWRITE_ERR;
640                         goto rc_return;
641                 }
642
643                 snprintf( filter, sizeof( filter ), lud->lud_filter,
644                                 key->bv_val );
645
646                 if ( strcasecmp( lud->lud_attrs[ 0 ], "dn" ) == 0 ) {
647                         attrsonly = 1;
648                 }
649                 rc = ldap_search_s( ld, lud->lud_dn, lud->lud_scope,
650                                 filter, lud->lud_attrs, attrsonly, &res );
651                 if ( rc != LDAP_SUCCESS ) {
652                         ldap_unbind( ld );
653                         rc = REWRITE_ERR;
654                         goto rc_return;
655                 }
656
657                 if ( ldap_count_entries( ld, res ) != 1 ) {
658                         ldap_unbind( ld );
659                         rc = REWRITE_ERR;
660                         goto rc_return;
661                 }
662
663                 entry = ldap_first_entry( ld, res );
664                 if ( entry == NULL ) {
665                         ldap_msgfree( res );
666                         ldap_unbind( ld );
667                         rc = REWRITE_ERR;
668                         goto rc_return;
669                 }
670                 if ( attrsonly == 1 ) {
671                         val->bv_val = ldap_get_dn( ld, entry );
672                         if ( val->bv_val == NULL ) {
673                                 ldap_msgfree( res );
674                                 ldap_unbind( ld );
675                                 rc = REWRITE_ERR;
676                                 goto rc_return;
677                         }
678                 } else {
679                         values = ldap_get_values( ld, entry,
680                                         lud->lud_attrs[0] );
681                         if ( values == NULL ) {
682                                 ldap_msgfree( res );
683                                 ldap_unbind( ld );
684                                 rc = REWRITE_ERR;
685                                 goto rc_return;
686                         }
687                         val->bv_val = strdup( values[ 0 ] );
688                         ldap_value_free( values );
689                 }
690                 val->bv_len = strlen( val->bv_val );
691
692                 ldap_msgfree( res );
693                 ldap_unbind( ld );
694                 
695                 rc = REWRITE_SUCCESS;
696         }
697         }
698
699 rc_return:;
700         return rc;
701 }
702
703 /*
704  * Applies the new map type
705  */
706 int
707 rewrite_map_apply(
708                 struct rewrite_info *info,
709                 struct rewrite_op *op,
710                 struct rewrite_map *map,
711                 struct berval *key,
712                 struct berval *val
713 )
714 {
715         int rc = REWRITE_SUCCESS;
716
717         assert( info != NULL );
718         assert( op != NULL );
719         assert( map != NULL );
720         assert( key != NULL );
721         assert( val != NULL );
722
723         val->bv_val = NULL;
724         val->bv_len = 0;
725         
726         switch ( map->lm_type ) {
727         case REWRITE_MAP_SUBCONTEXT:
728                 rc = rewrite_context_apply( info, op, 
729                                 ( struct rewrite_context * )map->lm_data,
730                                 key->bv_val, &val->bv_val );
731                 if ( val->bv_val != NULL ) {
732                         val->bv_len = strlen( val->bv_val );
733                 }
734                 break;
735
736         case REWRITE_MAP_SET_OP_VAR:
737         case REWRITE_MAP_SETW_OP_VAR:
738                 rc = rewrite_var_set( &op->lo_vars, map->lm_name,
739                                 key->bv_val, 1 )
740                         ? REWRITE_SUCCESS : REWRITE_ERR;
741                 if ( map->lm_type == REWRITE_MAP_SET_OP_VAR ) {
742                         val->bv_val = strdup( "" );
743                 } else {
744                         val->bv_val = strdup( key->bv_val );
745                         val->bv_len = key->bv_len;
746                 }
747                 break;
748         
749         case REWRITE_MAP_GET_OP_VAR: {
750                 struct rewrite_var *var;
751
752                 var = rewrite_var_find( op->lo_vars, map->lm_name );
753                 if ( var == NULL ) {
754                         rc = REWRITE_ERR;
755                 } else {
756                         val->bv_val = strdup( var->lv_value.bv_val );
757                         val->bv_len = var->lv_value.bv_len;
758                 }
759                 break;  
760         }
761
762         case REWRITE_MAP_SET_SESN_VAR:
763         case REWRITE_MAP_SETW_SESN_VAR:
764                 if ( op->lo_cookie == NULL ) {
765                         rc = REWRITE_ERR;
766                         break;
767                 }
768                 rc = rewrite_session_var_set( info, op->lo_cookie, 
769                                 map->lm_name, key->bv_val );
770                 if ( map->lm_type == REWRITE_MAP_SET_SESN_VAR ) {
771                         val->bv_val = strdup( "" );
772                 } else {
773                         val->bv_val = strdup( key->bv_val );
774                         val->bv_len = key->bv_len;
775                 }
776                 break;
777
778         case REWRITE_MAP_GET_SESN_VAR:
779                 rc = rewrite_session_var_get( info, op->lo_cookie,
780                                 map->lm_name, val );
781                 break;          
782
783         case REWRITE_MAP_GET_PARAM:
784                 rc = rewrite_param_get( info, map->lm_name, val );
785                 break;
786
787         case REWRITE_MAP_BUILTIN: {
788                 struct rewrite_builtin_map *bmap = map->lm_data;
789                 switch ( bmap->lb_type ) {
790                 case REWRITE_BUILTIN_MAP_LDAP:
791                         rc = map_ldap_apply( bmap, key->bv_val, val );
792                         break;
793                 default:
794                         rc = REWRITE_ERR;
795                         break;
796                 }
797                 break;
798         }
799
800         default:
801                 rc = REWRITE_ERR;
802                 break;
803         }
804
805         return rc;
806 }
807