summaryrefslogtreecommitdiff
path: root/server/db
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2009-11-04 15:33:45 -0500
committerSimo Sorce <ssorce@redhat.com>2009-11-06 17:26:08 -0500
commiteda1d66399659430f372c342fbcbd10e34a3d75c (patch)
tree2f5f02b7ec91fea2be01671f3ef11a6e52af753e /server/db
parent9d56215d973676130fede91e39ee34d56ca19fb6 (diff)
downloadsssd-eda1d66399659430f372c342fbcbd10e34a3d75c.tar.gz
sssd-eda1d66399659430f372c342fbcbd10e34a3d75c.tar.bz2
sssd-eda1d66399659430f372c342fbcbd10e34a3d75c.zip
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.
Diffstat (limited to 'server/db')
-rw-r--r--server/db/sysdb.c35
-rw-r--r--server/db/sysdb.h3
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);