summaryrefslogtreecommitdiffstats
path: root/src/db/sysdb_ops.c
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2014-06-17 12:06:29 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-06-20 13:45:30 +0200
commit7ecb5aea65cb1899f16e7a41bffa93d074defd4a (patch)
treed73d0fd053ffd7a2a6716b2e8ff52bcfacd7b4a2 /src/db/sysdb_ops.c
parent9ad2756fcf4df945f4cd09238e3f9fe707b0b70c (diff)
downloadsssd-7ecb5aea65cb1899f16e7a41bffa93d074defd4a.tar.gz
sssd-7ecb5aea65cb1899f16e7a41bffa93d074defd4a.tar.xz
sssd-7ecb5aea65cb1899f16e7a41bffa93d074defd4a.zip
sysdb: add sysdb_search_user_by_upn() with tests
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/db/sysdb_ops.c')
-rw-r--r--src/db/sysdb_ops.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 915ef1ad9..50f339149 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -435,6 +435,66 @@ int sysdb_search_user_by_sid_str(TALLOC_CTX *mem_ctx,
sid_str, attrs, msg);
}
+int sysdb_search_user_by_upn(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *domain,
+ const char *upn,
+ const char **attrs,
+ struct ldb_message **msg)
+{
+ TALLOC_CTX *tmp_ctx;
+ const char *def_attrs[] = { SYSDB_NAME, SYSDB_UPN, SYSDB_CANONICAL_UPN,
+ NULL };
+ struct ldb_message **msgs = NULL;
+ struct ldb_dn *basedn;
+ size_t msgs_count = 0;
+ char *filter;
+ int ret;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
+ SYSDB_TMPL_USER_BASE, domain->name);
+ if (basedn == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ filter = talloc_asprintf(tmp_ctx, SYSDB_PWUPN_FILTER, upn, upn);
+ if (filter == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = sysdb_search_entry(tmp_ctx, domain->sysdb, basedn, LDB_SCOPE_SUBTREE,
+ filter, attrs?attrs:def_attrs, &msgs_count,
+ &msgs);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ if (msgs_count > 1) {
+ DEBUG(SSSDBG_OP_FAILURE,
+ "Search for upn [%s] returns more than one result.\n", upn);
+ ret = EINVAL;
+ goto done;
+ }
+
+ *msg = talloc_steal(mem_ctx, msgs[0]);
+
+done:
+ if (ret == ENOENT) {
+ DEBUG(SSSDBG_TRACE_FUNC, "No entry with upn [%s] found.\n", upn);
+ } else if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "Error: %d (%s)\n", ret, strerror(ret));
+ }
+
+ talloc_zfree(tmp_ctx);
+ return ret;
+}
+
/* =Search-Group-by-[GID/SID/NAME]============================================ */
int sysdb_search_group_by_name(TALLOC_CTX *mem_ctx,