Browse Source

The ber_* namespace is used by liblber since time immemorial,

so move our BER API to the unused ober_* prefix to avoid some
breakage in ports.
Problem diagnosed by jmatthew with ber_free() in samba, but
there are many others as pointed out by sthen.
tests & ok rob
ok sthen (who had an almost identical diff for libutil)
"go head hit it" deraadt
OpenBSD 6.6 errata 002
OPENBSD_6_6
tb 5 years ago
parent
commit
726bfd4a65
8 changed files with 433 additions and 433 deletions
  1. +45
    -45
      src/lib/libutil/Symbols.map
  2. +152
    -152
      src/lib/libutil/ber.c
  3. +46
    -46
      src/lib/libutil/ber.h
  4. +62
    -62
      src/lib/libutil/ber_add_string.3
  5. +49
    -49
      src/lib/libutil/ber_get_string.3
  6. +19
    -19
      src/lib/libutil/ber_oid_cmp.3
  7. +27
    -27
      src/lib/libutil/ber_read_elements.3
  8. +33
    -33
      src/lib/libutil/ber_set_header.3

+ 45
- 45
src/lib/libutil/Symbols.map View File

@ -9,51 +9,6 @@
{ {
global: global:
bcrypt_pbkdf; bcrypt_pbkdf;
ber_add_bitstring;
ber_add_boolean;
ber_add_enumerated;
ber_add_eoc;
ber_add_integer;
ber_add_noid;
ber_add_nstring;
ber_add_null;
ber_add_oid;
ber_add_oidstring;
ber_add_ostring;
ber_add_sequence;
ber_add_set;
ber_add_string;
ber_calc_len;
ber_free;
ber_free_element;
ber_free_elements;
ber_get_bitstring;
ber_get_boolean;
ber_get_element;
ber_get_enumerated;
ber_get_eoc;
ber_get_integer;
ber_get_nstring;
ber_get_null;
ber_get_oid;
ber_get_ostring;
ber_get_string;
ber_get_writebuf;
ber_getpos;
ber_link_elements;
ber_oid2ber;
ber_oid_cmp;
ber_printf_elements;
ber_read_elements;
ber_replace_elements;
ber_scanf_elements;
ber_set_application;
ber_set_header;
ber_set_readbuf;
ber_set_writecallback;
ber_string2oid;
ber_unlink_elements;
ber_write_elements;
fdforkpty; fdforkpty;
fdopenpty; fdopenpty;
fmt_scaled; fmt_scaled;
@ -95,6 +50,51 @@
msgbuf_drain; msgbuf_drain;
msgbuf_init; msgbuf_init;
msgbuf_write; msgbuf_write;
ober_add_bitstring;
ober_add_boolean;
ober_add_enumerated;
ober_add_eoc;
ober_add_integer;
ober_add_noid;
ober_add_nstring;
ober_add_null;
ober_add_oid;
ober_add_oidstring;
ober_add_ostring;
ober_add_sequence;
ober_add_set;
ober_add_string;
ober_calc_len;
ober_free;
ober_free_element;
ober_free_elements;
ober_get_bitstring;
ober_get_boolean;
ober_get_element;
ober_get_enumerated;
ober_get_eoc;
ober_get_integer;
ober_get_nstring;
ober_get_null;
ober_get_oid;
ober_get_ostring;
ober_get_string;
ober_get_writebuf;
ober_getpos;
ober_link_elements;
ober_oid2ber;
ober_oid_cmp;
ober_printf_elements;
ober_read_elements;
ober_replace_elements;
ober_scanf_elements;
ober_set_application;
ober_set_header;
ober_set_readbuf;
ober_set_writecallback;
ober_string2oid;
ober_unlink_elements;
ober_write_elements;
ohash_create_entry; ohash_create_entry;
ohash_delete; ohash_delete;
ohash_entries; ohash_entries;


+ 152
- 152
src/lib/libutil/ber.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ber.c,v 1.14 2019/08/15 06:11:18 martijn Exp $ */
/* $OpenBSD: ber.c,v 1.14.2.1 2019/10/27 20:05:12 tb Exp $ */
/* /*
* Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
@ -38,16 +38,16 @@
#define BER_TAG_TYPE_MASK 0x7f #define BER_TAG_TYPE_MASK 0x7f
#define BER_CLASS_SHIFT 6 #define BER_CLASS_SHIFT 6
static int ber_dump_element(struct ber *ber, struct ber_element *root);
static void ber_dump_header(struct ber *ber, struct ber_element *root);
static void ber_putc(struct ber *ber, u_char c);
static void ber_write(struct ber *ber, void *buf, size_t len);
static int ober_dump_element(struct ber *ber, struct ber_element *root);
static void ober_dump_header(struct ber *ber, struct ber_element *root);
static void ober_putc(struct ber *ber, u_char c);
static void ober_write(struct ber *ber, void *buf, size_t len);
static ssize_t get_id(struct ber *b, unsigned int *tag, int *class, static ssize_t get_id(struct ber *b, unsigned int *tag, int *class,
int *cstruct); int *cstruct);
static ssize_t get_len(struct ber *b, ssize_t *len); static ssize_t get_len(struct ber *b, ssize_t *len);
static ssize_t ber_read_element(struct ber *ber, struct ber_element *elm);
static ssize_t ber_getc(struct ber *b, u_char *c);
static ssize_t ber_read(struct ber *ber, void *buf, size_t len);
static ssize_t ober_read_element(struct ber *ber, struct ber_element *elm);
static ssize_t ober_getc(struct ber *b, u_char *c);
static ssize_t ober_read(struct ber *ber, void *buf, size_t len);
#ifdef DEBUG #ifdef DEBUG
#define DPRINTF(...) printf(__VA_ARGS__) #define DPRINTF(...) printf(__VA_ARGS__)
@ -56,7 +56,7 @@ static ssize_t ber_read(struct ber *ber, void *buf, size_t len);
#endif #endif
struct ber_element * struct ber_element *
ber_get_element(unsigned int encoding)
ober_get_element(unsigned int encoding)
{ {
struct ber_element *elm; struct ber_element *elm;
@ -64,13 +64,13 @@ ber_get_element(unsigned int encoding)
return NULL; return NULL;
elm->be_encoding = encoding; elm->be_encoding = encoding;
ber_set_header(elm, BER_CLASS_UNIVERSAL, BER_TYPE_DEFAULT);
ober_set_header(elm, BER_CLASS_UNIVERSAL, BER_TYPE_DEFAULT);
return elm; return elm;
} }
void void
ber_set_header(struct ber_element *elm, int class, unsigned int type)
ober_set_header(struct ber_element *elm, int class, unsigned int type)
{ {
elm->be_class = class & BER_CLASS_MASK; elm->be_class = class & BER_CLASS_MASK;
if (type == BER_TYPE_DEFAULT) if (type == BER_TYPE_DEFAULT)
@ -79,7 +79,7 @@ ber_set_header(struct ber_element *elm, int class, unsigned int type)
} }
void void
ber_link_elements(struct ber_element *prev, struct ber_element *elm)
ober_link_elements(struct ber_element *prev, struct ber_element *elm)
{ {
if (prev != NULL) { if (prev != NULL) {
if ((prev->be_encoding == BER_TYPE_SEQUENCE || if ((prev->be_encoding == BER_TYPE_SEQUENCE ||
@ -92,7 +92,7 @@ ber_link_elements(struct ber_element *prev, struct ber_element *elm)
} }
struct ber_element * struct ber_element *
ber_unlink_elements(struct ber_element *prev)
ober_unlink_elements(struct ber_element *prev)
{ {
struct ber_element *elm; struct ber_element *elm;
@ -110,53 +110,53 @@ ber_unlink_elements(struct ber_element *prev)
} }
void void
ber_replace_elements(struct ber_element *prev, struct ber_element *new)
ober_replace_elements(struct ber_element *prev, struct ber_element *new)
{ {
struct ber_element *ber, *next; struct ber_element *ber, *next;
ber = ber_unlink_elements(prev);
next = ber_unlink_elements(ber);
ber_link_elements(new, next);
ber_link_elements(prev, new);
ber = ober_unlink_elements(prev);
next = ober_unlink_elements(ber);
ober_link_elements(new, next);
ober_link_elements(prev, new);
/* cleanup old element */ /* cleanup old element */
ber_free_elements(ber);
ober_free_elements(ber);
} }
struct ber_element * struct ber_element *
ber_add_sequence(struct ber_element *prev)
ober_add_sequence(struct ber_element *prev)
{ {
struct ber_element *elm; struct ber_element *elm;
if ((elm = ber_get_element(BER_TYPE_SEQUENCE)) == NULL)
if ((elm = ober_get_element(BER_TYPE_SEQUENCE)) == NULL)
return NULL; return NULL;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
struct ber_element * struct ber_element *
ber_add_set(struct ber_element *prev)
ober_add_set(struct ber_element *prev)
{ {
struct ber_element *elm; struct ber_element *elm;
if ((elm = ber_get_element(BER_TYPE_SET)) == NULL)
if ((elm = ober_get_element(BER_TYPE_SET)) == NULL)
return NULL; return NULL;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
struct ber_element * struct ber_element *
ber_add_enumerated(struct ber_element *prev, long long val)
ober_add_enumerated(struct ber_element *prev, long long val)
{ {
struct ber_element *elm; struct ber_element *elm;
u_int i, len = 0; u_int i, len = 0;
u_char cur, last = 0; u_char cur, last = 0;
if ((elm = ber_get_element(BER_TYPE_ENUMERATED)) == NULL)
if ((elm = ober_get_element(BER_TYPE_ENUMERATED)) == NULL)
return NULL; return NULL;
elm->be_numeric = val; elm->be_numeric = val;
@ -173,19 +173,19 @@ ber_add_enumerated(struct ber_element *prev, long long val)
} }
elm->be_len = len + 1; elm->be_len = len + 1;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
struct ber_element * struct ber_element *
ber_add_integer(struct ber_element *prev, long long val)
ober_add_integer(struct ber_element *prev, long long val)
{ {
struct ber_element *elm; struct ber_element *elm;
u_int i, len = 0; u_int i, len = 0;
u_char cur, last = 0; u_char cur, last = 0;
if ((elm = ber_get_element(BER_TYPE_INTEGER)) == NULL)
if ((elm = ober_get_element(BER_TYPE_INTEGER)) == NULL)
return NULL; return NULL;
elm->be_numeric = val; elm->be_numeric = val;
@ -202,13 +202,13 @@ ber_add_integer(struct ber_element *prev, long long val)
} }
elm->be_len = len + 1; elm->be_len = len + 1;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
int int
ber_get_integer(struct ber_element *elm, long long *n)
ober_get_integer(struct ber_element *elm, long long *n)
{ {
if (elm->be_encoding != BER_TYPE_INTEGER) if (elm->be_encoding != BER_TYPE_INTEGER)
return -1; return -1;
@ -218,7 +218,7 @@ ber_get_integer(struct ber_element *elm, long long *n)
} }
int int
ber_get_enumerated(struct ber_element *elm, long long *n)
ober_get_enumerated(struct ber_element *elm, long long *n)
{ {
if (elm->be_encoding != BER_TYPE_ENUMERATED) if (elm->be_encoding != BER_TYPE_ENUMERATED)
return -1; return -1;
@ -228,23 +228,23 @@ ber_get_enumerated(struct ber_element *elm, long long *n)
} }
struct ber_element * struct ber_element *
ber_add_boolean(struct ber_element *prev, int bool)
ober_add_boolean(struct ber_element *prev, int bool)
{ {
struct ber_element *elm; struct ber_element *elm;
if ((elm = ber_get_element(BER_TYPE_BOOLEAN)) == NULL)
if ((elm = ober_get_element(BER_TYPE_BOOLEAN)) == NULL)
return NULL; return NULL;
elm->be_numeric = bool ? 0xff : 0; elm->be_numeric = bool ? 0xff : 0;
elm->be_len = 1; elm->be_len = 1;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
int int
ber_get_boolean(struct ber_element *elm, int *b)
ober_get_boolean(struct ber_element *elm, int *b)
{ {
if (elm->be_encoding != BER_TYPE_BOOLEAN) if (elm->be_encoding != BER_TYPE_BOOLEAN)
return -1; return -1;
@ -254,20 +254,20 @@ ber_get_boolean(struct ber_element *elm, int *b)
} }
struct ber_element * struct ber_element *
ber_add_string(struct ber_element *prev, const char *string)
ober_add_string(struct ber_element *prev, const char *string)
{ {
return ber_add_nstring(prev, string, strlen(string));
return ober_add_nstring(prev, string, strlen(string));
} }
struct ber_element * struct ber_element *
ber_add_nstring(struct ber_element *prev, const char *string0, size_t len)
ober_add_nstring(struct ber_element *prev, const char *string0, size_t len)
{ {
struct ber_element *elm; struct ber_element *elm;
char *string; char *string;
if ((string = calloc(1, len + 1)) == NULL) if ((string = calloc(1, len + 1)) == NULL)
return NULL; return NULL;
if ((elm = ber_get_element(BER_TYPE_OCTETSTRING)) == NULL) {
if ((elm = ober_get_element(BER_TYPE_OCTETSTRING)) == NULL) {
free(string); free(string);
return NULL; return NULL;
} }
@ -277,19 +277,19 @@ ber_add_nstring(struct ber_element *prev, const char *string0, size_t len)
elm->be_len = len; elm->be_len = len;
elm->be_free = 1; /* free string on cleanup */ elm->be_free = 1; /* free string on cleanup */
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
struct ber_element * struct ber_element *
ber_add_ostring(struct ber_element *prev, struct ber_octetstring *s)
ober_add_ostring(struct ber_element *prev, struct ber_octetstring *s)
{ {
return ber_add_nstring(prev, s->ostr_val, s->ostr_len);
return ober_add_nstring(prev, s->ostr_val, s->ostr_len);
} }
int int
ber_get_string(struct ber_element *elm, char **s)
ober_get_string(struct ber_element *elm, char **s)
{ {
if (elm->be_encoding != BER_TYPE_OCTETSTRING) if (elm->be_encoding != BER_TYPE_OCTETSTRING)
return -1; return -1;
@ -304,7 +304,7 @@ ber_get_string(struct ber_element *elm, char **s)
} }
int int
ber_get_nstring(struct ber_element *elm, void **p, size_t *len)
ober_get_nstring(struct ber_element *elm, void **p, size_t *len)
{ {
if (elm->be_encoding != BER_TYPE_OCTETSTRING) if (elm->be_encoding != BER_TYPE_OCTETSTRING)
return -1; return -1;
@ -315,7 +315,7 @@ ber_get_nstring(struct ber_element *elm, void **p, size_t *len)
} }
int int
ber_get_ostring(struct ber_element *elm, struct ber_octetstring *s)
ober_get_ostring(struct ber_element *elm, struct ber_octetstring *s)
{ {
if (elm->be_encoding != BER_TYPE_OCTETSTRING) if (elm->be_encoding != BER_TYPE_OCTETSTRING)
return -1; return -1;
@ -326,14 +326,14 @@ ber_get_ostring(struct ber_element *elm, struct ber_octetstring *s)
} }
struct ber_element * struct ber_element *
ber_add_bitstring(struct ber_element *prev, const void *v0, size_t len)
ober_add_bitstring(struct ber_element *prev, const void *v0, size_t len)
{ {
struct ber_element *elm; struct ber_element *elm;
void *v; void *v;
if ((v = calloc(1, len)) == NULL) if ((v = calloc(1, len)) == NULL)
return NULL; return NULL;
if ((elm = ber_get_element(BER_TYPE_BITSTRING)) == NULL) {
if ((elm = ober_get_element(BER_TYPE_BITSTRING)) == NULL) {
free(v); free(v);
return NULL; return NULL;
} }
@ -343,13 +343,13 @@ ber_add_bitstring(struct ber_element *prev, const void *v0, size_t len)
elm->be_len = len; elm->be_len = len;
elm->be_free = 1; /* free string on cleanup */ elm->be_free = 1; /* free string on cleanup */
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
int int
ber_get_bitstring(struct ber_element *elm, void **v, size_t *len)
ober_get_bitstring(struct ber_element *elm, void **v, size_t *len)
{ {
if (elm->be_encoding != BER_TYPE_BITSTRING) if (elm->be_encoding != BER_TYPE_BITSTRING)
return -1; return -1;
@ -360,20 +360,20 @@ ber_get_bitstring(struct ber_element *elm, void **v, size_t *len)
} }
struct ber_element * struct ber_element *
ber_add_null(struct ber_element *prev)
ober_add_null(struct ber_element *prev)
{ {
struct ber_element *elm; struct ber_element *elm;
if ((elm = ber_get_element(BER_TYPE_NULL)) == NULL)
if ((elm = ober_get_element(BER_TYPE_NULL)) == NULL)
return NULL; return NULL;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
int int
ber_get_null(struct ber_element *elm)
ober_get_null(struct ber_element *elm)
{ {
if (elm->be_encoding != BER_TYPE_NULL) if (elm->be_encoding != BER_TYPE_NULL)
return -1; return -1;
@ -382,20 +382,20 @@ ber_get_null(struct ber_element *elm)
} }
struct ber_element * struct ber_element *
ber_add_eoc(struct ber_element *prev)
ober_add_eoc(struct ber_element *prev)
{ {
struct ber_element *elm; struct ber_element *elm;
if ((elm = ber_get_element(BER_TYPE_EOC)) == NULL)
if ((elm = ober_get_element(BER_TYPE_EOC)) == NULL)
return NULL; return NULL;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return elm; return elm;
} }
int int
ber_get_eoc(struct ber_element *elm)
ober_get_eoc(struct ber_element *elm)
{ {
if (elm->be_encoding != BER_TYPE_EOC) if (elm->be_encoding != BER_TYPE_EOC)
return -1; return -1;
@ -404,7 +404,7 @@ ber_get_eoc(struct ber_element *elm)
} }
size_t size_t
ber_oid2ber(struct ber_oid *o, u_int8_t *buf, size_t len)
ober_oid2ber(struct ber_oid *o, u_int8_t *buf, size_t len)
{ {
u_int32_t v; u_int32_t v;
u_int i, j = 0, k; u_int i, j = 0, k;
@ -431,7 +431,7 @@ ber_oid2ber(struct ber_oid *o, u_int8_t *buf, size_t len)
} }
int int
ber_string2oid(const char *oidstr, struct ber_oid *o)
ober_string2oid(const char *oidstr, struct ber_oid *o)
{ {
char *sp, *p, str[BUFSIZ]; char *sp, *p, str[BUFSIZ];
const char *errstr; const char *errstr;
@ -453,7 +453,7 @@ ber_string2oid(const char *oidstr, struct ber_oid *o)
} }
int int
ber_oid_cmp(struct ber_oid *a, struct ber_oid *b)
ober_oid_cmp(struct ber_oid *a, struct ber_oid *b)
{ {
size_t i; size_t i;
for (i = 0; i < a->bo_n && i < b->bo_n; i++) { for (i = 0; i < a->bo_n && i < b->bo_n; i++) {
@ -479,16 +479,16 @@ ber_oid_cmp(struct ber_oid *a, struct ber_oid *b)
} }
struct ber_element * struct ber_element *
ber_add_oid(struct ber_element *prev, struct ber_oid *o)
ober_add_oid(struct ber_element *prev, struct ber_oid *o)
{ {
struct ber_element *elm; struct ber_element *elm;
u_int8_t *buf; u_int8_t *buf;
size_t len; size_t len;
if ((elm = ber_get_element(BER_TYPE_OBJECT)) == NULL)
if ((elm = ober_get_element(BER_TYPE_OBJECT)) == NULL)
return (NULL); return (NULL);
if ((len = ber_oid2ber(o, NULL, 0)) == 0)
if ((len = ober_oid2ber(o, NULL, 0)) == 0)
goto fail; goto fail;
if ((buf = calloc(1, len)) == NULL) if ((buf = calloc(1, len)) == NULL)
@ -498,20 +498,20 @@ ber_add_oid(struct ber_element *prev, struct ber_oid *o)
elm->be_len = len; elm->be_len = len;
elm->be_free = 1; elm->be_free = 1;
if (ber_oid2ber(o, buf, len) != len)
if (ober_oid2ber(o, buf, len) != len)
goto fail; goto fail;
ber_link_elements(prev, elm);
ober_link_elements(prev, elm);
return (elm); return (elm);
fail: fail:
ber_free_elements(elm);
ober_free_elements(elm);
return (NULL); return (NULL);
} }
struct ber_element * struct ber_element *
ber_add_noid(struct ber_element *prev, struct ber_oid *o, int n)
ober_add_noid(struct ber_element *prev, struct ber_oid *o, int n)
{ {
struct ber_oid no; struct ber_oid no;
@ -520,22 +520,22 @@ ber_add_noid(struct ber_element *prev, struct ber_oid *o, int n)
no.bo_n = n; no.bo_n = n;
bcopy(&o->bo_id, &no.bo_id, sizeof(no.bo_id)); bcopy(&o->bo_id, &no.bo_id, sizeof(no.bo_id));
return (ber_add_oid(prev, &no));
return (ober_add_oid(prev, &no));
} }
struct ber_element * struct ber_element *
ber_add_oidstring(struct ber_element *prev, const char *oidstr)
ober_add_oidstring(struct ber_element *prev, const char *oidstr)
{ {
struct ber_oid o; struct ber_oid o;
if (ber_string2oid(oidstr, &o) == -1)
if (ober_string2oid(oidstr, &o) == -1)
return (NULL); return (NULL);
return (ber_add_oid(prev, &o));
return (ober_add_oid(prev, &o));
} }
int int
ber_get_oid(struct ber_element *elm, struct ber_oid *o)
ober_get_oid(struct ber_element *elm, struct ber_oid *o)
{ {
u_int8_t *buf; u_int8_t *buf;
size_t len, i = 0, j = 0; size_t len, i = 0, j = 0;
@ -561,7 +561,7 @@ ber_get_oid(struct ber_element *elm, struct ber_oid *o)
} }
struct ber_element * struct ber_element *
ber_printf_elements(struct ber_element *ber, char *fmt, ...)
ober_printf_elements(struct ber_element *ber, char *fmt, ...)
{ {
va_list ap; va_list ap;
int d, class; int d, class;
@ -579,69 +579,69 @@ ber_printf_elements(struct ber_element *ber, char *fmt, ...)
case 'B': case 'B':
p = va_arg(ap, void *); p = va_arg(ap, void *);
len = va_arg(ap, size_t); len = va_arg(ap, size_t);
if ((ber = ber_add_bitstring(ber, p, len)) == NULL)
if ((ber = ober_add_bitstring(ber, p, len)) == NULL)
goto fail; goto fail;
break; break;
case 'b': case 'b':
d = va_arg(ap, int); d = va_arg(ap, int);
if ((ber = ber_add_boolean(ber, d)) == NULL)
if ((ber = ober_add_boolean(ber, d)) == NULL)
goto fail; goto fail;
break; break;
case 'd': case 'd':
d = va_arg(ap, int); d = va_arg(ap, int);
if ((ber = ber_add_integer(ber, d)) == NULL)
if ((ber = ober_add_integer(ber, d)) == NULL)
goto fail; goto fail;
break; break;
case 'e': case 'e':
e = va_arg(ap, struct ber_element *); e = va_arg(ap, struct ber_element *);
ber_link_elements(ber, e);
ober_link_elements(ber, e);
break; break;
case 'E': case 'E':
i = va_arg(ap, long long); i = va_arg(ap, long long);
if ((ber = ber_add_enumerated(ber, i)) == NULL)
if ((ber = ober_add_enumerated(ber, i)) == NULL)
goto fail; goto fail;
break; break;
case 'i': case 'i':
i = va_arg(ap, long long); i = va_arg(ap, long long);
if ((ber = ber_add_integer(ber, i)) == NULL)
if ((ber = ober_add_integer(ber, i)) == NULL)
goto fail; goto fail;
break; break;
case 'O': case 'O':
o = va_arg(ap, struct ber_oid *); o = va_arg(ap, struct ber_oid *);
if ((ber = ber_add_oid(ber, o)) == NULL)
if ((ber = ober_add_oid(ber, o)) == NULL)
goto fail; goto fail;
break; break;
case 'o': case 'o':
s = va_arg(ap, char *); s = va_arg(ap, char *);
if ((ber = ber_add_oidstring(ber, s)) == NULL)
if ((ber = ober_add_oidstring(ber, s)) == NULL)
goto fail; goto fail;
break; break;
case 's': case 's':
s = va_arg(ap, char *); s = va_arg(ap, char *);
if ((ber = ber_add_string(ber, s)) == NULL)
if ((ber = ober_add_string(ber, s)) == NULL)
goto fail; goto fail;
break; break;
case 't': case 't':
class = va_arg(ap, int); class = va_arg(ap, int);
type = va_arg(ap, unsigned int); type = va_arg(ap, unsigned int);
ber_set_header(ber, class, type);
ober_set_header(ber, class, type);
break; break;
case 'x': case 'x':
s = va_arg(ap, char *); s = va_arg(ap, char *);
len = va_arg(ap, size_t); len = va_arg(ap, size_t);
if ((ber = ber_add_nstring(ber, s, len)) == NULL)
if ((ber = ober_add_nstring(ber, s, len)) == NULL)
goto fail; goto fail;
break; break;
case '0': case '0':
if ((ber = ber_add_null(ber)) == NULL)
if ((ber = ober_add_null(ber)) == NULL)
goto fail; goto fail;
break; break;
case '{': case '{':
if ((ber = sub = ber_add_sequence(ber)) == NULL)
if ((ber = sub = ober_add_sequence(ber)) == NULL)
goto fail; goto fail;
break; break;
case '(': case '(':
if ((ber = sub = ber_add_set(ber)) == NULL)
if ((ber = sub = ober_add_set(ber)) == NULL)
goto fail; goto fail;
break; break;
case '}': case '}':
@ -649,7 +649,7 @@ ber_printf_elements(struct ber_element *ber, char *fmt, ...)
ber = sub; ber = sub;
break; break;
case '.': case '.':
if ((e = ber_add_eoc(ber)) == NULL)
if ((e = ober_add_eoc(ber)) == NULL)
goto fail; goto fail;
ber = e; ber = e;
break; break;
@ -661,12 +661,12 @@ ber_printf_elements(struct ber_element *ber, char *fmt, ...)
return (ber); return (ber);
fail: fail:
ber_free_elements(ber);
ober_free_elements(ber);
return (NULL); return (NULL);
} }
int int
ber_scanf_elements(struct ber_element *ber, char *fmt, ...)
ober_scanf_elements(struct ber_element *ber, char *fmt, ...)
{ {
#define _MAX_SEQ 128 #define _MAX_SEQ 128
va_list ap; va_list ap;
@ -690,19 +690,19 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...)
case 'B': case 'B':
ptr = va_arg(ap, void **); ptr = va_arg(ap, void **);
len = va_arg(ap, size_t *); len = va_arg(ap, size_t *);
if (ber_get_bitstring(ber, ptr, len) == -1)
if (ober_get_bitstring(ber, ptr, len) == -1)
goto fail; goto fail;
ret++; ret++;
break; break;
case 'b': case 'b':
d = va_arg(ap, int *); d = va_arg(ap, int *);
if (ber_get_boolean(ber, d) == -1)
if (ober_get_boolean(ber, d) == -1)
goto fail; goto fail;
ret++; ret++;
break; break;
case 'd': case 'd':
d = va_arg(ap, int *); d = va_arg(ap, int *);
if (ber_get_integer(ber, &l) == -1)
if (ober_get_integer(ber, &l) == -1)
goto fail; goto fail;
*d = l; *d = l;
ret++; ret++;
@ -714,19 +714,19 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...)
continue; continue;
case 'E': case 'E':
i = va_arg(ap, long long *); i = va_arg(ap, long long *);
if (ber_get_enumerated(ber, i) == -1)
if (ober_get_enumerated(ber, i) == -1)
goto fail; goto fail;
ret++; ret++;
break; break;
case 'i': case 'i':
i = va_arg(ap, long long *); i = va_arg(ap, long long *);
if (ber_get_integer(ber, i) == -1)
if (ober_get_integer(ber, i) == -1)
goto fail; goto fail;
ret++; ret++;
break; break;
case 'o': case 'o':
o = va_arg(ap, struct ber_oid *); o = va_arg(ap, struct ber_oid *);
if (ber_get_oid(ber, o) == -1)
if (ober_get_oid(ber, o) == -1)
goto fail; goto fail;
ret++; ret++;
break; break;
@ -735,7 +735,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...)
break; break;
case 's': case 's':
s = va_arg(ap, char **); s = va_arg(ap, char **);
if (ber_get_string(ber, s) == -1)
if (ober_get_string(ber, s) == -1)
goto fail; goto fail;
ret++; ret++;
break; break;
@ -749,7 +749,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...)
case 'x': case 'x':
ptr = va_arg(ap, void **); ptr = va_arg(ap, void **);
len = va_arg(ap, size_t *); len = va_arg(ap, size_t *);
if (ber_get_nstring(ber, ptr, len) == -1)
if (ober_get_nstring(ber, ptr, len) == -1)
goto fail; goto fail;
ret++; ret++;
break; break;
@ -765,7 +765,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...)
break; break;
case 'p': case 'p':
pos = va_arg(ap, off_t *); pos = va_arg(ap, off_t *);
*pos = ber_getpos(ber);
*pos = ober_getpos(ber);
ret++; ret++;
continue; continue;
case '{': case '{':
@ -802,7 +802,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...)
} }
ssize_t ssize_t
ber_get_writebuf(struct ber *b, void **buf)
ober_get_writebuf(struct ber *b, void **buf)
{ {
if (b->br_wbuf == NULL) if (b->br_wbuf == NULL)
return -1; return -1;
@ -822,12 +822,12 @@ ber_get_writebuf(struct ber *b, void **buf)
* -1 on failure and sets errno * -1 on failure and sets errno
*/ */
ssize_t ssize_t
ber_write_elements(struct ber *ber, struct ber_element *root)
ober_write_elements(struct ber *ber, struct ber_element *root)
{ {
size_t len; size_t len;
/* calculate length because only the definite form is required */ /* calculate length because only the definite form is required */
len = ber_calc_len(root);
len = ober_calc_len(root);
DPRINTF("write ber element of %zd bytes length\n", len); DPRINTF("write ber element of %zd bytes length\n", len);
if (ber->br_wbuf != NULL && ber->br_wbuf + len > ber->br_wend) { if (ber->br_wbuf != NULL && ber->br_wbuf + len > ber->br_wend) {
@ -843,14 +843,14 @@ ber_write_elements(struct ber *ber, struct ber_element *root)
/* reset write pointer */ /* reset write pointer */
ber->br_wptr = ber->br_wbuf; ber->br_wptr = ber->br_wbuf;
if (ber_dump_element(ber, root) == -1)
if (ober_dump_element(ber, root) == -1)
return -1; return -1;
return (len); return (len);
} }
void void
ber_set_readbuf(struct ber *b, void *buf, size_t len)
ober_set_readbuf(struct ber *b, void *buf, size_t len)
{ {
b->br_rbuf = b->br_rptr = buf; b->br_rbuf = b->br_rptr = buf;
b->br_rend = (u_int8_t *)buf + len; b->br_rend = (u_int8_t *)buf + len;
@ -870,21 +870,21 @@ ber_set_readbuf(struct ber *b, void *buf, size_t len)
* NULL, type mismatch or read error * NULL, type mismatch or read error
*/ */
struct ber_element * struct ber_element *
ber_read_elements(struct ber *ber, struct ber_element *elm)
ober_read_elements(struct ber *ber, struct ber_element *elm)
{ {
struct ber_element *root = elm; struct ber_element *root = elm;
if (root == NULL) { if (root == NULL) {
if ((root = ber_get_element(0)) == NULL)
if ((root = ober_get_element(0)) == NULL)
return NULL; return NULL;
} }
DPRINTF("read ber elements, root %p\n", root); DPRINTF("read ber elements, root %p\n", root);
if (ber_read_element(ber, root) == -1) {
if (ober_read_element(ber, root) == -1) {
/* Cleanup if root was allocated by us */ /* Cleanup if root was allocated by us */
if (elm == NULL) if (elm == NULL)
ber_free_elements(root);
ober_free_elements(root);
return NULL; return NULL;
} }
@ -892,17 +892,17 @@ ber_read_elements(struct ber *ber, struct ber_element *elm)
} }
off_t off_t
ber_getpos(struct ber_element *elm)
ober_getpos(struct ber_element *elm)
{ {
return elm->be_offs; return elm->be_offs;
} }
void void
ber_free_element(struct ber_element *root)
ober_free_element(struct ber_element *root)
{ {
if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE || if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE ||
root->be_encoding == BER_TYPE_SET)) root->be_encoding == BER_TYPE_SET))
ber_free_elements(root->be_sub);
ober_free_elements(root->be_sub);
if (root->be_free && (root->be_encoding == BER_TYPE_OCTETSTRING || if (root->be_free && (root->be_encoding == BER_TYPE_OCTETSTRING ||
root->be_encoding == BER_TYPE_BITSTRING || root->be_encoding == BER_TYPE_BITSTRING ||
root->be_encoding == BER_TYPE_OBJECT)) root->be_encoding == BER_TYPE_OBJECT))
@ -911,15 +911,15 @@ ber_free_element(struct ber_element *root)
} }
void void
ber_free_elements(struct ber_element *root)
ober_free_elements(struct ber_element *root)
{ {
if (root == NULL) if (root == NULL)
return; return;
if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE || if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE ||
root->be_encoding == BER_TYPE_SET)) root->be_encoding == BER_TYPE_SET))
ber_free_elements(root->be_sub);
ober_free_elements(root->be_sub);
if (root->be_next) if (root->be_next)
ber_free_elements(root->be_next);
ober_free_elements(root->be_next);
if (root->be_free && (root->be_encoding == BER_TYPE_OCTETSTRING || if (root->be_free && (root->be_encoding == BER_TYPE_OCTETSTRING ||
root->be_encoding == BER_TYPE_BITSTRING || root->be_encoding == BER_TYPE_BITSTRING ||
root->be_encoding == BER_TYPE_OBJECT)) root->be_encoding == BER_TYPE_OBJECT))
@ -928,7 +928,7 @@ ber_free_elements(struct ber_element *root)
} }
size_t size_t
ber_calc_len(struct ber_element *root)
ober_calc_len(struct ber_element *root)
{ {
unsigned int t; unsigned int t;
size_t s; size_t s;
@ -937,7 +937,7 @@ ber_calc_len(struct ber_element *root)
/* calculate the real length of a sequence or set */ /* calculate the real length of a sequence or set */
if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE || if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE ||
root->be_encoding == BER_TYPE_SET)) root->be_encoding == BER_TYPE_SET))
root->be_len = ber_calc_len(root->be_sub);
root->be_len = ober_calc_len(root->be_sub);
/* fix header length for extended types */ /* fix header length for extended types */
if (root->be_type > BER_TYPE_SINGLE_MAX) if (root->be_type > BER_TYPE_SINGLE_MAX)
@ -949,7 +949,7 @@ ber_calc_len(struct ber_element *root)
/* calculate the length of the following elements */ /* calculate the length of the following elements */
if (root->be_next) if (root->be_next)
size += ber_calc_len(root->be_next);
size += ober_calc_len(root->be_next);
/* This is an empty element, do not use a minimal size */ /* This is an empty element, do not use a minimal size */
if (root->be_class == BER_CLASS_UNIVERSAL && if (root->be_class == BER_CLASS_UNIVERSAL &&
@ -960,13 +960,13 @@ ber_calc_len(struct ber_element *root)
} }
void void
ber_set_application(struct ber *b, unsigned int (*cb)(struct ber_element *))
ober_set_application(struct ber *b, unsigned int (*cb)(struct ber_element *))
{ {
b->br_application = cb; b->br_application = cb;
} }
void void
ber_set_writecallback(struct ber_element *elm, void (*cb)(void *, size_t),
ober_set_writecallback(struct ber_element *elm, void (*cb)(void *, size_t),
void *arg) void *arg)
{ {
elm->be_cb = cb; elm->be_cb = cb;
@ -974,7 +974,7 @@ ber_set_writecallback(struct ber_element *elm, void (*cb)(void *, size_t),
} }
void void
ber_free(struct ber *b)
ober_free(struct ber *b)
{ {
free(b->br_wbuf); free(b->br_wbuf);
} }
@ -984,13 +984,13 @@ ber_free(struct ber *b)
*/ */
static int static int
ber_dump_element(struct ber *ber, struct ber_element *root)
ober_dump_element(struct ber *ber, struct ber_element *root)
{ {
unsigned long long l; unsigned long long l;
int i; int i;
uint8_t u; uint8_t u;
ber_dump_header(ber, root);
ober_dump_header(ber, root);
if (root->be_cb) if (root->be_cb)
root->be_cb(root->be_cbarg, ber->br_wptr - ber->br_wbuf); root->be_cb(root->be_cbarg, ber->br_wptr - ber->br_wbuf);
@ -1001,31 +1001,31 @@ ber_dump_element(struct ber *ber, struct ber_element *root)
l = (unsigned long long)root->be_numeric; l = (unsigned long long)root->be_numeric;
for (i = root->be_len; i > 0; i--) { for (i = root->be_len; i > 0; i--) {
u = (l >> ((i - 1) * 8)) & 0xff; u = (l >> ((i - 1) * 8)) & 0xff;
ber_putc(ber, u);
ober_putc(ber, u);
} }
break; break;
case BER_TYPE_BITSTRING: case BER_TYPE_BITSTRING:
case BER_TYPE_OCTETSTRING: case BER_TYPE_OCTETSTRING:
case BER_TYPE_OBJECT: case BER_TYPE_OBJECT:
ber_write(ber, root->be_val, root->be_len);
ober_write(ber, root->be_val, root->be_len);
break; break;
case BER_TYPE_NULL: /* no payload */ case BER_TYPE_NULL: /* no payload */
case BER_TYPE_EOC: case BER_TYPE_EOC:
break; break;
case BER_TYPE_SEQUENCE: case BER_TYPE_SEQUENCE:
case BER_TYPE_SET: case BER_TYPE_SET:
if (root->be_sub && ber_dump_element(ber, root->be_sub) == -1)
if (root->be_sub && ober_dump_element(ber, root->be_sub) == -1)
return -1; return -1;
break; break;
} }
if (root->be_next == NULL) if (root->be_next == NULL)
return 0; return 0;
return ber_dump_element(ber, root->be_next);
return ober_dump_element(ber, root->be_next);
} }
static void static void
ber_dump_header(struct ber *ber, struct ber_element *root)
ober_dump_header(struct ber *ber, struct ber_element *root)
{ {
u_char id = 0, t, buf[5]; u_char id = 0, t, buf[5];
unsigned int type; unsigned int type;
@ -1039,14 +1039,14 @@ ber_dump_header(struct ber *ber, struct ber_element *root)
root->be_encoding == BER_TYPE_SET) root->be_encoding == BER_TYPE_SET)
id |= BER_TYPE_CONSTRUCTED; id |= BER_TYPE_CONSTRUCTED;
ber_putc(ber, id);
ober_putc(ber, id);
} else { } else {
id = BER_TAG_MASK | (root->be_class << BER_CLASS_SHIFT); id = BER_TAG_MASK | (root->be_class << BER_CLASS_SHIFT);
if (root->be_encoding == BER_TYPE_SEQUENCE || if (root->be_encoding == BER_TYPE_SEQUENCE ||
root->be_encoding == BER_TYPE_SET) root->be_encoding == BER_TYPE_SET)
id |= BER_TYPE_CONSTRUCTED; id |= BER_TYPE_CONSTRUCTED;
ber_putc(ber, id);
ober_putc(ber, id);
for (t = 0, type = root->be_type; type > 0; type >>= 7) for (t = 0, type = root->be_type; type > 0; type >>= 7)
buf[t++] = type & ~BER_TAG_MORE; buf[t++] = type & ~BER_TAG_MORE;
@ -1054,26 +1054,26 @@ ber_dump_header(struct ber *ber, struct ber_element *root)
while (t-- > 0) { while (t-- > 0) {
if (t > 0) if (t > 0)
buf[t] |= BER_TAG_MORE; buf[t] |= BER_TAG_MORE;
ber_putc(ber, buf[t]);
ober_putc(ber, buf[t]);
} }
} }
if (root->be_len < BER_TAG_MORE) { if (root->be_len < BER_TAG_MORE) {
/* short form */ /* short form */
ber_putc(ber, root->be_len);
ober_putc(ber, root->be_len);
} else { } else {
for (t = 0, size = root->be_len; size > 0; size >>= 8) for (t = 0, size = root->be_len; size > 0; size >>= 8)
buf[t++] = size & 0xff; buf[t++] = size & 0xff;
ber_putc(ber, t | BER_TAG_MORE);
ober_putc(ber, t | BER_TAG_MORE);
while (t > 0) while (t > 0)
ber_putc(ber, buf[--t]);
ober_putc(ber, buf[--t]);
} }
} }
static void static void
ber_putc(struct ber *ber, u_char c)
ober_putc(struct ber *ber, u_char c)
{ {
if (ber->br_wptr + 1 <= ber->br_wend) if (ber->br_wptr + 1 <= ber->br_wend)
*ber->br_wptr = c; *ber->br_wptr = c;
@ -1081,7 +1081,7 @@ ber_putc(struct ber *ber, u_char c)
} }
static void static void
ber_write(struct ber *ber, void *buf, size_t len)
ober_write(struct ber *ber, void *buf, size_t len)
{ {
if (ber->br_wptr + len <= ber->br_wend) if (ber->br_wptr + len <= ber->br_wend)
bcopy(buf, ber->br_wptr, len); bcopy(buf, ber->br_wptr, len);
@ -1098,7 +1098,7 @@ get_id(struct ber *b, unsigned int *tag, int *class, int *cstruct)
size_t i = 0; size_t i = 0;
unsigned int t = 0; unsigned int t = 0;
if (ber_getc(b, &u) == -1)
if (ober_getc(b, &u) == -1)
return -1; return -1;
*class = (u >> BER_CLASS_SHIFT) & BER_CLASS_MASK; *class = (u >> BER_CLASS_SHIFT) & BER_CLASS_MASK;
@ -1110,7 +1110,7 @@ get_id(struct ber *b, unsigned int *tag, int *class, int *cstruct)
} }
do { do {
if (ber_getc(b, &u) == -1)
if (ober_getc(b, &u) == -1)
return -1; return -1;
/* enforce minimal number of octets for tag > 30 */ /* enforce minimal number of octets for tag > 30 */
@ -1140,7 +1140,7 @@ get_len(struct ber *b, ssize_t *len)
u_char u, n; u_char u, n;
ssize_t s, r; ssize_t s, r;
if (ber_getc(b, &u) == -1)
if (ober_getc(b, &u) == -1)
return -1; return -1;
if ((u & BER_TAG_MORE) == 0) { if ((u & BER_TAG_MORE) == 0) {
/* short form */ /* short form */
@ -1171,7 +1171,7 @@ get_len(struct ber *b, ssize_t *len)
r = n + 1; r = n + 1;
for (s = 0; n > 0; n--) { for (s = 0; n > 0; n--) {
if (ber_getc(b, &u) == -1)
if (ober_getc(b, &u) == -1)
return -1; return -1;
s = (s << 8) | u; s = (s << 8) | u;
} }
@ -1187,7 +1187,7 @@ get_len(struct ber *b, ssize_t *len)
} }
static ssize_t static ssize_t
ber_read_element(struct ber *ber, struct ber_element *elm)
ober_read_element(struct ber *ber, struct ber_element *elm)
{ {
long long val = 0; long long val = 0;
struct ber_element *next; struct ber_element *next;
@ -1261,7 +1261,7 @@ ber_read_element(struct ber *ber, struct ber_element *elm)
if (len > (ssize_t)sizeof(long long)) if (len > (ssize_t)sizeof(long long))
return -1; return -1;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (ber_getc(ber, &c) != 1)
if (ober_getc(ber, &c) != 1)
return -1; return -1;
/* smallest number of contents octets only */ /* smallest number of contents octets only */
@ -1286,7 +1286,7 @@ ber_read_element(struct ber *ber, struct ber_element *elm)
return -1; return -1;
elm->be_free = 1; elm->be_free = 1;
elm->be_len = len; elm->be_len = len;
ber_read(ber, elm->be_val, len);
ober_read(ber, elm->be_val, len);
break; break;
case BER_TYPE_OCTETSTRING: case BER_TYPE_OCTETSTRING:
case BER_TYPE_OBJECT: case BER_TYPE_OBJECT:
@ -1295,7 +1295,7 @@ ber_read_element(struct ber *ber, struct ber_element *elm)
return -1; return -1;
elm->be_free = 1; elm->be_free = 1;
elm->be_len = len; elm->be_len = len;
ber_read(ber, elm->be_val, len);
ober_read(ber, elm->be_val, len);
((u_char *)elm->be_val)[len] = '\0'; ((u_char *)elm->be_val)[len] = '\0';
break; break;
case BER_TYPE_NULL: /* no payload */ case BER_TYPE_NULL: /* no payload */
@ -1305,26 +1305,26 @@ ber_read_element(struct ber *ber, struct ber_element *elm)
case BER_TYPE_SEQUENCE: case BER_TYPE_SEQUENCE:
case BER_TYPE_SET: case BER_TYPE_SET:
if (elm->be_sub == NULL) { if (elm->be_sub == NULL) {
if ((elm->be_sub = ber_get_element(0)) == NULL)
if ((elm->be_sub = ober_get_element(0)) == NULL)
return -1; return -1;
} }
next = elm->be_sub; next = elm->be_sub;
while (len > 0) { while (len > 0) {
/* /*
* Prevent stack overflow from excessive recursion * Prevent stack overflow from excessive recursion
* depth in ber_free_elements().
* depth in ober_free_elements().
*/ */
if (elements >= BER_MAX_SEQ_ELEMENTS) { if (elements >= BER_MAX_SEQ_ELEMENTS) {
errno = ERANGE; errno = ERANGE;
return -1; return -1;
} }
r = ber_read_element(ber, next);
r = ober_read_element(ber, next);
if (r == -1) if (r == -1)
return -1; return -1;
elements++; elements++;
len -= r; len -= r;
if (len > 0 && next->be_next == NULL) { if (len > 0 && next->be_next == NULL) {
if ((next->be_next = ber_get_element(0)) ==
if ((next->be_next = ober_get_element(0)) ==
NULL) NULL)
return -1; return -1;
} }
@ -1336,13 +1336,13 @@ ber_read_element(struct ber *ber, struct ber_element *elm)
} }
static ssize_t static ssize_t
ber_getc(struct ber *b, u_char *c)
ober_getc(struct ber *b, u_char *c)
{ {
return ber_read(b, c, 1);
return ober_read(b, c, 1);
} }
static ssize_t static ssize_t
ber_read(struct ber *ber, void *buf, size_t len)
ober_read(struct ber *ber, void *buf, size_t len)
{ {
size_t sz; size_t sz;


+ 46
- 46
src/lib/libutil/ber.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: ber.h,v 1.1 2019/05/11 17:46:02 rob Exp $ */
/* $OpenBSD: ber.h,v 1.1.2.1 2019/10/27 20:05:12 tb Exp $ */
/* /*
* Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
@ -90,62 +90,62 @@ struct ber_oid {
}; };
__BEGIN_DECLS __BEGIN_DECLS
struct ber_element *ber_get_element(unsigned int);
void ber_set_header(struct ber_element *, int,
struct ber_element *ober_get_element(unsigned int);
void ober_set_header(struct ber_element *, int,
unsigned int); unsigned int);
void ber_link_elements(struct ber_element *,
void ober_link_elements(struct ber_element *,
struct ber_element *); struct ber_element *);
struct ber_element *ber_unlink_elements(struct ber_element *);
void ber_replace_elements(struct ber_element *,
struct ber_element *ober_unlink_elements(struct ber_element *);
void ober_replace_elements(struct ber_element *,
struct ber_element *); struct ber_element *);
struct ber_element *ber_add_sequence(struct ber_element *);
struct ber_element *ber_add_set(struct ber_element *);
struct ber_element *ber_add_integer(struct ber_element *, long long);
int ber_get_integer(struct ber_element *, long long *);
struct ber_element *ber_add_enumerated(struct ber_element *, long long);
int ber_get_enumerated(struct ber_element *, long long *);
struct ber_element *ber_add_boolean(struct ber_element *, int);
int ber_get_boolean(struct ber_element *, int *);
struct ber_element *ber_add_string(struct ber_element *, const char *);
struct ber_element *ber_add_nstring(struct ber_element *, const char *,
struct ber_element *ober_add_sequence(struct ber_element *);
struct ber_element *ober_add_set(struct ber_element *);
struct ber_element *ober_add_integer(struct ber_element *, long long);
int ober_get_integer(struct ber_element *, long long *);
struct ber_element *ober_add_enumerated(struct ber_element *, long long);
int ober_get_enumerated(struct ber_element *, long long *);
struct ber_element *ober_add_boolean(struct ber_element *, int);
int ober_get_boolean(struct ber_element *, int *);
struct ber_element *ober_add_string(struct ber_element *, const char *);
struct ber_element *ober_add_nstring(struct ber_element *, const char *,
size_t); size_t);
struct ber_element *ber_add_ostring(struct ber_element *,
struct ber_element *ober_add_ostring(struct ber_element *,
struct ber_octetstring *); struct ber_octetstring *);
int ber_get_string(struct ber_element *, char **);
int ber_get_nstring(struct ber_element *, void **,
int ober_get_string(struct ber_element *, char **);
int ober_get_nstring(struct ber_element *, void **,
size_t *); size_t *);
int ber_get_ostring(struct ber_element *,
int ober_get_ostring(struct ber_element *,
struct ber_octetstring *); struct ber_octetstring *);
struct ber_element *ber_add_bitstring(struct ber_element *, const void *,
struct ber_element *ober_add_bitstring(struct ber_element *, const void *,
size_t); size_t);
int ber_get_bitstring(struct ber_element *, void **,
int ober_get_bitstring(struct ber_element *, void **,
size_t *); size_t *);
struct ber_element *ber_add_null(struct ber_element *);
int ber_get_null(struct ber_element *);
struct ber_element *ber_add_eoc(struct ber_element *);
int ber_get_eoc(struct ber_element *);
struct ber_element *ber_add_oid(struct ber_element *, struct ber_oid *);
struct ber_element *ber_add_noid(struct ber_element *, struct ber_oid *, int);
struct ber_element *ber_add_oidstring(struct ber_element *, const char *);
int ber_get_oid(struct ber_element *, struct ber_oid *);
size_t ber_oid2ber(struct ber_oid *, u_int8_t *, size_t);
int ber_string2oid(const char *, struct ber_oid *);
struct ber_element *ber_printf_elements(struct ber_element *, char *, ...);
int ber_scanf_elements(struct ber_element *, char *, ...);
ssize_t ber_get_writebuf(struct ber *, void **);
ssize_t ber_write_elements(struct ber *, struct ber_element *);
void ber_set_readbuf(struct ber *, void *, size_t);
struct ber_element *ber_read_elements(struct ber *, struct ber_element *);
off_t ber_getpos(struct ber_element *);
void ber_free_element(struct ber_element *);
void ber_free_elements(struct ber_element *);
size_t ber_calc_len(struct ber_element *);
void ber_set_application(struct ber *,
struct ber_element *ober_add_null(struct ber_element *);
int ober_get_null(struct ber_element *);
struct ber_element *ober_add_eoc(struct ber_element *);
int ober_get_eoc(struct ber_element *);
struct ber_element *ober_add_oid(struct ber_element *, struct ber_oid *);
struct ber_element *ober_add_noid(struct ber_element *, struct ber_oid *, int);
struct ber_element *ober_add_oidstring(struct ber_element *, const char *);
int ober_get_oid(struct ber_element *, struct ber_oid *);
size_t ober_oid2ber(struct ber_oid *, u_int8_t *, size_t);
int ober_string2oid(const char *, struct ber_oid *);
struct ber_element *ober_printf_elements(struct ber_element *, char *, ...);
int ober_scanf_elements(struct ber_element *, char *, ...);
ssize_t ober_get_writebuf(struct ber *, void **);
ssize_t ober_write_elements(struct ber *, struct ber_element *);
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 *);
void ober_free_element(struct ber_element *);
void ober_free_elements(struct ber_element *);
size_t ober_calc_len(struct ber_element *);
void ober_set_application(struct ber *,
unsigned int (*)(struct ber_element *)); unsigned int (*)(struct ber_element *));
void ber_set_writecallback(struct ber_element *,
void ober_set_writecallback(struct ber_element *,
void (*)(void *, size_t), void *); void (*)(void *, size_t), void *);
void ber_free(struct ber *);
int ber_oid_cmp(struct ber_oid *, struct ber_oid *);
void ober_free(struct ber *);
int ober_oid_cmp(struct ber_oid *, struct ber_oid *);
__END_DECLS __END_DECLS


+ 62
- 62
src/lib/libutil/ber_add_string.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: ber_add_string.3,v 1.3 2019/05/21 12:30:07 rob Exp $
.\" $OpenBSD: ber_add_string.3,v 1.3.2.1 2019/10/27 20:05:12 tb Exp $
.\" .\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> .\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\" .\"
@ -14,69 +14,69 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: May 21 2019 $
.Dt BER_ADD_STRING 3
.Dd $Mdocdate: October 27 2019 $
.Dt OBER_ADD_STRING 3
.Os .Os
.Sh NAME .Sh NAME
.Nm ber_get_element ,
.Nm ber_add_sequence ,
.Nm ber_add_set ,
.Nm ber_add_null ,
.Nm ber_add_eoc ,
.Nm ber_add_integer ,
.Nm ber_add_enumerated ,
.Nm ber_add_boolean ,
.Nm ber_add_string ,
.Nm ber_add_nstring ,
.Nm ber_add_ostring ,
.Nm ber_add_bitstring ,
.Nm ber_add_oid ,
.Nm ber_add_noid ,
.Nm ber_add_oidstring ,
.Nm ber_printf_elements
.Nm ober_get_element ,
.Nm ober_add_sequence ,
.Nm ober_add_set ,
.Nm ober_add_null ,
.Nm ober_add_eoc ,
.Nm ober_add_integer ,
.Nm ober_add_enumerated ,
.Nm ober_add_boolean ,
.Nm ober_add_string ,
.Nm ober_add_nstring ,
.Nm ober_add_ostring ,
.Nm ober_add_bitstring ,
.Nm ober_add_oid ,
.Nm ober_add_noid ,
.Nm ober_add_oidstring ,
.Nm ober_printf_elements
.Nd create ASN.1 objects for BER encoding .Nd create ASN.1 objects for BER encoding
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h
.In ber.h .In ber.h
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_get_element" "unsigned int encoding"
.Fn "ober_get_element" "unsigned int encoding"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_sequence" "struct ber_element *prev"
.Fn "ober_add_sequence" "struct ber_element *prev"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_set" "struct ber_element *prev"
.Fn "ober_add_set" "struct ber_element *prev"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_null" "struct ber_element *prev"
.Fn "ober_add_null" "struct ber_element *prev"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_eoc" "struct ber_element *prev"
.Fn "ober_add_eoc" "struct ber_element *prev"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_integer" "struct ber_element *prev" "long long val"
.Fn "ober_add_integer" "struct ber_element *prev" "long long val"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_enumerated" "struct ber_element *prev" "long long val"
.Fn "ober_add_enumerated" "struct ber_element *prev" "long long val"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_boolean" "struct ber_element *prev" "int bool"
.Fn "ober_add_boolean" "struct ber_element *prev" "int bool"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_string" "struct ber_element *prev" "const char *string"
.Fn "ober_add_string" "struct ber_element *prev" "const char *string"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_nstring" "struct ber_element *prev" "const char *string" "size_t size"
.Fn "ober_add_nstring" "struct ber_element *prev" "const char *string" "size_t size"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fo "ber_add_ostring"
.Fo "ober_add_ostring"
.Fa "struct ber_element *prev" .Fa "struct ber_element *prev"
.Fa "struct ber_octetstring *ostring" .Fa "struct ber_octetstring *ostring"
.Fc .Fc
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fo "ber_add_bitstring"
.Fo "ober_add_bitstring"
.Fa "struct ber_element *prev" .Fa "struct ber_element *prev"
.Fa "const void *buf" .Fa "const void *buf"
.Fa "size_t size" .Fa "size_t size"
.Fc .Fc
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_oid" "struct ber_element *prev" "struct ber_oid *oid"
.Fn "ober_add_oid" "struct ber_element *prev" "struct ber_oid *oid"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_noid" "struct ber_element *prev" "struct ber_oid *oid" "int n"
.Fn "ober_add_noid" "struct ber_element *prev" "struct ber_oid *oid" "int n"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_add_oidstring" "struct ber_element *prev" "const char *string"
.Fn "ober_add_oidstring" "struct ber_element *prev" "const char *string"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_printf_elements" "struct ber_element *prev" "char *format" "..."
.Fn "ober_printf_elements" "struct ber_element *prev" "char *format" "..."
.Sh DESCRIPTION .Sh DESCRIPTION
Intermediary storage of BER elements during encoding and decoding uses the Intermediary storage of BER elements during encoding and decoding uses the
following structure: following structure:
@ -102,7 +102,7 @@ struct ber_element {
}; };
.Ed .Ed
.Pp .Pp
.Fn ber_get_element
.Fn ober_get_element
creates a new creates a new
.Vt ber_element .Vt ber_element
with default values, dynamically allocates required storage, and sets with default values, dynamically allocates required storage, and sets
@ -111,7 +111,7 @@ to
.Fa encoding . .Fa encoding .
.Pp .Pp
The The
.Fn ber_add_*
.Fn ober_add_*
functions allocate a new functions allocate a new
.Vt ber_element .Vt ber_element
of the respective type. of the respective type.
@ -128,7 +128,7 @@ they put it behind
Those functions taking a second argument initialize the content Those functions taking a second argument initialize the content
of the new element from the second argument. of the new element from the second argument.
.Pp .Pp
.Fn ber_printf_elements
.Fn ober_printf_elements
creates zero or more creates zero or more
.Vt ber_element .Vt ber_element
structures. structures.
@ -139,25 +139,25 @@ and passed to the listed function, creating one
.Vt ber_element .Vt ber_element
per byte. per byte.
The following bytes are valid: The following bytes are valid:
.Bl -column -offset indent byte ber_add_enumerated "struct ber_element *"
.Bl -column -offset indent byte ober_add_enumerated "struct ber_element *"
.It Sy byte Ta Sy function Ta Sy arguments .It Sy byte Ta Sy function Ta Sy arguments
.It B Ta Fn ber_add_bitstring Ta 2: Vt void * , size_t
.It b Ta Fn ber_add_boolean Ta 1: Vt int
.It d Ta Fn ber_add_integer Ta 1: Vt int
.It E Ta Fn ber_add_enumerated Ta 1: Vt long long
.It e Ta see below Ta 1: Vt struct ber_element *
.It i Ta Fn ber_add_integer Ta 1: Vt long long
.It O Ta Fn ber_add_oid Ta 1: Vt struct ber_oid *
.It o Ta Fn ber_add_oidstring Ta 1: Vt char *
.It s Ta Fn ber_add_string Ta 1: Vt char *
.It t Ta Xr ber_set_header 3 Ta 2: Vt int , unsigned int
.It x Ta Fn ber_add_nstring Ta 2: Vt char * , size_t
.It \&( Ta Fn ber_add_set Ta 0
.It \&) Ta see below Ta 0
.It \&. Ta Fn ber_add_eoc Ta 0
.It 0 Ta Fn ber_add_null Ta 0
.It { Ta Fn ber_add_sequence Ta 0
.It } Ta see below Ta 0
.It B Ta Fn ober_add_bitstring Ta 2: Vt void * , size_t
.It b Ta Fn ober_add_boolean Ta 1: Vt int
.It d Ta Fn ober_add_integer Ta 1: Vt int
.It E Ta Fn ober_add_enumerated Ta 1: Vt long long
.It e Ta see below Ta 1: Vt struct ber_element *
.It i Ta Fn ober_add_integer Ta 1: Vt long long
.It O Ta Fn ober_add_oid Ta 1: Vt struct ber_oid *
.It o Ta Fn ober_add_oidstring Ta 1: Vt char *
.It s Ta Fn ober_add_string Ta 1: Vt char *
.It t Ta Xr ober_set_header 3 Ta 2: Vt int , unsigned int
.It x Ta Fn ober_add_nstring Ta 2: Vt char * , size_t
.It \&( Ta Fn ober_add_set Ta 0
.It \&) Ta see below Ta 0
.It \&. Ta Fn ober_add_eoc Ta 0
.It 0 Ta Fn ober_add_null Ta 0
.It { Ta Fn ober_add_sequence Ta 0
.It } Ta see below Ta 0
.El .El
.Pp .Pp
The The
@ -175,7 +175,7 @@ if the
is the first byte in is the first byte in
.Fa fmt , .Fa fmt ,
just like the just like the
.Fn ber_add_*
.Fn ober_add_*
functions would add a new element. functions would add a new element.
The The
.Sq t .Sq t
@ -202,7 +202,7 @@ is returned and the global variable
.Va errno .Va errno
is set to indicate the error. is set to indicate the error.
.Pp .Pp
.Fn ber_printf_elements
.Fn ober_printf_elements
returns returns
.Dv NULL .Dv NULL
without setting without setting
@ -214,10 +214,10 @@ is an empty string and
is is
.Dv NULL . .Dv NULL .
.Sh SEE ALSO .Sh SEE ALSO
.Xr ber_get_string 3 ,
.Xr ber_oid_cmp 3 ,
.Xr ber_read_elements 3 ,
.Xr ber_set_header 3
.Xr ober_get_string 3 ,
.Xr ober_oid_cmp 3 ,
.Xr ober_read_elements 3 ,
.Xr ober_set_header 3
.Sh STANDARDS .Sh STANDARDS
ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: ITU-T Recommendation X.690, also known as ISO/IEC 8825-1:
Information technology - ASN.1 encoding rules. Information technology - ASN.1 encoding rules.


+ 49
- 49
src/lib/libutil/ber_get_string.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: ber_get_string.3,v 1.7 2019/08/14 17:36:04 jmc Exp $
.\" $OpenBSD: ber_get_string.3,v 1.7.2.1 2019/10/27 20:05:12 tb Exp $
.\" .\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> .\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\" .\"
@ -14,62 +14,62 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: August 14 2019 $
.Dt BER_GET_STRING 3
.Dd $Mdocdate: October 27 2019 $
.Dt OBER_GET_STRING 3
.Os .Os
.Sh NAME .Sh NAME
.Nm ber_get_null ,
.Nm ber_get_eoc ,
.Nm ber_get_integer ,
.Nm ber_get_enumerated ,
.Nm ber_get_boolean ,
.Nm ber_get_string ,
.Nm ber_get_nstring ,
.Nm ber_get_ostring ,
.Nm ber_get_bitstring ,
.Nm ber_get_oid ,
.Nm ber_getpos ,
.Nm ber_scanf_elements
.Nm ober_get_null ,
.Nm ober_get_eoc ,
.Nm ober_get_integer ,
.Nm ober_get_enumerated ,
.Nm ober_get_boolean ,
.Nm ober_get_string ,
.Nm ober_get_nstring ,
.Nm ober_get_ostring ,
.Nm ober_get_bitstring ,
.Nm ober_get_oid ,
.Nm ober_getpos ,
.Nm ober_scanf_elements
.Nd access properties of ASN.1 objects decoded from BER .Nd access properties of ASN.1 objects decoded from BER
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h
.In ber.h .In ber.h
.Ft "int" .Ft "int"
.Fn "ber_get_null" "struct ber_element *root"
.Fn "ober_get_null" "struct ber_element *root"
.Ft "int" .Ft "int"
.Fn "ber_get_eoc" "struct ber_element *root"
.Fn "ober_get_eoc" "struct ber_element *root"
.Ft "int" .Ft "int"
.Fn "ber_get_integer" "struct ber_element *root" "long long *val"
.Fn "ober_get_integer" "struct ber_element *root" "long long *val"
.Ft "int" .Ft "int"
.Fn "ber_get_enumerated" "struct ber_element *root" "long long *val"
.Fn "ober_get_enumerated" "struct ber_element *root" "long long *val"
.Ft "int" .Ft "int"
.Fn "ber_get_boolean" "struct ber_element *root" "int *bool"
.Fn "ober_get_boolean" "struct ber_element *root" "int *bool"
.Ft "int" .Ft "int"
.Fn "ber_get_string" "struct ber_element *root" "char **charbuf"
.Fn "ober_get_string" "struct ber_element *root" "char **charbuf"
.Ft "int" .Ft "int"
.Fn "ber_get_nstring" "struct ber_element *root" "void **buf" "size_t *size"
.Fn "ober_get_nstring" "struct ber_element *root" "void **buf" "size_t *size"
.Ft "int" .Ft "int"
.Fn "ber_get_ostring" "struct ber_element *root" "struct ber_octetstring *ostring"
.Fn "ober_get_ostring" "struct ber_element *root" "struct ber_octetstring *ostring"
.Ft "int" .Ft "int"
.Fn "ber_get_bitstring" "struct ber_element *root" "void **buf" "size_t *size"
.Fn "ober_get_bitstring" "struct ber_element *root" "void **buf" "size_t *size"
.Ft "int" .Ft "int"
.Fn "ber_get_oid" "struct ber_element *root" "struct ber_oid *oid"
.Fn "ober_get_oid" "struct ber_element *root" "struct ber_oid *oid"
.Ft off_t .Ft off_t
.Fn "ber_getpos" "struct ber_element *elm"
.Fn "ober_getpos" "struct ber_element *elm"
.Ft "int" .Ft "int"
.Fn "ber_scanf_elements" "struct ber_element *root" "char *format" "..."
.Fn "ober_scanf_elements" "struct ber_element *root" "char *format" "..."
.Sh DESCRIPTION .Sh DESCRIPTION
Functions which take two arguments save the value contained in the Functions which take two arguments save the value contained in the
.Fa root .Fa root
element into the storage location pointed to by the second argument. element into the storage location pointed to by the second argument.
Additionally, Additionally,
.Fn ber_get_nstring
.Fn ober_get_nstring
and and
.Fn ber_get_bitstring
.Fn ober_get_bitstring
save the number of bytes contained in the string into save the number of bytes contained in the string into
.Pf * Fa size . .Pf * Fa size .
.Pp .Pp
.Fn ber_scanf_elements
.Fn ober_scanf_elements
retrieves the values from zero or more elements starting at retrieves the values from zero or more elements starting at
.Fa root . .Fa root .
For each byte in For each byte in
@ -79,24 +79,24 @@ and passed to the function listed, processing one
.Vt ber_element .Vt ber_element
per byte. per byte.
The following bytes are valid: The following bytes are valid:
.Bl -column -offset indent bytes ber_get_enumerated() "1: struct ber_element **"
.Bl -column -offset indent bytes ober_get_enumerated() "1: struct ber_element **"
.It Sy byte Ta Sy function Ta Sy arguments .It Sy byte Ta Sy function Ta Sy arguments
.It B Ta Fn ber_get_bitstring Ta 2: Vt void ** , size_t *
.It b Ta Fn ber_get_boolean Ta 1: Vt int *
.It d Ta Fn ber_get_integer Ta 1: Vt int *
.It E Ta Fn ber_get_enumerated Ta 1: Vt long long *
.It B Ta Fn ober_get_bitstring Ta 2: Vt void ** , size_t *
.It b Ta Fn ober_get_boolean Ta 1: Vt int *
.It d Ta Fn ober_get_integer Ta 1: Vt int *
.It E Ta Fn ober_get_enumerated Ta 1: Vt long long *
.It e Ta see below Ta 1: Vt struct ber_element ** .It e Ta see below Ta 1: Vt struct ber_element **
.It i Ta Fn ber_get_integer Ta 1: Vt long long *
.It o Ta Fn ber_get_oid Ta 1: Vt struct ber_oid *
.It p Ta Fn ber_getpos Ta 1: Vt off_t *
.It i Ta Fn ober_get_integer Ta 1: Vt long long *
.It o Ta Fn ober_get_oid Ta 1: Vt struct ber_oid *
.It p Ta Fn ober_getpos Ta 1: Vt off_t *
.It S Ta see below Ta 0 .It S Ta see below Ta 0
.It s Ta Fn ber_get_string Ta 1: Vt char **
.It s Ta Fn ober_get_string Ta 1: Vt char **
.It t Ta see below Ta 2: Vt int * , unsigned int * .It t Ta see below Ta 2: Vt int * , unsigned int *
.It x Ta Fn ber_get_nstring Ta 2: Vt void **, size_t *
.It x Ta Fn ober_get_nstring Ta 2: Vt void **, size_t *
.It \&( or { Ta see below Ta 0 .It \&( or { Ta see below Ta 0
.It \&) or } Ta see below Ta 0 .It \&) or } Ta see below Ta 0
.It \&. Ta Fn ber_get_eoc Ta 0
.It 0 Ta Fn ber_get_null Ta 0
.It \&. Ta Fn ober_get_eoc Ta 0
.It 0 Ta Fn ober_get_null Ta 0
.El .El
.Pp .Pp
For For
@ -128,11 +128,11 @@ For a closing parenthesis or brace, parsing of the current sequence
or set is ended and parsing continues with the element following or set is ended and parsing continues with the element following
the sequence or set. the sequence or set.
.Sh RETURN VALUES .Sh RETURN VALUES
.Fn ber_getpos
.Fn ober_getpos
returns the value of returns the value of
.Vt be_offs . .Vt be_offs .
.Pp .Pp
.Fn ber_scanf_elements
.Fn ober_scanf_elements
returns 0 for success or \-1 when encountering elements that do not returns 0 for success or \-1 when encountering elements that do not
agree with the expectations of agree with the expectations of
.Fa fmt .Fa fmt
@ -140,17 +140,17 @@ or when
.Fa fmt .Fa fmt
is syntactically invalid. is syntactically invalid.
Even when Even when
.Fn ber_scanf_elements
.Fn ober_scanf_elements
fails, some of the arguments may already have been filled in. fails, some of the arguments may already have been filled in.
.Pp .Pp
The other functions return 0 if The other functions return 0 if
.Va root .Va root
is of the requested type or \-1 otherwise. is of the requested type or \-1 otherwise.
.Sh SEE ALSO .Sh SEE ALSO
.Xr ber_add_string 3 ,
.Xr ber_oid_cmp 3 ,
.Xr ber_read_elements 3 ,
.Xr ber_set_header 3
.Xr ober_add_string 3 ,
.Xr ober_oid_cmp 3 ,
.Xr ober_read_elements 3 ,
.Xr ober_set_header 3
.Sh STANDARDS .Sh STANDARDS
ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: ITU-T Recommendation X.690, also known as ISO/IEC 8825-1:
Information technology - ASN.1 encoding rules. Information technology - ASN.1 encoding rules.


+ 19
- 19
src/lib/libutil/ber_oid_cmp.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: ber_oid_cmp.3,v 1.2 2019/05/21 12:30:07 rob Exp $
.\" $OpenBSD: ber_oid_cmp.3,v 1.2.2.1 2019/10/27 20:05:12 tb Exp $
.\" .\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> .\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\" .\"
@ -14,23 +14,23 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: May 21 2019 $
.Dt BER_OID_CMP 3
.Dd $Mdocdate: October 27 2019 $
.Dt OBER_OID_CMP 3
.Os .Os
.Sh NAME .Sh NAME
.Nm ber_oid_cmp ,
.Nm ber_oid2ber ,
.Nm ber_string2oid
.Nm ober_oid_cmp ,
.Nm ober_oid2ber ,
.Nm ober_string2oid
.Nd OID helper functions for the BER library .Nd OID helper functions for the BER library
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h
.In ber.h .In ber.h
.Ft "int" .Ft "int"
.Fn "ber_oid_cmp" "struct ber_oid *a" "struct ber_oid *b"
.Fn "ober_oid_cmp" "struct ber_oid *a" "struct ber_oid *b"
.Ft "size_t" .Ft "size_t"
.Fn "ber_oid2ber" "struct ber_oid *oid" "u_int8_t *buf" "size_t size"
.Fn "ober_oid2ber" "struct ber_oid *oid" "u_int8_t *buf" "size_t size"
.Ft "int" .Ft "int"
.Fn "ber_string2oid" "const char *string" "struct ber_oid *oid"
.Fn "ober_string2oid" "const char *string" "struct ber_oid *oid"
.Sh DESCRIPTION .Sh DESCRIPTION
Object Identifiers are commonly used in ASN.1-based protocols. Object Identifiers are commonly used in ASN.1-based protocols.
These functions provide an interface to parse OIDs. These functions provide an interface to parse OIDs.
@ -48,24 +48,24 @@ struct ber_oid {
.Ed .Ed
.Pp .Pp
The The
.Fn ber_oid2ber
.Fn ober_oid2ber
and and
.Fn ber_string2oid
.Fn ober_string2oid
functions may be used to convert from and to functions may be used to convert from and to
.Vt struct ber_oid . .Vt struct ber_oid .
.Pp .Pp
.Fn ber_oid_cmp
.Fn ober_oid_cmp
may be used to compare two may be used to compare two
.Vt ber_oid .Vt ber_oid
structures. structures.
.Sh RETURN VALUES .Sh RETURN VALUES
.Fn ber_oid2ber
.Fn ober_oid2ber
returns the number of bytes written or 0 on faliure. returns the number of bytes written or 0 on faliure.
.Pp .Pp
.Fn ber_string2oid
.Fn ober_string2oid
returns 0 on success or -1 on failure. returns 0 on success or -1 on failure.
.Pp .Pp
.Fn ber_oid_cmp
.Fn ober_oid_cmp
returns 0 when oids returns 0 when oids
.Fa a .Fa a
and and
@ -87,10 +87,10 @@ is larger, but a child of
.Fa a , .Fa a ,
2 is returned. 2 is returned.
.Sh SEE ALSO .Sh SEE ALSO
.Xr ber_add_string 3 ,
.Xr ber_get_string 3 ,
.Xr ber_read_elements 3 ,
.Xr ber_set_header 3
.Xr ober_add_string 3 ,
.Xr ober_get_string 3 ,
.Xr ober_read_elements 3 ,
.Xr ober_set_header 3
.Sh HISTORY .Sh HISTORY
These functions first appeared as internal functions in These functions first appeared as internal functions in
.Xr snmpd 8 .Xr snmpd 8


+ 27
- 27
src/lib/libutil/ber_read_elements.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: ber_read_elements.3,v 1.5 2019/05/21 12:30:07 rob Exp $
.\" $OpenBSD: ber_read_elements.3,v 1.5.2.1 2019/10/27 20:05:12 tb Exp $
.\" .\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> .\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\" .\"
@ -14,35 +14,35 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: May 21 2019 $
.Dt BER_READ_ELEMENTS 3
.Dd $Mdocdate: October 27 2019 $
.Dt OBER_READ_ELEMENTS 3
.Os .Os
.Sh NAME .Sh NAME
.Nm ber_set_readbuf ,
.Nm ber_set_application ,
.Nm ber_read_elements ,
.Nm ber_get_writebuf ,
.Nm ber_write_elements ,
.Nm ber_free
.Nm ober_set_readbuf ,
.Nm ober_set_application ,
.Nm ober_read_elements ,
.Nm ober_get_writebuf ,
.Nm ober_write_elements ,
.Nm ober_free
.Nd encode and decode ASN.1 with Basic Encoding Rules .Nd encode and decode ASN.1 with Basic Encoding Rules
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h
.In ber.h .In ber.h
.Ft "void" .Ft "void"
.Fn "ber_set_readbuf" "struct ber *ber" "void *buf" "size_t len"
.Fn "ober_set_readbuf" "struct ber *ber" "void *buf" "size_t len"
.Ft "void" .Ft "void"
.Fo "ber_set_application"
.Fo "ober_set_application"
.Fa "struct ber *ber" .Fa "struct ber *ber"
.Fa "unsigned int (*cb)(struct ber_element *)" .Fa "unsigned int (*cb)(struct ber_element *)"
.Fc .Fc
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_read_elements" "struct ber *ber" "struct ber_element *root"
.Fn "ober_read_elements" "struct ber *ber" "struct ber_element *root"
.Ft "ssize_t" .Ft "ssize_t"
.Fn "ber_get_writebuf" "struct ber *ber" "void **buf"
.Fn "ober_get_writebuf" "struct ber *ber" "void **buf"
.Ft "ssize_t" .Ft "ssize_t"
.Fn "ber_write_elements" "struct ber *ber" "struct ber_element *root"
.Fn "ober_write_elements" "struct ber *ber" "struct ber_element *root"
.Ft "void" .Ft "void"
.Fn "ber_free" "struct ber *ber"
.Fn "ober_free" "struct ber *ber"
.Sh DESCRIPTION .Sh DESCRIPTION
The BER API provides a mechanism to read and write ASN.1 using the The BER API provides a mechanism to read and write ASN.1 using the
Basic Encoding Rules. Basic Encoding Rules.
@ -95,7 +95,7 @@ struct ber_element {
}; };
.Ed .Ed
.Pp .Pp
.Fn ber_set_readbuf
.Fn ober_set_readbuf
sets sets
.Fa br_rbuf .Fa br_rbuf
to point an input buffer of BER encoded bytes in preparation for decoding. to point an input buffer of BER encoded bytes in preparation for decoding.
@ -108,7 +108,7 @@ application, commonly obtained by
or or
.Xr tls_read 3 . .Xr tls_read 3 .
.Pp .Pp
.Fn ber_read_elements
.Fn ober_read_elements
may then be called to parse, validate, and store the may then be called to parse, validate, and store the
.Fa ber .Fa ber
data stream into its data stream into its
@ -118,12 +118,12 @@ parts for subsequent processing.
The calling application must have explicit knowledge of the expected data The calling application must have explicit knowledge of the expected data
types in order for correct decoding. types in order for correct decoding.
.Pp .Pp
.Fn ber_get_writebuf
.Fn ober_get_writebuf
sets sets
.Fa br_wbuf .Fa br_wbuf
to point to an output buffer for writing a BER byte stream. to point to an output buffer for writing a BER byte stream.
.Pp .Pp
.Fn ber_write_elements
.Fn ober_write_elements
encodes encodes
.Fa root .Fa root
into a compliant BER byte stream which is written to into a compliant BER byte stream which is written to
@ -135,23 +135,23 @@ functions such as
or or
.Xr tls_write 3 . .Xr tls_write 3 .
.Pp .Pp
.Fn ber_free
.Fn ober_free
frees any dynamically allocated storage associated with frees any dynamically allocated storage associated with
.Fa ber . .Fa ber .
.Sh RETURN VALUES .Sh RETURN VALUES
.Fn ber_read_elements
.Fn ober_read_elements
returns a pointer to a fully populated list of one or more returns a pointer to a fully populated list of one or more
.Vt ber_element .Vt ber_element
structures or structures or
.Dv NULL .Dv NULL
on a type mismatch or read error. on a type mismatch or read error.
.Pp .Pp
.Fn ber_get_writebuf
.Fn ober_get_writebuf
returns the number of bytes contained within the buffer returns the number of bytes contained within the buffer
.Fa buf .Fa buf
or \-1 on failure. or \-1 on failure.
.Pp .Pp
.Fn ber_write_elements
.Fn ober_write_elements
returns the number of bytes written. returns the number of bytes written.
Otherwise \-1 is returned and the global variable Otherwise \-1 is returned and the global variable
.Va errno .Va errno
@ -161,10 +161,10 @@ is set to indicate the error.
.Xr recv 2 , .Xr recv 2 ,
.Xr send 2 , .Xr send 2 ,
.Xr write 2 , .Xr write 2 ,
.Xr ber_add_string 3 ,
.Xr ber_get_string 3 ,
.Xr ber_oid_cmp 3 ,
.Xr ber_set_header 3 ,
.Xr ober_add_string 3 ,
.Xr ober_get_string 3 ,
.Xr ober_oid_cmp 3 ,
.Xr ober_set_header 3 ,
.Xr tls_read 3 .Xr tls_read 3
.Sh STANDARDS .Sh STANDARDS
ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: ITU-T Recommendation X.690, also known as ISO/IEC 8825-1:


+ 33
- 33
src/lib/libutil/ber_set_header.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: ber_set_header.3,v 1.3 2019/08/14 19:08:03 martijn Exp $
.\" $OpenBSD: ber_set_header.3,v 1.3.2.1 2019/10/27 20:05:12 tb Exp $
.\" .\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> .\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\" .\"
@ -14,42 +14,42 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: August 14 2019 $
.Dt BER_SET_HEADER 3
.Dd $Mdocdate: October 27 2019 $
.Dt OBER_SET_HEADER 3
.Os .Os
.Sh NAME .Sh NAME
.Nm ber_set_header ,
.Nm ber_calc_len ,
.Nm ber_set_writecallback ,
.Nm ber_link_elements ,
.Nm ber_replace_elements ,
.Nm ber_unlink_elements ,
.Nm ber_free_element ,
.Nm ber_free_elements
.Nm ober_set_header ,
.Nm ober_calc_len ,
.Nm ober_set_writecallback ,
.Nm ober_link_elements ,
.Nm ober_replace_elements ,
.Nm ober_unlink_elements ,
.Nm ober_free_element ,
.Nm ober_free_elements
.Nd change and destroy ASN.1 objects for BER encoding .Nd change and destroy ASN.1 objects for BER encoding
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h
.In ber.h .In ber.h
.Ft "void" .Ft "void"
.Fn "ber_set_header" "struct ber_element *elm" "int class" "unsigned int type"
.Fn "ober_set_header" "struct ber_element *elm" "int class" "unsigned int type"
.Ft "size_t" .Ft "size_t"
.Fn "ber_calc_len" "struct ber_element *root"
.Fn "ober_calc_len" "struct ber_element *root"
.Ft "void" .Ft "void"
.Fo "ber_set_writecallback"
.Fo "ober_set_writecallback"
.Fa "struct ber_element *elm" .Fa "struct ber_element *elm"
.Fa "void (*cb)(void *arg, size_t offs)" .Fa "void (*cb)(void *arg, size_t offs)"
.Fa "void *arg" .Fa "void *arg"
.Fc .Fc
.Ft "void" .Ft "void"
.Fn "ber_link_elements" "struct ber_element *prev" "struct ber_element *elm"
.Fn "ober_link_elements" "struct ber_element *prev" "struct ber_element *elm"
.Ft "void" .Ft "void"
.Fn "ber_replace_elements" "struct ber_element *prev" "struct ber_element *elm"
.Fn "ober_replace_elements" "struct ber_element *prev" "struct ber_element *elm"
.Ft "struct ber_element *" .Ft "struct ber_element *"
.Fn "ber_unlink_elements" "struct ber_element *prev"
.Fn "ober_unlink_elements" "struct ber_element *prev"
.Ft "void" .Ft "void"
.Fn "ber_free_element" "struct ber_element *root"
.Fn "ober_free_element" "struct ber_element *root"
.Ft "void" .Ft "void"
.Fn "ber_free_elements" "struct ber_element *root"
.Fn "ober_free_elements" "struct ber_element *root"
.Pp .Pp
.Fd #define BER_TYPE_BOOLEAN 1 .Fd #define BER_TYPE_BOOLEAN 1
.Fd #define BER_TYPE_INTEGER 2 .Fd #define BER_TYPE_INTEGER 2
@ -70,7 +70,7 @@
.Fd #define BER_CLASS_CONTEXT 0x2 .Fd #define BER_CLASS_CONTEXT 0x2
.Fd #define BER_CLASS_PRIVATE 0x3 .Fd #define BER_CLASS_PRIVATE 0x3
.Sh DESCRIPTION .Sh DESCRIPTION
.Fn ber_set_header
.Fn ober_set_header
sets the sets the
.Fa class .Fa class
and and
@ -78,22 +78,22 @@ and
of of
.Fa elm . .Fa elm .
.Pp .Pp
.Fn ber_calc_len
.Fn ober_calc_len
determines the total length of determines the total length of
.Fa root . .Fa root .
.Pp .Pp
.Fn ber_set_writecallback
.Fn ober_set_writecallback
registers the registers the
.Vt br_cb .Vt br_cb
callback function. callback function.
.Pp .Pp
.Fn ber_link_elements
.Fn ober_link_elements
links links
.Fa prev .Fa prev
and and
.Fa elm . .Fa elm .
.Pp .Pp
.Fn ber_replace_elements
.Fn ober_replace_elements
replaces replaces
.Fa prev .Fa prev
with with
@ -101,30 +101,30 @@ with
and frees any dynamically allocated storage assocated with and frees any dynamically allocated storage assocated with
.Fa prev . .Fa prev .
.Pp .Pp
.Fn ber_unlink_elements
.Fn ober_unlink_elements
unlinks unlinks
.Fa prev . .Fa prev .
.Pp .Pp
.Fn ber_free_element
.Fn ober_free_element
and and
.Fn ber_free_elements
.Fn ober_free_elements
free any dynamically allocated storage associated with free any dynamically allocated storage associated with
.Fa root . .Fa root .
.Sh RETURN VALUES .Sh RETURN VALUES
.Fn ber_calc_len
.Fn ober_calc_len
returns the total length of a fully populated returns the total length of a fully populated
.Fa root .Fa root
containing one or more containing one or more
.Vt ber_element . .Vt ber_element .
.Pp .Pp
.Fn ber_unlink_elements
.Fn ober_unlink_elements
returns a pointer to returns a pointer to
.Vt ber_element . .Vt ber_element .
.Sh SEE ALSO .Sh SEE ALSO
.Xr ber_add_string 3 ,
.Xr ber_get_string 3 ,
.Xr ber_oid_cmp 3 ,
.Xr ber_read_elements 3
.Xr ober_add_string 3 ,
.Xr ober_get_string 3 ,
.Xr ober_oid_cmp 3 ,
.Xr ober_read_elements 3
.Sh STANDARDS .Sh STANDARDS
ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: ITU-T Recommendation X.690, also known as ISO/IEC 8825-1:
Information technology - ASN.1 encoding rules. Information technology - ASN.1 encoding rules.


Loading…
Cancel
Save