]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move fr_tacacs_decode() to use fr_cursor_t
authorAlan T. DeKok <aland@freeradius.org>
Wed, 14 Oct 2020 17:47:47 +0000 (13:47 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 14 Oct 2020 20:22:58 +0000 (16:22 -0400)
src/modules/proto_tacacs/proto_tacacs.c
src/protocols/tacacs/decode.c
src/protocols/tacacs/tacacs.h

index 4f76f528425827173b00149eb7900e2c91463bc7..571c5fb3827931798e43e5df61619084c508bd86 100644 (file)
@@ -226,6 +226,7 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat
        fr_io_address_t const   *address = track->address;
        RADCLIENT const         *client;
        fr_tacacs_packet_t const *pkt = (fr_tacacs_packet_t const *)data;
+       fr_cursor_t             cursor;
 
        RHEXDUMP3(data, data_len, "proto_tacacs decode packet");
 
@@ -277,9 +278,10 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat
         *      That MUST be set and checked in the underlying
         *      transport, via a call to ???
         */
+       fr_cursor_init(&cursor, &request->request_pairs);
        if (fr_tacacs_decode(request->packet, request->packet->data, request->packet->data_len,
                             NULL, client->secret, talloc_array_length(client->secret) - 1,
-                            &request->request_pairs) < 0) {
+                            &cursor) < 0) {
                RPEDEBUG("Failed decoding packet");
                return -1;
        }
@@ -302,7 +304,6 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat
         *      values.
         */
        if (!client->active) {
-               fr_cursor_t cursor;
                VALUE_PAIR *vp;
 
                fr_assert(client->dynamic);
index 99227002c458d89dec238068185b5ec0277403bd..05335c9e6c210ed376c7a8b3a72ce71ab01738c7 100644 (file)
        vp = fr_pair_afrom_da(ctx, _da); \
        if (!vp) goto fail; \
        vp->vp_uint8 = _field; \
-       fr_cursor_append(&cursor, vp); \
+       fr_cursor_append(cursor, vp); \
 } while (0)
 
 #define DECODE_FIELD_STRING8(_da, _field) do { \
-       if (tacacs_decode_field(ctx, &cursor, _da, &p, \
+       if (tacacs_decode_field(ctx, cursor, _da, &p, \
            _field, end) < 0) goto fail; \
 } while (0)
 
 #define DECODE_FIELD_STRING16(_da, _field) do { \
-       if (tacacs_decode_field(ctx, &cursor, _da, &p, \
+       if (tacacs_decode_field(ctx, cursor, _da, &p, \
            ntohs(_field), end) < 0) goto fail; \
 } while (0)
 
@@ -155,14 +155,13 @@ static int tacacs_decode_field(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_att
 /**
  *     Decode a TACACS+ packet
  */
-ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_len, UNUSED const uint8_t *original, char const * const secret, size_t secret_len, VALUE_PAIR **vps)
+ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_len, UNUSED const uint8_t *original, char const * const secret, size_t secret_len, fr_cursor_t *cursor)
 {
        fr_dict_attr_t const    *tlv;
        fr_tacacs_packet_t const *pkt;
        VALUE_PAIR              *vp;
        uint8_t const           *p, *end;
        uint8_t                 *decrypted = NULL;
-       fr_cursor_t             cursor;
 
        /*
         * 3.4. The TACACS+ Packet Header
@@ -230,12 +229,10 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_l
                return -1;
        }
 
-       fr_cursor_init(&cursor, vps);
-
        /*
         *      Call the struct encoder to do the actual work.
         */
-       if (fr_struct_from_network(ctx, &cursor, attr_tacacs_packet, buffer, buffer_len, &tlv, NULL, NULL) < 0) {
+       if (fr_struct_from_network(ctx, cursor, attr_tacacs_packet, buffer, buffer_len, &tlv, NULL, NULL) < 0) {
                fr_strerror_printf("Problems to decode %s using fr_struct_from_network()", attr_tacacs_packet->name);
                return -1;
        }
@@ -504,7 +501,7 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_l
                        /*
                         *      Decode 'arg_N' arguments (horrible format)
                         */
-                       if (tacacs_decode_args(ctx, &cursor, attr_tacacs_argument_list,
+                       if (tacacs_decode_args(ctx, cursor, attr_tacacs_argument_list,
                                               pkt->author.req.arg_cnt, pkt->author.req.body, &p, end) < 0) goto fail;
 
                } else if (packet_is_author_response(pkt)) {
@@ -555,7 +552,7 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_l
                        /*
                         *      Decode 'arg_N' arguments (horrible format)
                         */
-                       if (tacacs_decode_args(ctx, &cursor, attr_tacacs_argument_list,
+                       if (tacacs_decode_args(ctx, cursor, attr_tacacs_argument_list,
                                        pkt->author.res.arg_cnt, pkt->author.res.body, &p, end) < 0) goto fail;
 
                } else {
@@ -618,7 +615,7 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_l
                        /*
                         *      Decode 'arg_N' arguments (horrible format)
                         */
-                       if (tacacs_decode_args(ctx, &cursor, attr_tacacs_argument_list,
+                       if (tacacs_decode_args(ctx, cursor, attr_tacacs_argument_list,
                                        pkt->acct.req.arg_cnt, pkt->acct.req.body, &p, end) < 0) goto fail;
 
                } else if (packet_is_acct_reply(pkt)) {
@@ -671,8 +668,12 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_l
 static ssize_t fr_tacacs_decode_proto(TALLOC_CTX *ctx, VALUE_PAIR **vps, uint8_t const *data, size_t data_len, void *proto_ctx)
 {
        fr_tacacs_ctx_t *test_ctx = talloc_get_type_abort(proto_ctx, fr_tacacs_ctx_t);
+       fr_cursor_t cursor;
+
+       *vps = NULL;
+       fr_cursor_init(&cursor, vps);
 
-       return fr_tacacs_decode(ctx, data, data_len, NULL, test_ctx->secret, (talloc_array_length(test_ctx->secret)-1), vps);
+       return fr_tacacs_decode(ctx, data, data_len, NULL, test_ctx->secret, (talloc_array_length(test_ctx->secret)-1), &cursor);
 }
 
 static int _encode_test_ctx(fr_tacacs_ctx_t *proto_ctx)
index 93a639eb715f376931a5aa46dd5a6038f91af081..0c27b3193272dac8d7303a19b97467ffc44b4daa 100644 (file)
@@ -289,7 +289,7 @@ typedef struct {
 ssize_t fr_tacacs_encode(uint8_t *buffer, size_t buffer_len, uint8_t const *original, char const *const secret, size_t secret_len, VALUE_PAIR *vps);
 
 /* decode.c */
-ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_len, UNUSED const uint8_t *original, char const * const secret, size_t secret_len, VALUE_PAIR **vps);
+ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_len, UNUSED const uint8_t *original, char const * const secret, size_t secret_len, fr_cursor_t *cursor);
 
 /* base.c */
 ssize_t                fr_tacacs_length(uint8_t const *buffer, size_t buffer_len);