From: claudio Date: Tue, 31 Jul 2018 11:01:00 +0000 (+0000) Subject: Make ber type and encoding a unsigned int instead of unsigned long. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f9444383b205b225e201591012958d22373516dc;p=openbsd 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@ --- diff --git a/usr.sbin/ldapd/ber.c b/usr.sbin/ldapd/ber.c index e55c41a73d6..47a8cf891b6 100644 --- a/usr.sbin/ldapd/ber.c +++ b/usr.sbin/ldapd/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.24 2018/07/13 08:50:38 rob Exp $ */ +/* $OpenBSD: ber.c,v 1.25 2018/07/31 11:01:00 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/ldapd/ber.h b/usr.sbin/ldapd/ber.h index a97b1b756dd..d7d19631104 100644 --- a/usr.sbin/ldapd/ber.h +++ b/usr.sbin/ldapd/ber.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.h,v 1.5 2018/07/03 18:49:10 rob Exp $ */ +/* $OpenBSD: ber.h,v 1.6 2018/07/31 11:01:00 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 *); diff --git a/usr.sbin/ldapd/conn.c b/usr.sbin/ldapd/conn.c index fff636db48e..8c3ffc1daf8 100644 --- a/usr.sbin/ldapd/conn.c +++ b/usr.sbin/ldapd/conn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conn.c,v 1.16 2018/05/15 11:19:21 reyk Exp $ */ +/* $OpenBSD: conn.c,v 1.17 2018/07/31 11:01:00 claudio Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk @@ -28,11 +28,11 @@ int conn_dispatch(struct conn *conn); int conn_tls_init(struct conn *); -unsigned long ldap_application(struct ber_element *elm); +unsigned int ldap_application(struct ber_element *elm); struct conn_list conn_list; -unsigned long +unsigned int ldap_application(struct ber_element *elm) { return BER_TYPE_OCTETSTRING; @@ -99,7 +99,7 @@ request_dispatch(struct request *req) { unsigned long i; struct { - unsigned long type; + unsigned int type; int (*fn)(struct request *); } requests[] = { { LDAP_REQ_SEARCH, ldap_search }, @@ -132,7 +132,7 @@ request_dispatch(struct request *req) } if (requests[i].fn == NULL) { - log_warnx("unhandled request %lu (not implemented)", req->type); + log_warnx("unhandled request %u (not implemented)", req->type); ldap_respond(req, LDAP_PROTOCOL_ERROR); } } @@ -183,7 +183,7 @@ conn_dispatch(struct conn *conn) ldap_debug_elements(req->root, req->type, "received request on fd %d", conn->fd); - log_debug("got request type %lu, id %lld", req->type, req->msgid); + log_debug("got request type %u, id %lld", req->type, req->msgid); request_dispatch(req); return 0; } diff --git a/usr.sbin/ldapd/filter.c b/usr.sbin/ldapd/filter.c index a56b14b2bf4..15fadfa1ed9 100644 --- a/usr.sbin/ldapd/filter.c +++ b/usr.sbin/ldapd/filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filter.c,v 1.5 2018/05/15 11:19:21 reyk Exp $ */ +/* $OpenBSD: filter.c,v 1.6 2018/07/31 11:01:00 claudio Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk @@ -64,7 +64,7 @@ static int ldap_filt_subs_value(struct ber_element *v, struct ber_element *sub) { int class; - unsigned long type; + unsigned int type; const char *cmpval; char *vs, *p, *end; @@ -101,7 +101,7 @@ ldap_filt_subs_value(struct ber_element *v, struct ber_element *sub) return 1; /* no match */ break; default: - log_warnx("invalid subfilter type %lu", type); + log_warnx("invalid subfilter type %u", type); return -1; } } diff --git a/usr.sbin/ldapd/ldapd.h b/usr.sbin/ldapd/ldapd.h index f6249594537..3f995d184b4 100644 --- a/usr.sbin/ldapd/ldapd.h +++ b/usr.sbin/ldapd/ldapd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldapd.h,v 1.30 2018/05/15 11:19:21 reyk Exp $ */ +/* $OpenBSD: ldapd.h,v 1.31 2018/07/31 11:01:00 claudio Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk @@ -82,7 +82,7 @@ SIMPLEQ_HEAD(acl, aci); */ struct request { TAILQ_ENTRY(request) next; - unsigned long type; + unsigned int type; long long msgid; struct ber_element *root; struct ber_element *op; @@ -365,7 +365,7 @@ int ldap_compare(struct request *req); int ldap_extended(struct request *req); void send_ldap_result(struct conn *conn, int msgid, - unsigned long type, long long result_code); + unsigned int type, long long result_code); int ldap_respond(struct request *req, int code); int ldap_refer(struct request *req, const char *basedn, struct search *search, struct referrals *refs); diff --git a/usr.sbin/ldapd/ldape.c b/usr.sbin/ldapd/ldape.c index 0bdb6191ed4..1d852f1ff7c 100644 --- a/usr.sbin/ldapd/ldape.c +++ b/usr.sbin/ldapd/ldape.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldape.c,v 1.28 2018/07/04 10:05:56 rob Exp $ */ +/* $OpenBSD: ldape.c,v 1.29 2018/07/31 11:01:00 claudio Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk @@ -42,7 +42,7 @@ static void ldape_needfd(struct imsgev *iev); int ldap_starttls(struct request *req); void send_ldap_extended_response(struct conn *conn, - int msgid, unsigned long type, + int msgid, unsigned int type, long long result_code, const char *extended_oid); @@ -69,14 +69,14 @@ ldape_sig_handler(int sig, short why, void *data) } void -send_ldap_extended_response(struct conn *conn, int msgid, unsigned long type, +send_ldap_extended_response(struct conn *conn, int msgid, unsigned int type, long long result_code, const char *extended_oid) { int rc; struct ber_element *root, *elm; void *buf; - log_debug("sending response %lu with result %lld", type, result_code); + log_debug("sending response %u with result %lld", type, result_code); if ((root = ber_add_sequence(NULL)) == NULL) goto fail; @@ -116,7 +116,7 @@ ldap_refer(struct request *req, const char *basedn, struct search *search, struct ber_element *root, *elm, *ref_root = NULL; struct referral *ref; long long result_code = LDAP_REFERRAL; - unsigned long type; + unsigned int type; int rc; void *buf; char *url, *scope_str = NULL; @@ -133,7 +133,7 @@ ldap_refer(struct request *req, const char *basedn, struct search *search, scope_str = "sub"; } - log_debug("sending referral in response %lu on msgid %lld", + log_debug("sending referral in response %u on msgid %lld", type, req->msgid); if ((root = ber_add_sequence(NULL)) == NULL) @@ -189,7 +189,7 @@ fail: } void -send_ldap_result(struct conn *conn, int msgid, unsigned long type, +send_ldap_result(struct conn *conn, int msgid, unsigned int type, long long result_code) { send_ldap_extended_response(conn, msgid, type, result_code, NULL); diff --git a/usr.sbin/ldapd/logmsg.c b/usr.sbin/ldapd/logmsg.c index 4fe2e0f8ba6..ccf7d54a3de 100644 --- a/usr.sbin/ldapd/logmsg.c +++ b/usr.sbin/ldapd/logmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: logmsg.c,v 1.2 2018/05/15 11:19:21 reyk Exp $ */ +/* $OpenBSD: logmsg.c,v 1.3 2018/07/31 11:01:00 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -208,7 +208,7 @@ ldap_debug_elements(struct ber_element *root, int context, const char *fmt, ...) break; case BER_CLASS_PRIVATE: fprintf(stderr, "class: private(%u) type: ", root->be_class); - fprintf(stderr, "encoding (%lu) type: ", root->be_encoding); + fprintf(stderr, "encoding (%u) type: ", root->be_encoding); break; case BER_CLASS_CONTEXT: fprintf(stderr, "class: context(%u) type: ", root->be_class); @@ -257,7 +257,7 @@ ldap_debug_elements(struct ber_element *root, int context, const char *fmt, ...) fprintf(stderr, "class: (%u) type: ", root->be_class); break; } - fprintf(stderr, "(%lu) encoding %lu ", + fprintf(stderr, "(%u) encoding %u ", root->be_type, root->be_encoding); if (constructed) diff --git a/usr.sbin/ldapd/search.c b/usr.sbin/ldapd/search.c index d583c89d6ce..85b3d2d2b86 100644 --- a/usr.sbin/ldapd/search.c +++ b/usr.sbin/ldapd/search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: search.c,v 1.22 2018/05/18 12:36:30 reyk Exp $ */ +/* $OpenBSD: search.c,v 1.23 2018/07/31 11:01:00 claudio Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk @@ -140,7 +140,7 @@ search_result(const char *dn, size_t dnlen, struct ber_element *attrs, } elm = ber_printf_elements(root, "i{txe", search->req->msgid, - BER_CLASS_APP, (unsigned long)LDAP_RES_SEARCH_ENTRY, + BER_CLASS_APP, LDAP_RES_SEARCH_ENTRY, dn, dnlen, filtered_attrs); if (elm == NULL) goto fail; @@ -678,7 +678,7 @@ static struct plan * search_planner(struct namespace *ns, struct ber_element *filter) { int class; - unsigned long type; + unsigned int type; char *s, *attr; struct ber_element *elm; struct index *indx; @@ -815,7 +815,7 @@ search_planner(struct namespace *ns, struct ber_element *filter) break; default: - log_warnx("filter type %lu not implemented", filter->be_type); + log_warnx("filter type %u not implemented", filter->be_type); plan->undefined = 1; break; }