summaryrefslogtreecommitdiffstats
path: root/src/db/sysdb.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2011-12-12 18:47:27 +0100
committerStephen Gallagher <sgallagh@redhat.com>2011-12-16 14:46:16 -0500
commita26ea060ec4001daf5614bd9afcc092d29174662 (patch)
tree4d6bf14aff848d3da8d61b05364d80c49466be2a /src/db/sysdb.c
parent70a33bdf7db34fe4d1ba194cf9ea28c758719b4b (diff)
downloadsssd-a26ea060ec4001daf5614bd9afcc092d29174662.tar.gz
sssd-a26ea060ec4001daf5614bd9afcc092d29174662.tar.xz
sssd-a26ea060ec4001daf5614bd9afcc092d29174662.zip
sysdb_get_real_name helper function
Diffstat (limited to 'src/db/sysdb.c')
-rw-r--r--src/db/sysdb.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index c49399f7d..d66cc53cc 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -1691,3 +1691,49 @@ done:
}
return ret;
}
+
+errno_t sysdb_get_real_name(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ const char *name,
+ const char **_cname)
+{
+ errno_t ret;
+ TALLOC_CTX *tmp_ctx;
+ struct ldb_result *res;
+ const char *cname;
+
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) {
+ return ENOMEM;
+ }
+
+ ret = sysdb_getpwnam(tmp_ctx, sysdb, name, &res);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Cannot canonicalize username\n"));
+ goto done;
+ }
+
+ if (res->count == 0) {
+ /* User is not cached yet */
+ ret = ENOENT;
+ goto done;
+ } else if (res->count != 1) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("sysdb_getpwnam returned count: [%d]\n", res->count));
+ ret = EIO;
+ goto done;
+ }
+
+ cname = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
+ if (!cname) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("A user with no name?\n"));
+ ret = ENOENT;
+ goto done;
+ }
+
+ ret = EOK;
+ *_cname = talloc_steal(mem_ctx, cname);
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}