* - -1 on failure.
*/
int tmpl_attr_tail_unresolved_add(fr_dict_t *dict_def, tmpl_t *vpt,
- fr_type_t type, fr_dict_attr_flags_t const *flags)
+ fr_type_t type, fr_dict_attr_flags_t const *flags)
{
fr_dict_attr_t const *da;
+ fr_dict_attr_flags_t our_flags = *flags;
+
+ our_flags.name_only = true;
if (!vpt) return -1;
if (!tmpl_is_attr_unresolved(vpt)) return 1;
if (fr_dict_attr_add(dict_def,
- fr_dict_root(fr_dict_internal()), tmpl_attr_tail_unresolved(vpt), -1, type, flags) < 0) {
+ fr_dict_root(fr_dict_internal()), tmpl_attr_tail_unresolved(vpt), 0, type, &our_flags) < 0) {
return -1;
}
da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_def), tmpl_attr_tail_unresolved(vpt));
fr_dict_attr_flags_t flags = {
.internal = true,
+ .name_only = true,
.local = true,
};
return -1;
}
- if (fr_dict_attr_add(dict, parent, value, -1, type, &flags) < 0) {
+ if (fr_dict_attr_add(dict, parent, value, 0, type, &flags) < 0) {
cf_log_err(ci, "Failed adding local variable '%s' - %s", value, fr_strerror());
return -1;
}
* If the group attribute was not in the dictionary, create it
*/
if (!boot->group_da) {
- fr_dict_attr_flags_t flags;
+ fr_dict_attr_flags_t flags = { .name_only = 1 };
- memset(&flags, 0, sizeof(flags));
if (fr_dict_attr_add(fr_dict_unconst(dict_freeradius), fr_dict_root(dict_freeradius),
- group_attribute, -1, FR_TYPE_STRING, &flags) < 0) {
+ group_attribute, 0, FR_TYPE_STRING, &flags) < 0) {
PERROR("Error creating group attribute");
return -1;
* Setup the cache attribute
*/
if (inst->group.cache_attribute) {
- fr_dict_attr_flags_t flags;
+ fr_dict_attr_flags_t flags = { .name_only = 1 };
- memset(&flags, 0, sizeof(flags));
if (fr_dict_attr_add(fr_dict_unconst(dict_freeradius), fr_dict_root(dict_freeradius),
- inst->group.cache_attribute, -1, FR_TYPE_STRING, &flags) < 0) {
+ inst->group.cache_attribute, 0, FR_TYPE_STRING, &flags) < 0) {
PERROR("Error creating cache attribute");
return -1;
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/pairmove.h>
#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/dict.h>
#include <freeradius-devel/util/table.h>
#include <freeradius-devel/unlang/function.h>
#include <freeradius-devel/unlang/xlat_func.h>
*/
if (cf_pair_find(conf, "group_membership_query")) {
char const *group_attribute;
- fr_dict_attr_flags_t flags = {};
+ fr_dict_attr_flags_t flags = { .name_only = 1 };
char buffer[256];
if (inst->config.group_attribute) {
group_attribute = "SQL-Group";
}
- if (fr_dict_attr_add(fr_dict_unconst(dict_freeradius), fr_dict_root(dict_freeradius), group_attribute, -1,
- FR_TYPE_STRING, &flags) < 0) {
- cf_log_perr(conf, "Failed defining group attribute");
- return -1;
- }
-
- boot->group_da = fr_dict_attr_search_by_qualified_oid(NULL, dict_freeradius, group_attribute,
- false, false);
+ boot->group_da = fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), group_attribute);
if (!boot->group_da) {
- cf_log_perr(conf, "Failed resolving group attribute");
- return -1;
+ if (fr_dict_attr_add(fr_dict_unconst(dict_freeradius), fr_dict_root(dict_freeradius), group_attribute, 0,
+ FR_TYPE_STRING, &flags) < 0) {
+ cf_log_perr(conf, "Failed defining group attribute");
+ return -1;
+ }
+
+ boot->group_da = fr_dict_attr_search_by_qualified_oid(NULL, dict_freeradius, group_attribute,
+ false, false);
+ if (!boot->group_da) {
+ cf_log_perr(conf, "Failed resolving group attribute");
+ return -1;
+ }
}
/*
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/dict.h>
#include <freeradius-devel/unlang/function.h>
#include <ctype.h>
return 0;
}
-#define ATTR_CHECK(_tmpl, _name) if (tmpl_is_attr_unresolved(inst->_tmpl)) { \
- if (fr_dict_attr_add(fr_dict_unconst(dict_freeradius), fr_dict_root(dict_freeradius), tmpl_attr_tail_unresolved(inst->_tmpl), -1, FR_TYPE_UINT64, &flags) < 0) { \
- cf_log_perr(conf, "Failed defining %s attribute", _name); \
- return -1; \
- } \
-} else if (tmpl_is_attr(inst->_tmpl)) { \
- if (tmpl_attr_tail_da(inst->_tmpl)->type != FR_TYPE_UINT64) { \
- cf_log_err(conf, "%s attribute %s must be uint64", _name, tmpl_attr_tail_da(inst->_tmpl)->name); \
- return -1; \
- } \
+static inline int attr_check(CONF_SECTION *conf, tmpl_t *tmpl, char const *name, fr_dict_attr_flags_t *flags)
+{
+ if (tmpl_is_attr_unresolved(tmpl) && !fr_dict_attr_by_name(NULL, fr_dict_root(dict_freeradius), tmpl_attr_tail_unresolved(tmpl))) {
+ if (fr_dict_attr_add(fr_dict_unconst(dict_freeradius), fr_dict_root(dict_freeradius),
+ tmpl_attr_tail_unresolved(tmpl), 0, FR_TYPE_UINT64, flags) < 0) {
+ cf_log_perr(conf, "Failed defining %s attribute", name);
+ return -1;
+ }
+ } else if (tmpl_is_attr(tmpl)) {
+ if (tmpl_attr_tail_da(tmpl)->type != FR_TYPE_UINT64) {
+ cf_log_err(conf, "%s attribute %s must be uint64", name, tmpl_attr_tail_da(tmpl)->name);
+ return -1;
+ }
+ }
+
+ return 0;
}
static int mod_bootstrap(module_inst_ctx_t const *mctx)
{
rlm_sqlcounter_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_sqlcounter_t);
CONF_SECTION *conf = mctx->mi->conf;
- fr_dict_attr_flags_t flags = (fr_dict_attr_flags_t) { .internal = 1, .length = 8 };
+ fr_dict_attr_flags_t flags = { .internal = 1, .length = 8, .name_only = 1 };
- ATTR_CHECK(start_attr, "reset_period_start")
- ATTR_CHECK(end_attr, "reset_period_end")
- ATTR_CHECK(counter_attr, "counter")
- ATTR_CHECK(limit_attr, "check")
+ if (unlikely(attr_check(conf, inst->start_attr, "reset_period_start", &flags) < 0)) return -1;
+ if (unlikely(attr_check(conf, inst->end_attr, "reset_period_end", &flags) < 0)) return -1;
+ if (unlikely(attr_check(conf, inst->counter_attr, "counter", &flags) < 0)) return -1;
+ if (unlikely(attr_check(conf, inst->limit_attr, "check", &flags) < 0)) return -1;
return 0;
}