1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

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
This commit is contained in:
Stefan Metzmacher 2010-01-11 20:18:09 +01:00
parent 5d08309204
commit ca9bc96b96

View File

@ -353,10 +353,19 @@ unsigned int ldb_msg_find_attr_as_uint(const struct ldb_message *msg,
const char *attr_name, const char *attr_name,
unsigned int default_value) unsigned int default_value)
{ {
unsigned int ret;
const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name);
if (!v || !v->data) { if (!v || !v->data) {
return default_value; 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); 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, const char *attr_name,
uint64_t default_value) uint64_t default_value)
{ {
uint64_t ret;
const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name);
if (!v || !v->data) { if (!v || !v->data) {
return default_value; 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); return strtoull((const char *)v->data, NULL, 0);
} }