]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move verify to set_verify callback
authorAlan T. DeKok <aland@freeradius.org>
Wed, 21 Feb 2024 16:21:46 +0000 (11:21 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 28 Feb 2024 15:23:20 +0000 (10:23 -0500)
so that we can add verification to bios which have both read and
write buffers

src/lib/bio/mem.c
src/lib/bio/mem.h

index dbc8cb8778c85e1330b0e0944596ec88b5ac736c..23ca923be5a02662ba638fc8928dfce32e67c5ee 100644 (file)
@@ -686,34 +686,6 @@ fr_bio_t *fr_bio_mem_alloc(TALLOC_CTX *ctx, size_t read_size, size_t write_size,
        return (fr_bio_t *) my;
 }
 
-/** Only return verified packets.
- *
- *  Like fr_bio_mem_alloc(), but only returns packets.
- *
- *  Writes pass straight through to the next bio.
- */
-fr_bio_t *fr_bio_mem_packet_alloc(TALLOC_CTX *ctx, size_t read_size, fr_bio_verify_t verify, bool datagram, fr_bio_t *next)
-{
-       fr_bio_mem_t *my;
-
-       if (!datagram) {
-               my = (fr_bio_mem_t *) fr_bio_mem_sink_alloc(ctx, read_size);
-       } else {
-               my = talloc_zero(ctx, fr_bio_mem_t);
-               if (!my) return NULL;
-
-               talloc_set_destructor((fr_bio_t *) my, fr_bio_destructor);
-       }
-       if (!my) return NULL;
-
-       my->verify = verify;
-       my->bio.read = datagram ? fr_bio_mem_read_packet_datagram : fr_bio_mem_read_packet;
-       my->bio.write = fr_bio_next_write;
-
-       fr_bio_chain(&my->bio, next);
-
-       return (fr_bio_t *) my;
-}
 
 /** Allocate a memory buffer which sources data from the callers application into the bio system.
  *
@@ -804,3 +776,29 @@ fr_bio_t *fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t read_size)
        talloc_set_destructor((fr_bio_t *) my, fr_bio_destructor);
        return (fr_bio_t *) my;
 }
+
+/** Set the verification function for memory bios.
+ *
+ *  It is possible to add a verification function.  It is not currently possible to remove one.
+ *
+ *  @param bio         the binary IO handler
+ *  @param verify      the verification function
+ *  @param datagram    whether or not this bio is a datagram one.
+ *  @return
+ *     - <0 on error
+ *     - 0 on success
+ */
+int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, bool datagram)
+{
+       fr_bio_mem_t *my = talloc_get_type_abort(bio, fr_bio_mem_t);
+
+       if (my->bio.read != fr_bio_mem_read) {
+               fr_strerror_const("Cannot add verify to a memory sink bio");
+               return fr_bio_error(GENERIC);
+       }
+
+       my->verify = verify;
+       my->bio.read = datagram ? fr_bio_mem_read_packet_datagram : fr_bio_mem_read_packet;
+
+       return 0;
+}
index 60478cecaaff2dbae406f87bdc91b2cd7929acbd..d0fcac39711a936358a224f8eaaeaaaa6ad98ddf 100644 (file)
@@ -51,8 +51,6 @@ typedef fr_bio_verify_action_t (*fr_bio_verify_t)(fr_bio_t *bio, void *packet_ct
 
 fr_bio_t       *fr_bio_mem_alloc(TALLOC_CTX *ctx, size_t read_size, size_t write_size, fr_bio_t *next) CC_HINT(nonnull);
 
-fr_bio_t       *fr_bio_mem_packet_alloc(TALLOC_CTX *ctx, size_t read_size, fr_bio_verify_t verify, bool datagram, fr_bio_t *next) CC_HINT(nonnull);
-
 fr_bio_t       *fr_bio_mem_source_alloc(TALLOC_CTX *ctx, size_t buffer_size, fr_bio_t *next) CC_HINT(nonnull);
 
 fr_bio_t       *fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t buffer_size) CC_HINT(nonnull);
@@ -60,3 +58,5 @@ fr_bio_t      *fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t buffer_size) CC_HINT(non
 uint8_t const  *fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size) CC_HINT(nonnull);
 
 void           fr_bio_mem_read_discard(fr_bio_t *bio, size_t size) CC_HINT(nonnull);
+
+int            fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, bool datagram) CC_HINT(nonnull);