From: Arran Cudbard-Bell Date: Wed, 6 Aug 2014 14:48:24 +0000 (-0400) Subject: Distinguish between single VP inserts, and list merges X-Git-Tag: release_3_0_4_rc2~52 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=e322a2008160b24715010fbd3d54072d4fde5d26;p=freeradius.git Distinguish between single VP inserts, and list merges --- diff --git a/src/include/libradius.h b/src/include/libradius.h index 1895848..f6b2df1 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -576,6 +576,7 @@ VALUE_PAIR *fr_cursor_next(vp_cursor_t *cursor); VALUE_PAIR *fr_cursor_next_peek(vp_cursor_t *cursor); VALUE_PAIR *fr_cursor_current(vp_cursor_t *cursor); void fr_cursor_insert(vp_cursor_t *cursor, VALUE_PAIR *vp); +void fr_cursor_merge(vp_cursor_t *cursor, VALUE_PAIR *vp); VALUE_PAIR *fr_cursor_remove(vp_cursor_t *cursor); VALUE_PAIR *fr_cursor_replace(vp_cursor_t *cursor, VALUE_PAIR *new); void pairdelete(VALUE_PAIR **, unsigned int attr, unsigned int vendor, int8_t tag); diff --git a/src/lib/cursor.c b/src/lib/cursor.c index de91d98..9b02b8c 100644 --- a/src/lib/cursor.c +++ b/src/lib/cursor.c @@ -183,7 +183,7 @@ VALUE_PAIR *fr_cursor_current(vp_cursor_t *cursor) return cursor->current; } -/** Insert a VP +/** Insert a single VP * * @todo don't use with pairdelete */ @@ -198,6 +198,11 @@ void fr_cursor_insert(vp_cursor_t *cursor, VALUE_PAIR *add) VERIFY_VP(add); /* + * Only allow one VP to by inserted at a time + */ + add->next = NULL; + + /* * Cursor was initialised with a pointer to a NULL value_pair */ if (!*cursor->first) { @@ -247,6 +252,26 @@ void fr_cursor_insert(vp_cursor_t *cursor, VALUE_PAIR *add) cursor->last->next = add; } +/** Merges two sets of VPs + * + * The list represented by cursor will hold the union of cursor and + * add lists. + * + * @param cursor to insert VALUE_PAIRs with + * @param add one or more VALUE_PAIRs. + */ +void fr_cursor_merge(vp_cursor_t *cursor, VALUE_PAIR *add) +{ + vp_cursor_t from; + VALUE_PAIR *vp; + + for (vp = fr_cursor_init(&from, &add); + vp; + vp = fr_cursor_next(&from)) { + fr_cursor_insert(cursor, vp); + } +} + /** Remove the current pair * * @todo this is really inefficient and should be fixed... diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c index dcc6669..4e21fdd 100644 --- a/src/lib/valuepair.c +++ b/src/lib/valuepair.c @@ -2208,7 +2208,7 @@ int readvp2(VALUE_PAIR **out, TALLOC_CTX *ctx, FILE *fp, bool *pfiledone) break; } - fr_cursor_insert(&cursor, vp); + fr_cursor_merge(&cursor, vp); buf[0] = '\0'; } diff --git a/src/main/detail.c b/src/main/detail.c index c761811..0bb1c0a 100644 --- a/src/main/detail.c +++ b/src/main/detail.c @@ -626,7 +626,7 @@ open_file: vp = NULL; if ((userparse(data, buffer, &vp) > 0) && (vp != NULL)) { - fr_cursor_insert(&cursor, vp); + fr_cursor_merge(&cursor, vp); } } diff --git a/src/main/process.c b/src/main/process.c index da6c810..f237714 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -2666,7 +2666,7 @@ static int request_will_proxy(REQUEST *request) /* Insert at the START of the list */ /* FIXME: Can't make assumptions about ordering */ fr_cursor_init(&cursor, &vp); - fr_cursor_insert(&cursor, request->proxy->vps); + fr_cursor_merge(&cursor, request->proxy->vps); request->proxy->vps = vp; } pairstrcpy(vp, strippedname->vp_strvalue); @@ -4258,7 +4258,7 @@ static int event_new_fd(rad_listen_t *this) INFO(" ... adding new socket %s (%u of %u)", buffer, home->limit.num_connections, home->limit.max_connections); } - + #endif } else { INFO(" ... adding new socket %s", buffer); diff --git a/src/main/valuepair.c b/src/main/valuepair.c index 47a40eb..5eb54fe 100644 --- a/src/main/valuepair.c +++ b/src/main/valuepair.c @@ -1238,7 +1238,7 @@ int radius_map2request(REQUEST *request, value_pair_map_t const *map, radius_tmp */ if (!dst) { RDEBUG3("No existing attribute to filter, adding instead"); - fr_cursor_insert(&dst_list, head); + fr_cursor_merge(&dst_list, head); head = NULL; goto finish; } @@ -1813,7 +1813,7 @@ int radius_tmpl_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, val vp = paircopy(ctx, *vps); if (!vp) return 0; - fr_cursor_insert(&to, vp); + fr_cursor_merge(&to, vp); break; default: diff --git a/src/modules/proto_dhcp/dhcp.c b/src/modules/proto_dhcp/dhcp.c index 18d469b..a5880b7 100644 --- a/src/modules/proto_dhcp/dhcp.c +++ b/src/modules/proto_dhcp/dhcp.c @@ -597,7 +597,7 @@ static int fr_dhcp_decode_vsa(VALUE_PAIR **tlv, TALLOC_CTX *ctx, uint8_t const * return -1; } - fr_cursor_insert(&cursor, vp); + fr_cursor_merge(&cursor, vp); p += 4 + 1 + p[4]; /* vendor id (4) + len (1) + vsa len (n) */ } @@ -620,7 +620,7 @@ static int fr_dhcp_decode_vsa(VALUE_PAIR **tlv, TALLOC_CTX *ctx, uint8_t const * * ->next directly. */ fr_cursor_init(&tlv_cursor, tlv); - fr_cursor_insert(&tlv_cursor, head); + fr_cursor_merge(&tlv_cursor, head); } return 0; @@ -750,7 +750,7 @@ static int fr_dhcp_decode_suboption(VALUE_PAIR **tlv, TALLOC_CTX *ctx, uint8_t c pairfree(&head); goto malformed; } - fr_cursor_insert(&cursor, vp); + fr_cursor_merge(&cursor, vp); a_p += a_len; } @@ -775,7 +775,7 @@ static int fr_dhcp_decode_suboption(VALUE_PAIR **tlv, TALLOC_CTX *ctx, uint8_t c * ->next directly. */ fr_cursor_init(&tlv_cursor, tlv); - fr_cursor_insert(&tlv_cursor, head); + fr_cursor_merge(&tlv_cursor, head); } return 0; @@ -1117,9 +1117,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet) return -1; } - if (options) { - fr_cursor_insert(&cursor, options); - } + if (options) fr_cursor_merge(&cursor, options); } /* @@ -1474,7 +1472,7 @@ int fr_dhcp_encode(RADIUS_PACKET *packet) /* XXX Ugly ... should be set by the caller */ if (packet->code == 0) packet->code = PW_DHCP_NAK; - + /* store xid */ if ((vp = pairfind(packet->vps, 260, DHCP_MAGIC_VENDOR, TAG_ANY))) { packet->id = vp->vp_integer; diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index bf97f9a..ddd2316 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -380,7 +380,6 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request, char co break; } - RDEBUG2("Adding to cache entry:"); if (debug_flag) radius_map_debug(request, map, vp); (void) talloc_steal(c, vp); diff --git a/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c b/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c index f4e8120..152f4ca 100644 --- a/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c +++ b/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c @@ -249,7 +249,7 @@ static VALUE_PAIR *diameter2vp(REQUEST *request, REQUEST *fake, SSL *ssl, goto do_octets; } - fr_cursor_insert(&out, vp); + fr_cursor_merge(&out, vp); goto next_attr; } diff --git a/src/modules/rlm_ldap/attrmap.c b/src/modules/rlm_ldap/attrmap.c index a1ac219..aabc527 100644 --- a/src/modules/rlm_ldap/attrmap.c +++ b/src/modules/rlm_ldap/attrmap.c @@ -88,7 +88,7 @@ static int rlm_ldap_map_getvalue(VALUE_PAIR **out, REQUEST *request, value_pair_ goto next_pair; } - fr_cursor_insert(&cursor, vp); + fr_cursor_merge(&cursor, vp); talloc_free(attr); } break;