27RCSID(
"$Id: 3992d7d7edaeb41b78556cc77873c1030c9dd0ca $")
29#include <freeradius-devel/server/base.h>
30#include <freeradius-devel/server/module_rlm.h>
31#include <freeradius-devel/unlang/call_env.h>
32#include <freeradius-devel/unlang/xlat_func.h>
33#include <freeradius-devel/util/debug.h>
99 struct wbcContext *wb_ctx;
102 gid_t *wb_groups = NULL;
104 char const *domain = NULL;
105 size_t domain_len = 0;
107 char *username_buff = NULL;
108 size_t backslash = 0;
122 domain = env->
domain.vb_strvalue;
123 domain_len = env->
domain.vb_length;
130 RWDEBUG(
"Searching group with plain username, this will probably fail");
131 RWDEBUG(
"Ensure winbind domain is correctly set");
137 wbctx = winbind_slab_reserve(t->
slab);
139 RERROR(
"Unable to get winbind context");
146 err = wbcCtxGetGroups(wb_ctx,
username, &num_groups, &wb_groups);
148 case WBC_ERR_SUCCESS:
154 RDEBUG2(
"Successfully retrieved user's groups");
157 case WBC_ERR_WINBIND_NOT_AVAILABLE:
158 RERROR(
"Failed retrieving groups: Unable to contact winbindd");
161 case WBC_ERR_DOMAIN_NOT_FOUND:
163 REDEBUG(
"Failed retrieving groups: User or Domain not found");
166 case WBC_ERR_UNKNOWN_USER:
167 REDEBUG(
"Failed retrieving groups: User cannot be found");
171 REDEBUG(
"Failed retrieving groups: %s", wbcErrorString(
err));
188 if (domain_len > 0) backslash = domain_len - 1;
190 for (i = 0; i < num_groups; i++) {
195 err = wbcCtxGetgrgid(wb_ctx, wb_groups[i], &group);
196 if (
err != WBC_ERR_SUCCESS) {
197 REDEBUG(
"Failed resolving GID %i: %s", wb_groups[i], wbcErrorString(
err));
198 if (wb_groups[i] == UINT32_MAX) {
199 REDEBUG(
"GID appears to be winbind placeholder value, idmap likely failed");
204 RDEBUG3(
"Resolved GID %i to name \"%s\"", wb_groups[i], group->gr_name);
207 if ((backslash < strlen(group->gr_name)) && (group->gr_name[backslash] ==
'\\')) {
208 group_name = group->gr_name + backslash + 1;
209 }
else if ((group_name = strchr(group->gr_name,
'\\'))) {
211 backslash = group_name - (group->gr_name - 1);
213 group_name = group->gr_name;
217 RDEBUG3(
"Checking plain group name \"%s\"", group_name);
219 RDEBUG2(
"Found matching group: %s", group_name);
222 wbcFreeMemory(group);
228 if (!rcode)
RWDEBUG2(
"No groups found that match");
231 wbcFreeMemory(wb_groups);
232 winbind_slab_release(wbctx);
258 char const *p = arg->vb_strvalue;
276 wbcCtxFree(wbctx->
ctx);
285 wbctx->
ctx = wbcCtxCreate();
313 if (!
inst->auth_type) {
314 WARN(
"Failed to find 'authenticate %s {...}' section. Winbind authentication will likely not work",
341 REDEBUG2(
"No %s found in the request; not doing winbind authentication.",
346 if (!
inst->auth_type) {
347 WARN(
"No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup Winbind authentication",
373 REDEBUG(
"User-Password must not be empty");
383 RDEBUG2(
"Login attempt with password");
392 RDEBUG2(
"User authenticated successfully using winbind");
403 .pair.dflt =
"&User-Password", .pair.dflt_quote =
T_BARE_WORD },
412 tmpl_t *parsed_tmpl = NULL;
413 struct wbcInterfaceDetails *wb_info = NULL;
419 NULL, t_rules) < 0)
return -1;
426 struct wbcContext *wb_ctx;
428 cf_log_warn(ci,
"winbind domain unspecified; trying to get it from winbind");
430 wb_ctx = wbcCtxCreate();
433 cf_log_err(ci,
"Unable to get libwbclient context, cannot get domain");
437 err = wbcCtxInterfaceDetails(wb_ctx, &wb_info);
440 if (
err != WBC_ERR_SUCCESS) {
441 cf_log_err(ci,
"libwbclient returned wbcErr code %d; unable to get domain name.",
err);
442 cf_log_err(ci,
"Is winbind running and does the winbind_privileged socket have");
447 if (!wb_info->netbios_domain) {
448 cf_log_err(ci,
"winbind returned blank domain name");
453 &
FR_SBUFF_IN(wb_info->netbios_domain, strlen(wb_info->netbios_domain)),
457 wbcFreeMemory(wb_info);
461 cf_log_info(ci,
"Using winbind_domain '%s'", parsed_tmpl->name);
464 wbcFreeMemory(wb_info);
467 *(
void **)
out = parsed_tmpl;
468 return parsed_tmpl ? 0 : -1;
478 .pair.dflt =
"&User-Password", .pair.dflt_quote =
T_BARE_WORD },
534 ERROR(
"Connection handle pool instantiation failed");
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
int do_auth_wbclient_pap(request_t *request, winbind_auth_call_env_t *env, rlm_winbind_thread_t *t)
PAP authentication direct to winbind via Samba's libwbclient library.
#define CALL_ENV_TERMINATOR
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
call_env_parser_t const * env
Parsing rules for call method env.
#define FR_CALL_ENV_SUBSECTION(_name, _name2, _flags, _subcs)
Specify a call_env_parser_t which defines a nested subsection.
@ CALL_ENV_FLAG_ATTRIBUTE
Tmpl must contain an attribute reference.
@ CALL_ENV_FLAG_PARSE_ONLY
The result of parsing will not be evaluated at runtime.
@ CALL_ENV_FLAG_SECRET
The value is a secret, and should not be logged.
@ CALL_ENV_FLAG_REQUIRED
Associated conf pair or section is required.
#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 FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
#define CONF_PARSER_TERMINATOR
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Defines a CONF_PAIR to C data type mapping.
Common header for all CONF_* types.
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_info(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
#define cf_log_warn(_cf, _fmt,...)
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.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
static xlat_action_t winbind_group_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Check if the user is a member of a particular winbind group.
#define REXDENT()
Exdent (unindent) R* messages by one level.
#define RDEBUG_ENABLED3
True if request debug level 1-3 messages are enabled.
#define RWDEBUG2(fmt,...)
#define REDEBUG2(fmt,...)
#define RINDENT()
Indent R* messages by one level.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_BOOL
A truth value.
#define fr_skip_whitespace(_p)
Skip whitespace ('\t', '\n', '\v', '\f', '\r', ' ')
int strcasecmp(char *s1, char *s2)
void * env_data
Per call environment data.
module_instance_t const * mi
Instance of the module being instantiated.
void * thread
Thread specific instance data.
fr_event_list_t * el
Event list to register any IO handlers and timers against.
void * thread
Thread instance 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.
Temporary structure to hold arguments for thread_instantiation calls.
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)
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.
module_t common
Common fields presented by all modules.
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.
static const conf_parser_t config[]
#define RETURN_MODULE_REJECT
#define RETURN_MODULE_NOOP
#define RETURN_MODULE_INVALID
rlm_rcode_t
Return codes indicating the result of the module call.
static int instantiate(module_inst_ctx_t const *mctx)
static int domain_call_env_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, UNUSED call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
static const call_env_method_t winbind_autz_method_env
static xlat_arg_parser_t const winbind_group_xlat_arg[]
static int winbind_ctx_alloc(winbind_ctx_t *wbctx, UNUSED void *uctx)
fr_dict_attr_autoload_t rlm_winbind_dict_attr[]
static const call_env_method_t winbind_auth_method_env
static const conf_parser_t group_config[]
static fr_dict_t const * dict_freeradius
static fr_dict_attr_t const * attr_expr_bool_enum
static unlang_action_t mod_authenticate(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Authenticate the user via libwbclient and winbind.
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Bootstrap this module.
static fr_dict_attr_t const * attr_auth_type
static conf_parser_t reuse_winbind_config[]
static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Authorize for libwbclient/winbind authentication.
static int _mod_ctx_free(winbind_ctx_t *wbctx)
static const call_env_method_t winbind_group_xlat_call_env
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static bool winbind_check_group(rlm_winbind_t const *inst, request_t *request, char const *name, winbind_group_xlat_call_env_t *env, rlm_winbind_thread_t *t)
Group comparison for Winbind-Group.
static const conf_parser_t module_config[]
fr_dict_autoload_t rlm_winbind_dict[]
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate this module.
rlm_winbind_t const * inst
Instance of rlm_winbind.
winbind_slab_list_t * slab
Slab list for winbind handles.
#define FR_SBUFF_IN(_start, _len_or_end)
#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.
CONF_SECTION * conf
Module's instance configuration.
size_t inst_size
Size of the module's instance data.
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.
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Optional arguments passed to vp_tmpl functions.
#define FR_SLAB_CONFIG_CONF_PARSER
conf_parser_t entries to populate user configurable slab values
eap_aka_sim_process_conf_t * inst
Stores an attribute, a value and various bits of other data.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
#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.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
static size_t char ** out
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.