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