diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2011-12-12 18:47:27 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-12-16 14:46:16 -0500 |
commit | a26ea060ec4001daf5614bd9afcc092d29174662 (patch) | |
tree | 4d6bf14aff848d3da8d61b05364d80c49466be2a | |
parent | 70a33bdf7db34fe4d1ba194cf9ea28c758719b4b (diff) | |
download | sssd-a26ea060ec4001daf5614bd9afcc092d29174662.tar.gz sssd-a26ea060ec4001daf5614bd9afcc092d29174662.tar.bz2 sssd-a26ea060ec4001daf5614bd9afcc092d29174662.zip |
sysdb_get_real_name helper function
-rw-r--r-- | src/db/sysdb.c | 46 | ||||
-rw-r--r-- | src/db/sysdb.h | 4 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index c49399f7..d66cc53c 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; +} diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 5fc36ab5..e5e781f6 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -248,6 +248,10 @@ errno_t sysdb_attrs_primary_name_list(struct sysdb_ctx *sysdb, size_t attr_count, const char *ldap_attr, char ***name_list); +errno_t sysdb_get_real_name(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + const char *name, + const char **_cname); /* convert an ldb error into an errno error */ int sysdb_error_to_errno(int ldberr); |