snmpd(8).
OK jmatthew@
OK deraadt@ for bumping libutil now.
ober_add_set;
ober_add_string;
ober_calc_len;
+ ober_dup;
ober_free;
ober_free_element;
ober_free_elements;
-/* $OpenBSD: ber.c,v 1.21 2021/02/22 17:15:02 martijn Exp $ */
+/* $OpenBSD: ber.c,v 1.22 2021/08/29 13:27:11 martijn Exp $ */
/*
* Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
return elm->be_offs;
}
+struct ber_element *
+ober_dup(struct ber_element *orig)
+{
+ struct ber_element *new;
+
+ if ((new = malloc(sizeof(*new))) == NULL)
+ return NULL;
+ memcpy(new, orig, sizeof(*new));
+ new->be_next = NULL;
+ new->be_sub = NULL;
+
+ if (orig->be_next != NULL) {
+ if ((new->be_next = ober_dup(orig->be_next)) == NULL)
+ goto fail;
+ }
+ if (orig->be_encoding == BER_TYPE_SEQUENCE ||
+ orig->be_encoding == BER_TYPE_SET) {
+ if (orig->be_sub != NULL) {
+ if ((new->be_sub = ober_dup(orig->be_sub)) == NULL)
+ goto fail;
+ }
+ } else if (orig->be_encoding == BER_TYPE_OCTETSTRING ||
+ orig->be_encoding == BER_TYPE_BITSTRING ||
+ orig->be_encoding == BER_TYPE_OBJECT) {
+ if (orig->be_val != NULL) {
+ if ((new->be_val = malloc(orig->be_len)) == NULL)
+ goto fail;
+ memcpy(new->be_val, orig->be_val, orig->be_len);
+ }
+ } else
+ new->be_numeric = orig->be_numeric;
+ return new;
+ fail:
+ ober_free_elements(new);
+ return NULL;
+}
+
void
ober_free_element(struct ber_element *root)
{
-/* $OpenBSD: ber.h,v 1.3 2019/12/31 10:34:14 martijn Exp $ */
+/* $OpenBSD: ber.h,v 1.4 2021/08/29 13:27:11 martijn Exp $ */
/*
* Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
void ober_set_readbuf(struct ber *, void *, size_t);
struct ber_element *ober_read_elements(struct ber *, struct ber_element *);
off_t ober_getpos(struct ber_element *);
+struct ber_element *ober_dup(struct ber_element *);
void ober_free_element(struct ber_element *);
void ober_free_elements(struct ber_element *);
size_t ober_calc_len(struct ber_element *);
-.\" $OpenBSD: ober_set_header.3,v 1.2 2021/03/12 05:18:01 jsg Exp $
+.\" $OpenBSD: ober_set_header.3,v 1.3 2021/08/29 13:27:11 martijn Exp $
.\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: March 12 2021 $
+.Dd $Mdocdate: August 29 2021 $
.Dt OBER_SET_HEADER 3
.Os
.Sh NAME
.Nm ober_set_writecallback ,
.Nm ober_link_elements ,
.Nm ober_replace_elements ,
+.Nm ober_dup ,
.Nm ober_unlink_elements ,
.Nm ober_free_element ,
.Nm ober_free_elements
.Ft "void"
.Fn "ober_replace_elements" "struct ber_element *prev" "struct ber_element *elm"
.Ft "struct ber_element *"
+.Ft "struct ber_element *"
+.Fn "ober_dup" "struct ber_element *orig"
.Fn "ober_unlink_elements" "struct ber_element *prev"
.Ft "void"
.Fn "ober_free_element" "struct ber_element *root"
and frees any dynamically allocated storage associated with
.Fa prev .
.Pp
+.Fn ober_dup
+duplicates an element and all linked elements.
+.Pp
.Fn ober_unlink_elements
unlinks
.Fa prev .
containing one or more
.Vt ber_element .
.Pp
+.Fn ober_dup
+returns a pointer to the duplicated element or
+.Dv NULL
+on error.
+.Pp
.Fn ober_unlink_elements
returns a pointer to
.Vt ber_element .
major=15
-minor=0
+minor=1