From eda1d66399659430f372c342fbcbd10e34a3d75c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 4 Nov 2009 15:33:45 -0500 Subject: Make available method to quickly retrive string sysdb_attrs has a lot of methods to add them but very little to get information out. Start adding a way to retrieve a single valued attribute as a string. --- server/db/sysdb.c | 35 ++++++++++++++++++++++++++++++++--- server/db/sysdb.h | 3 +++ 2 files changed, 35 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/db/sysdb.c b/server/db/sysdb.c index ae32ef4ba..4e6e71e48 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 0b4742211..394b524ef 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); -- cgit