void fr_pair_replace(VALUE_PAIR **head, VALUE_PAIR *add);
-int fr_pair_update_by_num(TALLOC_CTX *ctx, VALUE_PAIR **list,
- unsigned int vendor, unsigned int attr, int8_t tag,
- fr_value_box_t *value);
-
void fr_pair_delete_by_num(VALUE_PAIR **head, unsigned int vendor, unsigned int attr, int8_t tag);
void fr_pair_delete_by_child_num(VALUE_PAIR **head, fr_dict_attr_t const *parent,
* Example:
@code{.c}
static vp_tmpl_t list = tmpl_initialiser_list(CURRENT_REQUEST, PAIR_LIST_REQUEST);
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR *vp;
// Iterate over all pairs in the request list
value.strvalue = talloc_typed_strdup(NULL, "my new username");
value.length = talloc_array_length(value.strvalue) - 1;
-
- if (fr_pair_update_by_num(ctx, head, FR_USERNAME, 0, TAG_ANY, FR_TYPE_STRING, &value) < 0) return -1; // error
@endcode
*
* @param _ctx new #VALUE_PAIR s should be allocated in for the specified list.
LDAPControl *acctmultisessionid_control = NULL;
struct berval tracking_id;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR const *vp;
memcpy(&hostname, &main_config.name, sizeof(hostname)); /* const / non-const issues */
- for (vp = fr_pair_cursor_init(&cursor, &request->packet->vps);
+ for (vp = fr_cursor_init(&cursor, &request->packet->vps);
vp;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
if (fr_dict_attr_is_top_level(vp->da)) switch (vp->da->attr) {
case FR_NAS_IP_ADDRESS:
case FR_NAS_IPV6_ADDRESS:
{
fr_ldap_result_t *self = uctx;
VALUE_PAIR *head = NULL, *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor, to_append;
int i;
- fr_pair_cursor_init(&cursor, &head);
+ fr_cursor_init(&cursor, &head);
switch (map->lhs->type) {
/*
goto next_pair;
}
- fr_pair_cursor_merge(&cursor, vp);
+ fr_cursor_init(&to_append, &vp);
+ fr_cursor_merge(&cursor, &to_append);
talloc_free(attr);
/*
return -1;
}
- instance_count++;
+
return 0;
}
*/
VALUE_PAIR *fr_pair_find_by_da(VALUE_PAIR *head, fr_dict_attr_t const *da, int8_t tag)
{
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
+ VALUE_PAIR *vp;
+
+ /* List head may be NULL if it contains no VPs */
+ if (!head) return NULL;
+
+ LIST_VERIFY(head);
- if (!fr_cond_assert(da)) return NULL;
+ if (!da) return NULL;
- (void) fr_pair_cursor_init(&cursor, &head);
- return fr_pair_cursor_next_by_da(&cursor, da, tag);
+ for (vp = fr_cursor_init(&cursor, &head);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
+ if ((da == vp->da) && TAG_EQ(tag, vp->tag)) return vp;
+ }
+
+ return NULL;
}
*/
VALUE_PAIR *fr_pair_find_by_num(VALUE_PAIR *head, unsigned int vendor, unsigned int attr, int8_t tag)
{
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
+ VALUE_PAIR *vp;
/* List head may be NULL if it contains no VPs */
if (!head) return NULL;
LIST_VERIFY(head);
- (void) fr_pair_cursor_init(&cursor, &head);
- return fr_pair_cursor_next_by_num(&cursor, vendor, attr, tag);
+ for (vp = fr_cursor_init(&cursor, &head);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
+ if (!fr_dict_attr_is_top_level(vp->da)) continue;
+
+ if (vendor > 0) {
+ fr_dict_vendor_t const *dv;
+
+ dv = fr_dict_vendor_by_da(vp->da);
+ if (!dv) continue;
+
+ if (dv->pen != vendor) continue;
+ }
+
+ if ((attr == vp->da->attr) && TAG_EQ(tag, vp->tag)) return vp;
+ }
+
+ return NULL;
}
/** Find the pair with the matching attribute
*/
VALUE_PAIR *fr_pair_find_by_child_num(VALUE_PAIR *head, fr_dict_attr_t const *parent, unsigned int attr, int8_t tag)
{
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
+ fr_dict_attr_t const *da;
+ VALUE_PAIR *vp;
/* List head may be NULL if it contains no VPs */
if (!head) return NULL;
LIST_VERIFY(head);
- (void) fr_pair_cursor_init(&cursor, &head);
- return fr_pair_cursor_next_by_child_num(&cursor, parent, attr, tag);
+ da = fr_dict_attr_child_by_num(parent, attr);
+ if (!da) return NULL;
+
+ for (vp = fr_cursor_init(&cursor, &head);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
+ if ((da == vp->da) && TAG_EQ(tag, vp->tag)) return vp;
+ }
+
+ return NULL;
}
*prev = replace;
}
-/** Create a new VALUE_PAIR or replace the value of the head pair in the specified list
- *
- * @note Any buffers associated with value, will be stolen to the context of the
- * VALUE_PAIR we create, or find.
- *
- * @param[in] ctx to allocate new #VALUE_PAIR in.
- * @param[in,out] list in search and insert into it.
- * @param[in] attr Number of attribute to update.
- * @param[in] vendor of attribute to update.
- * @param[in] tag of attribute to update.
- * @param[in] value to set.
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-int fr_pair_update_by_num(TALLOC_CTX *ctx, VALUE_PAIR **list,
- unsigned int vendor, unsigned int attr, int8_t tag,
- fr_value_box_t *value)
-{
- vp_cursor_t cursor;
- VALUE_PAIR *vp;
-
- (void)fr_pair_cursor_init(&cursor, list);
- vp = fr_pair_cursor_next_by_num(&cursor, vendor, attr, tag);
- if (vp) {
- VP_VERIFY(vp);
- if (fr_value_box_steal(vp, &vp->data, value) < 0) return -1;
- return 0;
- }
-
- vp = fr_pair_afrom_num(ctx, vendor, attr);
- if (!vp) return -1;
- vp->tag = tag;
- if (fr_value_box_steal(vp, &vp->data, value) < 0) return -1;
-
- fr_pair_cursor_append(&cursor, vp);
-
- return 0;
-}
-
/** Delete matching pairs
*
* Delete matching pairs from the attribute list.
*/
bool fr_pair_validate_relaxed(VALUE_PAIR const *failed[2], VALUE_PAIR *filter, VALUE_PAIR *list)
{
- vp_cursor_t filter_cursor;
- vp_cursor_t list_cursor;
+ vp_cursor_t filter_cursor;
+ vp_cursor_t list_cursor;
VALUE_PAIR *check, *last_check = NULL, *match = NULL;
char buf[8192];
FR_TOKEN last_token = T_EOL;
- vp_cursor_t cursor;
+ fr_cursor_t cursor, to_append;
VALUE_PAIR *vp = NULL;
- fr_pair_cursor_init(&cursor, out);
+ fr_cursor_init(&cursor, out);
while (fgets(buf, sizeof(buf), fp) != NULL) {
/*
break;
}
- fr_pair_cursor_merge(&cursor, vp);
+ fr_cursor_init(&to_append, &vp);
+ fr_cursor_merge(&cursor, &to_append);
buf[0] = '\0';
}
*pfiledone = true;
error:
*pfiledone = false;
- vp = fr_pair_cursor_head(&cursor);
+ vp = fr_cursor_head(&cursor);
if (vp) fr_pair_list_free(&vp);
return -1;
void fr_pair_list_fprint(FILE *fp, VALUE_PAIR const *const_vp)
{
VALUE_PAIR *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
memcpy(&vp, &const_vp, sizeof(vp)); /* const work-arounds */
- for (vp = fr_pair_cursor_init(&cursor, &vp); vp; vp = fr_pair_cursor_next(&cursor)) {
+ for (vp = fr_cursor_init(&cursor, &vp); vp; vp = fr_cursor_next(&cursor)) {
fr_pair_fprint(fp, vp);
}
}
*/
void fr_pair_list_verify(char const *file, int line, TALLOC_CTX const *expected, VALUE_PAIR *vps)
{
- vp_cursor_t slow_cursor, fast_cursor;
+ fr_cursor_t slow_cursor, fast_cursor;
VALUE_PAIR *slow, *fast;
TALLOC_CTX *parent;
if (!vps) return; /* Fast path */
- fr_pair_cursor_init(&fast_cursor, &vps);
+ fr_cursor_init(&fast_cursor, &vps);
- for (slow = fr_pair_cursor_init(&slow_cursor, &vps), fast = fr_pair_cursor_init(&fast_cursor, &vps);
+ for (slow = fr_cursor_init(&slow_cursor, &vps), fast = fr_cursor_init(&fast_cursor, &vps);
slow && fast;
- slow = fr_pair_cursor_next(&fast_cursor), fast = fr_pair_cursor_next(&fast_cursor)) {
+ slow = fr_cursor_next(&fast_cursor), fast = fr_cursor_next(&fast_cursor)) {
VP_VERIFY(slow);
/*
* Advances twice as fast as slow...
*/
- fast = fr_pair_cursor_next(&fast_cursor);
+ fast = fr_cursor_next(&fast_cursor);
if (fast == slow) {
FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: Looping list found. Fast pointer hit "
"slow pointer at \"%s\"", file, line, slow->da->name);
void fr_pair_list_tainted(VALUE_PAIR *vps)
{
VALUE_PAIR *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
- if (!vps) {
- return;
- }
+ if (!vps) return;
- for (vp = fr_pair_cursor_init(&cursor, &vps);
+ for (vp = fr_cursor_init(&cursor, &vps);
vp;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
VP_VERIFY(vp);
vp->vp_tainted = true;
}
*/
static int CC_HINT(nonnull) rad_check_password(REQUEST *request)
{
- vp_cursor_t cursor;
- VALUE_PAIR *auth_type_pair;
- int auth_type = -1;
- int result;
- int auth_type_count = 0;
+ fr_cursor_t cursor;
+ VALUE_PAIR *auth_type_pair;
+ int auth_type = -1;
+ int result;
+ int auth_type_count = 0;
+ fr_dict_attr_t const *da;
+
+ da = fr_dict_attr_child_by_num(fr_dict_root(fr_dict_internal), FR_AUTH_TYPE);
+ if (!da) {
+ RERROR("Missing definition for Auth-Type");
+ return -1;
+ }
/*
* Look for matching check items. We skip the whole lot
* if the authentication type is FR_AUTH_TYPE_ACCEPT or
* FR_AUTH_TYPE_REJECT.
*/
- fr_pair_cursor_init(&cursor, &request->control);
- while ((auth_type_pair = fr_pair_cursor_next_by_num(&cursor, 0, FR_AUTH_TYPE, TAG_ANY))) {
+ for (auth_type_pair = fr_cursor_iter_by_da_init(&cursor, &request->control, da);
+ auth_type_pair;
+ auth_type_pair = fr_cursor_next(&cursor)) {
auth_type = auth_type_pair->vp_uint32;
auth_type_count++;
- RDEBUG2("Using 'Auth-Type = %s' for authenticate {...}",
- fr_dict_enum_alias_by_value(auth_type_pair->da, fr_box_uint32(auth_type)));
+ RDEBUG2("Using '%pP' for authenticate {...}", auth_type_pair);
if (auth_type == FR_AUTH_TYPE_REJECT) {
RDEBUG2("Auth-Type = Reject, rejecting user");
static int cnt;
CONF_SECTION *cs;
char src_buf[128], buffer[256];
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR *vp;
RADCLIENT *c;
cs = cf_section_alloc(ctx, NULL, "client", buffer);
- fr_pair_cursor_init(&cursor, &request->control);
+ fr_cursor_init(&cursor, &request->control);
RDEBUG2("Converting &request:control to client {...} section");
RINDENT();
- for (vp = fr_pair_cursor_init(&cursor, &request->control);
+ for (vp = fr_cursor_init(&cursor, &request->control);
vp != NULL;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
CONF_PAIR *cp = NULL;
char const *value;
char const *attr;
envp[0] = NULL;
if (input_pairs) {
- char *p;
- vp_cursor_t cursor;
- char buffer[1024];
+ char *p;
+ fr_cursor_t cursor;
+ char buffer[1024];
+ fr_dict_attr_t const *da;
input_ctx = talloc_new(request);
* hold mutexes. They might be locked when we fork,
* and will remain locked in the child.
*/
- for (vp = fr_pair_cursor_init(&cursor, &input_pairs);
+ for (vp = fr_cursor_init(&cursor, &input_pairs);
vp && (envlen < ((sizeof(envp) / sizeof(*envp)) - 1));
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
/*
* Hmm... maybe we shouldn't pass the
* user's password in an environment
envp[envlen++] = talloc_typed_strdup(input_ctx, buffer);
}
- fr_pair_cursor_init(&cursor, radius_list(request, PAIR_LIST_CONTROL));
- while ((envlen < ((sizeof(envp) / sizeof(*envp)) - 1)) &&
- (vp = fr_pair_cursor_next_by_num(&cursor, 0, FR_EXEC_EXPORT, TAG_ANY))) {
- DEBUG3("export %s", vp->vp_strvalue);
+ da = fr_dict_attr_child_by_num(fr_dict_root(fr_dict_internal), FR_EXEC_EXPORT);
+ if (!da) {
+ ERROR("Missing Exec-Export definition");
+ return -1;
+ }
+
+ for (vp = fr_cursor_iter_by_da_init(&cursor, radius_list(request, PAIR_LIST_CONTROL), da);
+ vp && (envlen < ((sizeof(envp) / sizeof(*envp)) - 1));
+ vp = fr_cursor_next(&cursor)) {
+ DEBUG3("export %pV", &vp->data);
memcpy(&envp[envlen++], &vp->vp_strvalue, sizeof(*envp));
}
static int _state_entry_free(fr_state_entry_t *entry)
{
#ifdef WITH_VERIFY_PTR
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR *vp;
/*
* by the state context.
*/
if (entry->ctx) {
- for (vp = fr_pair_cursor_init(&cursor, &entry->vps);
+ for (vp = fr_cursor_init(&cursor, &entry->vps);
vp;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
rad_assert(entry->ctx == talloc_parent(vp));
}
}
return NULL;
}
-/** Initialise a #vp_cursor_t to the #VALUE_PAIR specified by a #vp_tmpl_t
+/** Initialise a #fr_cursor_t to the #VALUE_PAIR specified by a #vp_tmpl_t
*
* This makes iterating over the one or more #VALUE_PAIR specified by a #vp_tmpl_t
* significantly easier.
fr_dict_attr_t const *server_da;
fr_dict_attr_t const *port_da;
VALUE_PAIR *out = NULL, *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
server_da = fr_dict_attr_child_by_num(fr_dict_root(fr_dict_internal), FR_CONNECTION_POOL_SERVER);
if (!server_da) {
return NULL;
}
- fr_pair_cursor_init(&cursor, &out);
+ fr_cursor_init(&cursor, &out);
MEM(vp = fr_pair_afrom_da(ctx, server_da));
fr_pair_value_strcpy(vp, server);
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(ctx, port_da));
vp->vp_uint16 = port;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
return out;
}
FR_TOKEN parsecode;
#ifdef HAVE_REGEX_H
VALUE_PAIR *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
#endif
char newfile[8192];
/*
* Do some more sanity checks.
*/
- for (vp = fr_pair_cursor_init(&cursor, &check_tmp);
+ for (vp = fr_cursor_init(&cursor, &check_tmp);
vp;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
if (((vp->op == T_OP_REG_EQ) ||
(vp->op == T_OP_REG_NE)) &&
(vp->vp_type != FR_TYPE_STRING)) {
int num, lineno;
uint8_t const *p, *end;
VALUE_PAIR *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
time_t timestamp = 0;
- if (DEBUG_ENABLED3) {
- RDEBUG("proto_detail decode packet");
-// fr_radius_print_hex(fr_log_fp, data, data_len);
- }
+ RHEXDUMP(L_DBG_LVL_3, data, data_len, "proto_detail decode packet");
request->packet->code = inst->code;
}
lineno = 1;
- fr_pair_cursor_init(&cursor, &request->packet->vps);
+ fr_cursor_init(&cursor, &request->packet->vps);
/*
* Parse each individual line.
if (vp) {
vp->vp_date = (uint32_t) timestamp;
vp->type = VT_DATA;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
}
goto next;
}
*/
vp = NULL;
if ((fr_pair_list_afrom_str(request->packet, (char const *) p, &vp) > 0) && vp) {
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
} else {
RWDEBUG("Ignoring line %d - :%s", lineno, p);
}
static RADIUS_PACKET *request_init(char const *filename)
{
FILE *fp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR *vp;
bool filedone = false;
RADIUS_PACKET *request;
/*
* Fix / set various options
*/
- for (vp = fr_pair_cursor_init(&cursor, &request->vps);
+ for (vp = fr_cursor_init(&cursor, &request->vps);
vp;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
/*
* Allow to set packet type using DHCP-Message-Type
*/
static void dhcp_packet_debug(RADIUS_PACKET *packet, bool received)
{
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
char buffer[256];
char src_ipaddr[INET6_ADDRSTRLEN];
#endif
packet->data_len);
- for (vp = fr_pair_cursor_init(&cursor, &packet->vps);
+ for (vp = fr_cursor_init(&cursor, &packet->vps);
vp;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
VP_VERIFY(vp);
fr_pair_snprint(buffer, sizeof(buffer), vp);
* values.
*/
if (!client->active) {
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR *vp;
rad_assert(client->dynamic);
- for (vp = fr_pair_cursor_init(&cursor, &request->packet->vps);
+ for (vp = fr_cursor_init(&cursor, &request->packet->vps);
vp != NULL;
- vp = fr_pair_cursor_next(&cursor)) {
+ vp = fr_cursor_next(&cursor)) {
if (vp->da->flags.encrypt != FLAG_ENCRYPT_NONE) {
switch (vp->da->type) {
default:
CONF_SECTION *unlang;
fr_dict_enum_t const *dv = NULL;
VALUE_PAIR *vp, *auth_type;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
int rc;
REQUEST_VERIFY(request);
/*
* Find Auth-Type, and complain if they have too many.
*/
- fr_pair_cursor_init(&cursor, &request->control);
auth_type = NULL;
- while ((vp = fr_pair_cursor_next_by_da(&cursor, attr_auth_type, TAG_ANY)) != NULL) {
+ for (vp = fr_cursor_iter_by_da_init(&cursor, &request->control, attr_auth_type);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
if (!auth_type) {
auth_type = vp;
continue;
{
client_get_vp_ctx_t *client = uctx;
VALUE_PAIR *head = NULL, *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
fr_dict_attr_t const *da;
CONF_PAIR const *cp;
rad_assert(ctx != NULL);
- fr_pair_cursor_init(&cursor, &head);
+ fr_cursor_init(&cursor, &head);
/*
* FIXME: allow multiple entries.
}
vp->op = map->op;
- fr_pair_cursor_merge(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
if (map->op != T_OP_ADD) break; /* Create multiple attribute for multiple CONF_PAIRs */
}
*/
static int csv_map_getvalue(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx)
{
- char const *str = uctx;
- VALUE_PAIR *head = NULL, *vp;
- vp_cursor_t cursor;
- fr_dict_attr_t const *da;
+ char const *str = uctx;
+ VALUE_PAIR *head = NULL, *vp;
+ fr_cursor_t cursor;
+ fr_dict_attr_t const *da;
rad_assert(ctx != NULL);
- fr_pair_cursor_init(&cursor, &head);
+ fr_cursor_init(&cursor, &head);
/*
* FIXME: allow multiple entries.
}
vp->op = map->op;
- fr_pair_cursor_merge(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
*out = head;
return 0;
static int digest_fix(REQUEST *request)
{
VALUE_PAIR *first, *i;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
/*
* We need both of these attributes to do the authentication.
*/
RDEBUG("Checking for correctly formatted Digest-Attributes");
- first = fr_pair_find_by_da(request->packet->vps, attr_digest_attributes, TAG_ANY);
- if (!first) {
- return RLM_MODULE_NOOP;
- }
+ first = fr_cursor_iter_by_da_init(&cursor, &request->packet->vps, attr_digest_attributes);
+ if (!first) return RLM_MODULE_NOOP;
- fr_pair_cursor_init(&cursor, &first);
- while ((i = fr_pair_cursor_next_by_da(&cursor, attr_digest_attributes, TAG_ANY))) {
- int length = i->vp_length;
- int attrlen;
+ for (i = fr_cursor_head(&cursor);
+ i;
+ i = fr_cursor_next(&cursor)) {
+ size_t length = i->vp_length;
+ size_t attrlen;
uint8_t const *p = i->vp_octets;
/*
* Convert them to something sane.
*/
RDEBUG("Digest-Attributes look OK. Converting them to something more useful");
- fr_pair_cursor_head(&cursor);
- while ((i = fr_pair_cursor_next_by_da(&cursor, attr_digest_attributes, TAG_ANY))) {
- int length = i->vp_length;
- int attrlen;
- uint8_t const *p = &i->vp_octets[0];
- VALUE_PAIR *sub;
+ fr_cursor_head(&cursor);
+ for (i = fr_cursor_head(&cursor);
+ i;
+ i = fr_cursor_next(&cursor)) {
+ size_t length = i->vp_length;
+ size_t attrlen;
+ uint8_t const *p = &i->vp_octets[0];
+ VALUE_PAIR *sub;
/*
* Until this stupidly encoded attribute is exhausted.
* Too short.
*/
if (attrlen < 3) {
- REDEBUG("Received Digest-Attributes with short sub-attribute %d, of length %d",
+ REDEBUG("Received Digest-Attributes with short sub-attribute %d, of length %zu",
p[0], attrlen);
return RLM_MODULE_INVALID;
}
* Too long.
*/
if (attrlen > length) {
- REDEBUG("Received Digest-Attributes with long sub-attribute %d, of length %d",
+ REDEBUG("Received Digest-Attributes with long sub-attribute %d, of length %zu",
p[0], attrlen);
return RLM_MODULE_INVALID;
}
uint8_t const *ptr;
VALUE_PAIR *head = NULL;
VALUE_PAIR *vp;
- vp_cursor_t out;
+ fr_cursor_t out;
total = eap->length[0] * 256 + eap->length[1];
ptr = (uint8_t const *) eap;
- fr_pair_cursor_init(&out, &head);
+ fr_cursor_init(&out, &head);
do {
size = total;
if (size > 253) size = 253;
}
fr_pair_value_memcpy(vp, ptr, size);
- fr_pair_cursor_append(&out, vp);
+ fr_cursor_append(&out, vp);
ptr += size;
total -= size;
*/
eap_packet_raw_t *eap_vp2packet(TALLOC_CTX *ctx, VALUE_PAIR *vps)
{
- VALUE_PAIR *first, *i;
- eap_packet_raw_t *eap_packet;
- unsigned char *ptr;
- uint16_t len;
- int total_len;
- vp_cursor_t cursor;
+ VALUE_PAIR *vp;
+ eap_packet_raw_t *eap_packet;
+ unsigned char *ptr;
+ uint16_t len;
+ int total_len;
+ fr_cursor_t cursor;
/*
* Get only EAP-Message attribute list
*/
- first = fr_pair_find_by_da(vps, attr_eap_message, TAG_ANY);
- if (!first) {
+ vp = fr_cursor_iter_by_da_init(&cursor, &vps, attr_eap_message);
+ if (!vp) {
fr_strerror_printf("EAP-Message not found");
return NULL;
}
/*
* Sanity check the length before doing anything.
*/
- if (first->vp_length < 4) {
+ if (vp->vp_length < 4) {
fr_strerror_printf("EAP packet is too short");
return NULL;
}
* Get the Actual length from the EAP packet
* First EAP-Message contains the EAP packet header
*/
- memcpy(&len, first->vp_strvalue + 2, sizeof(len));
+ memcpy(&len, vp->vp_strvalue + 2, sizeof(len));
len = ntohs(len);
/*
* Sanity check the length, BEFORE allocating memory.
*/
total_len = 0;
- fr_pair_cursor_init(&cursor, &first);
- while ((i = fr_pair_cursor_next_by_da(&cursor, attr_eap_message, TAG_ANY))) {
- total_len += i->vp_length;
+ for (vp = fr_cursor_head(&cursor);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
+ total_len += vp->vp_length;
if (total_len > len) {
fr_strerror_printf("Malformed EAP packet. Length in packet header %i, "
ptr = (unsigned char *)eap_packet;
/* RADIUS ensures order of attrs, so just concatenate all */
- fr_pair_cursor_head(&cursor);
- while ((i = fr_pair_cursor_next_by_da(&cursor, attr_eap_message, TAG_ANY))) {
- memcpy(ptr, i->vp_strvalue, i->vp_length);
- ptr += i->vp_length;
+ for (vp = fr_cursor_head(&cursor);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
+ memcpy(ptr, vp->vp_strvalue, vp->vp_length);
+ ptr += vp->vp_length;
}
return eap_packet;
{
size_t length;
uint8_t *ptr;
- VALUE_PAIR *first, *vp;
+ VALUE_PAIR *vp;
chbind_packet_t *packet;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
- first = fr_pair_find_by_da(vps, attr_eap_channel_binding_message, TAG_ANY);
- if (!first) return NULL;
+ if (!fr_cursor_iter_by_da_init(&cursor, &vps, attr_eap_channel_binding_message)) return NULL;
/*
* Compute the total length of the channel binding data.
*/
length = 0;
- for (vp = fr_pair_cursor_init(&cursor, &first);
- vp != NULL;
- vp = fr_pair_cursor_next_by_da(&cursor, attr_eap_channel_binding_message, TAG_ANY)) {
+ for (vp = fr_cursor_current(&cursor);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
length += vp->vp_length;
}
* Copy the data over to our packet.
*/
packet = (chbind_packet_t *) ptr;
- for (vp = fr_pair_cursor_init(&cursor, &first);
+ for (vp = fr_cursor_head(&cursor);
vp != NULL;
- vp = fr_pair_cursor_next_by_da(&cursor, attr_eap_channel_binding_message, TAG_ANY)) {
+ vp = fr_cursor_next(&cursor)) {
memcpy(ptr, vp->vp_octets, vp->vp_length);
ptr += vp->vp_length;
}
char *p;
VALUE_PAIR *vp;
eap_session_t *eap_session;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
rlm_eap_t const *inst = instance;
/*
* This is vendor Cisco (9), Cisco-AVPair
* attribute (1)
*/
- fr_pair_cursor_init(&cursor, &request->proxy->reply->vps);
- while ((vp = fr_pair_cursor_next_by_da(&cursor, attr_cisco_avpair, TAG_ANY))) {
+ for (vp = fr_cursor_iter_by_da_init(&cursor, &request->proxy->reply->vps, attr_cisco_avpair);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
/*
* If it's "leap:session-key", then stop.
*
*
* FIXME do something with mandatory
*/
-ssize_t eap_fast_decode_pair(TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *parent,
+ssize_t eap_fast_decode_pair(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_attr_t const *parent,
uint8_t const *data, size_t data_len,
void *decoder_ctx)
{
fr_pair_to_unknown(vp);
fr_pair_value_memcpy(vp, p, len);
}
- fr_pair_cursor_append(cursor, vp);
+ fr_cursor_append(cursor, vp);
p += len;
}
{
rlm_rcode_t rcode = RLM_MODULE_REJECT;
VALUE_PAIR *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
* Copy what we need into the TTLS tunnel and leave
* the rest to be cleaned up.
*/
- for (vp = fr_pair_cursor_init(&cursor, &reply->vps); vp; vp = fr_pair_cursor_next(&cursor)) {
+ for (vp = fr_cursor_init(&cursor, &reply->vps); vp; vp = fr_cursor_next(&cursor)) {
if (fr_dict_vendor_num_by_da(vp->da) != VENDORPEC_MICROSOFT) continue;
/* FIXME must be a better way to capture/re-derive this later for ISK */
/*
* Copy the EAP-Message back to the tunnel.
*/
- (void) fr_pair_cursor_init(&cursor, &reply->vps);
+ (void) fr_cursor_init(&cursor, &reply->vps);
- while ((vp = fr_pair_cursor_next_by_da(&cursor, attr_eap_message, TAG_ANY)) != NULL) {
+ for (vp = fr_cursor_iter_by_da_init(&cursor, &reply->vps, attr_eap_message);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
eap_fast_tlv_append(tls_session, attr_eap_fast_eap_payload, true, vp->vp_length, vp->vp_octets);
}
{
eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
VALUE_PAIR *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
eap_tlv_crypto_binding_tlv_t my_binding, *binding = NULL;
memset(&my_binding, 0, sizeof(my_binding));
- for (vp = fr_pair_cursor_init(&cursor, &fast_vps); vp; vp = fr_pair_cursor_next(&cursor)) {
+ for (vp = fr_cursor_init(&cursor, &fast_vps);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
FR_CODE code = FR_CODE_ACCESS_REJECT;
char *value;
{
FR_CODE code;
VALUE_PAIR *fast_vps = NULL;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
uint8_t const *data;
size_t data_len;
eap_fast_tunnel_t *t;
return FR_CODE_ACCESS_CHALLENGE;
}
- fr_pair_cursor_init(&cursor, &fast_vps);
+ fr_cursor_init(&cursor, &fast_vps);
if (eap_fast_decode_pair(request, &cursor, attr_eap_fast_tlv,
data, data_len, NULL) < 0) return FR_CODE_ACCESS_REJECT;
/*
* A bunch of EAP-FAST helper functions.
*/
-ssize_t eap_fast_decode_pair(TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *parent,
+ssize_t eap_fast_decode_pair(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_attr_t const *parent,
uint8_t const *data, size_t data_len,
UNUSED void *decoder_ctx);
REQUEST *request = (REQUEST *)SSL_get_ex_data(s, FR_TLS_EX_INDEX_REQUEST);
eap_fast_tunnel_t *t;
VALUE_PAIR *fast_vps = NULL, *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
char const *errmsg;
int dlen, plen;
uint16_t length;
RHEXDUMP(L_DBG_LVL_MAX, (uint8_t const *)&opaque_plaintext, plen, "PAC-Opaque plaintext data section");
- fr_pair_cursor_init(&cursor, &fast_vps);
+ fr_cursor_init(&cursor, &fast_vps);
if (eap_fast_decode_pair(tls_session, &cursor, attr_eap_fast_pac_opaque_tlv, (uint8_t *)&opaque_plaintext, plen, NULL) < 0) {
errmsg = fr_strerror();
goto error;
}
- for (vp = fr_pair_cursor_head(&cursor); vp; vp = fr_pair_cursor_next(&cursor)) {
+ for (vp = fr_cursor_head(&cursor);
+ vp;
+ vp = fr_cursor_next(&cursor)) {
char *value;
if (vp->da == attr_eap_fast_pac_info_pac_type) {
size_t total;
uint8_t *p;
VALUE_PAIR *vp = NULL, *head = NULL;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
if (data_len > 65535) return NULL; /* paranoia */
memcpy(p + EAP_HEADER_LEN, data, total);
fr_pair_value_memsteal(vp, p);
- fr_pair_cursor_init(&cursor, &head);
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_init(&cursor, &head);
+ fr_cursor_append(&cursor, vp);
while (total < data_len) {
vp = fr_pair_afrom_da(packet, attr_eap_message);
if (!vp) {
total += vp->vp_length;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
}
return head;
{
rad_assert(vp != NULL);
VALUE_PAIR *this;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
/*
* Send the EAP data in the first attribute, WITHOUT the
/*
* Send the rest of the EAP data, but skipping the first VP.
*/
- fr_pair_cursor_init(&cursor, &vp);
- for (this = fr_pair_cursor_next(&cursor);
+ fr_cursor_init(&cursor, &vp);
+ for (this = fr_cursor_next(&cursor);
this;
- this = fr_pair_cursor_next(&cursor)) {
+ this = fr_cursor_next(&cursor)) {
(tls_session->record_from_buff)(&tls_session->clean_in, this->vp_octets, this->vp_length);
}
/*
* decode.c
*/
-ssize_t fr_dhcpv6_decode_option(TALLOC_CTX *ctx, vp_cursor_t *cursor,
+ssize_t fr_dhcpv6_decode_option(TALLOC_CTX *ctx, fr_cursor_t *cursor,
uint8_t const *data, size_t data_len, void *decoder_ctx);
uint16_t length_hdr;
uint16_t length_body;
VALUE_PAIR const *vp;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
tacacs_packet_t *pkt;
struct {
VALUE_PAIR const *server_msg;
: TAC_PLUS_UNENCRYPTED_FLAG;
length_body = 0;
- for (vp = fr_pair_cursor_init(&cursor, &packet->vps); vp != NULL; vp = fr_pair_cursor_next(&cursor)) {
+ for (vp = fr_cursor_init(&cursor, &packet->vps);
+ vp != NULL;
+ vp = fr_cursor_next(&cursor)) {
VP_VERIFY(vp);
if (!vp->da->flags.internal) continue;
}
-static int tacacs_decode_field(TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *da,
+static int tacacs_decode_field(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_attr_t const *da,
char const *field_name, uint8_t **field_data, size_t field_len, size_t *remaining)
{
uint8_t *p;
fr_pair_value_bstrncpy(vp, p, field_len);
p += field_len;
*remaining -= field_len;
- fr_pair_cursor_append(cursor, vp);
+ fr_cursor_append(cursor, vp);
*field_data = p;
{
int i;
tacacs_packet_t *pkt;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR *vp;
uint8_t *p;
uint32_t session_id;
size_t remaining;
- fr_pair_cursor_init(&cursor, &packet->vps);
+ fr_cursor_init(&cursor, &packet->vps);
/*
* There MUST be at least a TACACS packert header, and
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_version_minor));
vp->vp_uint8 = pkt->hdr.ver.minor;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_packet_type));
vp->vp_uint8 = pkt->hdr.type;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
packet->code = pkt->hdr.type;
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_sequence_number));
vp->vp_uint8 = pkt->hdr.seq_no;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_session_id));
vp->vp_uint32 = ntohl(pkt->hdr.session_id);
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
session_id = vp->vp_uint32;
switch ((tacacs_type_t)pkt->hdr.type) {
*/
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_action));
vp->vp_uint8 = pkt->authen.start.action;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_privilege_level));
vp->vp_uint8 = pkt->authen.start.priv_lvl;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_type));
vp->vp_uint8 = pkt->authen.start.authen_type;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_service));
if (!vp) return -1;
vp->vp_uint8 = pkt->authen.start.authen_service;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
/*
* Decode 4 fields, based on their "length"
*/
if (pkt->authen.cont.flags & TAC_PLUS_CONTINUE_FLAG_ABORT) {
if (!ntohs(pkt->authen.cont.data_len) ||
- !(vp = fr_pair_cursor_tail(&cursor))) {
+ !(vp = fr_cursor_tail(&cursor))) {
fr_strerror_printf("Client aborted authentication session %u "
"with no message", session_id);
return -2;
*/
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_method));
vp->vp_uint8 = pkt->author.req.authen_method;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_privilege_level));
vp->vp_uint8 = pkt->author.req.priv_lvl;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_type));
vp->vp_uint8 = pkt->author.req.authen_type;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_service));
vp->vp_uint8 = pkt->author.req.authen_service;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
/*
* Decode 3 fields, based on their "length"
*/
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_accounting_flags));
vp->vp_uint8 = pkt->acct.req.flags;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_method));
vp->vp_uint8 = pkt->acct.req.authen_method;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_privilege_level));
vp->vp_uint8 = pkt->acct.req.priv_lvl;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_type));
vp->vp_uint8 = pkt->acct.req.authen_type;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_tacacs_authentication_service));
vp->vp_uint8 = pkt->acct.req.authen_service;
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
/*
* Decode 3 fields, based on their "length"
uint8_t *ptr, *end;
int attr;
size_t attr_len;
- vp_cursor_t cursor;
+ fr_cursor_t cursor;
VALUE_PAIR *vp;
if (!packet || !packet->data) return -1;
if (packet->data_len < VQP_HDR_LEN) return -1;
- fr_pair_cursor_init(&cursor, &packet->vps);
+ fr_cursor_init(&cursor, &packet->vps);
MEM(vp = fr_pair_afrom_da(packet, attr_vqp_packet_type));
vp->vp_uint32 = packet->data[1];
vp->vp_tainted = true;
DEBUG2("&%pP", vp);
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_vqp_error_code));
vp->vp_uint32 = packet->data[2];
vp->vp_tainted = true;
DEBUG2("&%pP", vp);
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(packet, attr_vqp_sequence_number));
vp->vp_uint32 = packet->id; /* already set by vqp_recv */
vp->vp_tainted = true;
DEBUG2("&%pP", vp);
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
ptr = packet->data + VQP_HDR_LEN;
end = packet->data + packet->data_len;
ptr += attr_len;
vp->vp_tainted = true;
DEBUG2("&%pP", vp);
- fr_pair_cursor_append(&cursor, vp);
+ fr_cursor_append(&cursor, vp);
}
/*