summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2010-01-11 20:18:09 +0100
committerStefan Metzmacher <metze@samba.org>2010-01-13 14:52:00 +0100
commitca9bc96b96425b7cb13797acf57704502bac1514 (patch)
treef0cf042447eda4e9a63649f94509b716698070a0 /source4/lib/ldb/common
parent5d08309204e475e85250a34ff7986c896e8c3c01 (diff)
downloadsamba-ca9bc96b96425b7cb13797acf57704502bac1514.tar.gz
samba-ca9bc96b96425b7cb13797acf57704502bac1514.tar.bz2
samba-ca9bc96b96425b7cb13797acf57704502bac1514.zip
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
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb_msg.c18
1 files changed, 18 insertions, 0 deletions
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);
}