From 8defa1f363740db22e1847d700fab2ee9b97f04e Mon Sep 17 00:00:00 2001 From: claudio Date: Tue, 31 Jul 2018 11:00:12 +0000 Subject: [PATCH] Make ber type and encoding a unsigned int instead of unsigned long. This way the size is the same on all archs and 32bit should be good enough. OK rob@ --- usr.sbin/ypldap/aldap.c | 19 +++++++++---------- usr.sbin/ypldap/ber.c | 32 ++++++++++++++++---------------- usr.sbin/ypldap/ber.h | 16 ++++++++-------- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/usr.sbin/ypldap/aldap.c b/usr.sbin/ypldap/aldap.c index bf3a7833539..d54a0ac27e6 100644 --- a/usr.sbin/ypldap/aldap.c +++ b/usr.sbin/ypldap/aldap.c @@ -1,5 +1,5 @@ -/* $Id: aldap.c,v 1.40 2018/06/21 10:37:00 reyk Exp $ */ -/* $OpenBSD: aldap.c,v 1.40 2018/06/21 10:37:00 reyk Exp $ */ +/* $Id: aldap.c,v 1.41 2018/07/31 11:00:12 claudio Exp $ */ +/* $OpenBSD: aldap.c,v 1.41 2018/07/31 11:00:12 claudio Exp $ */ /* * Copyright (c) 2008 Alexander Schrijver @@ -47,7 +47,7 @@ int aldap_create_page_control(struct ber_element *, int, struct aldap_page_control *); int aldap_send(struct aldap *, struct ber_element *); -unsigned long aldap_application(struct ber_element *); +unsigned int aldap_application(struct ber_element *); #ifdef DEBUG void ldap_debug_elements(struct ber_element *); @@ -61,7 +61,7 @@ void ldap_debug_elements(struct ber_element *); #define LDAP_DEBUG(x, y) do { } while (0) #endif -unsigned long +unsigned int aldap_application(struct ber_element *elm) { return BER_TYPE_OCTETSTRING; @@ -168,8 +168,7 @@ aldap_req_starttls(struct aldap *ldap) goto fail; ber = ber_printf_elements(root, "d{tst", ++ldap->msgid, BER_CLASS_APP, - (unsigned long) LDAP_REQ_EXTENDED, LDAP_STARTTLS_OID, - BER_CLASS_CONTEXT, (unsigned long) 0); + LDAP_REQ_EXTENDED, LDAP_STARTTLS_OID, BER_CLASS_CONTEXT, 0); if (ber == NULL) { ldap->err = ALDAP_ERR_OPERATION_FAILED; goto fail; @@ -201,8 +200,8 @@ aldap_bind(struct aldap *ldap, char *binddn, char *bindcred) goto fail; elm = ber_printf_elements(root, "d{tdsst", ++ldap->msgid, BER_CLASS_APP, - (unsigned long)LDAP_REQ_BIND, VERSION, binddn, bindcred, - BER_CLASS_CONTEXT, (unsigned long)LDAP_AUTH_SIMPLE); + LDAP_REQ_BIND, VERSION, binddn, bindcred, + BER_CLASS_CONTEXT, LDAP_AUTH_SIMPLE); if (elm == NULL) goto fail; @@ -261,7 +260,7 @@ aldap_search(struct aldap *ldap, char *basedn, enum scope scope, char *filter, goto fail; ber = ber_printf_elements(root, "d{t", ++ldap->msgid, BER_CLASS_APP, - (unsigned long) LDAP_REQ_SEARCH); + LDAP_REQ_SEARCH); if (ber == NULL) { ldap->err = ALDAP_ERR_OPERATION_FAILED; goto fail; @@ -350,7 +349,7 @@ struct aldap_message * aldap_parse(struct aldap *ldap) { int class; - unsigned long type; + unsigned int type; long long msgid = 0; struct aldap_message *m; struct ber_element *a = NULL, *ep; diff --git a/usr.sbin/ypldap/ber.c b/usr.sbin/ypldap/ber.c index 4db5645cb0e..81bf6328214 100644 --- a/usr.sbin/ypldap/ber.c +++ b/usr.sbin/ypldap/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.26 2018/07/13 08:50:38 rob Exp $ */ +/* $OpenBSD: ber.c,v 1.27 2018/07/31 11:00:12 claudio Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -42,7 +42,7 @@ 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 ssize_t get_id(struct ber *b, unsigned long *tag, int *class, +static ssize_t get_id(struct ber *b, unsigned int *tag, int *class, int *cstruct); static ssize_t get_len(struct ber *b, ssize_t *len); static ssize_t ber_read_element(struct ber *ber, struct ber_element *elm); @@ -56,7 +56,7 @@ static ssize_t ber_read(struct ber *ber, void *buf, size_t len); #endif struct ber_element * -ber_get_element(unsigned long encoding) +ber_get_element(unsigned int encoding) { struct ber_element *elm; @@ -70,7 +70,7 @@ ber_get_element(unsigned long encoding) } void -ber_set_header(struct ber_element *elm, int class, unsigned long type) +ber_set_header(struct ber_element *elm, int class, unsigned int type) { elm->be_class = class & BER_CLASS_MASK; if (type == BER_TYPE_DEFAULT) @@ -521,7 +521,7 @@ ber_printf_elements(struct ber_element *ber, char *fmt, ...) va_list ap; int d, class; size_t len; - unsigned long type; + unsigned int type; long long i; char *s; void *p; @@ -578,7 +578,7 @@ ber_printf_elements(struct ber_element *ber, char *fmt, ...) break; case 't': class = va_arg(ap, int); - type = va_arg(ap, unsigned long); + type = va_arg(ap, unsigned int); ber_set_header(ber, class, type); break; case 'x': @@ -626,7 +626,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...) #define _MAX_SEQ 128 va_list ap; int *d, level = -1; - unsigned long *t; + unsigned int *t; long long *i, l; void **ptr; size_t *len, ret = 0, n = strlen(fmt); @@ -694,7 +694,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...) break; case 't': d = va_arg(ap, int *); - t = va_arg(ap, unsigned long *); + t = va_arg(ap, unsigned int *); *d = ber->be_class; *t = ber->be_type; ret++; @@ -867,7 +867,7 @@ ber_free_elements(struct ber_element *root) size_t ber_calc_len(struct ber_element *root) { - unsigned long t; + unsigned int t; size_t s; size_t size = 2; /* minimum 1 byte head and 1 byte size */ @@ -945,8 +945,8 @@ ber_dump_element(struct ber *ber, struct ber_element *root) static void ber_dump_header(struct ber *ber, struct ber_element *root) { - u_char id = 0, t, buf[8]; - unsigned long type; + u_char id = 0, t, buf[5]; + unsigned int type; size_t size; /* class universal, type encoding depending on type value */ @@ -1010,11 +1010,11 @@ ber_write(struct ber *ber, void *buf, size_t len) * extract a BER encoded tag. There are two types, a short and long form. */ static ssize_t -get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) +get_id(struct ber *b, unsigned int *tag, int *class, int *cstruct) { u_char u; size_t i = 0; - unsigned long t = 0; + unsigned int t = 0; if (ber_getc(b, &u) == -1) return -1; @@ -1032,7 +1032,7 @@ get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) return -1; t = (t << 7) | (u & ~BER_TAG_MORE); i++; - if (i > sizeof(unsigned long)) { + if (i > sizeof(unsigned int)) { errno = ERANGE; return -1; } @@ -1093,7 +1093,7 @@ ber_read_element(struct ber *ber, struct ber_element *elm) { long long val = 0; struct ber_element *next; - unsigned long type; + unsigned int type; int i, class, cstruct; ssize_t len, r, totlen = 0; u_char c; @@ -1221,7 +1221,7 @@ ber_get_writebuf(struct ber *b, void **buf) } void -ber_set_application(struct ber *b, unsigned long (*cb)(struct ber_element *)) +ber_set_application(struct ber *b, unsigned int (*cb)(struct ber_element *)) { b->br_application = cb; } diff --git a/usr.sbin/ypldap/ber.h b/usr.sbin/ypldap/ber.h index 95932649f1e..55e6cd44eb2 100644 --- a/usr.sbin/ypldap/ber.h +++ b/usr.sbin/ypldap/ber.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.h,v 1.6 2018/07/03 18:49:10 rob Exp $ */ +/* $OpenBSD: ber.h,v 1.7 2018/07/31 11:00:12 claudio Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -22,8 +22,8 @@ struct ber_element { struct ber_element *be_next; - unsigned long be_type; - unsigned long be_encoding; + unsigned int be_type; + unsigned int be_encoding; size_t be_len; off_t be_offs; int be_free; @@ -49,11 +49,11 @@ struct ber { u_char *br_rptr; u_char *br_rend; - unsigned long (*br_application)(struct ber_element *); + unsigned int (*br_application)(struct ber_element *); }; /* well-known ber_element types */ -#define BER_TYPE_DEFAULT ((unsigned long)-1) +#define BER_TYPE_DEFAULT ((unsigned int)-1) #define BER_TYPE_EOC 0 #define BER_TYPE_BOOLEAN 1 #define BER_TYPE_INTEGER 2 @@ -84,9 +84,9 @@ struct ber_oid { }; __BEGIN_DECLS -struct ber_element *ber_get_element(unsigned long); +struct ber_element *ber_get_element(unsigned int); void ber_set_header(struct ber_element *, int, - unsigned long); + unsigned int); void ber_link_elements(struct ber_element *, struct ber_element *); struct ber_element *ber_unlink_elements(struct ber_element *); @@ -131,7 +131,7 @@ 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 *, - unsigned long (*)(struct ber_element *)); + unsigned int (*)(struct ber_element *)); void ber_set_writecallback(struct ber_element *, void (*)(void *, size_t), void *); void ber_free(struct ber *); -- 2.20.1