diff options
-rw-r--r-- | src/db/sysdb.c | 26 | ||||
-rw-r--r-- | src/db/sysdb.h | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index 399beee3..6bd787f7 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -388,6 +388,32 @@ int sysdb_attrs_get_uint32_t(struct sysdb_attrs *attrs, const char *name, return EOK; } +int sysdb_attrs_get_uint16_t(struct sysdb_attrs *attrs, const char *name, + uint16_t *value) +{ + struct ldb_message_element *el; + int ret; + char *endptr; + uint16_t val; + + ret = sysdb_attrs_get_el_int(attrs, name, false, &el); + if (ret) { + return ret; + } + + if (el->num_values != 1) { + return ERANGE; + } + + errno = 0; + val = strtouint16((const char *) el->values[0].data, &endptr, 10); + if (errno != 0) return errno; + if (*endptr) return EINVAL; + + *value = val; + return EOK; +} + errno_t sysdb_attrs_get_bool(struct sysdb_attrs *attrs, const char *name, bool *value) { diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 5863afc9..31b988eb 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -219,6 +219,8 @@ int sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name, TALLOC_CTX *mem_ctx, const char ***string); errno_t sysdb_attrs_get_bool(struct sysdb_attrs *attrs, const char *name, bool *value); +int sysdb_attrs_get_uint16_t(struct sysdb_attrs *attrs, const char *name, + uint16_t *value); int sysdb_attrs_get_uint32_t(struct sysdb_attrs *attrs, const char *name, uint32_t *value); |