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
|
|
|
*
|
2016-01-30 03:32:05 +08:00
|
|
|
* Copyright 2000-2016 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>
|
|
|
|
|
2003-12-14 10:47:42 +08:00
|
|
|
#define LDAP_DEPRECATED 1
|
2001-05-12 08:51:28 +08:00
|
|
|
#include "rewrite-int.h"
|
|
|
|
#include "rewrite-map.h"
|
|
|
|
|
2006-09-25 01:50:48 +08:00
|
|
|
typedef enum {
|
|
|
|
MAP_LDAP_UNKNOWN,
|
|
|
|
MAP_LDAP_EVERYTIME,
|
|
|
|
MAP_LDAP_NOW,
|
|
|
|
MAP_LDAP_LATER
|
|
|
|
} bindwhen_t;
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* LDAP map data structure
|
|
|
|
*/
|
|
|
|
struct ldap_map_data {
|
2003-11-29 19:09:52 +08:00
|
|
|
char *lm_url;
|
|
|
|
LDAPURLDesc *lm_lud;
|
2006-09-23 21:04:55 +08:00
|
|
|
int lm_version;
|
2003-11-29 19:09:52 +08:00
|
|
|
char *lm_binddn;
|
2006-09-25 01:26:17 +08:00
|
|
|
struct berval lm_cred;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2006-09-25 01:50:48 +08:00
|
|
|
bindwhen_t lm_when;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
LDAP *lm_ld;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2006-09-23 21:04:55 +08:00
|
|
|
int lm_wantdn;
|
|
|
|
char *lm_attrs[ 2 ];
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
2003-11-29 19:09:52 +08:00
|
|
|
ldap_pvt_thread_mutex_t lm_mutex;
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
map_ldap_free(
|
|
|
|
struct ldap_map_data *data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
assert( data != NULL );
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_url != NULL ) {
|
|
|
|
free( data->lm_url );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_lud != NULL ) {
|
|
|
|
ldap_free_urldesc( data->lm_lud );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_binddn != NULL ) {
|
|
|
|
free( data->lm_binddn );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2006-09-25 01:26:17 +08:00
|
|
|
if ( data->lm_cred.bv_val != NULL ) {
|
|
|
|
memset( data->lm_cred.bv_val, 0, data->lm_cred.bv_len );
|
|
|
|
free( data->lm_cred.bv_val );
|
|
|
|
data->lm_cred.bv_val = NULL;
|
|
|
|
data->lm_cred.bv_len = 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_when != MAP_LDAP_EVERYTIME && data->lm_ld != NULL ) {
|
2006-09-25 01:26:17 +08:00
|
|
|
ldap_unbind_ext( data->lm_ld, NULL, NULL );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
free( data );
|
|
|
|
}
|
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
static void *
|
2001-05-12 08:51:28 +08:00
|
|
|
map_ldap_parse(
|
|
|
|
const char *fname,
|
|
|
|
int lineno,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ldap_map_data *data;
|
2006-09-25 01:50:48 +08:00
|
|
|
char *p, *uri;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
assert( fname != NULL );
|
|
|
|
assert( argv != NULL );
|
|
|
|
|
|
|
|
data = calloc( sizeof( struct ldap_map_data ), 1 );
|
|
|
|
if ( data == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( argc < 1 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"[%s:%d] ldap map needs URI\n%s",
|
|
|
|
fname, lineno, "" );
|
|
|
|
free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-25 01:50:48 +08:00
|
|
|
uri = argv[ 0 ];
|
|
|
|
if ( strncasecmp( uri, "uri=", STRLENOF( "uri=" ) ) == 0 ) {
|
|
|
|
uri += STRLENOF( "uri=" );
|
|
|
|
}
|
|
|
|
|
|
|
|
data->lm_url = strdup( uri );
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_url == NULL ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-25 01:50:48 +08:00
|
|
|
if ( ldap_url_parse( uri, &data->lm_lud ) != REWRITE_SUCCESS ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"[%s:%d] illegal URI '%s'\n",
|
|
|
|
fname, lineno, argv[ 0 ] );
|
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-25 01:50:48 +08:00
|
|
|
/* trim everything after [host][:port] */
|
2003-11-29 19:09:52 +08:00
|
|
|
p = strchr( data->lm_url, '/' );
|
2001-05-12 08:51:28 +08:00
|
|
|
assert( p[ 1 ] == '/' );
|
|
|
|
if ( ( p = strchr( p + 2, '/' ) ) != NULL ) {
|
|
|
|
p[ 0 ] = '\0';
|
|
|
|
}
|
|
|
|
|
2006-09-23 21:04:55 +08:00
|
|
|
if ( data->lm_lud->lud_attrs == NULL ) {
|
|
|
|
data->lm_attrs[ 0 ] = LDAP_NO_ATTRS;
|
|
|
|
data->lm_wantdn = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if ( data->lm_lud->lud_attrs[ 1 ] != NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"[%s:%d] only one attribute allowed in URI\n",
|
|
|
|
fname, lineno, 0 );
|
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( data->lm_lud->lud_attrs[ 0 ], "dn" ) == 0
|
|
|
|
|| strcasecmp( data->lm_lud->lud_attrs[ 0 ], "entryDN" ) == 0 )
|
|
|
|
{
|
|
|
|
ldap_memfree( data->lm_lud->lud_attrs[ 0 ] );
|
|
|
|
ldap_memfree( data->lm_lud->lud_attrs );
|
|
|
|
data->lm_lud->lud_attrs = NULL;
|
|
|
|
data->lm_attrs[ 0 ] = LDAP_NO_ATTRS;
|
|
|
|
data->lm_wantdn = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
data->lm_attrs[ 0 ] = data->lm_lud->lud_attrs[ 0 ];
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2006-09-23 21:04:55 +08:00
|
|
|
|
|
|
|
data->lm_attrs[ 1 ] = NULL;
|
|
|
|
|
|
|
|
/* safe defaults */
|
|
|
|
data->lm_version = LDAP_VERSION3;
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
for ( argc--, argv++; argc > 0; argc--, argv++ ) {
|
2006-09-23 21:04:55 +08:00
|
|
|
if ( strncasecmp( argv[ 0 ], "binddn=", STRLENOF( "binddn=" ) ) == 0 ) {
|
|
|
|
char *p = argv[ 0 ] + STRLENOF( "binddn=" );
|
2001-05-12 08:51:28 +08:00
|
|
|
int l;
|
|
|
|
|
|
|
|
if ( p[ 0 ] == '\"' || p [ 0 ] == '\'' ) {
|
|
|
|
l = strlen( p ) - 2;
|
|
|
|
p++;
|
|
|
|
if ( p[ l ] != p[ 0 ] ) {
|
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
l = strlen( p );
|
|
|
|
}
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
data->lm_binddn = strdup( p );
|
|
|
|
if ( data->lm_binddn == NULL ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_binddn[ l ] == '\"'
|
|
|
|
|| data->lm_binddn[ l ] == '\'' ) {
|
|
|
|
data->lm_binddn[ l ] = '\0';
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2006-09-23 21:04:55 +08:00
|
|
|
|
2006-09-25 01:26:17 +08:00
|
|
|
/* deprecated */
|
2006-09-23 21:04:55 +08:00
|
|
|
} else if ( strncasecmp( argv[ 0 ], "bindpw=", STRLENOF( "bindpw=" ) ) == 0 ) {
|
2006-09-25 01:26:17 +08:00
|
|
|
ber_str2bv( argv[ 0 ] + STRLENOF( "bindpw=" ), 0, 1, &data->lm_cred );
|
|
|
|
if ( data->lm_cred.bv_val == NULL ) {
|
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( strncasecmp( argv[ 0 ], "credentials=", STRLENOF( "credentials=" ) ) == 0 ) {
|
|
|
|
ber_str2bv( argv[ 0 ] + STRLENOF( "credentials=" ), 0, 1, &data->lm_cred );
|
|
|
|
if ( data->lm_cred.bv_val == NULL ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-09-23 21:04:55 +08:00
|
|
|
|
|
|
|
} else if ( strncasecmp( argv[ 0 ], "bindwhen=", STRLENOF( "bindwhen=" ) ) == 0 ) {
|
|
|
|
char *p = argv[ 0 ] + STRLENOF( "bindwhen=" );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
if ( strcasecmp( p, "now" ) == 0 ) {
|
|
|
|
int rc;
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
data->lm_when = MAP_LDAP_NOW;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Init LDAP handler ...
|
|
|
|
*/
|
2003-11-29 19:09:52 +08:00
|
|
|
rc = ldap_initialize( &data->lm_ld, data->lm_url );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-23 21:04:55 +08:00
|
|
|
ldap_set_option( data->lm_ld,
|
|
|
|
LDAP_OPT_PROTOCOL_VERSION,
|
|
|
|
(void *)&data->lm_version );
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
2003-11-29 19:09:52 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &data->lm_mutex );
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
|
|
|
|
} else if ( strcasecmp( p, "later" ) == 0 ) {
|
2003-11-29 19:09:52 +08:00
|
|
|
data->lm_when = MAP_LDAP_LATER;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
2003-11-29 19:09:52 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &data->lm_mutex );
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
|
|
|
|
} else if ( strcasecmp( p, "everytime" ) == 0 ) {
|
2003-11-29 19:09:52 +08:00
|
|
|
data->lm_when = MAP_LDAP_EVERYTIME;
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
|
|
|
/* ignore ... */
|
|
|
|
}
|
2006-09-23 21:04:55 +08:00
|
|
|
|
|
|
|
} else if ( strncasecmp( argv[ 0 ], "version=", STRLENOF( "version=" ) ) == 0 ) {
|
|
|
|
if ( lutil_atoi( &data->lm_version, argv[ 0 ] + STRLENOF( "version=" ) ) ) {
|
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( data->lm_version ) {
|
|
|
|
case LDAP_VERSION2:
|
|
|
|
case LDAP_VERSION3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"[%s:%d] unknown version %s\n",
|
|
|
|
fname, lineno, p );
|
|
|
|
map_ldap_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"[%s:%d] unknown option %s (ignored)\n",
|
|
|
|
fname, lineno, argv[0] );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-25 01:50:48 +08:00
|
|
|
if ( data->lm_when == MAP_LDAP_UNKNOWN ) {
|
|
|
|
data->lm_when = MAP_LDAP_EVERYTIME;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
return ( void * )data;
|
|
|
|
}
|
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
static int
|
2001-05-12 08:51:28 +08:00
|
|
|
map_ldap_apply(
|
2007-01-13 07:20:17 +08:00
|
|
|
void *private,
|
2001-05-12 08:51:28 +08:00
|
|
|
const char *filter,
|
|
|
|
struct berval *val
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LDAP *ld;
|
|
|
|
LDAPMessage *res = NULL, *entry;
|
|
|
|
int rc;
|
2007-01-13 07:20:17 +08:00
|
|
|
struct ldap_map_data *data = private;
|
2003-11-29 19:09:52 +08:00
|
|
|
LDAPURLDesc *lud = data->lm_lud;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2006-09-23 21:04:55 +08:00
|
|
|
int first_try = 1, set_version = 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
assert( private != NULL );
|
2001-05-12 08:51:28 +08:00
|
|
|
assert( filter != NULL );
|
|
|
|
assert( val != NULL );
|
|
|
|
|
|
|
|
val->bv_val = NULL;
|
|
|
|
val->bv_len = 0;
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_when == MAP_LDAP_EVERYTIME ) {
|
|
|
|
rc = ldap_initialize( &ld, data->lm_url );
|
2006-09-23 21:04:55 +08:00
|
|
|
set_version = 1;
|
2003-11-29 19:09:52 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
2003-11-29 19:09:52 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &data->lm_mutex );
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
|
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_when == MAP_LDAP_LATER && data->lm_ld == NULL ) {
|
|
|
|
rc = ldap_initialize( &data->lm_ld, data->lm_url );
|
2006-09-23 21:04:55 +08:00
|
|
|
set_version = 1;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
ld = data->lm_ld;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
rc = REWRITE_ERR;
|
|
|
|
goto rc_return;
|
|
|
|
}
|
|
|
|
|
2001-06-03 16:52:22 +08:00
|
|
|
do_bind:;
|
2006-09-23 21:04:55 +08:00
|
|
|
if ( set_version ) {
|
|
|
|
ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
|
|
|
|
(void *)&data->lm_version );
|
|
|
|
set_version = 0;
|
|
|
|
}
|
|
|
|
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_binddn != NULL ) {
|
2006-09-25 01:26:17 +08:00
|
|
|
rc = ldap_sasl_bind_s( ld, data->lm_binddn,
|
|
|
|
LDAP_SASL_SIMPLE, &data->lm_cred,
|
|
|
|
NULL, NULL, NULL );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( rc == LDAP_SERVER_DOWN && first_try ) {
|
|
|
|
first_try = 0;
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( ldap_initialize( &ld, data->lm_url ) != LDAP_SUCCESS ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
rc = REWRITE_ERR;
|
|
|
|
goto rc_return;
|
|
|
|
}
|
2006-09-23 21:04:55 +08:00
|
|
|
set_version = 1;
|
2001-05-12 08:51:28 +08:00
|
|
|
goto do_bind;
|
2003-11-29 19:09:52 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else if ( rc != REWRITE_SUCCESS ) {
|
|
|
|
rc = REWRITE_ERR;
|
|
|
|
goto rc_return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-25 01:26:17 +08:00
|
|
|
rc = ldap_search_ext_s( ld, lud->lud_dn, lud->lud_scope, ( char * )filter,
|
|
|
|
data->lm_attrs, 0, NULL, NULL, NULL, 1, &res );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( rc == LDAP_SERVER_DOWN && first_try ) {
|
|
|
|
first_try = 0;
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( ldap_initialize( &ld, data->lm_url ) != LDAP_SUCCESS ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
rc = REWRITE_ERR;
|
|
|
|
goto rc_return;
|
|
|
|
}
|
2006-09-23 21:04:55 +08:00
|
|
|
set_version = 1;
|
2001-05-12 08:51:28 +08:00
|
|
|
goto do_bind;
|
2003-11-29 19:09:52 +08:00
|
|
|
|
2006-09-25 01:26:17 +08:00
|
|
|
} else if ( rc != LDAP_SUCCESS ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
rc = REWRITE_ERR;
|
|
|
|
goto rc_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ldap_count_entries( ld, res ) != 1 ) {
|
|
|
|
ldap_msgfree( res );
|
|
|
|
rc = REWRITE_ERR;
|
|
|
|
goto rc_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = ldap_first_entry( ld, res );
|
|
|
|
assert( entry != NULL );
|
|
|
|
|
2006-09-23 21:04:55 +08:00
|
|
|
if ( data->lm_wantdn == 1 ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* dn is newly allocated, so there's no need to strdup it
|
|
|
|
*/
|
|
|
|
val->bv_val = ldap_get_dn( ld, entry );
|
2006-09-25 01:26:17 +08:00
|
|
|
val->bv_len = strlen( val->bv_val );
|
2003-11-29 19:09:52 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
2006-09-25 01:26:17 +08:00
|
|
|
struct berval **values;
|
|
|
|
|
|
|
|
values = ldap_get_values_len( ld, entry, data->lm_attrs[ 0 ] );
|
|
|
|
if ( values != NULL ) {
|
|
|
|
if ( values[ 0 ] != NULL && values[ 0 ]->bv_val != NULL ) {
|
|
|
|
#if 0
|
|
|
|
/* NOTE: in principle, multiple values
|
|
|
|
* should not be acceptable according
|
|
|
|
* to the current API; ignore by now */
|
|
|
|
if ( values[ 1 ] != NULL ) {
|
|
|
|
/* error */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ber_dupbv( val, values[ 0 ] );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2006-09-25 01:26:17 +08:00
|
|
|
ldap_value_free_len( values );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_msgfree( res );
|
|
|
|
|
|
|
|
if ( val->bv_val == NULL ) {
|
|
|
|
rc = REWRITE_ERR;
|
|
|
|
goto rc_return;
|
|
|
|
}
|
|
|
|
|
2001-06-03 16:52:22 +08:00
|
|
|
rc_return:;
|
2003-11-29 19:09:52 +08:00
|
|
|
if ( data->lm_when == MAP_LDAP_EVERYTIME ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( ld != NULL ) {
|
2006-09-25 01:26:17 +08:00
|
|
|
ldap_unbind_ext( ld, NULL, NULL );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-11-29 19:09:52 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
2003-11-29 19:09:52 +08:00
|
|
|
data->lm_ld = ld;
|
2001-05-12 08:51:28 +08:00
|
|
|
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
2003-11-29 19:09:52 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &data->lm_mutex );
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
static int
|
2003-11-15 04:00:20 +08:00
|
|
|
map_ldap_destroy(
|
2007-01-13 07:20:17 +08:00
|
|
|
void *private
|
2003-11-15 04:00:20 +08:00
|
|
|
)
|
|
|
|
{
|
2007-01-13 07:20:17 +08:00
|
|
|
struct ldap_map_data *data = private;
|
2003-11-15 04:00:20 +08:00
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
assert( private != NULL );
|
2003-11-15 04:00:20 +08:00
|
|
|
|
2006-09-25 01:26:17 +08:00
|
|
|
map_ldap_free( data );
|
2003-11-29 19:09:52 +08:00
|
|
|
|
2003-11-15 04:00:20 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-29 19:09:52 +08:00
|
|
|
|
2007-01-13 07:20:17 +08:00
|
|
|
const rewrite_mapper rewrite_ldap_mapper = {
|
|
|
|
"ldap",
|
|
|
|
map_ldap_parse,
|
|
|
|
map_ldap_apply,
|
|
|
|
map_ldap_destroy
|
|
|
|
};
|
|
|
|
|