24 RCSID(
"$Id: 770156e5666917114753a2976460ecd582b8837c $")
26 #define LOG_PREFIX mctx->mi->name
28 #include <freeradius-devel/server/base.h>
29 #include <freeradius-devel/server/password.h>
30 #include <freeradius-devel/server/module_rlm.h>
31 #include <freeradius-devel/server/cf_parse.h>
32 #include <freeradius-devel/util/chap.h>
33 #include <freeradius-devel/unlang/xlat_func.h>
34 #include <freeradius-devel/unlang/call_env.h>
56 chap_challenge), .pair.dflt =
"&Chap-Challenge", .pair.dflt_quote =
T_BARE_WORD },
73 .pair.dflt =
"&Chap-Password", .pair.dflt_quote =
T_BARE_WORD },
77 .pair.dflt =
"&Chap-Challenge", .pair.dflt_quote =
T_BARE_WORD },
94 .pair.dflt =
"&User-Name", .pair.dflt_quote =
T_BARE_WORD },
98 .pair.dflt =
"&Chap-Password", .pair.dflt_quote =
T_BARE_WORD },
102 .pair.dflt =
"&Chap-Challenge", .pair.dflt_quote =
T_BARE_WORD },
148 size_t challenge_len;
162 RWDEBUG(
"&request.CHAP-Challenge shorter than minimum length (%ld)",
inst->min_challenge_len);
163 challenge = request->packet->vector;
167 in_head->vb_strvalue, in_head->vb_length);
183 RDEBUG3(
"Auth-Type is already set. Not setting 'Auth-Type := %s'", mctx->
mi->
name);
209 if (!
inst->auth_type) {
210 WARN(
"No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup CHAP authentication",
241 size_t challenge_len;
244 REDEBUG(
"&User-Name attribute is required for authentication");
249 REDEBUG(
"You set '&control.Auth-Type = CHAP' for a request that "
250 "does not contain a CHAP-Password attribute!");
255 REDEBUG(
"&request.CHAP-Password is empty");
260 REDEBUG(
"&request.CHAP-Password has invalid length");
274 REDEBUG(
"No \"known good\" password found for user");
292 RWDEBUG(
"&request.CHAP-Challenge shorter than minimum length (%ld)",
inst->min_challenge_len);
293 challenge = request->packet->vector;
297 known_good->vp_strvalue, known_good->vp_length);
309 RDEBUG2(
"Using challenge from &request.CHAP-Challenge");
313 RDEBUG2(
"Using challenge from authenticator field");
314 p = request->packet->vector;
315 length =
sizeof(request->packet->vector);
331 if (ephemeral) TALLOC_FREE(known_good);
333 REDEBUG(
"Password comparison failed: password is incorrect");
338 RDEBUG2(
"CHAP user \"%pV\" authenticated successfully", &env_data->
username);
352 if (!
inst->auth_type) {
353 WARN(
"Failed to find 'authenticate %s {...}' section. CHAP authentication will likely not work",
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
#define CALL_ENV_TERMINATOR
#define FR_CALL_ENV_PARSE_OFFSET(_name, _cast_type, _flags, _struct, _field, _parse_field)
Specify a call_env_parser_t which writes out runtime results and the result of the parsing phase to t...
call_env_parser_t const * env
Parsing rules for call method env.
@ CALL_ENV_FLAG_CONCAT
If the tmpl produced multiple boxes they should be concatenated.
@ CALL_ENV_FLAG_ATTRIBUTE
Tmpl must contain an attribute reference.
@ CALL_ENV_FLAG_REQUIRED
Associated conf pair or section is required.
@ CALL_ENV_FLAG_NULLABLE
Tmpl expansions are allowed to produce no output.
#define FR_CALL_ENV_OFFSET(_name, _cast_type, _flags, _struct, _field)
Specify a call_env_parser_t which writes out runtime results to the specified field.
#define CONF_PARSER_TERMINATOR
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Defines a CONF_PAIR to C data type mapping.
void fr_chap_encode(uint8_t out[static 1+FR_CHAP_CHALLENGE_LENGTH], uint8_t id, uint8_t const *challenge, size_t challenge_len, char const *password, size_t password_len)
Encode a CHAP password.
#define FR_CHAP_CHALLENGE_LENGTH
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Specifies an attribute which must be present for the module to function.
Specifies a dictionary which must be loaded/loadable for the module to function.
Value of an enumerated attribute.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
static xlat_action_t xlat_func_chap_password(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Produce a CHAP-Password hash value.
#define REXDENT()
Exdent (unindent) R* messages by one level.
#define RDEBUG_ENABLED3
True if request debug level 1-3 messages are enabled.
#define RINDENT()
Indent R* messages by one level.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_OCTETS
Raw octets.
int fr_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length)
Do a comparison of two authentication digests by comparing the FULL data.
void * env_data
Per call environment data.
module_instance_t const * mi
Instance of the module being instantiated.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for module calls.
Temporary structure to hold arguments for instantiation calls.
bool module_rlm_section_type_set(request_t *request, fr_dict_attr_t const *type_da, fr_dict_enum_value_t const *enumv)
Set the next section type if it's not already set.
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
module_t common
Common fields presented by all modules.
#define RADIUS_AUTH_VECTOR_LENGTH
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
fr_pair_t * password_find(bool *ephemeral, TALLOC_CTX *ctx, request_t *request, fr_dict_attr_t const *allowed_attrs[], size_t allowed_attrs_len, bool normify)
Find a "known good" password in the control list of a request.
static const conf_parser_t config[]
uint32_t fr_rand(void)
Return a 32-bit random number.
#define RETURN_MODULE_REJECT
#define RETURN_MODULE_NOOP
#define RETURN_MODULE_INVALID
rlm_rcode_t
Return codes indicating the result of the module call.
fr_dict_attr_autoload_t rlm_chap_dict_attr[]
static const call_env_method_t chap_autz_method_env
fr_value_box_t chap_password
fr_dict_enum_value_t * auth_type
static fr_dict_t const * dict_freeradius
fr_value_box_t chap_challenge
static unlang_action_t mod_authenticate(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
static int mod_bootstrap(module_inst_ctx_t const *mctx)
fr_value_box_t chap_password
fr_dict_autoload_t rlm_chap_dict[]
static const call_env_method_t chap_auth_method_env
static fr_dict_attr_t const * attr_auth_type
static xlat_arg_parser_t const xlat_func_chap_password_args[]
static fr_dict_attr_t const * attr_cleartext_password
static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
fr_value_box_t chap_challenge
static const call_env_method_t chap_xlat_method_env
tmpl_t * chap_challenge_tmpl
static const conf_parser_t module_config[]
static int mod_instantiate(module_inst_ctx_t const *mctx)
fr_value_box_t chap_challenge
static int instantiate(module_inst_ctx_t const *mctx)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
char const * name
Instance name e.g. user_database.
void * data
Module's instance data.
void * boot
Data allocated during the boostrap phase.
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Named methods exported by a module.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
eap_aka_sim_process_conf_t * inst
Stores an attribute, a value and various bits of other data.
#define talloc_get_type_abort_const
bool required
Argument must be present, and non-empty.
#define XLAT_ARG_PARSER_TERMINATOR
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition for a single argument consumend by an xlat function.
int fr_value_box_memdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted)
Copy a buffer to a fr_value_box_t.
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
static size_t char ** out
#define fr_box_octets(_val, _len)
void * env_data
Expanded call env data.
module_ctx_t const * mctx
Synthesised module calling ctx.
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env_method)
Register call environment of an xlat.