*/
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 */
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,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}
};
/*
* 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 (outlen <= 3) break;
+ static const char hex[] = "0123456789abcdef";
+
+ /*
+ * 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++;
continue;
}
/*
- * Else it's a nice character.
+ * Only one byte left.
+ */
+ if (outlen <= 1) {
+ break;
+ }
+
+ /*
+ * Allowed character.
*/
*(out++) = *(in++);
outlen--;
/*
* 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);
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':
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;
}
}
if (do_xlat) {
newpair->flags.do_xlat = 1;
- strNcpy(newpair->strvalue, buf,
- sizeof(newpair->strvalue));
+ strNcpy(newpair->vp_strvalue, buf,
+ sizeof(newpair->vp_strvalue));
newpair->length = 0;
}