From bc06a68ef97c654f54f6947125e548e04c5b2709 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Tue, 12 Feb 2013 18:58:51 -0500 Subject: [PATCH] Add CONST to functions that return DICT_ATTR Reformat documentation for some structs Change VALUE_PAIR type from int to PW_TYPE --- src/include/libradius.h | 10 +- src/lib/dhcp.c | 2 +- src/lib/dict.c | 137 +++++++++--------- src/lib/print.c | 9 +- src/lib/radius.c | 8 +- src/lib/valuepair.c | 4 +- src/main/client.c | 2 +- src/main/evaluate.c | 2 +- src/main/modules.c | 2 +- src/main/xlat.c | 4 +- .../rlm_attr_rewrite/rlm_attr_rewrite.c | 4 +- src/modules/rlm_cache/rlm_cache.c | 2 +- src/modules/rlm_checkval/rlm_checkval.c | 22 ++- src/modules/rlm_counter/rlm_counter.c | 2 +- src/modules/rlm_detail/rlm_detail.c | 6 +- src/modules/rlm_ldap/rlm_ldap.c | 2 +- src/modules/rlm_otp/extern.h | 2 +- src/modules/rlm_otp/otp_pwe.c | 4 +- src/modules/rlm_passwd/rlm_passwd.c | 28 ++-- src/modules/rlm_policy/parse.c | 2 +- src/modules/rlm_preprocess/rlm_preprocess.c | 4 +- src/modules/rlm_sometimes/rlm_sometimes.c | 12 +- src/modules/rlm_sql/rlm_sql.c | 2 +- src/modules/rlm_sqlcounter/rlm_sqlcounter.c | 31 ++-- 24 files changed, 157 insertions(+), 146 deletions(-) diff --git a/src/include/libradius.h b/src/include/libradius.h index e723484ea2..ab94e9d800 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -189,7 +189,7 @@ typedef struct value_pair { */ unsigned int attribute; unsigned int vendor; - int type; + PW_TYPE type; FR_TOKEN op; //!< Operator to use when //!< moving or inserting @@ -284,11 +284,11 @@ void dict_attr_free(DICT_ATTR * const *da); const DICT_ATTR *dict_attr_copy(const DICT_ATTR *da); const DICT_ATTR *dict_attrunknown(unsigned int attr, unsigned int vendor); const DICT_ATTR *dict_attrunknownbyname(const char *attribute); -DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor); -DICT_ATTR *dict_attrbyname(const char *attr); -DICT_ATTR *dict_attrbytype(unsigned int attr, unsigned int vendor, +const DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor); +const DICT_ATTR *dict_attrbyname(const char *attr); +const DICT_ATTR *dict_attrbytype(unsigned int attr, unsigned int vendor, PW_TYPE type); -DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr); +const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr); DICT_VALUE *dict_valbyattr(unsigned int attr, unsigned int vendor, int val); DICT_VALUE *dict_valbyname(unsigned int attr, unsigned int vendor, const char *val); const char *dict_valnamebyattr(unsigned int attr, unsigned int vendor, int value); diff --git a/src/lib/dhcp.c b/src/lib/dhcp.c index 7337a60c4f..ef9518049c 100644 --- a/src/lib/dhcp.c +++ b/src/lib/dhcp.c @@ -557,7 +557,7 @@ ssize_t fr_dhcp_decode_options(uint8_t *data, size_t len, VALUE_PAIR **head) */ while (next < (data + len)) { int num_entries, alen; - DICT_ATTR *da; + const DICT_ATTR *da; p = next; diff --git a/src/lib/dict.c b/src/lib/dict.c index 0e0a3cf413..0b79aa791e 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -575,8 +575,9 @@ int dict_addattr(const char *name, int attr, unsigned int vendor, int type, size_t namelen; static int max_attr = 0; const char *p; - DICT_ATTR *da; - + const DICT_ATTR *da; + DICT_ATTR *n; + namelen = strlen(name); if (namelen >= DICT_ATTR_MAX_NAME_LEN) { fr_strerror_printf("dict_addattr: attribute name too long"); @@ -780,34 +781,34 @@ int dict_addattr(const char *name, int attr, unsigned int vendor, int type, /* * Create a new attribute for the list */ - if ((da = fr_pool_alloc(sizeof(*da) + namelen)) == NULL) { + if ((n = fr_pool_alloc(sizeof(*n) + namelen)) == NULL) { oom: - fr_strerror_printf("dict_addattr: out of memory"); + fr_strerror_printf("dict_adnttr: out of memory"); return -1; } - memcpy(da->name, name, namelen); - da->name[namelen] = '\0'; - da->attr = attr; - da->vendor = vendor; - da->type = type; - da->flags = flags; + memcpy(n->name, name, namelen); + n->name[namelen] = '\0'; + n->attr = attr; + n->vendor = vendor; + n->type = type; + n->flags = flags; /* * Insert the attribute, only if it's not a duplicate. */ - if (!fr_hash_table_insert(attributes_byname, da)) { + if (!fr_hash_table_insert(attributes_byname, n)) { DICT_ATTR *a; /* * If the attribute has identical number, then * ignore the duplicate. */ - a = fr_hash_table_finddata(attributes_byname, da); - if (a && (strcasecmp(a->name, da->name) == 0)) { - if (a->attr != da->attr) { - fr_strerror_printf("dict_addattr: Duplicate attribute name %s", name); - fr_pool_free(da); + a = fr_hash_table_finddata(attributes_byname, n); + if (a && (strcasecmp(a->name, n->name) == 0)) { + if (a->attr != n->attr) { + fr_strerror_printf("dict_adnttr: Duplicate attribute name %s", name); + fr_pool_free(n); return -1; } @@ -822,9 +823,9 @@ int dict_addattr(const char *name, int attr, unsigned int vendor, int type, fr_hash_table_delete(attributes_byvalue, a); - if (!fr_hash_table_replace(attributes_byname, da)) { - fr_strerror_printf("dict_addattr: Internal error storing attribute %s", name); - fr_pool_free(da); + if (!fr_hash_table_replace(attributes_byname, n)) { + fr_strerror_printf("dict_adnttr: Internal error storing attribute %s", name); + fr_pool_free(n); return -1; } } @@ -838,15 +839,15 @@ int dict_addattr(const char *name, int attr, unsigned int vendor, int type, * files, but when we're printing them, (and looking up * by value) we want to use the NEW name. */ - if (!fr_hash_table_replace(attributes_byvalue, da)) { - fr_strerror_printf("dict_addattr: Failed inserting attribute name %s", name); + if (!fr_hash_table_replace(attributes_byvalue, n)) { + fr_strerror_printf("dict_adnttr: Failed inserting attribute name %s", name); return -1; } /* * Hacks for combo-IP */ - if (da->type == PW_TYPE_COMBO_IP) { + if (n->type == PW_TYPE_COMBO_IP) { DICT_ATTR *v4, *v6; v4 = malloc(sizeof(*v4)); @@ -858,28 +859,28 @@ int dict_addattr(const char *name, int attr, unsigned int vendor, int type, goto oom; } - memcpy(v4, da, sizeof(*v4)); + memcpy(v4, n, sizeof(*v4)); v4->type = PW_TYPE_IPADDR; - memcpy(v6, da, sizeof(*v6)); + memcpy(v6, n, sizeof(*v6)); v6->type = PW_TYPE_IPV6ADDR; if (fr_hash_table_insert(attributes_combo, v4)) { - fr_strerror_printf("dict_addattr: Failed inserting attribute name %s", name); + fr_strerror_printf("dict_adnttr: Failed inserting attribute name %s", name); free(v4); free(v6); return -1; } if (fr_hash_table_insert(attributes_combo, v6)) { - fr_strerror_printf("dict_addattr: Failed inserting attribute name %s", name); + fr_strerror_printf("dict_adnttr: Failed inserting attribute name %s", name); free(v6); return -1; } } if (!vendor && (attr > 0) && (attr < 256)) { - dict_base_attrs[attr] = da; + dict_base_attrs[attr] = n; } return 0; @@ -892,10 +893,10 @@ int dict_addattr(const char *name, int attr, unsigned int vendor, int type, int dict_addvalue(const char *namestr, const char *attrstr, int value) { size_t length; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; DICT_VALUE *dval; - static DICT_ATTR *last_attr = NULL; + static const DICT_ATTR *last_attr = NULL; if (!*namestr) { fr_strerror_printf("dict_addvalue: empty names are not permitted"); @@ -978,8 +979,6 @@ int dict_addvalue(const char *namestr, const char *attrstr, int value) fr_int2str(dict_attr_types, dattr->type, "?Unknown?")); return -1; } - - dattr->flags.has_value = 1; } else { value_fixup_t *fixup; @@ -1006,25 +1005,30 @@ int dict_addvalue(const char *namestr, const char *attrstr, int value) /* * Add the value into the dictionary. */ - if (!fr_hash_table_insert(values_byname, dval)) { - if (dattr) { - DICT_VALUE *old; + { + DICT_ATTR *tmp; + memcpy(&tmp, &dval, sizeof(tmp)); + + if (!fr_hash_table_insert(values_byname, tmp)) { + if (dattr) { + DICT_VALUE *old; - /* - * Suppress duplicates with the same - * name and value. There are lots in - * dictionary.ascend. - */ - old = dict_valbyname(dattr->attr, dattr->vendor, namestr); - if (old && (old->value == dval->value)) { - fr_pool_free(dval); - return 0; + /* + * Suppress duplicates with the same + * name and value. There are lots in + * dictionary.ascend. + */ + old = dict_valbyname(dattr->attr, dattr->vendor, namestr); + if (old && (old->value == dval->value)) { + fr_pool_free(dval); + return 0; + } } - } - fr_pool_free(dval); - fr_strerror_printf("dict_addvalue: Duplicate value name %s for attribute %s", namestr, attrstr); - return -1; + fr_pool_free(dval); + fr_strerror_printf("dict_addvalue: Duplicate value name %s for attribute %s", namestr, attrstr); + return -1; + } } /* @@ -1091,7 +1095,7 @@ int dict_str2oid(const char *ptr, unsigned int *pvalue, unsigned int *pvendor, { const char *p; unsigned int value; - DICT_ATTR *da; + const DICT_ATTR *da; if (tlv_depth > fr_attr_max_tlv) { fr_strerror_printf("Too many sub-attributes"); @@ -1201,7 +1205,7 @@ int dict_str2oid(const char *ptr, unsigned int *pvalue, unsigned int *pvendor, /* * Bamboo skewers under the fingernails in 5, 4, 3, 2, ... */ -static DICT_ATTR *dict_parent(unsigned int attr, unsigned int vendor) +static const DICT_ATTR *dict_parent(unsigned int attr, unsigned int vendor) { if (vendor < FR_MAX_VENDOR) { return dict_attrbyvalue(attr & 0xff, vendor); @@ -1219,8 +1223,9 @@ static DICT_ATTR *dict_parent(unsigned int attr, unsigned int vendor) * Process the ATTRIBUTE command */ static int process_attribute(const char* fn, const int line, - unsigned int block_vendor, DICT_ATTR *block_tlv, - int tlv_depth, char **argv, int argc) + unsigned int block_vendor, + const DICT_ATTR *block_tlv, int tlv_depth, + char **argv, int argc) { int oid = 0; unsigned int vendor = 0; @@ -1262,7 +1267,7 @@ static int process_attribute(const char* fn, const int line, } if (oid) { - DICT_ATTR *da; + const DICT_ATTR *da; vendor = block_vendor; @@ -1638,7 +1643,7 @@ static int process_value(const char* fn, const int line, char **argv, static int process_value_alias(const char* fn, const int line, char **argv, int argc) { - DICT_ATTR *my_da, *da; + const DICT_ATTR *my_da, *da; DICT_VALUE *dval; if (argc != 2) { @@ -1654,12 +1659,6 @@ static int process_value_alias(const char* fn, const int line, char **argv, return -1; } - if (my_da->flags.has_value) { - fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE", - fn, line, argv[0]); - return -1; - } - if (my_da->flags.has_value_alias) { fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE-ALIAS", fn, line, argv[0]); @@ -1673,12 +1672,6 @@ static int process_value_alias(const char* fn, const int line, char **argv, return -1; } - if (!da->flags.has_value) { - fr_strerror_printf("dict_init: %s[%d]: VALUE-ALIAS cannot refer to ATTRIBUTE %s: It has no values", - fn, line, argv[1]); - return -1; - } - if (da->flags.has_value_alias) { fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" which itself has a VALUE-ALIAS", fn, line, argv[1]); @@ -1898,7 +1891,7 @@ static int my_dict_init(const char *dir, const char *fn, struct stat statbuf; char *argv[MAX_ARGV]; int argc; - DICT_ATTR *da, *block_tlv[MAX_TLV_NEST + 1]; + const DICT_ATTR *da, *block_tlv[MAX_TLV_NEST + 1]; int which_block_tlv = 0; block_tlv[0] = NULL; @@ -2346,7 +2339,7 @@ int dict_init(const char *dir, const char *fn) return -1; if (value_fixup) { - DICT_ATTR *a; + const DICT_ATTR *a; value_fixup_t *this, *next; for (this = value_fixup; this != NULL; this = next) { @@ -2588,7 +2581,7 @@ const DICT_ATTR *dict_attrunknownbyname(const char *attribute) char *q; DICT_VENDOR *dv; - DICT_ATTR *da; + const DICT_ATTR *da; /* * Pull off vendor prefix first. @@ -2779,7 +2772,7 @@ const DICT_ATTR *dict_attrunknownbyname(const char *attribute) /* * Get an attribute by its numerical value. */ -DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor) +const DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor) { DICT_ATTR dattr; @@ -2799,7 +2792,7 @@ DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor) * * @return The attribute, or NULL if not found */ -DICT_ATTR *dict_attrbytype(unsigned int attr, unsigned int vendor, +const DICT_ATTR *dict_attrbytype(unsigned int attr, unsigned int vendor, PW_TYPE type) { DICT_ATTR dattr; @@ -2815,7 +2808,7 @@ DICT_ATTR *dict_attrbytype(unsigned int attr, unsigned int vendor, /* * Get an attribute by it's numerical value, and the parent */ -DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr) +const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr) { DICT_ATTR dattr; @@ -2874,7 +2867,7 @@ find: /* * Get an attribute by its name. */ -DICT_ATTR *dict_attrbyname(const char *name) +const DICT_ATTR *dict_attrbyname(const char *name) { DICT_ATTR *da; uint32_t buffer[(sizeof(*da) + DICT_ATTR_MAX_NAME_LEN + 3)/4]; diff --git a/src/lib/print.c b/src/lib/print.c index 97ff9794b1..faa91702db 100644 --- a/src/lib/print.c +++ b/src/lib/print.c @@ -380,12 +380,14 @@ int vp_prints_value(char * out, size_t outlen, const VALUE_PAIR *vp, int delimit return strlen(out); } -/* +/** * Almost identical to vp_prints_value, but escapes certain chars so the string * may be used as a JSON value. * * Returns < 0 if the buffer may be (or have been) too small to write the encoded * JSON value to. + * + * @todo must check to see if the attribute has a dictionary value */ int vp_prints_value_json(char *buffer, size_t bufsize, const VALUE_PAIR *vp) { @@ -399,7 +401,10 @@ int vp_prints_value_json(char *buffer, size_t bufsize, const VALUE_PAIR *vp) case PW_TYPE_INTEGER: case PW_TYPE_BYTE: case PW_TYPE_SHORT: - if (vp->flags.has_value) break; + if (dict_valbyattr(vp->attribute, vp->vendor, + vp->vp_integer)) { + break; + } len = snprintf(buffer, bufsize, "%u", vp->vp_integer); return ((unsigned) len >= (bufsize - 1)) ? -1 : len; diff --git a/src/lib/radius.c b/src/lib/radius.c index 75e36a5dbf..22c1602f77 100644 --- a/src/lib/radius.c +++ b/src/lib/radius.c @@ -788,7 +788,7 @@ static ssize_t vp2data_tlvs(const RADIUS_PACKET *packet, #ifndef NDEBUG if ((fr_debug_flag > 3) && fr_log_fp) { - DICT_ATTR *da; + const DICT_ATTR *da; da = dict_attrbyvalue(svp->attribute & ((1 << fr_attr_shift[nest ]) - 1), svp->vendor); if (da) fprintf(fr_log_fp, "\t%s = ...\n", da->name); @@ -2861,7 +2861,7 @@ static ssize_t data2vp_any(const RADIUS_PACKET *packet, VALUE_PAIR **pvp) { int data_offset = 0; - DICT_ATTR *da; + const DICT_ATTR *da; VALUE_PAIR *vp = NULL; uint8_t buffer[256]; @@ -3745,7 +3745,7 @@ ssize_t rad_attr2vp_extended(const RADIUS_PACKET *packet, unsigned int vendor = 0; size_t data_len = length; const uint8_t *data; - DICT_ATTR *da; + const DICT_ATTR *da; data = start; @@ -3885,7 +3885,7 @@ ssize_t rad_attr2vp(const RADIUS_PACKET *packet, const uint8_t *data, size_t length, VALUE_PAIR **pvp) { - DICT_ATTR *da; + const DICT_ATTR *da; if ((length < 2) || (data[1] < 2) || (data[1] > length)) { fr_strerror_printf("rad_attr2vp: Insufficient data"); diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c index 88f2c0d782..25b6cd5f95 100644 --- a/src/lib/valuepair.c +++ b/src/lib/valuepair.c @@ -187,7 +187,7 @@ VALUE_PAIR *paircreate_raw(int attr, int vendor, int type, VALUE_PAIR *vp) VALUE_PAIR *paircreate(int attr, int vendor, int type) { VALUE_PAIR *vp; - DICT_ATTR *da; + const DICT_ATTR *da; da = dict_attrbyvalue(attr, vendor); if ((vp = pairalloc(da)) == NULL) { @@ -1689,7 +1689,7 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value, */ VALUE_PAIR *pairmake(const char *attribute, const char *value, FR_TOKEN op) { - DICT_ATTR *da; + const DICT_ATTR *da; VALUE_PAIR *vp; char *tc, *ts; signed char tag; diff --git a/src/main/client.c b/src/main/client.c index 5a2b2e0e16..720b758231 100644 --- a/src/main/client.c +++ b/src/main/client.c @@ -1087,7 +1087,7 @@ RADCLIENT *client_create(RADCLIENT_LIST *clients, REQUEST *request) c->src_ipaddr.af = AF_UNSPEC; for (i = 0; dynamic_config[i].name != NULL; i++) { - DICT_ATTR *da; + const DICT_ATTR *da; VALUE_PAIR *vp; da = dict_attrbyname(dynamic_config[i].name); diff --git a/src/main/evaluate.c b/src/main/evaluate.c index ccae4dec96..2286e4806f 100644 --- a/src/main/evaluate.c +++ b/src/main/evaluate.c @@ -254,7 +254,7 @@ static int radius_do_cmp(REQUEST *request, int *presult, } if (!vp) { - DICT_ATTR *da; + const DICT_ATTR *da; /* * The attribute on the LHS may diff --git a/src/main/modules.c b/src/main/modules.c index 21d8190821..502fe5112b 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -1074,7 +1074,7 @@ static int load_byserver(CONF_SECTION *cs) for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) { CONF_SECTION *subcs; CONF_ITEM *modref; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; subcs = cf_section_sub_find(cs, section_type_value[comp].section); diff --git a/src/main/xlat.c b/src/main/xlat.c index d7606c87b1..4bed1120df 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -114,7 +114,7 @@ static int valuepair2str(char * out,int outlen,VALUE_PAIR * pair, int type) static size_t xlat_packet(void *instance, REQUEST *request, const char *fmt, char *out, size_t outlen) { - DICT_ATTR *da; + const DICT_ATTR *da; VALUE_PAIR *vp; VALUE_PAIR *vps = NULL; RADIUS_PACKET *packet = NULL; @@ -508,6 +508,8 @@ static size_t xlat_integer(UNUSED void *instance, REQUEST *request, case PW_TYPE_BYTE: case PW_TYPE_DATE: return snprintf(out, outlen, "%u", vp->vp_integer); + default: + break; } *out = '\0'; diff --git a/src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c b/src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c index 88f3285b0b..10c4f1289a 100644 --- a/src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c +++ b/src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c @@ -39,7 +39,7 @@ RCSID("$Id$") typedef struct rlm_attr_rewrite_t { char *attribute; //!< The attribute to search for. - DICT_ATTR *da; //!< The attribute definition. + const DICT_ATTR *da; //!< The attribute definition. char *search; //!< The pattern to search for. int search_len; //!< The length of the search pattern. char *searchin_str; //!< The VALUE_PAIR list to search in. @@ -73,7 +73,7 @@ static const CONF_PARSER module_config[] = { static int attr_rewrite_instantiate(CONF_SECTION *conf, void **instance) { rlm_attr_rewrite_t *data; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; /* * Set up a storage area for instance data diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index 6f710c274b..cbb6c34c0b 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -606,7 +606,7 @@ static size_t cache_xlat(void *instance, REQUEST *request, rlm_cache_t *inst = instance; VALUE_PAIR *vp, *vps; pair_lists_t list; - DICT_ATTR *target; + const DICT_ATTR *target; const char *p = fmt; char buffer[1024]; int ret = 0; diff --git a/src/modules/rlm_checkval/rlm_checkval.c b/src/modules/rlm_checkval/rlm_checkval.c index 14b04562c4..bf35fec524 100644 --- a/src/modules/rlm_checkval/rlm_checkval.c +++ b/src/modules/rlm_checkval/rlm_checkval.c @@ -45,13 +45,19 @@ RCSID("$Id$") * be used as the instance handle. */ typedef struct rlm_checkval_t { - char *item_name; /* The attribute inside Access-Request ie Calling-Station-Id */ - char *check_name; /* The attribute to check it with ie Allowed-Calling-Station-Id */ - char *data_type; /* string,integer,ipaddr,date,abinary,octets */ - int dat_type; - DICT_ATTR *item_attr; - DICT_ATTR *chk_attr; - int notfound_reject; /* If we don't find the item_name in the request send back a reject */ + char *item_name; //!< The attribute inside + //!< Access-Request ie + //!< Calling-Station-Id. + char *check_name; //!< The attribute to check it with ie + //!< Allowed-Calling-Station-Id. + char *data_type; //!< String, integer, ipaddr, date, + //!< abinary,octets. + int dat_type; + const DICT_ATTR *item_attr; + const DICT_ATTR *chk_attr; + int notfound_reject; //!< If we don't find the + //!< item_name in the request + //!< send back a reject. } rlm_checkval_t; /* @@ -91,7 +97,7 @@ static int checkval_detach(void *instance) static int checkval_instantiate(CONF_SECTION *conf, void **instance) { rlm_checkval_t *data; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; ATTR_FLAGS flags; static const FR_NAME_NUMBER names[] = { diff --git a/src/modules/rlm_counter/rlm_counter.c b/src/modules/rlm_counter/rlm_counter.c index ebdfe8da5e..aa6e75e060 100644 --- a/src/modules/rlm_counter/rlm_counter.c +++ b/src/modules/rlm_counter/rlm_counter.c @@ -325,7 +325,7 @@ static int find_next_reset(rlm_counter_t *inst, time_t timeval) static int counter_instantiate(CONF_SECTION *conf, void **instance) { rlm_counter_t *inst; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; DICT_VALUE *dval; ATTR_FLAGS flags; time_t now; diff --git a/src/modules/rlm_detail/rlm_detail.c b/src/modules/rlm_detail/rlm_detail.c index b35ae77797..83e0698280 100644 --- a/src/modules/rlm_detail/rlm_detail.c +++ b/src/modules/rlm_detail/rlm_detail.c @@ -142,7 +142,8 @@ static int detail_instantiate(CONF_SECTION *conf, void **instance) ci != NULL; ci = cf_item_find_next(cs, ci)) { const char *attr; - DICT_ATTR *da; + const DICT_ATTR *da; + DICT_ATTR *tmp; if (!cf_item_is_pair(ci)) continue; @@ -161,7 +162,8 @@ static int detail_instantiate(CONF_SECTION *conf, void **instance) * since the suppression list will usually * be small, it doesn't matter. */ - if (!fr_hash_table_insert(inst->ht, da)) { + memcpy(&tmp, &da, sizeof(tmp)); + if (!fr_hash_table_insert(inst->ht, tmp)) { radlog(L_ERR, "rlm_detail: Failed trying to remember %s", attr); detail_detach(inst); return -1; diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index 8fae0888cb..a13ce30193 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -1528,7 +1528,7 @@ static int ldap_instantiate(CONF_SECTION * conf, void **instance) */ paircompare_register(PW_LDAP_GROUP, PW_USER_NAME, ldap_groupcmp, inst); if (cf_section_name2(conf)) { - DICT_ATTR *da; + const DICT_ATTR *da; ATTR_FLAGS flags; char buffer[256]; diff --git a/src/modules/rlm_otp/extern.h b/src/modules/rlm_otp/extern.h index df8380057f..d9edf4f74f 100644 --- a/src/modules/rlm_otp/extern.h +++ b/src/modules/rlm_otp/extern.h @@ -76,7 +76,7 @@ extern int otp_gen_state(char [OTP_MAX_RADSTATE_LEN], int32_t, int32_t, const unsigned char [16]); /* otp_pwe.c */ -extern DICT_ATTR *pwattr[8]; +extern const DICT_ATTR *pwattr[8]; extern void otp_pwe_init(void); extern otp_pwe_t otp_pwe_present(const REQUEST *); diff --git a/src/modules/rlm_otp/otp_pwe.c b/src/modules/rlm_otp/otp_pwe.c index 0f79d4625a..45e3bc19d9 100644 --- a/src/modules/rlm_otp/otp_pwe.c +++ b/src/modules/rlm_otp/otp_pwe.c @@ -45,14 +45,14 @@ RCSID("$Id$") /* Attribute IDs for supported password encodings. */ #define SIZEOF_PWATTR (4 * 2) -DICT_ATTR *pwattr[SIZEOF_PWATTR]; +const DICT_ATTR *pwattr[SIZEOF_PWATTR]; /* Initialize the pwattr array for supported password encodings. */ void otp_pwe_init(void) { - DICT_ATTR *da; + const DICT_ATTR *da; /* * Setup known password types. These are pairs. diff --git a/src/modules/rlm_passwd/rlm_passwd.c b/src/modules/rlm_passwd/rlm_passwd.c index 3b28c31842..9f9bf69a9f 100644 --- a/src/modules/rlm_passwd/rlm_passwd.c +++ b/src/modules/rlm_passwd/rlm_passwd.c @@ -353,19 +353,19 @@ int main(void){ #else /* TEST */ struct passwd_instance { - struct hashtable *ht; - struct mypasswd *pwdfmt; - char *filename; - char *format; - char * delimiter; - int allowmultiple; - int ignorenislike; - int hashsize; - int nfields; - int keyfield; - int listable; - DICT_ATTR *keyattr; - int ignoreempty; + struct hashtable *ht; + struct mypasswd *pwdfmt; + char *filename; + char *format; + char *delimiter; + int allowmultiple; + int ignorenislike; + int hashsize; + int nfields; + int keyfield; + int listable; + const DICT_ATTR *keyattr; + int ignoreempty; }; static const CONF_PARSER module_config[] = { @@ -394,7 +394,7 @@ static int passwd_instantiate(CONF_SECTION *conf, void **instance) char *lf=NULL; /* destination list flags temporary */ size_t len; int i; - DICT_ATTR * da; + const DICT_ATTR * da; *instance = rad_malloc(sizeof(struct passwd_instance)); if ( !*instance) { diff --git a/src/modules/rlm_policy/parse.c b/src/modules/rlm_policy/parse.c index 99376c7e4e..55bc8b35c9 100644 --- a/src/modules/rlm_policy/parse.c +++ b/src/modules/rlm_policy/parse.c @@ -1486,7 +1486,7 @@ static int parse_named_policy(policy_lex_file_t *lexer) policy_lex_t token; char mystring[256]; policy_named_t *this; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; debug_tokens("[POLICY] "); diff --git a/src/modules/rlm_preprocess/rlm_preprocess.c b/src/modules/rlm_preprocess/rlm_preprocess.c index efbcccb55d..4b385dec48 100644 --- a/src/modules/rlm_preprocess/rlm_preprocess.c +++ b/src/modules/rlm_preprocess/rlm_preprocess.c @@ -145,7 +145,7 @@ static void cisco_vsa_hack(VALUE_PAIR *vp) */ if (vp->attribute == 1) { const char *p; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; p = vp->vp_strvalue; gettoken(&p, newattr, sizeof(newattr)); @@ -184,7 +184,7 @@ static void alvarion_vsa_hack(VALUE_PAIR *vp) int number = 1; for ( ; vp != NULL; vp = vp->next) { - DICT_ATTR *da; + const DICT_ATTR *da; if (vp->vendor != 12394) continue; if (vp->type != PW_TYPE_STRING) continue; diff --git a/src/modules/rlm_sometimes/rlm_sometimes.c b/src/modules/rlm_sometimes/rlm_sometimes.c index 7601dd7054..6bbb9b8087 100644 --- a/src/modules/rlm_sometimes/rlm_sometimes.c +++ b/src/modules/rlm_sometimes/rlm_sometimes.c @@ -31,12 +31,12 @@ RCSID("$Id$") * going to return. */ typedef struct rlm_sometimes_t { - char *rcode_str; - int rcode; - int start; - int end; - char *key; - DICT_ATTR *da; + char *rcode_str; + int rcode; + int start; + int end; + char *key; + const DICT_ATTR *da; } rlm_sometimes_t; /* diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index 95dfd05b17..4ade980fc6 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -870,7 +870,7 @@ static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance) xlat_name = cf_section_name1(conf); } else { char *group_name; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; ATTR_FLAGS flags; /* diff --git a/src/modules/rlm_sqlcounter/rlm_sqlcounter.c b/src/modules/rlm_sqlcounter/rlm_sqlcounter.c index 783c0763a1..a32200948a 100644 --- a/src/modules/rlm_sqlcounter/rlm_sqlcounter.c +++ b/src/modules/rlm_sqlcounter/rlm_sqlcounter.c @@ -59,18 +59,21 @@ static int sqlcounter_detach(void *instance); * be used as the instance handle. */ typedef struct rlm_sqlcounter_t { - char *counter_name; /* Daily-Session-Time */ - char *check_name; /* Max-Daily-Session */ - char *reply_name; /* Session-Timeout */ - char *key_name; /* User-Name */ - char *sqlmod_inst; /* instance of SQL module to use, usually just 'sql' */ - char *query; /* SQL query to retrieve current session time */ - char *reset; /* daily, weekly, monthly, never or user defined */ - time_t reset_time; - time_t last_reset; - DICT_ATTR *key_attr; /* attribute number for key field */ - DICT_ATTR *dict_attr; /* attribute number for the counter. */ - DICT_ATTR *reply_attr; /* attribute number for the reply */ + char *counter_name; //!< Daily-Session-Time. + char *check_name; //!< Max-Daily-Session. + char *reply_name; //!< Session-Timeout. + char *key_name; //!< User-Name. + char *sqlmod_inst; //!< Instance of SQL module to use, + //!< usually just 'sql'. + char *query; //!< SQL query to retrieve current + //!< session time. + char *reset; //!< Daily, weekly, monthly, + //!< never or user defined. + time_t reset_time; + time_t last_reset; + const DICT_ATTR *key_attr; //!< Attribute number for key field. + const DICT_ATTR *dict_attr; //!< Attribute number for the counter. + const DICT_ATTR *reply_attr; //!< Attribute number for the reply. } rlm_sqlcounter_t; /* @@ -354,7 +357,7 @@ static int sqlcounter_cmp(void *instance, REQUEST *req, static int sqlcounter_instantiate(CONF_SECTION *conf, void **instance) { rlm_sqlcounter_t *data; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; ATTR_FLAGS flags; time_t now; @@ -517,7 +520,7 @@ static rlm_rcode_t sqlcounter_authorize(void *instance, REQUEST *request) rlm_sqlcounter_t *data = (rlm_sqlcounter_t *) instance; int rcode = RLM_MODULE_NOOP; unsigned int counter; - DICT_ATTR *dattr; + const DICT_ATTR *dattr; VALUE_PAIR *key_vp, *check_vp; VALUE_PAIR *reply_item; char msg[128]; -- 2.47.3