*/
static const char rcsid[] = "$Id$";
-#include "autoconf.h"
+#include <freeradius-devel/autoconf.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <pthread.h>
-#include "radiusd.h"
-#include "conffile.h"
-#include "modules.h"
-#include "rad_assert.h"
+#include <freeradius-devel/radiusd.h>
+#include <freeradius-devel/conffile.h>
+#include <freeradius-devel/modules.h>
+#include <freeradius-devel/rad_assert.h>
#ifndef HAVE_PTHREAD_H
/*
char *tls_randfile;
char *tls_require_cert;
#ifdef NOVELL
- int edir_account_policy_check;
+ int edir_account_policy_check;
#endif
+ int set_auth_type;
} ldap_instance;
/* The default setting for TLS Certificate Verification */
static CONF_PARSER tls_config[] = {
{"start_tls", PW_TYPE_BOOLEAN,
offsetof(ldap_instance,start_tls), NULL, "no"},
- {"cacertfile", PW_TYPE_STRING_PTR,
+ {"cacertfile", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_cacertfile), NULL, NULL},
- {"cacertdir", PW_TYPE_STRING_PTR,
+ {"cacertdir", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_cacertdir), NULL, NULL},
- {"certfile", PW_TYPE_STRING_PTR,
+ {"certfile", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_certfile), NULL, NULL},
- {"keyfile", PW_TYPE_STRING_PTR,
+ {"keyfile", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_keyfile), NULL, NULL},
- {"randfile", PW_TYPE_STRING_PTR,
+ {"randfile", PW_TYPE_STRING_PTR, /* OK if it changes on HUP */
offsetof(ldap_instance,tls_randfile), NULL, NULL},
{"require_cert", PW_TYPE_STRING_PTR,
offsetof(ldap_instance,tls_require_cert), NULL, TLS_DEFAULT_VERIFY},
{"start_tls", PW_TYPE_BOOLEAN,
offsetof(ldap_instance,start_tls), NULL, "no"},
- {"tls_cacertfile", PW_TYPE_STRING_PTR,
+ {"tls_cacertfile", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_cacertfile), NULL, NULL},
- {"tls_cacertdir", PW_TYPE_STRING_PTR,
+ {"tls_cacertdir", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_cacertdir), NULL, NULL},
- {"tls_certfile", PW_TYPE_STRING_PTR,
+ {"tls_certfile", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_certfile), NULL, NULL},
- {"tls_keyfile", PW_TYPE_STRING_PTR,
+ {"tls_keyfile", PW_TYPE_FILENAME,
offsetof(ldap_instance,tls_keyfile), NULL, NULL},
- {"tls_randfile", PW_TYPE_STRING_PTR,
+ {"tls_randfile", PW_TYPE_STRING_PTR, /* OK if it changes on HUP */
offsetof(ldap_instance,tls_randfile), NULL, NULL},
{"tls_require_cert", PW_TYPE_STRING_PTR,
offsetof(ldap_instance,tls_require_cert), NULL, TLS_DEFAULT_VERIFY},
- { "tls", PW_TYPE_SUBSECTION, 0, tls_config, NULL },
+ { "tls", PW_TYPE_SUBSECTION, 0, NULL, (const void *) tls_config },
/*
* DN's and filters.
offsetof(ldap_instance,groupmemb_attr), NULL, NULL},
/* file with mapping between LDAP and RADIUS attributes */
- {"dictionary_mapping", PW_TYPE_STRING_PTR,
+ {"dictionary_mapping", PW_TYPE_FILENAME,
offsetof(ldap_instance,dictionary_mapping), NULL, "${confdir}/ldap.attrmap"},
/*
offsetof(ldap_instance,edir_account_policy_check), NULL, "yes"},
#endif
+ {"set_auth_type", PW_TYPE_BOOLEAN, offsetof(ldap_instance,set_auth_type), NULL, "yes"},
{NULL, -1, 0, NULL, NULL}
};
for(i=0;i<inst->num_conns;i++){
DEBUG("rlm_ldap: ldap_get_conn: Checking Id: %d",i);
- if ((conns[i].locked == 0) &&
- (pthread_mutex_trylock(&conns[i].mutex) == 0)) {
+ if ((pthread_mutex_trylock(&conns[i].mutex) == 0)) {
+ if (conns[i].locked == 1) {
+ /* connection is already being used */
+ pthread_mutex_unlock(&(conns[i].mutex));
+ continue;
+ }
+ /* found an unused connection */
*ret = &conns[i];
conns[i].locked = 1;
DEBUG("rlm_ldap: ldap_get_conn: Got Id: %d",i);
/*
* Allocate room for <instance>-Ldap-Group
*/
- group_name = malloc((strlen(xlat_name) + 1 + 11) * sizeof(char));
- rad_assert(group_name != NULL);
+ group_name = rad_malloc((strlen(xlat_name) + 1 + 11) * sizeof(char));
sprintf(group_name,"%s-Ldap-Group",xlat_name);
DEBUG("rlm_ldap: Creating new attribute %s",group_name);
dict_addattr(group_name, 0, PW_TYPE_STRING, -1, flags);
dattr = dict_attrbyname(group_name);
if (dattr == NULL){
radlog(L_ERR, "rlm_ldap: Failed to create attribute %s",group_name);
+ free(group_name);
free(inst); /* FIXME: detach */
return -1;
}
DEBUG("rlm_ldap: Registering ldap_groupcmp for %s",group_name);
paircompare_register(dattr->attr, PW_USER_NAME, ldap_groupcmp, inst);
+ free(group_name);
}
else {
xlat_name = cf_section_name1(conf);
DEBUG("rlm_ldap: Registering ldap_xlat with xlat_name %s",xlat_name);
xlat_register(xlat_name,ldap_xlat,inst);
+ /*
+ * Over-ride set_auth_type if there's no Auth-Type of our name.
+ * This automagically catches the case where LDAP is listed
+ * in "authorize", but not "authenticate".
+ */
+ if (inst->set_auth_type) {
+ DICT_VALUE *dv = dict_valbyname(PW_AUTH_TYPE, xlat_name);
+ if (!dv) {
+ DEBUG2("rlm_ldap: Over-riding set_auth_type, as we're not listed in the \"authenticate\" section.");
+ inst->set_auth_type = 0;
+ }
+ } /* else no need to look up the value */
+
#ifdef NOVELL
/*
* (LDAP_Instance, V1) attribute-value pair in the config
while (in[0]) {
/*
- * Only one byte left.
+ * Encode unsafe characters.
*/
- if (outlen <= 1) {
- break;
- }
+ if (strchr("*=\\,()", *in)) {
+ static const char hex[] = "0123456789abcdef";
- if (strchr("*", *in)) {
+ /*
+ * Only 3 or less bytes available.
+ */
+ if (outlen <= 3) {
+ break;
+ }
+
+ *(out++) = '\\';
+ *(out++) = hex[((*in) >> 4) & 0x0f];
+ *(out++) = hex[(*in) & 0x0f];
+ outlen -= 3;
+ len += 3;
in++;
- outlen--;
continue;
}
/*
- * Else it's a nice character.
+ * Only one byte left.
*/
- *out = *in;
- out++;
- in++;
+ if (outlen <= 1) {
+ break;
+ }
+
+ /*
+ * Allowed character.
+ */
+ *(out++) = *(in++);
outlen--;
len++;
}
/*
* ldap_groupcmp(). Implement the Ldap-Group == "group" filter
*/
-static int ldap_groupcmp(void *instance, REQUEST *req, VALUE_PAIR *request,
- VALUE_PAIR *check, VALUE_PAIR *check_pairs,
- VALUE_PAIR **reply_pairs)
+static int ldap_groupcmp(void *instance, REQUEST *req,
+ UNUSED VALUE_PAIR *request, VALUE_PAIR *check,
+ UNUSED VALUE_PAIR *check_pairs,
+ UNUSED VALUE_PAIR **reply_pairs)
{
char filter[MAX_FILTER_STR_LEN];
char gr_filter[MAX_FILTER_STR_LEN];
DEBUG("rlm_ldap: Entering ldap_groupcmp()");
- if (check->strvalue == NULL || check->length == 0){
+ if (check->vp_strvalue == NULL || check->length == 0){
DEBUG("rlm_ldap::ldap_groupcmp: Illegal group name");
return 1;
}
return 1;
}
- if (strchr((char *)check->strvalue,',') != NULL) {
+ if (strchr((char *)check->vp_strvalue,',') != NULL) {
/* This looks like a DN */
snprintf(filter,sizeof(filter), "%s",gr_filter);
- snprintf(basedn,sizeof(basedn), "%s",(char *)check->strvalue);
+ snprintf(basedn,sizeof(basedn), "%s",(char *)check->vp_strvalue);
} else
snprintf(filter,sizeof(filter), "(&(%s=%s)%s)",
inst->groupname_attr,
- (char *)check->strvalue,gr_filter);
+ (char *)check->vp_strvalue,gr_filter);
if ((conn_id = ldap_get_conn(inst->conns,&conn,inst)) == -1) {
radlog(L_ERR, "rlm_ldap: All ldap connections are in use");
if ((res = perform_search(inst, conn, basedn, LDAP_SCOPE_SUBTREE,
filter, attrs, &result)) == RLM_MODULE_OK) {
DEBUG("rlm_ldap::ldap_groupcmp: User found in group %s",
- (char *)check->strvalue);
+ (char *)check->vp_strvalue);
ldap_msgfree(result);
ldap_release_conn(conn_id,inst->conns);
return 0;
* membership using user object attributes is not
* specified in config file
*/
- DEBUG("rlm_ldap::ldap_groupcmp: Group %s not found or user is not a member.",(char *)check->strvalue);
+ DEBUG("rlm_ldap::ldap_groupcmp: Group %s not found or user is not a member.",(char *)check->vp_strvalue);
return 1;
}
radlog(L_ERR, "rlm_ldap: Add ldap connections are in use");
return 1;
}
- if ((res = perform_search(inst, conn, vp_user_dn->strvalue,
+ if ((res = perform_search(inst, conn, vp_user_dn->vp_strvalue,
LDAP_SCOPE_BASE, filter, group_attrs,
&result)) != RLM_MODULE_OK) {
DEBUG("rlm_ldap::ldap_groupcmp: Search returned error");
LDAPMessage *gr_result = NULL;
snprintf(filter,sizeof(filter), "(%s=%s)",
inst->groupname_attr,
- (char *)check->strvalue);
+ (char *)check->vp_strvalue);
if ((res = perform_search(inst, conn, vals[i],
LDAP_SCOPE_BASE, filter,
attrs, &gr_result)) != RLM_MODULE_OK){
break;
}
} else {
- if (strcmp(vals[i],(char *)check->strvalue) == 0){
+ if (strcmp(vals[i],(char *)check->vp_strvalue) == 0){
found = 1;
break;
}
ldap_msgfree(result);
if (found == 0){
DEBUG("rlm_ldap::groupcmp: Group %s not found or user not a member",
- (char *)check->strvalue);
+ (char *)check->vp_strvalue);
ldap_release_conn(conn_id,inst->conns);
return 1;
}
return 1;
}
- DEBUG("rlm_ldap::ldap_groupcmp: User found in group %s",(char *)check->strvalue);
+ DEBUG("rlm_ldap::ldap_groupcmp: User found in group %s",(char *)check->vp_strvalue);
ldap_release_conn(conn_id,inst->conns);
return 0;
/*
* Check for valid input, zero length names not permitted
*/
- if (request->username->strvalue == 0) {
+ if (request->username->vp_strvalue == 0) {
radlog(L_ERR, "rlm_ldap: zero length username not permitted\n");
return RLM_MODULE_INVALID;
}
DEBUG("rlm_ldap: performing user authorization for %s",
- request->username->strvalue);
+ request->username->vp_strvalue);
if (!radius_xlat(filter, sizeof(filter), inst->filter,
request, ldap_escape_func)) {
if (inst->access_attr) {
if ((vals = ldap_get_values(conn->ld, msg, inst->access_attr)) != NULL) {
if (inst->default_allow){
- DEBUG("rlm_ldap: checking if remote access for %s is allowed by %s", request->username->strvalue, inst->access_attr);
+ DEBUG("rlm_ldap: checking if remote access for %s is allowed by %s", request->username->vp_strvalue, inst->access_attr);
if (!strncmp(vals[0], "FALSE", 5)) {
DEBUG("rlm_ldap: dialup access disabled");
snprintf(module_fmsg,sizeof(module_fmsg),"rlm_ldap: Access Attribute denies access");
strNcpy(filter,inst->base_filter,sizeof(filter));
if (user_profile)
- profile = user_profile->strvalue;
+ profile = user_profile->vp_strvalue;
if (profile && strlen(profile)){
if ((res = perform_search(instance, conn,
profile, LDAP_SCOPE_BASE,
if (!p) continue;
if ((p - value + 1) >= sizeof(autobuf))
continue; /* paranoia */
- memcpy(autobuf, p, p - value + 1);
+ memcpy(autobuf, value, p - value + 1);
autobuf[p - value + 1] = '\0';
attr = lrad_str2int(header_names,
strlen(inst->passwd_hdr)) == 0) {
value += strlen(inst->passwd_hdr);
} else {
- DEBUG("rlm_ldap: Password header not found in password %s for user %s", passwd_vals[0], request->username->strvalue);
+ DEBUG("rlm_ldap: Password header not found in password %s for user %s", passwd_vals[0], request->username->vp_strvalue);
}
}
if (!value) continue;
ldap_release_conn(conn_id,inst->conns);
return RLM_MODULE_FAIL;
}
- strNcpy(passwd_item->strvalue, value,
- sizeof(passwd_item->strvalue));
- passwd_item->length = strlen(passwd_item->strvalue);
+ strNcpy(passwd_item->vp_strvalue, value,
+ sizeof(passwd_item->vp_strvalue));
+ passwd_item->length = strlen(passwd_item->vp_strvalue);
pairadd(&request->config_items,passwd_item);
DEBUG("rlm_ldap: Added %s = %s in check items",
passwd_item->name,
- passwd_item->strvalue);
+ passwd_item->vp_strvalue);
}
ldap_value_free(passwd_vals);
#ifdef NOVELL_UNIVERSAL_PASSWORD
memset(universal_password, 0, universal_password_len);
vp_user_dn = pairfind(request->config_items,PW_LDAP_USERDN);
- res = nmasldap_get_password(conn->ld,vp_user_dn->strvalue,&universal_password_len,universal_password);
+ res = nmasldap_get_password(conn->ld,vp_user_dn->vp_strvalue,&universal_password_len,universal_password);
if (res == 0){
passwd_val = universal_password;
if (passwd_val != NULL)
passwd_val += strlen((char*)inst->passwd_hdr);
else
- DEBUG("rlm_ldap: Password header not found in password %s for user %s ",passwd_val,request->username->strvalue);
+ DEBUG("rlm_ldap: Password header not found in password %s for user %s ",passwd_val,request->username->vp_strvalue);
}
if (passwd_val){
}
passwd_len = strlen(passwd_val);
- strncpy(passwd_item->strvalue,passwd_val,MAX_STRING_LEN - 1);
+ strncpy(passwd_item->vp_strvalue,passwd_val,MAX_STRING_LEN - 1);
passwd_item->length = (passwd_len > (MAX_STRING_LEN - 1)) ? (MAX_STRING_LEN - 1) : passwd_len;
pairadd(&request->config_items,passwd_item);
free(universal_password);
return RLM_MODULE_FAIL;
}
- strcpy(vp_inst->strvalue, inst->xlat_name);
- vp_inst->length = strlen(vp_inst->strvalue);
+ strcpy(vp_inst->vp_strvalue, inst->xlat_name);
+ vp_inst->length = strlen(vp_inst->vp_strvalue);
pairadd(&request->config_items, vp_inst);
/*
if(!inst->edir_account_policy_check){
/* Do nothing */
- strcpy(vp_apc->strvalue, "1");
+ strcpy(vp_apc->vp_strvalue, "1");
}else{
/* Perform eDirectory account-policy check */
- strcpy(vp_apc->strvalue, "2");
+ strcpy(vp_apc->vp_strvalue, "2");
}
vp_apc->length = 1;
pairadd(&request->config_items, vp_apc);
}
#endif
- DEBUG("rlm_ldap: Added the eDirectory password %s in check items as %s",passwd_item->strvalue,passwd_item->name);
+ DEBUG("rlm_ldap: Added the eDirectory password %s in check items as %s",passwd_item->vp_strvalue,passwd_item->name);
}
}
else {
pairadd(reply_pairs,reply_tmp);
}
- if (inst->do_comp && paircmp(request,request->packet->vps,*check_pairs,reply_pairs) != 0){
+ if (inst->do_comp && paircompare(request,request->packet->vps,*check_pairs,reply_pairs) != 0){
#ifdef NOVELL
/* Don't perform eDirectory APC if RADIUS authorize fails */
int apc_attr;
vp_apc = pairfind(request->config_items, apc_attr);
if(vp_apc)
- vp_apc->strvalue[0] = '1';
+ vp_apc->vp_strvalue[0] = '1';
#endif
DEBUG("rlm_ldap: Pairs do not match. Rejecting user.");
/*
* Module should default to LDAP authentication if no Auth-Type
- * specified
+ * specified. Note that we do this ONLY if configured, AND we
+ * set the Auth-Type to our module name, which allows multiple
+ * ldap instances to work.
*/
- if ((pairfind(*check_pairs, PW_AUTH_TYPE) == NULL) &&
+ if (inst->set_auth_type &&
+ (pairfind(*check_pairs, PW_AUTH_TYPE) == NULL) &&
request->password &&
(request->password->attribute == PW_USER_PASSWORD))
- pairadd(check_pairs, pairmake("Auth-Type", "LDAP", T_OP_EQ));
-
+ pairadd(check_pairs, pairmake("Auth-Type", inst->xlat_name, T_OP_EQ));
DEBUG("rlm_ldap: user %s authorized to use remote access",
- request->username->strvalue);
+ request->username->vp_strvalue);
ldap_msgfree(result);
ldap_release_conn(conn_id,inst->conns);
char module_fmsg[MAX_STRING_LEN];
LDAP_CONN *conn;
int conn_id = -1;
+#ifdef NOVELL
+ char *err = NULL;
+#endif
DEBUG("rlm_ldap: - authenticate");
DEBUG("rlm_ldap: login attempt by \"%s\" with password \"%s\"",
- request->username->strvalue, request->password->strvalue);
+ request->username->vp_strvalue, request->password->vp_strvalue);
while ((vp_user_dn = pairfind(request->config_items,
PW_LDAP_USERDN)) == NULL) {
ldap_msgfree(result);
}
- user_dn = vp_user_dn->strvalue;
+ user_dn = vp_user_dn->vp_strvalue;
DEBUG("rlm_ldap: user DN: %s", user_dn);
#ifndef NOVELL
- ld_user = ldap_connect(instance, user_dn, request->password->strvalue,
+ ld_user = ldap_connect(instance, user_dn, request->password->vp_strvalue,
1, &res, NULL);
#else
- ld_user = ldap_connect(instance, user_dn, request->password->strvalue,
+ ld_user = ldap_connect(instance, user_dn, request->password->vp_strvalue,
1, &res, &err);
if(err != NULL){
dattr = dict_attrbyname("eDir-APC");
apc_attr = dattr->attr;
vp_apc = pairfind(request->config_items, apc_attr);
- if(vp_apc && vp_apc->strvalue[0] == '2')
- vp_apc->strvalue[0] = '3';
+ if(vp_apc && vp_apc->vp_strvalue[0] == '2')
+ vp_apc->vp_strvalue[0] = '3';
}
#endif
}
DEBUG("rlm_ldap: user %s authenticated succesfully",
- request->username->strvalue);
+ request->username->vp_strvalue);
ldap_unbind_s(ld_user);
inst->failed_conns = 0;
* Check if the password in the config items list is the user's UP which has
* been read in the authorize method of this instance of the LDAP module.
*/
- if((vp_inst == NULL) || strcmp(vp_inst->strvalue, inst->xlat_name))
+ if((vp_inst == NULL) || strcmp(vp_inst->vp_strvalue, inst->xlat_name))
return RLM_MODULE_NOOP;
vp_apc = pairfind(request->config_items, apc_attr);
- switch(vp_apc->strvalue[0]){
+ switch(vp_apc->vp_strvalue[0]){
case '1':
/* Account policy check not enabled */
case '3':
break;
case '2':
{
- int err, conn_id = -1, i;
+ int err, conn_id = -1;
char *error_msg = NULL;
- LDAP *ld;
VALUE_PAIR *vp_fdn, *vp_pwd;
DICT_ATTR *da;
- ldap_instance *inst = instance;
- LDAP_CONN *conn;
if (request->reply->code == PW_AUTHENTICATION_REJECT) {
/* Bind to eDirectory as the RADIUS user with a wrong password. */
vp_pwd = pairfind(request->config_items, PW_PASSWORD);
- strcpy(password, vp_pwd->strvalue);
+ strcpy(password, vp_pwd->vp_strvalue);
if (strlen(password) > 0) {
if (password[0] != 'a') {
password[0] = 'a';
DEBUG("rlm_ldap: User's Universal Password not in config items list.");
return RLM_MODULE_FAIL;
}
- strcpy(password, vp_pwd->strvalue);
+ strcpy(password, vp_pwd->vp_strvalue);
}
if ((da = dict_attrbyname("Ldap-UserDn")) == NULL) {
DEBUG2("rlm_ldap: closing existing LDAP connection");
ldap_unbind_s(conn->ld);
}
- if ((conn->ld = ldap_connect(instance, (char *)vp_fdn->strvalue, password, 0, &res, &error_msg)) == NULL) {
+ if ((conn->ld = ldap_connect(instance, (char *)vp_fdn->vp_strvalue, password, 0, &res, &error_msg)) == NULL) {
radlog(L_ERR, "rlm_ldap: eDirectory account policy check failed.");
if (error_msg != NULL) {
ldap_memfree((void *)error_msg);
}
- vp_apc->strvalue[0] = '3';
+ vp_apc->vp_strvalue[0] = '3';
ldap_release_conn(conn_id, inst->apc_conns);
return RLM_MODULE_REJECT;
}
conn->bound = 1;
- } else if((err = ldap_simple_bind_s(conn->ld, (char *)vp_fdn->strvalue, password)) != LDAP_SUCCESS) {
+ } else if((err = ldap_simple_bind_s(conn->ld, (char *)vp_fdn->vp_strvalue, password)) != LDAP_SUCCESS) {
if (err == LDAP_SERVER_DOWN) {
conn->bound = 0;
goto postauth_reconnect;
pairadd(&request->reply->vps, pairmake("Reply-Message", error_msg, T_OP_EQ));
ldap_memfree((void *)error_msg);
}
- vp_apc->strvalue[0] = '3';
+ vp_apc->vp_strvalue[0] = '3';
ldap_release_conn(conn_id, inst->apc_conns);
return RLM_MODULE_REJECT;
}
- vp_apc->strvalue[0] = '3';
+ vp_apc->vp_strvalue[0] = '3';
ldap_release_conn(conn_id, inst->apc_conns);
return RLM_MODULE_OK;
}
}
-#ifdef HAVE_INT_TLS_CONFIG
+#ifdef HAVE_LDAP_INT_TLS_CONFIG
if (ldap_int_tls_config(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT,
(inst->tls_require_cert)) != LDAP_OPT_SUCCESS) {
radlog(L_ERR, "rlm_ldap: could not set "
int vals_count;
int vals_idx;
char *ptr;
+ char *value;
TLDAP_RADIUS *element;
- LRAD_TOKEN token;
+ LRAD_TOKEN token, operator;
int is_generic_attribute;
- char value[256];
+ char buf[MAX_STRING_LEN];
VALUE_PAIR *pairlist = NULL;
VALUE_PAIR *newpair = NULL;
+ char do_xlat = FALSE;
/*
* check if there is a mapping from this LDAP attribute
is_generic_attribute = 1;
else
is_generic_attribute = 0;
-
+
/*
* Find out how many values there are for the
* attribute and extract all of them.
*/
vals_count = ldap_count_values(vals);
-
+
for (vals_idx = 0; vals_idx < vals_count; vals_idx++) {
- ptr = vals[vals_idx];
-
+ value = vals[vals_idx];
+
if (is_generic_attribute) {
- /* this is a generic attribute */
+ /*
+ * This is a generic attribute.
+ */
LRAD_TOKEN dummy; /* makes pairread happy */
-
+
/* not sure if using pairread here is ok ... */
- if ( (newpair = pairread(&ptr, &dummy)) != NULL) {
+ if ( (newpair = pairread(&value, &dummy)) != NULL) {
DEBUG("rlm_ldap: extracted attribute %s from generic item %s",
newpair->name, vals[vals_idx]);
pairadd(&pairlist, newpair);
element->attr, vals[vals_idx]);
}
} else {
- /* this is a one-to-one-mapped attribute */
- token = gettoken(&ptr, value, sizeof(value) - 1);
- if (token < T_EQSTART || token > T_EQEND) {
- if (is_check) {
- token = T_OP_CMP_EQ;
- } else {
- token = T_OP_EQ;
- }
-
- if (element->operator != T_OP_INVALID) {
- token = element->operator;
- }
+ /*
+ * This is a one-to-one-mapped attribute
+ */
+ ptr = value;
+ operator = gettoken(&ptr, buf, sizeof(buf));
+ if (operator < T_EQSTART || operator > T_EQEND) {
+ /* no leading operator found */
+ if (element->operator != T_OP_INVALID)
+ operator = element->operator;
+ else if (is_check)
+ operator = T_OP_CMP_EQ;
+ else
+ operator = T_OP_EQ;
} else {
- gettoken(&ptr, value, sizeof(value) - 1);
+ /* the value is after the operator */
+ value = ptr;
}
- if (value[0] == 0) {
+
+ /*
+ * Do xlat if the *entire* string
+ * is quoted.
+ */
+ if ((value[0] == '\'' || value[0] == '"' ||
+ value[0] == '`') &&
+ (value[0] == value[strlen(value)-1])) {
+ ptr = value;
+ token = gettoken(&ptr, buf, sizeof(buf));
+ switch (token) {
+ /* take the unquoted string */
+ case T_SINGLE_QUOTED_STRING:
+ case T_DOUBLE_QUOTED_STRING:
+ value = buf;
+ break;
+
+ /* the value will be xlat'ed later */
+ case T_BACK_QUOTED_STRING:
+ value = NULL;
+ do_xlat = TRUE;
+ break;
+
+ /* keep the original string */
+ default:
+ break;
+ }
+ }
+ if (value[0] == '\0') {
DEBUG("rlm_ldap: Attribute %s has no value", element->attr);
- break;
+ continue;
}
DEBUG("rlm_ldap: Adding LDAP attribute %s as RADIUS attribute %s %s %s",
- element->attr,
- element->radius_attr,
- lrad_int2str(tokens, token, "?"), value);
- if ((newpair = pairmake(element->radius_attr, value, token)) == NULL)
+ element->attr, element->radius_attr,
+ lrad_int2str(tokens, operator, "?"),
+ value);
+
+ /*
+ * Create the pair.
+ */
+ newpair = pairmake(element->radius_attr,
+ value, operator);
+ if (newpair == NULL) {
+ radlog(L_ERR, "rlm_ldap: Failed to create the pair: %s", librad_errstr);
continue;
+ }
+ if (do_xlat) {
+ newpair->flags.do_xlat = 1;
+ strNcpy(newpair->vp_strvalue, buf,
+ sizeof(newpair->vp_strvalue));
+ newpair->length = 0;
+ }
+
+ /*
+ * Add the pair into the packet.
+ */
if (!vals_idx){
pairdelete(pairs, newpair->attribute);
}
/* globally exported name */
module_t rlm_ldap = {
+ RLM_MODULE_INIT,
"LDAP",
RLM_TYPE_THREAD_SAFE, /* type: reserved */
- NULL, /* initialization */
ldap_instantiate, /* instantiation */
+ ldap_detach, /* detach */
{
ldap_authenticate, /* authentication */
ldap_authorize, /* authorization */
NULL
#endif
},
- ldap_detach, /* detach */
- NULL, /* destroy */
};