From fb263dd17c3fc00d9e5e8f366d60adbf5e76edf0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 8 Oct 2008 14:01:06 -0400 Subject: Add getpwuid support --- server/nss/nsssrv_ldb.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'server/nss/nsssrv_ldb.c') diff --git a/server/nss/nsssrv_ldb.c b/server/nss/nsssrv_ldb.c index 9ceb8f10..272ee366 100644 --- a/server/nss/nsssrv_ldb.c +++ b/server/nss/nsssrv_ldb.c @@ -43,8 +43,8 @@ static int request_done(struct nss_ldb_search_ctx *sctx) return sctx->callback(sctx->ptr, LDB_SUCCESS, sctx->res); } -static int getpwnam_callback(struct ldb_request *req, - struct ldb_reply *ares) +static int getpw_callback(struct ldb_request *req, + struct ldb_reply *ares) { struct nss_ldb_search_ctx *sctx; struct ldb_result *res; @@ -136,7 +136,56 @@ int nss_ldb_getpwnam(TALLOC_CTX *mem_ctx, ldb_dn_new(sctx, ldb, NSS_USER_BASE), LDB_SCOPE_SUBTREE, expression, attrs, NULL, - sctx, getpwnam_callback, + sctx, getpw_callback, + NULL); + if (ret != LDB_SUCCESS) { + return RES_ERROR; + } + + ret = ldb_request(ldb, req); + if (ret != LDB_SUCCESS) { + return RES_ERROR; + } + + return RES_SUCCESS; +} + +int nss_ldb_getpwuid(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct ldb_context *ldb, + uint64_t uid, + nss_ldb_callback_t fn, void *ptr) +{ + struct nss_ldb_search_ctx *sctx; + struct ldb_request *req; + static const char *attrs[] = NSS_PW_ATTRS; + unsigned long long int filter_uid = uid; + char *expression; + int ret; + + sctx = talloc(mem_ctx, struct nss_ldb_search_ctx); + if (!sctx) { + return RES_NOMEM; + } + sctx->callback = fn; + sctx->ptr = ptr; + sctx->res = talloc_zero(sctx, struct ldb_result); + if (!sctx->res) { + talloc_free(sctx); + return RES_NOMEM; + } + + expression = talloc_asprintf(sctx, NSS_PWUID_FILTER, filter_uid); + if (!expression) { + talloc_free(sctx); + return RES_NOMEM; + } + + ret = ldb_build_search_req(&req, ldb, sctx, + ldb_dn_new(sctx, ldb, NSS_USER_BASE), + LDB_SCOPE_SUBTREE, + expression, attrs, NULL, + sctx, getpw_callback, NULL); if (ret != LDB_SUCCESS) { return RES_ERROR; -- cgit