summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2014-09-26 20:09:25 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-10-20 16:15:06 +0200
commitba88f3617e5a56bba19a0d65d35069d8e4d0c89c (patch)
treebcfbfc6054789167a89c180295af63c1dfaee411 /src/db
parent89b065cb85f57e80760ce4d4b1215b533e249e92 (diff)
downloadsssd-ba88f3617e5a56bba19a0d65d35069d8e4d0c89c.tar.gz
sssd-ba88f3617e5a56bba19a0d65d35069d8e4d0c89c.tar.xz
sssd-ba88f3617e5a56bba19a0d65d35069d8e4d0c89c.zip
sysdb: add sss_view_ldb_msg_find_element/attr_as_string/uint64
Override-aware replacements for the corresponding ldb_msg_find_* calls. First it is check if an override value is available before the original value is returned. Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.h15
-rw-r--r--src/db/sysdb_views.c116
2 files changed, 131 insertions, 0 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 2db1a1c6a..8d2894acc 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -484,6 +484,21 @@ errno_t sysdb_getpwuid_with_views(TALLOC_CTX *mem_ctx,
uid_t uid,
struct ldb_result **res);
+struct ldb_message_element *
+sss_view_ldb_msg_find_element(struct sss_domain_info *dom,
+ const struct ldb_message *msg,
+ const char *attr_name);
+
+const char *sss_view_ldb_msg_find_attr_as_string(struct sss_domain_info *dom,
+ const struct ldb_message *msg,
+ const char *attr_name,
+ const char * default_value);
+
+uint64_t sss_view_ldb_msg_find_attr_as_uint64(struct sss_domain_info *dom,
+ const struct ldb_message *msg,
+ const char *attr_name,
+ uint64_t default_value);
+
/* Sysdb initialization.
* call this function *only* once to initialize the database and get
* the sysdb ctx */
diff --git a/src/db/sysdb_views.c b/src/db/sysdb_views.c
index 86c231dad..7252bad19 100644
--- a/src/db/sysdb_views.c
+++ b/src/db/sysdb_views.c
@@ -1056,3 +1056,119 @@ done:
return ret;
}
+
+struct ldb_message_element *
+sss_view_ldb_msg_find_element(struct sss_domain_info *dom,
+ const struct ldb_message *msg,
+ const char *attr_name)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ struct ldb_message_element *val;
+ char *override_attr_name;
+
+ if (DOM_HAS_VIEWS(dom)) {
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
+ val = NULL;
+ goto done;
+ }
+
+ override_attr_name = talloc_asprintf(tmp_ctx, "%s%s", OVERRIDE_PREFIX,
+ attr_name);
+ if (override_attr_name == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
+ val = NULL;
+ goto done;
+ }
+
+ val = ldb_msg_find_element(msg, override_attr_name);
+ if (val != NULL) {
+ goto done;
+ }
+ }
+
+ val = ldb_msg_find_element(msg, attr_name);
+
+done:
+ talloc_free(tmp_ctx);
+ return val;
+}
+
+uint64_t sss_view_ldb_msg_find_attr_as_uint64(struct sss_domain_info *dom,
+ const struct ldb_message *msg,
+ const char *attr_name,
+ uint64_t default_value)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ uint64_t val;
+ char *override_attr_name;
+
+ if (DOM_HAS_VIEWS(dom)) {
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
+ val = default_value;
+ goto done;
+ }
+
+ override_attr_name = talloc_asprintf(tmp_ctx, "%s%s", OVERRIDE_PREFIX,
+ attr_name);
+ if (override_attr_name == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
+ val = default_value;
+ goto done;
+ }
+
+ if (ldb_msg_find_element(msg, override_attr_name) != NULL) {
+ val = ldb_msg_find_attr_as_uint64(msg, override_attr_name,
+ default_value);
+ goto done;
+ }
+ }
+
+ val = ldb_msg_find_attr_as_uint64(msg, attr_name, default_value);
+
+done:
+ talloc_free(tmp_ctx);
+ return val;
+}
+
+const char *sss_view_ldb_msg_find_attr_as_string(struct sss_domain_info *dom,
+ const struct ldb_message *msg,
+ const char *attr_name,
+ const char * default_value)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ const char *val;
+ char *override_attr_name;
+
+ if (DOM_HAS_VIEWS(dom)) {
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
+ val = default_value;
+ goto done;
+ }
+
+ override_attr_name = talloc_asprintf(tmp_ctx, "%s%s", OVERRIDE_PREFIX,
+ attr_name);
+ if (override_attr_name == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
+ val = default_value;
+ goto done;
+ }
+
+ if (ldb_msg_find_element(msg, override_attr_name) != NULL) {
+ val = ldb_msg_find_attr_as_string(msg, override_attr_name,
+ default_value);
+ goto done;
+ }
+ }
+
+ val = ldb_msg_find_attr_as_string(msg, attr_name, default_value);
+
+done:
+ talloc_free(tmp_ctx);
+ return val;
+}