2003-12-09 01:41:40 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
2007-01-03 04:00:42 +08:00
|
|
|
* Copyright 2000-2007 The OpenLDAP Foundation.
|
2001-05-12 08:51:28 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2003-12-09 01:41:40 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
2003-12-09 01:41:40 +08:00
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENT:
|
|
|
|
* This work was initially developed by Pierangelo Masarati for
|
|
|
|
* inclusion in OpenLDAP Software.
|
|
|
|
*/
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#include <portable.h>
|
|
|
|
|
2002-07-26 21:21:27 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2001-12-07 11:19:29 +08:00
|
|
|
#ifdef HAVE_PWD_H
|
2001-05-12 08:51:28 +08:00
|
|
|
#include <pwd.h>
|
2001-12-07 11:19:29 +08:00
|
|
|
#endif
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#include "rewrite-int.h"
|
|
|
|
#include "rewrite-map.h"
|
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
static int num_mappers;
|
|
|
|
static const rewrite_mapper **mappers;
|
|
|
|
#define MAPPER_ALLOC 8
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
struct rewrite_map *
|
|
|
|
rewrite_map_parse(
|
|
|
|
struct rewrite_info *info,
|
|
|
|
const char *string,
|
|
|
|
const char **currpos
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct rewrite_map *map = NULL;
|
|
|
|
struct rewrite_subst *subst = NULL;
|
|
|
|
char *s, *begin = NULL, *end;
|
|
|
|
const char *p;
|
2003-11-15 02:39:18 +08:00
|
|
|
int l, cnt, mtx = 0, rc = 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
assert( info != NULL );
|
|
|
|
assert( string != NULL );
|
|
|
|
assert( currpos != NULL );
|
|
|
|
|
|
|
|
*currpos = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go to the end of the map invocation (the right closing brace)
|
|
|
|
*/
|
|
|
|
for ( p = string, cnt = 1; p[ 0 ] != '\0' && cnt > 0; p++ ) {
|
2004-03-11 03:21:39 +08:00
|
|
|
if ( IS_REWRITE_SUBMATCH_ESCAPE( p[ 0 ] ) ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
2002-04-16 02:29:39 +08:00
|
|
|
* '%' marks the beginning of a new map
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
|
|
|
if ( p[ 1 ] == '{' ) {
|
|
|
|
cnt++;
|
|
|
|
/*
|
2002-04-16 02:29:39 +08:00
|
|
|
* '%' followed by a digit may mark the beginning
|
2001-05-12 08:51:28 +08:00
|
|
|
* of an old map
|
|
|
|
*/
|
2002-04-08 17:43:22 +08:00
|
|
|
} else if ( isdigit( (unsigned char) p[ 1 ] ) && p[ 2 ] == '{' ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
cnt++;
|
|
|
|
p++;
|
|
|
|
}
|
2003-11-15 02:39:18 +08:00
|
|
|
|
|
|
|
if ( p[ 1 ] != '\0' ) {
|
2002-04-16 02:29:39 +08:00
|
|
|
p++;
|
2003-11-15 02:39:18 +08:00
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else if ( p[ 0 ] == '}' ) {
|
|
|
|
cnt--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( cnt != 0 ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*currpos = p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the map invocation
|
|
|
|
*/
|
|
|
|
l = p - string - 1;
|
|
|
|
s = calloc( sizeof( char ), l + 1 );
|
2001-10-22 17:39:02 +08:00
|
|
|
AC_MEMCPY( s, string, l );
|
2001-05-12 08:51:28 +08:00
|
|
|
s[ l ] = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Isolate the map name (except for variable deref)
|
|
|
|
*/
|
|
|
|
switch ( s[ 0 ] ) {
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_GET:
|
|
|
|
case REWRITE_OPERATOR_PARAM_GET:
|
|
|
|
break;
|
2003-11-15 02:39:18 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
default:
|
|
|
|
begin = strchr( s, '(' );
|
|
|
|
if ( begin == NULL ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
begin[ 0 ] = '\0';
|
|
|
|
begin++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for special map types
|
|
|
|
*/
|
|
|
|
p = s;
|
|
|
|
switch ( p[ 0 ] ) {
|
|
|
|
case REWRITE_OPERATOR_SUBCONTEXT:
|
|
|
|
case REWRITE_OPERATOR_COMMAND:
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_SET:
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_GET:
|
|
|
|
case REWRITE_OPERATOR_PARAM_GET:
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable set and get may be repeated to indicate session-wide
|
|
|
|
* instead of operation-wide variables
|
|
|
|
*/
|
|
|
|
switch ( p[ 0 ] ) {
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_SET:
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_GET:
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable get token can be appended to variable set to mean store
|
|
|
|
* AND rewrite
|
|
|
|
*/
|
|
|
|
if ( p[ 0 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the syntax of the variable name
|
|
|
|
*/
|
2002-04-08 17:43:22 +08:00
|
|
|
if ( !isalpha( (unsigned char) p[ 0 ] ) ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
for ( p++; p[ 0 ] != '\0'; p++ ) {
|
2002-04-08 17:43:22 +08:00
|
|
|
if ( !isalnum( (unsigned char) p[ 0 ] ) ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Isolate the argument of the map (except for variable deref)
|
|
|
|
*/
|
|
|
|
switch ( s[ 0 ] ) {
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_GET:
|
|
|
|
case REWRITE_OPERATOR_PARAM_GET:
|
|
|
|
break;
|
2003-11-15 02:39:18 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
default:
|
|
|
|
end = strrchr( begin, ')' );
|
|
|
|
if ( end == NULL ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
end[ 0 ] = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compile the substitution pattern of the map argument
|
|
|
|
*/
|
|
|
|
subst = rewrite_subst_compile( info, begin );
|
|
|
|
if ( subst == NULL ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the map
|
|
|
|
*/
|
|
|
|
map = calloc( sizeof( struct rewrite_map ), 1 );
|
|
|
|
if ( map == NULL ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-11-15 02:39:18 +08:00
|
|
|
memset( map, 0, sizeof( struct rewrite_map ) );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
|
|
|
if ( ldap_pvt_thread_mutex_init( &map->lm_mutex ) ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-11-15 02:39:18 +08:00
|
|
|
++mtx;
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No subst for variable deref
|
|
|
|
*/
|
|
|
|
switch ( s[ 0 ] ) {
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_GET:
|
|
|
|
case REWRITE_OPERATOR_PARAM_GET:
|
|
|
|
break;
|
2003-11-15 02:39:18 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
default:
|
|
|
|
map->lm_subst = subst;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parses special map types
|
|
|
|
*/
|
|
|
|
switch ( s[ 0 ] ) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Subcontext
|
|
|
|
*/
|
|
|
|
case REWRITE_OPERATOR_SUBCONTEXT: /* '>' */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch the rewrite context
|
|
|
|
* it MUST have been defined previously
|
|
|
|
*/
|
|
|
|
map->lm_type = REWRITE_MAP_SUBCONTEXT;
|
|
|
|
map->lm_name = strdup( s + 1 );
|
|
|
|
map->lm_data = rewrite_context_find( info, s + 1 );
|
|
|
|
if ( map->lm_data == NULL ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
2003-11-15 02:39:18 +08:00
|
|
|
* External command (not implemented yet)
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
|
|
|
case REWRITE_OPERATOR_COMMAND: /* '|' */
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable set
|
|
|
|
*/
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_SET: /* '&' */
|
|
|
|
if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_SET ) {
|
|
|
|
if ( s[ 2 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
|
|
|
|
map->lm_type = REWRITE_MAP_SETW_SESN_VAR;
|
|
|
|
map->lm_name = strdup( s + 3 );
|
|
|
|
} else {
|
|
|
|
map->lm_type = REWRITE_MAP_SET_SESN_VAR;
|
|
|
|
map->lm_name = strdup( s + 2 );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
|
|
|
|
map->lm_type = REWRITE_MAP_SETW_OP_VAR;
|
|
|
|
map->lm_name = strdup( s + 2 );
|
|
|
|
} else {
|
|
|
|
map->lm_type = REWRITE_MAP_SET_OP_VAR;
|
|
|
|
map->lm_name = strdup( s + 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable dereference
|
|
|
|
*/
|
|
|
|
case REWRITE_OPERATOR_VARIABLE_GET: /* '*' */
|
|
|
|
if ( s[ 1 ] == REWRITE_OPERATOR_VARIABLE_GET ) {
|
|
|
|
map->lm_type = REWRITE_MAP_GET_SESN_VAR;
|
|
|
|
map->lm_name = strdup( s + 2 );
|
|
|
|
} else {
|
|
|
|
map->lm_type = REWRITE_MAP_GET_OP_VAR;
|
|
|
|
map->lm_name = strdup( s + 1 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parameter
|
|
|
|
*/
|
|
|
|
case REWRITE_OPERATOR_PARAM_GET: /* '$' */
|
|
|
|
map->lm_type = REWRITE_MAP_GET_PARAM;
|
|
|
|
map->lm_name = strdup( s + 1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Built-in map
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
map->lm_type = REWRITE_MAP_BUILTIN;
|
|
|
|
map->lm_name = strdup( s );
|
|
|
|
map->lm_data = rewrite_builtin_map_find( info, s );
|
|
|
|
if ( map->lm_data == NULL ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-11-15 02:39:18 +08:00
|
|
|
cleanup:
|
|
|
|
free( s );
|
|
|
|
if ( rc ) {
|
|
|
|
if ( subst != NULL ) {
|
|
|
|
free( subst );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-11-15 02:39:18 +08:00
|
|
|
if ( map ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
2003-11-15 02:39:18 +08:00
|
|
|
if ( mtx ) {
|
|
|
|
ldap_pvt_thread_mutex_destroy( &map->lm_mutex );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
|
2003-11-15 02:39:18 +08:00
|
|
|
if ( map->lm_name ) {
|
|
|
|
free( map->lm_name );
|
|
|
|
map->lm_name = NULL;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-11-15 02:39:18 +08:00
|
|
|
free( map );
|
|
|
|
map = NULL;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-15 02:39:18 +08:00
|
|
|
return map;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Applies the new map type
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rewrite_map_apply(
|
|
|
|
struct rewrite_info *info,
|
|
|
|
struct rewrite_op *op,
|
|
|
|
struct rewrite_map *map,
|
|
|
|
struct berval *key,
|
|
|
|
struct berval *val
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc = REWRITE_SUCCESS;
|
|
|
|
|
|
|
|
assert( info != NULL );
|
|
|
|
assert( op != NULL );
|
|
|
|
assert( map != NULL );
|
|
|
|
assert( key != NULL );
|
|
|
|
assert( val != NULL );
|
|
|
|
|
|
|
|
val->bv_val = NULL;
|
|
|
|
val->bv_len = 0;
|
|
|
|
|
|
|
|
switch ( map->lm_type ) {
|
|
|
|
case REWRITE_MAP_SUBCONTEXT:
|
|
|
|
rc = rewrite_context_apply( info, op,
|
|
|
|
( struct rewrite_context * )map->lm_data,
|
|
|
|
key->bv_val, &val->bv_val );
|
|
|
|
if ( val->bv_val != NULL ) {
|
2006-09-24 00:10:07 +08:00
|
|
|
if ( val->bv_val == key->bv_val ) {
|
2006-09-23 23:43:55 +08:00
|
|
|
val->bv_len = key->bv_len;
|
|
|
|
key->bv_val = NULL;
|
|
|
|
} else {
|
|
|
|
val->bv_len = strlen( val->bv_val );
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_MAP_SET_OP_VAR:
|
|
|
|
case REWRITE_MAP_SETW_OP_VAR:
|
|
|
|
rc = rewrite_var_set( &op->lo_vars, map->lm_name,
|
|
|
|
key->bv_val, 1 )
|
|
|
|
? REWRITE_SUCCESS : REWRITE_ERR;
|
|
|
|
if ( map->lm_type == REWRITE_MAP_SET_OP_VAR ) {
|
|
|
|
val->bv_val = strdup( "" );
|
|
|
|
} else {
|
|
|
|
val->bv_val = strdup( key->bv_val );
|
|
|
|
val->bv_len = key->bv_len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_MAP_GET_OP_VAR: {
|
|
|
|
struct rewrite_var *var;
|
|
|
|
|
|
|
|
var = rewrite_var_find( op->lo_vars, map->lm_name );
|
|
|
|
if ( var == NULL ) {
|
|
|
|
rc = REWRITE_ERR;
|
|
|
|
} else {
|
|
|
|
val->bv_val = strdup( var->lv_value.bv_val );
|
|
|
|
val->bv_len = var->lv_value.bv_len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case REWRITE_MAP_SET_SESN_VAR:
|
|
|
|
case REWRITE_MAP_SETW_SESN_VAR:
|
|
|
|
if ( op->lo_cookie == NULL ) {
|
|
|
|
rc = REWRITE_ERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rc = rewrite_session_var_set( info, op->lo_cookie,
|
|
|
|
map->lm_name, key->bv_val );
|
|
|
|
if ( map->lm_type == REWRITE_MAP_SET_SESN_VAR ) {
|
|
|
|
val->bv_val = strdup( "" );
|
|
|
|
} else {
|
|
|
|
val->bv_val = strdup( key->bv_val );
|
|
|
|
val->bv_len = key->bv_len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_MAP_GET_SESN_VAR:
|
|
|
|
rc = rewrite_session_var_get( info, op->lo_cookie,
|
|
|
|
map->lm_name, val );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_MAP_GET_PARAM:
|
|
|
|
rc = rewrite_param_get( info, map->lm_name, val );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_MAP_BUILTIN: {
|
|
|
|
struct rewrite_builtin_map *bmap = map->lm_data;
|
2003-11-15 02:39:18 +08:00
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
if ( bmap->lb_mapper && bmap->lb_mapper->rm_apply )
|
|
|
|
rc = bmap->lb_mapper->rm_apply( bmap->lb_private, key->bv_val,
|
|
|
|
val );
|
|
|
|
else
|
2001-05-12 08:51:28 +08:00
|
|
|
rc = REWRITE_ERR;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
rc = REWRITE_ERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2003-11-15 04:00:20 +08:00
|
|
|
void
|
|
|
|
rewrite_builtin_map_free(
|
|
|
|
void *tmp
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct rewrite_builtin_map *map = ( struct rewrite_builtin_map * )tmp;
|
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( map != NULL );
|
2003-11-15 04:00:20 +08:00
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
if ( map->lb_mapper && map->lb_mapper->rm_destroy )
|
|
|
|
map->lb_mapper->rm_destroy( map->lb_private );
|
2003-11-15 04:00:20 +08:00
|
|
|
|
2003-11-15 18:02:44 +08:00
|
|
|
free( map->lb_name );
|
2003-11-15 04:00:20 +08:00
|
|
|
free( map );
|
|
|
|
}
|
|
|
|
|
2003-11-15 02:39:18 +08:00
|
|
|
int
|
|
|
|
rewrite_map_destroy(
|
|
|
|
struct rewrite_map **pmap
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct rewrite_map *map;
|
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( pmap != NULL );
|
|
|
|
assert( *pmap != NULL );
|
2003-11-15 02:39:18 +08:00
|
|
|
|
|
|
|
map = *pmap;
|
|
|
|
|
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
|
|
|
ldap_pvt_thread_mutex_lock( &map->lm_mutex );
|
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
|
|
|
|
if ( map->lm_name ) {
|
|
|
|
free( map->lm_name );
|
|
|
|
map->lm_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( map->lm_subst ) {
|
|
|
|
rewrite_subst_destroy( &map->lm_subst );
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
|
|
|
ldap_pvt_thread_mutex_unlock( &map->lm_mutex );
|
|
|
|
ldap_pvt_thread_mutex_destroy( &map->lm_mutex );
|
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
|
|
|
|
free( map );
|
|
|
|
*pmap = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
/* ldapmap.c */
|
|
|
|
extern const rewrite_mapper rewrite_ldap_mapper;
|
|
|
|
|
|
|
|
const rewrite_mapper *
|
|
|
|
rewrite_mapper_find(
|
|
|
|
const char *name
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( !strcasecmp( name, "ldap" ))
|
|
|
|
return &rewrite_ldap_mapper;
|
|
|
|
|
|
|
|
for (i=0; i<num_mappers; i++)
|
|
|
|
if ( !strcasecmp( name, mappers[i]->rm_name ))
|
|
|
|
return mappers[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rewrite_mapper_register(
|
|
|
|
const rewrite_mapper *map
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if ( num_mappers % MAPPER_ALLOC == 0 ) {
|
|
|
|
const rewrite_mapper **mnew;
|
|
|
|
mnew = realloc( mappers, (num_mappers + MAPPER_ALLOC) *
|
|
|
|
sizeof( rewrite_mapper * ));
|
|
|
|
if ( mnew )
|
|
|
|
mappers = mnew;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mappers[num_mappers++] = map;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rewrite_mapper_unregister(
|
|
|
|
const rewrite_mapper *map
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i<num_mappers; i++) {
|
|
|
|
if ( mappers[i] == map ) {
|
|
|
|
num_mappers--;
|
|
|
|
mappers[i] = mappers[num_mappers];
|
|
|
|
mappers[num_mappers] = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* not found */
|
|
|
|
return -1;
|
|
|
|
}
|