From ca9bc96b96425b7cb13797acf57704502bac1514 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 11 Jan 2010 20:18:09 +0100 Subject: s4:ldb_msg: first try to decode integers as signed and then fallback to unsigned LDAP only knowns about signed integers, so let ldb_msg_find_attr_as_uint() and ldb_msg_find_attr_as_uint64() cope with it. metze --- source4/lib/ldb/common/ldb_msg.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source4/lib/ldb') diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index cb8d4a8d9a..9f90f33405 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -353,10 +353,19 @@ unsigned int ldb_msg_find_attr_as_uint(const struct ldb_message *msg, const char *attr_name, unsigned int default_value) { + unsigned int ret; const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); if (!v || !v->data) { return default_value; } + + /* in LDAP there're only int32_t values */ + errno = 0; + ret = strtol((const char *)v->data, NULL, 0); + if (errno == 0) { + return ret; + } + return strtoul((const char *)v->data, NULL, 0); } @@ -375,10 +384,19 @@ uint64_t ldb_msg_find_attr_as_uint64(const struct ldb_message *msg, const char *attr_name, uint64_t default_value) { + uint64_t ret; const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); if (!v || !v->data) { return default_value; } + + /* in LDAP there're only int64_t values */ + errno = 0; + ret = strtoll((const char *)v->data, NULL, 0); + if (errno == 0) { + return ret; + } + return strtoull((const char *)v->data, NULL, 0); } -- cgit