]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Convert more things to fr_cursor_t
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 27 May 2018 16:57:30 +0000 (22:57 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 27 May 2018 16:57:30 +0000 (22:57 +0600)
src/modules/rlm_json/rlm_json.c
src/modules/rlm_ldap/groups.c
src/modules/rlm_lua/lua.c
src/modules/rlm_radius/rlm_radius.c

index 7b3e3603667fd3df89ce4388afaaa4e963149763..8666d18c4bfae30309e71d469861c9784ef3978e 100644 (file)
@@ -205,7 +205,7 @@ static int _json_map_proc_get_value(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *
                                    vp_map_t const *map, void *uctx)
 {
        VALUE_PAIR                      *vp;
-       vp_cursor_t                     cursor;
+       fr_cursor_t                     cursor;
        rlm_json_jpath_to_eval_t        *to_eval = uctx;
        fr_value_box_t                  *head, *value;
        int                             ret;
@@ -221,9 +221,9 @@ static int _json_map_proc_get_value(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *
        if (ret == 0) return 0;
        rad_assert(head);
 
-       for (fr_pair_cursor_init(&cursor, out), value = head;
+       for (fr_cursor_init(&cursor, out), value = head;
             value;
-            fr_pair_cursor_append(&cursor, vp), value = value->next) {
+            fr_cursor_append(&cursor, vp), value = value->next) {
                vp = fr_pair_afrom_da(ctx, map->lhs->tmpl_da);
                if (!vp) {
                error:
index 2e2032ade67daa2e257340bc559619d1403c23ba..f54cf80dc2bbf4f8c96a9ed408f4b3f70fe0e430 100644 (file)
@@ -280,7 +280,7 @@ rlm_rcode_t rlm_ldap_cacheable_userobj(rlm_ldap_t const *inst, REQUEST *request,
 
        VALUE_PAIR *vp, **list, *groups = NULL;
        TALLOC_CTX *list_ctx, *value_ctx;
-       vp_cursor_t list_cursor, groups_cursor;
+       fr_cursor_t list_cursor, groups_cursor;
 
        int is_dn, i, count;
 
@@ -311,7 +311,7 @@ rlm_rcode_t rlm_ldap_cacheable_userobj(rlm_ldap_t const *inst, REQUEST *request,
         *      once all group info has been gathered/resolved
         *      successfully.
         */
-       fr_pair_cursor_init(&groups_cursor, &groups);
+       fr_cursor_init(&groups_cursor, &groups);
 
        for (i = 0; (i < LDAP_MAX_CACHEABLE) && (i < count); i++) {
                is_dn = fr_ldap_util_is_dn(values[i]->bv_val, values[i]->bv_len);
@@ -323,7 +323,7 @@ rlm_rcode_t rlm_ldap_cacheable_userobj(rlm_ldap_t const *inst, REQUEST *request,
                        if (is_dn) {
                                MEM(vp = fr_pair_afrom_da(list_ctx, inst->cache_da));
                                fr_pair_value_bstrncpy(vp, values[i]->bv_val, values[i]->bv_len);
-                               fr_pair_cursor_append(&groups_cursor, vp);
+                               fr_cursor_append(&groups_cursor, vp);
                        /*
                         *      We were told to cache DNs but we got a name, we now need to resolve
                         *      this to a DN. Store all the group names in an array so we can do one query.
@@ -340,7 +340,7 @@ rlm_rcode_t rlm_ldap_cacheable_userobj(rlm_ldap_t const *inst, REQUEST *request,
                        if (!is_dn) {
                                MEM(vp = fr_pair_afrom_da(list_ctx, inst->cache_da));
                                fr_pair_value_bstrncpy(vp, values[i]->bv_val, values[i]->bv_len);
-                               fr_pair_cursor_append(&groups_cursor, vp);
+                               fr_cursor_append(&groups_cursor, vp);
                        /*
                         *      We were told to cache names but we got a DN, we now need to resolve
                         *      this to a name.
@@ -363,7 +363,7 @@ rlm_rcode_t rlm_ldap_cacheable_userobj(rlm_ldap_t const *inst, REQUEST *request,
 
                                MEM(vp = fr_pair_afrom_da(list_ctx, inst->cache_da));
                                fr_pair_value_bstrncpy(vp, name, talloc_array_length(name) - 1);
-                               fr_pair_cursor_append(&groups_cursor, vp);
+                               fr_cursor_append(&groups_cursor, vp);
                                talloc_free(name);
                        }
                }
@@ -377,24 +377,25 @@ rlm_rcode_t rlm_ldap_cacheable_userobj(rlm_ldap_t const *inst, REQUEST *request,
 
        if (rcode != RLM_MODULE_OK) return rcode;
 
-       fr_pair_cursor_init(&list_cursor, list);
+       fr_cursor_init(&list_cursor, list);
 
        RDEBUG("Adding cacheable user object memberships");
        RINDENT();
        if (RDEBUG_ENABLED) {
-               for (vp = fr_pair_cursor_first(&groups_cursor);
+               for (vp = fr_cursor_first(&groups_cursor);
                     vp;
-                    vp = fr_pair_cursor_next(&groups_cursor)) {
+                    vp = fr_cursor_next(&groups_cursor)) {
                        RDEBUG("&control:%s += \"%pV\"", inst->cache_da->name, &vp->data);
                }
        }
 
-       fr_pair_cursor_merge(&list_cursor, groups);
+       fr_cursor_head(&groups_cursor);
+       fr_cursor_merge(&list_cursor, &groups_Cursor);
 
        for (dn_p = group_dn; *dn_p; dn_p++) {
                MEM(vp = fr_pair_afrom_da(list_ctx, inst->cache_da));
                fr_pair_value_strcpy(vp, *dn_p);
-               fr_pair_cursor_append(&list_cursor, vp);
+               fr_cursor_append(&list_cursor, vp);
 
                RDEBUG("&control:%s += \"%pV\"", inst->cache_da->name, &vp->data);
                ldap_memfree(*dn_p);
@@ -819,8 +820,7 @@ rlm_rcode_t rlm_ldap_check_cached(rlm_ldap_t const *inst, REQUEST *request, VALU
         *      We return RLM_MODULE_INVALID here as an indication
         *      the caller should try a dynamic group lookup instead.
         */
-       vp = fr_cursor_talloc_iter_init(&cursor, &request->control,
-                                       fr_pair_iter_next_by_da, inst->cache_da, VALUE_PAIR);
+       vp =  fr_cursor_iter_by_da_init(&cursor, &request->control, inst->cache_da);
        if (!vp) return RLM_MODULE_INVALID;
 
        for (vp = fr_cursor_current(&cursor);
index b12b172fec8ad188fd0134460ae59cb545a72b47..e81606c0755ecd09c0e1b36648550194ca8b88a8 100644 (file)
@@ -328,7 +328,7 @@ static int rlm_lua_unmarshall(VALUE_PAIR **out, REQUEST *request, lua_State *L,
  */
 static int _lua_pair_get(lua_State *L)
 {
-       vp_cursor_t cursor;
+       fr_cursor_t cursor;
        fr_dict_attr_t const    *da;
        VALUE_PAIR              *vp = NULL;
        int                     index;
@@ -342,18 +342,14 @@ static int _lua_pair_get(lua_State *L)
        /*
         *      @fixme Packet list should be light user data too at some point
         */
-       fr_pair_cursor_init(&cursor, &request->packet->vps);
+       fr_cursor_iter_by_da_init(&cursor, &request->packet->vps, da);
 
        for (index = (int) lua_tointeger(L, -1); index >= 0; index--) {
-               vp = fr_pair_cursor_next_by_da(&cursor, da, TAG_ANY);
-               if (!vp) {
-                       return 0;
-               }
+               vp = fr_cursor_next(&cursor);
+               if (!vp) return 0;
        }
 
-       if (rlm_lua_marshall(L, vp) < 0) {
-               return -1;
-       }
+       if (rlm_lua_marshall(L, vp) < 0) return -1;
 
        return 1;
 }
@@ -370,7 +366,7 @@ static int _lua_pair_get(lua_State *L)
  */
 static int _lua_pair_set(lua_State *L)
 {
-       vp_cursor_t cursor;
+       fr_cursor_t cursor;
        fr_dict_attr_t const *da;
        VALUE_PAIR *vp = NULL, *new;
        int index;
@@ -392,13 +388,11 @@ static int _lua_pair_set(lua_State *L)
        /*
         *      @fixme Packet list should be light user data too at some point
         */
-       fr_pair_cursor_init(&cursor, &request->packet->vps);
+       fr_cursor_iter_by_da_init(&cursor, &request->packet->vps, da);
 
        for (index = (int) lua_tointeger(L, -2); index >= 0; index--) {
-               vp = fr_pair_cursor_next_by_da(&cursor, da, TAG_ANY);
-               if (vp) {
-                       break;
-               }
+               vp = fr_cursor_next(&cursor);
+               if (vp) break;
        }
 
        /*
@@ -406,7 +400,7 @@ static int _lua_pair_set(lua_State *L)
         *      attribute the cursor is currently positioned at.
         */
        if (delete) {
-               fr_pair_cursor_remove(&cursor);
+               fr_cursor_remove(&cursor);
                return 0;
        }
 
@@ -419,9 +413,9 @@ static int _lua_pair_set(lua_State *L)
         *      else we add a new VP to the list.
         */
        if (vp) {
-               fr_pair_cursor_replace(&cursor, new);
+               fr_cursor_replace(&cursor, new);
        } else {
-               fr_pair_cursor_append(&cursor, new);
+               fr_cursor_append(&cursor, new);
        }
 
        return 0;
@@ -429,8 +423,7 @@ static int _lua_pair_set(lua_State *L)
 
 static int _lua_pair_iterator(lua_State *L)
 {
-       vp_cursor_t *cursor;
-       fr_dict_attr_t const *da;
+       fr_cursor_t *cursor;
        VALUE_PAIR *vp;
 
        /*
@@ -443,13 +436,8 @@ static int _lua_pair_iterator(lua_State *L)
        cursor = lua_touserdata(L, lua_upvalueindex(1));
        rad_assert(cursor);
 
-       rad_assert(lua_isuserdata(L, lua_upvalueindex(2)));
-
-       da = lua_touserdata(L, lua_upvalueindex(2));
-       rad_assert(da);
-
        /* Packet list should be light user data too at some point... */
-       vp = fr_pair_cursor_next_by_da(cursor, da, TAG_ANY);
+       vp = fr_cursor_next(cursor);
        if (!vp) {
                lua_pushnil(L);
                return 1;
@@ -464,9 +452,8 @@ static int _lua_pair_iterator(lua_State *L)
 
 static int _lua_pair_iterator_init(lua_State *L)
 {
-       vp_cursor_t *cursor;
+       fr_cursor_t *cursor;
        fr_dict_attr_t const *da;
-       fr_dict_attr_t *up;
        REQUEST *request = rlm_lua_request;
 
        /*
@@ -478,24 +465,21 @@ static int _lua_pair_iterator_init(lua_State *L)
        da = lua_touserdata(L, lua_upvalueindex(2));
        rad_assert(da);
 
-       memcpy(&up, &da, sizeof(up));
-
-       cursor = (vp_cursor_t*) lua_newuserdata(L, sizeof(vp_cursor_t));
+       cursor = (fr_cursor_t*) lua_newuserdata(L, sizeof(fr_cursor_t));
        if (!cursor) {
                REDEBUG("Failed allocating user data to hold cursor");
                return -1;
        }
-       fr_pair_cursor_init(cursor, &request->packet->vps);     /* @FIXME: Shouldn't use list head */
+       fr_cursor_iter_by_da_init(cursor, &request->packet->vps, da);   /* @FIXME: Shouldn't use list head */
 
-       lua_pushlightuserdata(L, up);
-       lua_pushcclosure(L, _lua_pair_iterator, 2);
+       lua_pushcclosure(L, _lua_pair_iterator, 1);
 
        return 1;
 }
 
 static int _lua_list_iterator(lua_State *L)
 {
-       vp_cursor_t *cursor;
+       fr_cursor_t *cursor;
        VALUE_PAIR *vp;
 
        rad_assert(lua_isuserdata(L, lua_upvalueindex(1)));
@@ -504,7 +488,7 @@ static int _lua_list_iterator(lua_State *L)
        rad_assert(cursor);
 
        /* Packet list should be light user data too at some point... */
-       vp = fr_pair_cursor_current(cursor);
+       vp = fr_cursor_current(cursor);
        if(!vp) {
                lua_pushnil(L);
                return 1;
@@ -516,7 +500,7 @@ static int _lua_list_iterator(lua_State *L)
                return -1;
        }
 
-       fr_pair_cursor_next(cursor);
+       fr_cursor_next(cursor);
 
        return 2;
 }
@@ -526,15 +510,15 @@ static int _lua_list_iterator(lua_State *L)
  */
 static int _lua_list_iterator_init(lua_State *L)
 {
-       vp_cursor_t *cursor;
+       fr_cursor_t *cursor;
        REQUEST *request = rlm_lua_request;
 
-       cursor = (vp_cursor_t*) lua_newuserdata(L, sizeof(vp_cursor_t));
+       cursor = (fr_cursor_t*) lua_newuserdata(L, sizeof(fr_cursor_t));
        if (!cursor) {
                REDEBUG("Failed allocating user data to hold cursor");
                return -1;
        }
-       fr_pair_cursor_init(cursor, &request->packet->vps);     /* @FIXME: Shouldn't use list head */
+       fr_cursor_init(cursor, &request->packet->vps);  /* @FIXME: Shouldn't use list head */
 
        lua_pushlightuserdata(L, cursor);
        lua_pushcclosure(L, _lua_list_iterator, 1);
@@ -860,7 +844,7 @@ static lua_State *rlm_lua_get_interp(rlm_lua_t const *inst) {
 
 int do_lua(rlm_lua_t const *inst, REQUEST *request, char const *funcname)
 {
-       vp_cursor_t cursor;
+       fr_cursor_t cursor;
        lua_State *L;
 
        rlm_lua_request = request;
@@ -871,7 +855,7 @@ int do_lua(rlm_lua_t const *inst, REQUEST *request, char const *funcname)
        RDEBUG2("Calling %s() in interpreter %p", funcname, L);
 
        fr_pair_list_sort(&request->packet->vps, fr_pair_cmp_by_da_tag);
-       fr_pair_cursor_init(&cursor, &request->packet->vps);
+       fr_cursor_init(&cursor, &request->packet->vps);
 
        /*
         *      Setup the environment
index 3f38e7c1ab9487f3b4f0dee7c05777eba7740942..22c84a4d1b08bc944c79df6164a6bf8f0eb49e38 100644 (file)
@@ -456,10 +456,11 @@ static void radius_fixups(rlm_radius_t *inst, REQUEST *request)
         *      Check for proxy loops.
         */
        if (RDEBUG_ENABLED) {
-               vp_cursor_t cursor;
+               fr_cursor_t cursor;
 
-               fr_pair_cursor_init(&cursor, &request->packet->vps);
-               while ((vp = fr_pair_cursor_next_by_da(&cursor, attr_proxy_state, TAG_ANY)) != NULL) {
+               for (vp = fr_cursor_iter_by_da_init(&cursor, &request->packet->vps, attr_proxy_state);
+                    vp;
+                    vp = fr_cursor_next(&cursor)) {
                        if (vp->vp_length != 4) continue;
 
                        if (memcmp(&inst->proxy_state, vp->vp_octets, 4) == 0) {