diff options
Diffstat (limited to 'server/db')
-rw-r--r-- | server/db/sysdb.c | 35 | ||||
-rw-r--r-- | server/db/sysdb.h | 3 |
2 files changed, 35 insertions, 3 deletions
diff --git a/server/db/sysdb.c b/server/db/sysdb.c index ae32ef4b..4e6e71e4 100644 --- a/server/db/sysdb.c +++ b/server/db/sysdb.c @@ -65,8 +65,8 @@ struct sysdb_attrs *sysdb_new_attrs(TALLOC_CTX *memctx) return talloc_zero(memctx, struct sysdb_attrs); } -int sysdb_attrs_get_el(struct sysdb_attrs *attrs, const char *name, - struct ldb_message_element **el) +static int sysdb_attrs_get_el_int(struct sysdb_attrs *attrs, const char *name, + bool alloc, struct ldb_message_element **el) { struct ldb_message_element *e = NULL; int i; @@ -76,7 +76,7 @@ int sysdb_attrs_get_el(struct sysdb_attrs *attrs, const char *name, e = &(attrs->a[i]); } - if (!e) { + if (!e && alloc) { e = talloc_realloc(attrs, attrs->a, struct ldb_message_element, attrs->num+1); if (!e) return ENOMEM; @@ -93,11 +93,40 @@ int sysdb_attrs_get_el(struct sysdb_attrs *attrs, const char *name, attrs->num++; } + if (!e) { + return ENOENT; + } + *el = e; return EOK; } +int sysdb_attrs_get_el(struct sysdb_attrs *attrs, const char *name, + struct ldb_message_element **el) +{ + return sysdb_attrs_get_el_int(attrs, name, true, el); +} + +int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name, + const char **string) +{ + struct ldb_message_element *el; + int ret; + + ret = sysdb_attrs_get_el_int(attrs, name, false, &el); + if (ret) { + return ret; + } + + if (el->num_values != 1) { + return ERANGE; + } + + *string = (const char *)el->values[0].data; + return EOK; +} + int sysdb_attrs_add_val(struct sysdb_attrs *attrs, const char *name, const struct ldb_val *val) { diff --git a/server/db/sysdb.h b/server/db/sysdb.h index 0b474221..394b524e 100644 --- a/server/db/sysdb.h +++ b/server/db/sysdb.h @@ -74,6 +74,7 @@ #define SYSDB_ORIG_DN "originalDN" #define SYSDB_ORIG_MODSTAMP "originalModifyTimestamp" +#define SYSDB_ORIG_MEMBEROF "originalMemberOf" #define SYSDB_USN "entryUSN" #define SYSDB_HIGH_USN "highestUSN" @@ -173,6 +174,8 @@ int sysdb_attrs_get_el(struct sysdb_attrs *attrs, const char *name, struct ldb_message_element **el); int sysdb_attrs_steal_string(struct sysdb_attrs *attrs, const char *name, char *str); +int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name, + const char **string); int sysdb_attrs_replace_name(struct sysdb_attrs *attrs, const char *oldname, const char *newname); |