]> git.sur5r.net Git - openldap/blob - libraries/librewrite/map.c
Resync with HEAD
[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                         if ( p[ 1 ] != '\0' )
261                                 p++;
262                 } else if ( p[ 0 ] == '}' ) {
263                         cnt--;
264                 }
265         }
266         if ( cnt != 0 ) {
267                 return NULL;
268         }
269         *currpos = p;
270         
271         /*
272          * Copy the map invocation
273          */
274         l = p - string - 1;
275         s = calloc( sizeof( char ), l + 1 );
276         AC_MEMCPY( s, string, l );
277         s[ l ] = 0;
278
279         /*
280          * Isolate the map name (except for variable deref)
281          */
282         switch ( s[ 0 ] ) {
283         case REWRITE_OPERATOR_VARIABLE_GET:
284         case REWRITE_OPERATOR_PARAM_GET:
285                 break;
286         default:
287                 begin = strchr( s, '(' );
288                 if ( begin == NULL ) {
289                         free( s );
290                         return NULL;
291                 }
292                 begin[ 0 ] = '\0';
293                 begin++;
294                 break;
295         }
296
297         /*
298          * Check for special map types
299          */
300         p = s;
301         switch ( p[ 0 ] ) {
302         case REWRITE_OPERATOR_SUBCONTEXT:
303         case REWRITE_OPERATOR_COMMAND:
304         case REWRITE_OPERATOR_VARIABLE_SET:
305         case REWRITE_OPERATOR_VARIABLE_GET:
306         case REWRITE_OPERATOR_PARAM_GET:
307                 p++;
308                 break;
309         }
310
311         /*
312          * Variable set and get may be repeated to indicate session-wide
313          * instead of operation-wide variables
314          */
315         switch ( p[ 0 ] ) {
316         case REWRITE_OPERATOR_VARIABLE_SET:
317         case REWRITE_OPERATOR_VARIABLE_GET:
318                 p++;
319                 break;
320         }
321
322         /*
323          * Variable get token can be appended to variable set to mean store
324          * AND rewrite
325          */
326         if ( p[ 0 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
327                 p++;
328         }
329         
330         /*
331          * Check the syntax of the variable name
332          */
333         if ( !isalpha( (unsigned char) p[ 0 ] ) ) {
334                 free( s );
335                 return NULL;
336         }
337         for ( p++; p[ 0 ] != '\0'; p++ ) {
338                 if ( !isalnum( (unsigned char) p[ 0 ] ) ) {
339                         free( s );
340                         return NULL;
341                 }
342         }
343
344         /*
345          * Isolate the argument of the map (except for variable deref)
346          */
347         switch ( s[ 0 ] ) {
348         case REWRITE_OPERATOR_VARIABLE_GET:
349         case REWRITE_OPERATOR_PARAM_GET:
350                 break;
351         default:
352                 end = strrchr( begin, ')' );
353                 if ( end == NULL ) {
354                         free( s );
355                         return NULL;
356                 }
357                 end[ 0 ] = '\0';
358
359                 /*
360                  * Compile the substitution pattern of the map argument
361                  */
362                 subst = rewrite_subst_compile( info, begin );
363                 if ( subst == NULL ) {
364                         free( s );
365                         return NULL;
366                 }
367                 break;
368         }
369
370         /*
371          * Create the map
372          */
373         map = calloc( sizeof( struct rewrite_map ), 1 );
374         if ( map == NULL ) {
375                 if ( subst != NULL ) {
376                         free( subst );
377                 }
378                 free( s );
379                 return NULL;
380         }
381         
382 #ifdef USE_REWRITE_LDAP_PVT_THREADS
383         if ( ldap_pvt_thread_mutex_init( &map->lm_mutex ) ) {
384                 if ( subst != NULL ) {
385                         free( subst );
386                 }
387                 free( s );
388                 free( map );
389                 return NULL;
390         }
391 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
392                         
393         /*
394          * No subst for variable deref
395          */
396         switch ( s[ 0 ] ) {
397         case REWRITE_OPERATOR_VARIABLE_GET:
398         case REWRITE_OPERATOR_PARAM_GET:
399                 break;
400         default:
401                 map->lm_subst = subst;
402                 break;
403         }
404
405         /*
406          * Parses special map types
407          */
408         switch ( s[ 0 ] ) {
409         
410         /*
411          * Subcontext
412          */
413         case REWRITE_OPERATOR_SUBCONTEXT:               /* '>' */
414
415                 /*
416                  * Fetch the rewrite context
417                  * it MUST have been defined previously
418                  */
419                 map->lm_type = REWRITE_MAP_SUBCONTEXT;
420                 map->lm_name = strdup( s + 1 );
421                 map->lm_data = rewrite_context_find( info, s + 1 );
422                 if ( map->lm_data == NULL ) {
423                         free( s );
424                         free( map );
425                         return NULL;
426                 }
427                 break;
428
429         /*
430          * External command
431          */
432         case REWRITE_OPERATOR_COMMAND:          /* '|' */
433                 free( map );
434                 map = NULL;
435                 break;
436         
437         /*
438          * Variable set
439          */
440         case REWRITE_OPERATOR_VARIABLE_SET:     /* '&' */
441                 if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_SET ) {
442                         if ( s[ 2 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
443                                 map->lm_type = REWRITE_MAP_SETW_SESN_VAR;
444                                 map->lm_name = strdup( s + 3 );
445                         } else {
446                                 map->lm_type = REWRITE_MAP_SET_SESN_VAR;
447                                 map->lm_name = strdup( s + 2 );
448                         }
449                 } else {
450                         if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
451                                 map->lm_type = REWRITE_MAP_SETW_OP_VAR;
452                                 map->lm_name = strdup( s + 2 );
453                         } else {
454                                 map->lm_type = REWRITE_MAP_SET_OP_VAR;
455                                 map->lm_name = strdup( s + 1 );
456                         }
457                 }
458                 break;
459         
460         /*
461          * Variable dereference
462          */
463         case REWRITE_OPERATOR_VARIABLE_GET:     /* '*' */
464                 if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
465                         map->lm_type = REWRITE_MAP_GET_SESN_VAR;
466                         map->lm_name = strdup( s + 2 );
467                 } else {
468                         map->lm_type = REWRITE_MAP_GET_OP_VAR;
469                         map->lm_name = strdup( s + 1 );
470                 }
471                 break;
472         
473         /*
474          * Parameter
475          */
476         case REWRITE_OPERATOR_PARAM_GET:                /* '$' */
477                 map->lm_type = REWRITE_MAP_GET_PARAM;
478                 map->lm_name = strdup( s + 1 );
479                 break;
480         
481         /*
482          * Built-in map
483          */
484         default:
485                 map->lm_type = REWRITE_MAP_BUILTIN;
486                 map->lm_name = strdup( s );
487                 map->lm_data = rewrite_builtin_map_find( info, s );
488                 if ( map->lm_data == NULL ) {
489                         return NULL;
490                 }
491                 break;
492
493         }
494         
495         free( s );
496         return map;
497 }
498
499 /*
500  * Map key -> value resolution
501  * NOTE: these are old-fashion maps; new maps will be parsed on separate
502  * config lines, and referred by name.
503  */
504 int
505 rewrite_xmap_apply(
506                 struct rewrite_info *info,
507                 struct rewrite_op *op,
508                 struct rewrite_map *map,
509                 struct berval *key,
510                 struct berval *val
511 )
512 {
513         int rc = REWRITE_SUCCESS;
514         
515         assert( info != NULL );
516         assert( op != NULL );
517         assert( map != NULL );
518         assert( key != NULL );
519         assert( val != NULL );
520         
521         val->bv_val = NULL;
522         val->bv_len = 0;
523         
524         switch ( map->lm_type ) {
525 #ifdef HAVE_GETPWNAM
526         case REWRITE_MAP_XPWDMAP: {
527                 struct passwd *pwd;
528
529 #ifdef USE_REWRITE_LDAP_PVT_THREADS
530                 ldap_pvt_thread_mutex_lock( &xpasswd_mutex );
531 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
532                 
533                 pwd = getpwnam( key->bv_val );
534                 if ( pwd == NULL ) {
535
536 #ifdef USE_REWRITE_LDAP_PVT_THREADS
537                         ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
538 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
539
540                         rc = REWRITE_NO_SUCH_OBJECT;
541                         break;
542                 }
543
544                 if ( pwd->pw_gecos != NULL && pwd->pw_gecos[0] != '\0' ) {
545                         int l = strlen( pwd->pw_gecos );
546                         
547                         val->bv_val = strdup( pwd->pw_gecos );
548                         if ( val->bv_val == NULL ) {
549
550 #ifdef USE_REWRITE_LDAP_PVT_THREADS
551                                 ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
552 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
553
554                                 rc = REWRITE_ERR;
555                                 break;
556                         }
557                         val->bv_len = l;
558                 } else {
559                         val->bv_val = strdup( key->bv_val );
560                         val->bv_len = key->bv_len;
561                 }
562
563 #ifdef USE_REWRITE_LDAP_PVT_THREADS
564                 ldap_pvt_thread_mutex_unlock( &xpasswd_mutex );
565 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
566                         
567                 break;
568         }
569 #endif /* HAVE_GETPWNAM*/
570         
571         case REWRITE_MAP_XFILEMAP: {
572                 char buf[1024];
573                 
574                 if ( map->lm_args == NULL ) {
575                         rc = REWRITE_ERR;
576                         break;
577                 }
578                 
579 #ifdef USE_REWRITE_LDAP_PVT_THREADS
580                 ldap_pvt_thread_mutex_lock( &map->lm_mutex );
581 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
582
583                 rewind( ( FILE * )map->lm_args );
584                 
585                 while ( fgets( buf, sizeof( buf ), ( FILE * )map->lm_args ) ) {
586                         char *p;
587                         int blen;
588                         
589                         blen = strlen( buf );
590                         if ( buf[ blen - 1 ] == '\n' ) {
591                                 buf[ blen - 1 ] = '\0';
592                         }
593                         
594                         p = strtok( buf, " " );
595                         if ( p == NULL ) {
596 #ifdef USE_REWRITE_LDAP_PVT_THREADS
597                                 ldap_pvt_thread_mutex_unlock( &map->lm_mutex );
598 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
599                                 rc = REWRITE_ERR;
600                                 goto rc_return;
601                         }
602                         if ( strcasecmp( p, key->bv_val ) == 0 
603                                         && ( p = strtok( NULL, "" ) ) ) {
604                                 val->bv_val = strdup( p );
605                                 if ( val->bv_val == NULL ) {
606                                         return REWRITE_ERR;
607                                 }
608
609                                 val->bv_len = strlen( p );
610                                 
611 #ifdef USE_REWRITE_LDAP_PVT_THREADS
612                                 ldap_pvt_thread_mutex_unlock( &map->lm_mutex );
613 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
614                                 
615                                 goto rc_return;
616                         }
617                 }
618
619 #ifdef USE_REWRITE_LDAP_PVT_THREADS
620                 ldap_pvt_thread_mutex_unlock( &map->lm_mutex );
621 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
622
623                 rc = REWRITE_ERR;
624                 
625                 break;
626         }
627
628         case REWRITE_MAP_XLDAPMAP: {
629                 LDAP *ld;
630                 char filter[ LDAP_FILT_MAXSIZ ];
631                 LDAPMessage *res = NULL, *entry;
632                 LDAPURLDesc *lud = ( LDAPURLDesc * )map->lm_args;
633                 int attrsonly = 0;
634                 char **values;
635
636                 assert( lud != NULL );
637
638                 /*
639                  * No mutex because there is no write on the map data
640                  */
641                 
642                 ld = ldap_init( lud->lud_host, lud->lud_port );
643                 if ( ld == NULL ) {
644                         rc = REWRITE_ERR;
645                         goto rc_return;
646                 }
647
648                 snprintf( filter, sizeof( filter ), lud->lud_filter,
649                                 key->bv_val );
650
651                 if ( strcasecmp( lud->lud_attrs[ 0 ], "dn" ) == 0 ) {
652                         attrsonly = 1;
653                 }
654                 rc = ldap_search_s( ld, lud->lud_dn, lud->lud_scope,
655                                 filter, lud->lud_attrs, attrsonly, &res );
656                 if ( rc != LDAP_SUCCESS ) {
657                         ldap_unbind( ld );
658                         rc = REWRITE_ERR;
659                         goto rc_return;
660                 }
661
662                 if ( ldap_count_entries( ld, res ) != 1 ) {
663                         ldap_unbind( ld );
664                         rc = REWRITE_ERR;
665                         goto rc_return;
666                 }
667
668                 entry = ldap_first_entry( ld, res );
669                 if ( entry == NULL ) {
670                         ldap_msgfree( res );
671                         ldap_unbind( ld );
672                         rc = REWRITE_ERR;
673                         goto rc_return;
674                 }
675                 if ( attrsonly == 1 ) {
676                         val->bv_val = ldap_get_dn( ld, entry );
677                         if ( val->bv_val == NULL ) {
678                                 ldap_msgfree( res );
679                                 ldap_unbind( ld );
680                                 rc = REWRITE_ERR;
681                                 goto rc_return;
682                         }
683                 } else {
684                         values = ldap_get_values( ld, entry,
685                                         lud->lud_attrs[0] );
686                         if ( values == NULL ) {
687                                 ldap_msgfree( res );
688                                 ldap_unbind( ld );
689                                 rc = REWRITE_ERR;
690                                 goto rc_return;
691                         }
692                         val->bv_val = strdup( values[ 0 ] );
693                         ldap_value_free( values );
694                 }
695                 val->bv_len = strlen( val->bv_val );
696
697                 ldap_msgfree( res );
698                 ldap_unbind( ld );
699                 
700                 rc = REWRITE_SUCCESS;
701         }
702         }
703
704 rc_return:;
705         return rc;
706 }
707
708 /*
709  * Applies the new map type
710  */
711 int
712 rewrite_map_apply(
713                 struct rewrite_info *info,
714                 struct rewrite_op *op,
715                 struct rewrite_map *map,
716                 struct berval *key,
717                 struct berval *val
718 )
719 {
720         int rc = REWRITE_SUCCESS;
721
722         assert( info != NULL );
723         assert( op != NULL );
724         assert( map != NULL );
725         assert( key != NULL );
726         assert( val != NULL );
727
728         val->bv_val = NULL;
729         val->bv_len = 0;
730         
731         switch ( map->lm_type ) {
732         case REWRITE_MAP_SUBCONTEXT:
733                 rc = rewrite_context_apply( info, op, 
734                                 ( struct rewrite_context * )map->lm_data,
735                                 key->bv_val, &val->bv_val );
736                 if ( val->bv_val != NULL ) {
737                         val->bv_len = strlen( val->bv_val );
738                 }
739                 break;
740
741         case REWRITE_MAP_SET_OP_VAR:
742         case REWRITE_MAP_SETW_OP_VAR:
743                 rc = rewrite_var_set( &op->lo_vars, map->lm_name,
744                                 key->bv_val, 1 )
745                         ? REWRITE_SUCCESS : REWRITE_ERR;
746                 if ( map->lm_type == REWRITE_MAP_SET_OP_VAR ) {
747                         val->bv_val = strdup( "" );
748                 } else {
749                         val->bv_val = strdup( key->bv_val );
750                         val->bv_len = key->bv_len;
751                 }
752                 break;
753         
754         case REWRITE_MAP_GET_OP_VAR: {
755                 struct rewrite_var *var;
756
757                 var = rewrite_var_find( op->lo_vars, map->lm_name );
758                 if ( var == NULL ) {
759                         rc = REWRITE_ERR;
760                 } else {
761                         val->bv_val = strdup( var->lv_value.bv_val );
762                         val->bv_len = var->lv_value.bv_len;
763                 }
764                 break;  
765         }
766
767         case REWRITE_MAP_SET_SESN_VAR:
768         case REWRITE_MAP_SETW_SESN_VAR:
769                 if ( op->lo_cookie == NULL ) {
770                         rc = REWRITE_ERR;
771                         break;
772                 }
773                 rc = rewrite_session_var_set( info, op->lo_cookie, 
774                                 map->lm_name, key->bv_val );
775                 if ( map->lm_type == REWRITE_MAP_SET_SESN_VAR ) {
776                         val->bv_val = strdup( "" );
777                 } else {
778                         val->bv_val = strdup( key->bv_val );
779                         val->bv_len = key->bv_len;
780                 }
781                 break;
782
783         case REWRITE_MAP_GET_SESN_VAR:
784                 rc = rewrite_session_var_get( info, op->lo_cookie,
785                                 map->lm_name, val );
786                 break;          
787
788         case REWRITE_MAP_GET_PARAM:
789                 rc = rewrite_param_get( info, map->lm_name, val );
790                 break;
791
792         case REWRITE_MAP_BUILTIN: {
793                 struct rewrite_builtin_map *bmap = map->lm_data;
794                 switch ( bmap->lb_type ) {
795                 case REWRITE_BUILTIN_MAP_LDAP:
796                         rc = map_ldap_apply( bmap, key->bv_val, val );
797                         break;
798                 default:
799                         rc = REWRITE_ERR;
800                         break;
801                 }
802                 break;
803         }
804
805         default:
806                 rc = REWRITE_ERR;
807                 break;
808         }
809
810         return rc;
811 }
812