diff options
author | rob <rob@cvs.openbsd.org> | 2018-06-29 15:18:04 +0000 |
---|---|---|
committer | rob <rob@cvs.openbsd.org> | 2018-06-29 15:18:04 +0000 |
commit | 5c54f70a04a01fbf7edc97d7a8b26f24f82ce0f5 (patch) | |
tree | 1e9b83b2e8f12323c6ee94f4d338b1a8785be0e4 | |
parent | 267e3b2f28ab6cce44177df6d68069f25b7a902a (diff) |
Synchronize ber.c and ber.h across ldap, ldapd, and ypldap, and reduce diff
with snmpd. More tweaks to come once things are fully synchronized.
Feedback from claudio and Robert Klein.
Ok claudio@
-rw-r--r-- | usr.bin/ldap/ber.c | 29 | ||||
-rw-r--r-- | usr.bin/ldap/ber.h | 3 | ||||
-rw-r--r-- | usr.sbin/ldapd/ber.c | 4 | ||||
-rw-r--r-- | usr.sbin/snmpd/ber.3 | 35 | ||||
-rw-r--r-- | usr.sbin/snmpd/ber.c | 4 | ||||
-rw-r--r-- | usr.sbin/ypldap/ber.c | 29 | ||||
-rw-r--r-- | usr.sbin/ypldap/ber.h | 3 |
7 files changed, 81 insertions, 26 deletions
diff --git a/usr.bin/ldap/ber.c b/usr.bin/ldap/ber.c index 91a0a7cf648..f2266296e3a 100644 --- a/usr.bin/ldap/ber.c +++ b/usr.bin/ldap/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.4 2018/06/27 20:38:10 rob Exp $ */ +/* $OpenBSD: ber.c,v 1.5 2018/06/29 15:18:03 rob Exp $ */ /* * Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net> @@ -729,7 +729,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...) goto fail; ber = parent[level--]; ret++; - continue; + break; default: goto fail; } @@ -822,6 +822,19 @@ ber_read_elements(struct ber *ber, struct ber_element *elm) } void +ber_free_element(struct ber_element *root) +{ + if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE || + root->be_encoding == BER_TYPE_SET)) + ber_free_elements(root->be_sub); + if (root->be_free && (root->be_encoding == BER_TYPE_OCTETSTRING || + root->be_encoding == BER_TYPE_BITSTRING || + root->be_encoding == BER_TYPE_OBJECT)) + free(root->be_val); + free(root); +} + +void ber_free_elements(struct ber_element *root) { if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE || @@ -1030,6 +1043,12 @@ get_len(struct ber *b, ssize_t *len) return 1; } + if (u == 0x80) { + /* Indefinite length not supported. */ + errno = EINVAL; + return -1; + } + n = u & ~BER_TAG_MORE; if (sizeof(ssize_t) < n) { errno = ERANGE; @@ -1049,12 +1068,6 @@ get_len(struct ber *b, ssize_t *len) return -1; } - if (s == 0) { - /* invalid encoding */ - errno = EINVAL; - return -1; - } - *len = s; return r; } diff --git a/usr.bin/ldap/ber.h b/usr.bin/ldap/ber.h index d5b7ed99b37..a8b874c7bbe 100644 --- a/usr.bin/ldap/ber.h +++ b/usr.bin/ldap/ber.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.h,v 1.1 2018/06/13 15:45:57 reyk Exp $ */ +/* $OpenBSD: ber.h,v 1.2 2018/06/29 15:18:03 rob Exp $ */ /* * Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net> @@ -119,6 +119,7 @@ ssize_t ber_get_writebuf(struct ber *, void **); int 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 *); +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 *, diff --git a/usr.sbin/ldapd/ber.c b/usr.sbin/ldapd/ber.c index 2a3988db5ce..1c4f7ddccef 100644 --- a/usr.sbin/ldapd/ber.c +++ b/usr.sbin/ldapd/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.14 2018/06/27 13:22:17 rob Exp $ */ +/* $OpenBSD: ber.c,v 1.15 2018/06/29 15:18:03 rob Exp $ */ /* * Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net> @@ -729,7 +729,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...) goto fail; ber = parent[level--]; ret++; - continue; + break; default: goto fail; } diff --git a/usr.sbin/snmpd/ber.3 b/usr.sbin/snmpd/ber.3 index 4d7f29837a4..96ed5093c58 100644 --- a/usr.sbin/snmpd/ber.3 +++ b/usr.sbin/snmpd/ber.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ber.3,v 1.13 2013/10/01 12:48:27 reyk Exp $ +.\" $OpenBSD: ber.3,v 1.14 2018/06/29 15:18:03 rob Exp $ .\" .\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 1 2013 $ +.Dd $Mdocdate: June 29 2018 $ .Dt BER 3 .Os .Sh NAME @@ -25,8 +25,10 @@ .Nm ber_replace_elements , .Nm ber_add_sequence , .Nm ber_add_set , +.Nm ber_add_enumerated , .Nm ber_add_integer , .Nm ber_get_integer , +.Nm ber_get_enumerated , .Nm ber_add_boolean , .Nm ber_get_boolean , .Nm ber_add_string , @@ -40,10 +42,12 @@ .Nm ber_add_eoc , .Nm ber_get_eoc , .Nm ber_add_oid , +.Nm ber_add_noid , .Nm ber_add_oidstring , .Nm ber_get_oid , .Nm ber_oid2ber , .Nm ber_string2oid , +.Nm ber_oid_cmp , .Nm ber_printf_elements , .Nm ber_scanf_elements , .Nm ber_get_writebuf , @@ -54,7 +58,7 @@ .Nm ber_free_elements , .Nm ber_calc_len , .Nm ber_set_application , -.Nm ber_set_writecallback +.Nm ber_set_writecallback , .Nm ber_free .Nd parse ASN.1 with Basic Encoding Rules .Sh SYNOPSIS @@ -78,6 +82,10 @@ .Ft "int" .Fn "ber_get_integer" "struct ber_element *root" "long long *val" .Ft "struct ber_element *" +.Fn "ber_add_enumerated" "struct ber_element *prev" "long long val" +.Ft "int" +.Fn "ber_get_enumerated" "struct ber_element *root" "long long *val" +.Ft "struct ber_element *" .Fn "ber_add_boolean" "struct ber_element *prev" "int bool" .Ft "int" .Fn "ber_get_boolean" "struct ber_element *root" "int *bool" @@ -104,6 +112,8 @@ .Ft "struct ber_element *" .Fn "ber_add_oid" "struct ber_element *prev" "struct ber_oid *oid" .Ft "struct ber_element *" +.Fn "ber_add_noid" "struct ber_element *prev" "struct ber_oid *oid, int n" +.Ft "struct ber_element *" .Fn "ber_add_oidstring" "struct ber_element *prev" "const char *string" .Ft "int" .Fn "ber_get_oid" "struct ber_element *root" "struct ber_oid *oid" @@ -111,6 +121,8 @@ .Fn "ber_oid2ber" "struct ber_oid *oid" "u_int8_t *buf" "size_t size" .Ft "int" .Fn "ber_string2oid" "const char *string" "struct ber_oid *oid" +.Ft "int" +.Fn "ber_oid_cmp" "struct ber_oid *oid" "struct ber_oid *oid" .Ft "struct ber_element *" .Fn "ber_printf_elements" "struct ber_element *prev" "char *format" "..." .Ft "int" @@ -153,6 +165,8 @@ using the .Fn ber_add_set , .Fn ber_add_integer , .Fn ber_get_integer , +.Fn ber_add_enumerated , +.Fn ber_get_enumerated , .Fn ber_add_boolean , .Fn ber_get_boolean , .Fn ber_add_string , @@ -182,11 +196,12 @@ struct ber_oid { .Ed .Pp .Fn ber_add_oid , +.Fn ber_add_noid , .Fn ber_add_oidstring , .Fn ber_get_oid , .Fn ber_oid2ber , -.Fn ber_oid_cmp , .Fn ber_string2oid +.Fn ber_oid_cmp , .Sh FORMAT STRINGS .Fn ber_printf_elements , .Fn ber_scanf_elements @@ -203,6 +218,7 @@ struct ber_oid { .Sh RETURN VALUES Upon successful completion .Fn ber_get_integer , +.Fn ber_get_enumerated , .Fn ber_get_boolean , .Fn ber_get_string , .Fn ber_get_nstring , @@ -225,6 +241,9 @@ The .Nm ber manpage first appeared in .Ox 4.3 . +.Sh STANDARDS +ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: +Information technology - ASN.1 encoding rules. .Sh AUTHORS .An -nosplit The @@ -234,5 +253,13 @@ library was written by .An Marc Balmer Aq Mt marc@openbsd.org and .An Reyk Floeter Aq Mt reyk@openbsd.org . +.Sh CAVEATS +Only the subset of +.Nm ber +data types specified above are supported. +.Pp +Indefinite length +.Nm ber +encoding is not supported. .Sh BUGS This manpage is a stub. diff --git a/usr.sbin/snmpd/ber.c b/usr.sbin/snmpd/ber.c index 1f750fbd08a..1255910f6c7 100644 --- a/usr.sbin/snmpd/ber.c +++ b/usr.sbin/snmpd/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.33 2018/06/27 13:22:17 rob Exp $ */ +/* $OpenBSD: ber.c,v 1.34 2018/06/29 15:18:03 rob Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> @@ -1258,7 +1258,7 @@ ber_free(struct ber *b) static ssize_t ber_getc(struct ber *b, u_char *c) { - return ber_read(b, c, 1); + return ber_readbuf(b, c, 1); } static ssize_t diff --git a/usr.sbin/ypldap/ber.c b/usr.sbin/ypldap/ber.c index 38d3ad191f6..bf24d446aae 100644 --- a/usr.sbin/ypldap/ber.c +++ b/usr.sbin/ypldap/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.16 2018/06/27 20:38:10 rob Exp $ */ +/* $OpenBSD: ber.c,v 1.17 2018/06/29 15:18:03 rob Exp $ */ /* * Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net> @@ -729,7 +729,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...) goto fail; ber = parent[level--]; ret++; - continue; + break; default: goto fail; } @@ -822,6 +822,19 @@ ber_read_elements(struct ber *ber, struct ber_element *elm) } void +ber_free_element(struct ber_element *root) +{ + if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE || + root->be_encoding == BER_TYPE_SET)) + ber_free_elements(root->be_sub); + if (root->be_free && (root->be_encoding == BER_TYPE_OCTETSTRING || + root->be_encoding == BER_TYPE_BITSTRING || + root->be_encoding == BER_TYPE_OBJECT)) + free(root->be_val); + free(root); +} + +void ber_free_elements(struct ber_element *root) { if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE || @@ -1030,6 +1043,12 @@ get_len(struct ber *b, ssize_t *len) return 1; } + if (u == 0x80) { + /* Indefinite length not supported. */ + errno = EINVAL; + return -1; + } + n = u & ~BER_TAG_MORE; if (sizeof(ssize_t) < n) { errno = ERANGE; @@ -1049,12 +1068,6 @@ get_len(struct ber *b, ssize_t *len) return -1; } - if (s == 0) { - /* invalid encoding */ - errno = EINVAL; - return -1; - } - *len = s; return r; } diff --git a/usr.sbin/ypldap/ber.h b/usr.sbin/ypldap/ber.h index 153b959088e..04b303127f8 100644 --- a/usr.sbin/ypldap/ber.h +++ b/usr.sbin/ypldap/ber.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.h,v 1.3 2018/02/08 18:02:06 jca Exp $ */ +/* $OpenBSD: ber.h,v 1.4 2018/06/29 15:18:03 rob Exp $ */ /* * Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net> @@ -119,6 +119,7 @@ ssize_t ber_get_writebuf(struct ber *, void **); int 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 *); +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 *, |