dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0064-IFP-Search-both-POSIX-and-non-POSIX-domains.patch

ecf709
From bab9c21c9ec7ad39555db52511f0f2e425decd94 Mon Sep 17 00:00:00 2001
ecf709
From: Jakub Hrozek <jhrozek@redhat.com>
ecf709
Date: Fri, 24 Mar 2017 12:44:09 +0100
ecf709
Subject: [PATCH 64/72] IFP: Search both POSIX and non-POSIX domains
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
Related to:
ecf709
https://pagure.io/SSSD/sssd/issue/3310
ecf709
ecf709
Changes the behaviour of the InfoPipe responder so that both application
ecf709
and POSIX domains are searched. In general, the IFP responder uses the
ecf709
CACHE_REQ_ANY_DOM lookup type because we can't presume the intention of
ecf709
the caller. Therefore, deployments that combine both POSIX and non-POSIX
ecf709
domains must use fully qualified names or select the right domain order
ecf709
manually.
ecf709
ecf709
There is one change between the POSIX and non-POSIX users or groups -
ecf709
the object path. For the POSIX users, the object path includes the UID
ecf709
or GID. Because we don't have that for the non-POSIX objects, the object
ecf709
name is used in the path instead.
ecf709
ecf709
Reviewed-by: Sumit Bose <sbose@redhat.com>
ecf709
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ecf709
---
ecf709
 src/responder/ifp/ifp_groups.c | 135 ++++++++++++++++++++++-------------
ecf709
 src/responder/ifp/ifp_users.c  | 158 ++++++++++++++++++++++++++---------------
ecf709
 src/responder/ifp/ifpsrv_cmd.c |   6 +-
ecf709
 3 files changed, 194 insertions(+), 105 deletions(-)
ecf709
ecf709
diff --git a/src/responder/ifp/ifp_groups.c b/src/responder/ifp/ifp_groups.c
ecf709
index 99908e96bd971bce4b4e9064a77d8413f837d743..c568c62009cd4b777919dea048fd381a91bd3460 100644
ecf709
--- a/src/responder/ifp/ifp_groups.c
ecf709
+++ b/src/responder/ifp/ifp_groups.c
ecf709
@@ -35,25 +35,33 @@ char * ifp_groups_build_path_from_msg(TALLOC_CTX *mem_ctx,
ecf709
                                       struct sss_domain_info *domain,
ecf709
                                       struct ldb_message *msg)
ecf709
 {
ecf709
-    const char *gid;
ecf709
+    const char *key = NULL;
ecf709
 
ecf709
-    gid = ldb_msg_find_attr_as_string(msg, SYSDB_GIDNUM, NULL);
ecf709
+    switch (domain->type) {
ecf709
+    case DOM_TYPE_APPLICATION:
ecf709
+        key = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
ecf709
+        break;
ecf709
+    case DOM_TYPE_POSIX:
ecf709
+        key = ldb_msg_find_attr_as_string(msg, SYSDB_GIDNUM, NULL);
ecf709
+        break;
ecf709
+    }
ecf709
 
ecf709
-    if (gid == NULL) {
ecf709
+
ecf709
+    if (key == NULL) {
ecf709
         return NULL;
ecf709
     }
ecf709
 
ecf709
-    return sbus_opath_compose(mem_ctx, IFP_PATH_GROUPS, domain->name, gid);
ecf709
+    return sbus_opath_compose(mem_ctx, IFP_PATH_GROUPS, domain->name, key);
ecf709
 }
ecf709
 
ecf709
-static errno_t ifp_groups_decompose_path(struct sss_domain_info *domains,
ecf709
+static errno_t ifp_groups_decompose_path(TALLOC_CTX *mem_ctx,
ecf709
+                                         struct sss_domain_info *domains,
ecf709
                                          const char *path,
ecf709
                                          struct sss_domain_info **_domain,
ecf709
-                                         gid_t *_gid)
ecf709
+                                         char **_key)
ecf709
 {
ecf709
     char **parts = NULL;
ecf709
     struct sss_domain_info *domain;
ecf709
-    gid_t gid;
ecf709
     errno_t ret;
ecf709
 
ecf709
     ret = sbus_opath_decompose_exact(NULL, path, IFP_PATH_GROUPS, 2, &parts;;
ecf709
@@ -67,14 +75,8 @@ static errno_t ifp_groups_decompose_path(struct sss_domain_info *domains,
ecf709
         goto done;
ecf709
     }
ecf709
 
ecf709
-    gid = strtouint32(parts[1], NULL, 10);
ecf709
-    ret = errno;
ecf709
-    if (ret != EOK) {
ecf709
-        goto done;
ecf709
-    }
ecf709
-
ecf709
     *_domain = domain;
ecf709
-    *_gid = gid;
ecf709
+    *_key = talloc_steal(mem_ctx, parts[1]);
ecf709
 
ecf709
 done:
ecf709
     talloc_free(parts);
ecf709
@@ -119,7 +121,7 @@ int ifp_groups_find_by_name(struct sbus_request *sbus_req,
ecf709
 
ecf709
     req = cache_req_group_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx,
ecf709
                                        ctx->rctx->ncache, 0,
ecf709
-                                       CACHE_REQ_POSIX_DOM, NULL,
ecf709
+                                       CACHE_REQ_ANY_DOM, NULL,
ecf709
                                        name);
ecf709
     if (req == NULL) {
ecf709
         return ENOMEM;
ecf709
@@ -273,7 +275,7 @@ static int ifp_groups_list_by_name_step(struct ifp_list_ctx *list_ctx)
ecf709
     req = cache_req_group_by_filter_send(list_ctx,
ecf709
                                         list_ctx->ctx->rctx->ev,
ecf709
                                         list_ctx->ctx->rctx,
ecf709
-                                        CACHE_REQ_POSIX_DOM,
ecf709
+                                        CACHE_REQ_ANY_DOM,
ecf709
                                         list_ctx->dom->name,
ecf709
                                         list_ctx->filter);
ecf709
     if (req == NULL) {
ecf709
@@ -358,7 +360,7 @@ int ifp_groups_list_by_domain_and_name(struct sbus_request *sbus_req,
ecf709
     }
ecf709
 
ecf709
     req = cache_req_group_by_filter_send(list_ctx, ctx->rctx->ev, ctx->rctx,
ecf709
-                                         CACHE_REQ_POSIX_DOM,
ecf709
+                                         CACHE_REQ_ANY_DOM,
ecf709
                                          domain, filter);
ecf709
     if (req == NULL) {
ecf709
         return ENOMEM;
ecf709
@@ -412,16 +414,65 @@ done:
ecf709
 }
ecf709
 
ecf709
 static errno_t
ecf709
+ifp_groups_get_from_cache(struct sbus_request *sbus_req,
ecf709
+                         struct sss_domain_info *domain,
ecf709
+                         const char *key,
ecf709
+                         struct ldb_message **_group)
ecf709
+{
ecf709
+    struct ldb_result *group_res;
ecf709
+    errno_t ret;
ecf709
+    gid_t gid;
ecf709
+
ecf709
+    switch (domain->type) {
ecf709
+    case DOM_TYPE_POSIX:
ecf709
+        gid = strtouint32(key, NULL, 10);
ecf709
+        ret = errno;
ecf709
+        if (ret != EOK) {
ecf709
+            DEBUG(SSSDBG_CRIT_FAILURE, "Invalid UID value\n");
ecf709
+            return ret;
ecf709
+        }
ecf709
+
ecf709
+        ret = sysdb_getgrgid_with_views(sbus_req, domain, gid, &group_res);
ecf709
+        if (ret == EOK && group_res->count == 0) {
ecf709
+            *_group = NULL;
ecf709
+            return ENOENT;
ecf709
+        } else if (ret != EOK) {
ecf709
+            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup group %u@%s [%d]: %s\n",
ecf709
+                  gid, domain->name, ret, sss_strerror(ret));
ecf709
+            return ret;
ecf709
+        }
ecf709
+        break;
ecf709
+    case DOM_TYPE_APPLICATION:
ecf709
+        ret = sysdb_getgrnam_with_views(sbus_req, domain, key, &group_res);
ecf709
+        if (ret == EOK && group_res->count == 0) {
ecf709
+            *_group = NULL;
ecf709
+            return ENOENT;
ecf709
+        } else if (ret != EOK) {
ecf709
+            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup group %s@%s [%d]: %s\n",
ecf709
+                  key, domain->name, ret, sss_strerror(ret));
ecf709
+            return ret;
ecf709
+        }
ecf709
+        break;
ecf709
+    }
ecf709
+
ecf709
+    if (group_res->count > 1) {
ecf709
+        DEBUG(SSSDBG_CRIT_FAILURE, "More groups matched by the single key\n");
ecf709
+        return EIO;
ecf709
+    }
ecf709
+
ecf709
+    *_group = group_res->msgs[0];
ecf709
+    return EOK;
ecf709
+}
ecf709
+
ecf709
+static errno_t
ecf709
 ifp_groups_group_get(struct sbus_request *sbus_req,
ecf709
                      void *data,
ecf709
-                     gid_t *_gid,
ecf709
                      struct sss_domain_info **_domain,
ecf709
                      struct ldb_message **_group)
ecf709
 {
ecf709
     struct ifp_ctx *ctx;
ecf709
     struct sss_domain_info *domain;
ecf709
-    struct ldb_result *res;
ecf709
-    uid_t gid;
ecf709
+    char *key;
ecf709
     errno_t ret;
ecf709
 
ecf709
     ctx = talloc_get_type(data, struct ifp_ctx);
ecf709
@@ -430,8 +481,9 @@ ifp_groups_group_get(struct sbus_request *sbus_req,
ecf709
         return ERR_INTERNAL;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_groups_decompose_path(ctx->rctx->domains, sbus_req->path,
ecf709
-                                    &domain, &gid;;
ecf709
+    ret = ifp_groups_decompose_path(sbus_req,
ecf709
+                                    ctx->rctx->domains, sbus_req->path,
ecf709
+                                    &domain, &key);
ecf709
     if (ret != EOK) {
ecf709
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to decompose object path"
ecf709
               "[%s] [%d]: %s\n", sbus_req->path, ret, sss_strerror(ret));
ecf709
@@ -439,28 +491,15 @@ ifp_groups_group_get(struct sbus_request *sbus_req,
ecf709
     }
ecf709
 
ecf709
     if (_group != NULL) {
ecf709
-        ret = sysdb_getgrgid_with_views(sbus_req, domain, gid, &res;;
ecf709
-        if (ret == EOK && res->count == 0) {
ecf709
-            *_group = NULL;
ecf709
-            ret = ENOENT;
ecf709
-        }
ecf709
-
ecf709
-        if (ret != EOK) {
ecf709
-            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup group %u@%s [%d]: %s\n",
ecf709
-                  gid, domain->name, ret, sss_strerror(ret));
ecf709
-        } else {
ecf709
-            *_group = res->msgs[0];
ecf709
-        }
ecf709
+        ret = ifp_groups_get_from_cache(sbus_req, domain, key, _group);
ecf709
     }
ecf709
 
ecf709
     if (ret == EOK || ret == ENOENT) {
ecf709
-        if (_gid != NULL) {
ecf709
-            *_gid = gid;
ecf709
-        }
ecf709
-
ecf709
         if (_domain != NULL) {
ecf709
             *_domain = domain;
ecf709
         }
ecf709
+    } else if (ret != EOK) {
ecf709
+        DEBUG(SSSDBG_OP_FAILURE, "Unable to retrieve group from cache\n");
ecf709
     }
ecf709
 
ecf709
     return ret;
ecf709
@@ -513,7 +552,7 @@ static struct tevent_req *resolv_ghosts_send(TALLOC_CTX *mem_ctx,
ecf709
     state->ctx = ctx;
ecf709
     state->data = data;
ecf709
 
ecf709
-    ret = ifp_groups_group_get(sbus_req, data, NULL, &domain, &group);
ecf709
+    ret = ifp_groups_group_get(sbus_req, data, &domain, &group);
ecf709
     if (ret != EOK) {
ecf709
         goto immediately;
ecf709
     }
ecf709
@@ -527,7 +566,7 @@ static struct tevent_req *resolv_ghosts_send(TALLOC_CTX *mem_ctx,
ecf709
 
ecf709
     subreq = cache_req_group_by_name_send(state, ev, ctx->rctx,
ecf709
                                           ctx->rctx->ncache, 0,
ecf709
-                                          CACHE_REQ_POSIX_DOM,
ecf709
+                                          CACHE_REQ_ANY_DOM,
ecf709
                                           domain->name,
ecf709
                                           name);
ecf709
     if (subreq == NULL) {
ecf709
@@ -561,7 +600,7 @@ static void resolv_ghosts_group_done(struct tevent_req *subreq)
ecf709
     req = tevent_req_callback_data(subreq, struct tevent_req);
ecf709
     state = tevent_req_data(req, struct resolv_ghosts_state);
ecf709
 
ecf709
-    ret = ifp_groups_group_get(state->sbus_req, state->data, NULL,
ecf709
+    ret = ifp_groups_group_get(state->sbus_req, state->data,
ecf709
                                &state->domain, &group);
ecf709
     if (ret != EOK) {
ecf709
         goto done;
ecf709
@@ -608,7 +647,7 @@ errno_t resolv_ghosts_step(struct tevent_req *req)
ecf709
 
ecf709
     subreq = cache_req_user_by_name_send(state, state->ev, state->ctx->rctx,
ecf709
                                          state->ctx->rctx->ncache, 0,
ecf709
-                                         CACHE_REQ_POSIX_DOM,
ecf709
+                                         CACHE_REQ_ANY_DOM,
ecf709
                                          state->domain->name,
ecf709
                                          state->ghosts[state->index]);
ecf709
     if (subreq == NULL) {
ecf709
@@ -719,7 +758,7 @@ void ifp_groups_group_get_name(struct sbus_request *sbus_req,
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_groups_group_get(sbus_req, data, NULL, &domain, &msg;;
ecf709
+    ret = ifp_groups_group_get(sbus_req, data, &domain, &msg;;
ecf709
     if (ret != EOK) {
ecf709
         *_out = NULL;
ecf709
         return;
ecf709
@@ -744,7 +783,7 @@ void ifp_groups_group_get_gid_number(struct sbus_request *sbus_req,
ecf709
     struct sss_domain_info *domain;
ecf709
     errno_t ret;
ecf709
 
ecf709
-    ret = ifp_groups_group_get(sbus_req, data, NULL, &domain, &msg;;
ecf709
+    ret = ifp_groups_group_get(sbus_req, data, &domain, &msg;;
ecf709
     if (ret != EOK) {
ecf709
         *_out = 0;
ecf709
         return;
ecf709
@@ -763,7 +802,7 @@ void ifp_groups_group_get_unique_id(struct sbus_request *sbus_req,
ecf709
     struct sss_domain_info *domain;
ecf709
     errno_t ret;
ecf709
 
ecf709
-    ret = ifp_groups_group_get(sbus_req, data, NULL, &domain, &msg;;
ecf709
+    ret = ifp_groups_group_get(sbus_req, data, &domain, &msg;;
ecf709
     if (ret != EOK) {
ecf709
         *_out = 0;
ecf709
         return;
ecf709
@@ -803,7 +842,7 @@ ifp_groups_group_get_members(TALLOC_CTX *mem_ctx,
ecf709
         return ENOMEM;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_groups_group_get(sbus_req, data, NULL, &domain, &group);
ecf709
+    ret = ifp_groups_group_get(sbus_req, data, &domain, &group);
ecf709
     if (ret != EOK) {
ecf709
         goto done;
ecf709
     }
ecf709
@@ -954,7 +993,7 @@ int ifp_cache_object_store_group(struct sbus_request *sbus_req,
ecf709
     struct ldb_message *group;
ecf709
     errno_t ret;
ecf709
 
ecf709
-    ret = ifp_groups_group_get(sbus_req, data, NULL, &domain, &group);
ecf709
+    ret = ifp_groups_group_get(sbus_req, data, &domain, &group);
ecf709
     if (ret != EOK) {
ecf709
         error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
ecf709
                                "group [%d]: %s\n", ret, sss_strerror(ret));
ecf709
@@ -973,7 +1012,7 @@ int ifp_cache_object_remove_group(struct sbus_request *sbus_req,
ecf709
     struct ldb_message *group;
ecf709
     errno_t ret;
ecf709
 
ecf709
-    ret = ifp_groups_group_get(sbus_req, data, NULL, &domain, &group);
ecf709
+    ret = ifp_groups_group_get(sbus_req, data, &domain, &group);
ecf709
     if (ret != EOK) {
ecf709
         error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
ecf709
                                "group [%d]: %s\n", ret, sss_strerror(ret));
ecf709
diff --git a/src/responder/ifp/ifp_users.c b/src/responder/ifp/ifp_users.c
ecf709
index 436bb268fa9c78d72fb744e0d338aa561a7d8764..ce9557f94351b730ee46f3cbce31613cb5901942 100644
ecf709
--- a/src/responder/ifp/ifp_users.c
ecf709
+++ b/src/responder/ifp/ifp_users.c
ecf709
@@ -37,25 +37,33 @@ char * ifp_users_build_path_from_msg(TALLOC_CTX *mem_ctx,
ecf709
                                      struct sss_domain_info *domain,
ecf709
                                      struct ldb_message *msg)
ecf709
 {
ecf709
-    const char *uid;
ecf709
+    const char *key = NULL;
ecf709
 
ecf709
-    uid = ldb_msg_find_attr_as_string(msg, SYSDB_UIDNUM, NULL);
ecf709
+    switch (domain->type) {
ecf709
+    case DOM_TYPE_APPLICATION:
ecf709
+        key = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
ecf709
+        break;
ecf709
+    case DOM_TYPE_POSIX:
ecf709
+        key = ldb_msg_find_attr_as_string(msg, SYSDB_UIDNUM, NULL);
ecf709
+        break;
ecf709
+    }
ecf709
 
ecf709
-    if (uid == NULL) {
ecf709
+
ecf709
+    if (key == NULL) {
ecf709
         return NULL;
ecf709
     }
ecf709
 
ecf709
-    return sbus_opath_compose(mem_ctx, IFP_PATH_USERS, domain->name, uid);
ecf709
+    return sbus_opath_compose(mem_ctx, IFP_PATH_USERS, domain->name, key);
ecf709
 }
ecf709
 
ecf709
-static errno_t ifp_users_decompose_path(struct sss_domain_info *domains,
ecf709
+static errno_t ifp_users_decompose_path(TALLOC_CTX *mem_ctx,
ecf709
+                                        struct sss_domain_info *domains,
ecf709
                                         const char *path,
ecf709
                                         struct sss_domain_info **_domain,
ecf709
-                                        uid_t *_uid)
ecf709
+                                        char **_key)
ecf709
 {
ecf709
     char **parts = NULL;
ecf709
     struct sss_domain_info *domain;
ecf709
-    uid_t uid;
ecf709
     errno_t ret;
ecf709
 
ecf709
     ret = sbus_opath_decompose_exact(NULL, path, IFP_PATH_USERS, 2, &parts;;
ecf709
@@ -69,14 +77,8 @@ static errno_t ifp_users_decompose_path(struct sss_domain_info *domains,
ecf709
         goto done;
ecf709
     }
ecf709
 
ecf709
-    uid = strtouint32(parts[1], NULL, 10);
ecf709
-    ret = errno;
ecf709
-    if (ret != EOK) {
ecf709
-        goto done;
ecf709
-    }
ecf709
-
ecf709
     *_domain = domain;
ecf709
-    *_uid = uid;
ecf709
+    *_key = talloc_steal(mem_ctx, parts[1]);
ecf709
 
ecf709
 done:
ecf709
     talloc_free(parts);
ecf709
@@ -100,7 +102,7 @@ int ifp_users_find_by_name(struct sbus_request *sbus_req,
ecf709
 
ecf709
     req = cache_req_user_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx,
ecf709
                                       ctx->rctx->ncache, 0,
ecf709
-                                      CACHE_REQ_POSIX_DOM,
ecf709
+                                      CACHE_REQ_ANY_DOM,
ecf709
                                       NULL, name);
ecf709
     if (req == NULL) {
ecf709
         return ENOMEM;
ecf709
@@ -256,7 +258,7 @@ int ifp_users_find_by_cert(struct sbus_request *sbus_req, void *data,
ecf709
 
ecf709
     req = cache_req_user_by_cert_send(sbus_req, ctx->rctx->ev, ctx->rctx,
ecf709
                                       ctx->rctx->ncache, 0,
ecf709
-                                      CACHE_REQ_POSIX_DOM, NULL,
ecf709
+                                      CACHE_REQ_ANY_DOM, NULL,
ecf709
                                       derb64);
ecf709
     if (req == NULL) {
ecf709
         return ENOMEM;
ecf709
@@ -371,7 +373,7 @@ static int ifp_users_list_by_cert_step(struct ifp_list_ctx *list_ctx)
ecf709
                                       list_ctx->ctx->rctx,
ecf709
                                       list_ctx->ctx->rctx->ncache,
ecf709
                                       0,
ecf709
-                                      CACHE_REQ_POSIX_DOM,
ecf709
+                                      CACHE_REQ_ANY_DOM,
ecf709
                                       list_ctx->dom->name,
ecf709
                                       list_ctx->filter);
ecf709
     if (req == NULL) {
ecf709
@@ -538,7 +540,7 @@ int ifp_users_find_by_name_and_cert(struct sbus_request *sbus_req, void *data,
ecf709
     if (name_and_cert_ctx->name != NULL) {
ecf709
         req = cache_req_user_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx,
ecf709
                                           ctx->rctx->ncache, 0,
ecf709
-                                          CACHE_REQ_POSIX_DOM,
ecf709
+                                          CACHE_REQ_ANY_DOM,
ecf709
                                           NULL,
ecf709
                                           name_and_cert_ctx->name);
ecf709
         if (req == NULL) {
ecf709
@@ -621,7 +623,7 @@ static int ifp_users_find_by_name_and_cert_step(
ecf709
                                       list_ctx->ctx->rctx,
ecf709
                                       list_ctx->ctx->rctx->ncache,
ecf709
                                       0,
ecf709
-                                      CACHE_REQ_POSIX_DOM,
ecf709
+                                      CACHE_REQ_ANY_DOM,
ecf709
                                       list_ctx->dom->name,
ecf709
                                       list_ctx->filter);
ecf709
     if (req == NULL) {
ecf709
@@ -782,7 +784,7 @@ static int ifp_users_list_by_name_step(struct ifp_list_ctx *list_ctx)
ecf709
     req = cache_req_user_by_filter_send(list_ctx,
ecf709
                                         list_ctx->ctx->rctx->ev,
ecf709
                                         list_ctx->ctx->rctx,
ecf709
-                                        CACHE_REQ_POSIX_DOM,
ecf709
+                                        CACHE_REQ_ANY_DOM,
ecf709
                                         list_ctx->dom->name,
ecf709
                                         list_ctx->filter);
ecf709
     if (req == NULL) {
ecf709
@@ -867,7 +869,7 @@ int ifp_users_list_by_domain_and_name(struct sbus_request *sbus_req,
ecf709
     }
ecf709
 
ecf709
     req = cache_req_user_by_filter_send(list_ctx, ctx->rctx->ev, ctx->rctx,
ecf709
-                                        CACHE_REQ_POSIX_DOM,
ecf709
+                                        CACHE_REQ_ANY_DOM,
ecf709
                                         domain, filter);
ecf709
     if (req == NULL) {
ecf709
         return ENOMEM;
ecf709
@@ -930,19 +932,69 @@ done:
ecf709
 }
ecf709
 
ecf709
 static errno_t
ecf709
+ifp_users_get_from_cache(struct sbus_request *sbus_req,
ecf709
+                         struct sss_domain_info *domain,
ecf709
+                         const char *key,
ecf709
+                         struct ldb_message **_user)
ecf709
+{
ecf709
+    struct ldb_result *user_res;
ecf709
+    errno_t ret;
ecf709
+    uid_t uid;
ecf709
+
ecf709
+    switch (domain->type) {
ecf709
+    case DOM_TYPE_POSIX:
ecf709
+        uid = strtouint32(key, NULL, 10);
ecf709
+        ret = errno;
ecf709
+        if (ret != EOK) {
ecf709
+            DEBUG(SSSDBG_CRIT_FAILURE, "Invalid UID value\n");
ecf709
+            return ret;
ecf709
+        }
ecf709
+
ecf709
+        ret = sysdb_getpwuid_with_views(sbus_req, domain, uid, &user_res);
ecf709
+        if (ret == EOK && user_res->count == 0) {
ecf709
+            *_user = NULL;
ecf709
+            return ENOENT;
ecf709
+        } else if (ret != EOK) {
ecf709
+            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup user %u@%s [%d]: %s\n",
ecf709
+                  uid, domain->name, ret, sss_strerror(ret));
ecf709
+            return ret;
ecf709
+        }
ecf709
+        break;
ecf709
+    case DOM_TYPE_APPLICATION:
ecf709
+        ret = sysdb_getpwnam_with_views(sbus_req, domain, key, &user_res);
ecf709
+        if (ret == EOK && user_res->count == 0) {
ecf709
+            *_user = NULL;
ecf709
+            return ENOENT;
ecf709
+        } else if (ret != EOK) {
ecf709
+            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup user %s@%s [%d]: %s\n",
ecf709
+                  key, domain->name, ret, sss_strerror(ret));
ecf709
+            return ret;
ecf709
+        }
ecf709
+        break;
ecf709
+    }
ecf709
+
ecf709
+    if (user_res->count > 1) {
ecf709
+        DEBUG(SSSDBG_CRIT_FAILURE, "More users matched by the single key\n");
ecf709
+        return EIO;
ecf709
+    }
ecf709
+
ecf709
+    *_user = user_res->msgs[0];
ecf709
+    return EOK;
ecf709
+}
ecf709
+
ecf709
+static errno_t
ecf709
 ifp_users_user_get(struct sbus_request *sbus_req,
ecf709
                    struct ifp_ctx *ifp_ctx,
ecf709
-                   uid_t *_uid,
ecf709
                    struct sss_domain_info **_domain,
ecf709
                    struct ldb_message **_user)
ecf709
 {
ecf709
     struct sss_domain_info *domain;
ecf709
-    struct ldb_result *res;
ecf709
-    uid_t uid;
ecf709
+    char *key;
ecf709
     errno_t ret;
ecf709
 
ecf709
-    ret = ifp_users_decompose_path(ifp_ctx->rctx->domains, sbus_req->path,
ecf709
-                                   &domain, &uid);
ecf709
+    ret = ifp_users_decompose_path(sbus_req,
ecf709
+                                   ifp_ctx->rctx->domains, sbus_req->path,
ecf709
+                                   &domain, &key);
ecf709
     if (ret != EOK) {
ecf709
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to decompose object path"
ecf709
               "[%s] [%d]: %s\n", sbus_req->path, ret, sss_strerror(ret));
ecf709
@@ -950,28 +1002,15 @@ ifp_users_user_get(struct sbus_request *sbus_req,
ecf709
     }
ecf709
 
ecf709
     if (_user != NULL) {
ecf709
-        ret = sysdb_getpwuid_with_views(sbus_req, domain, uid, &res;;
ecf709
-        if (ret == EOK && res->count == 0) {
ecf709
-            *_user = NULL;
ecf709
-            ret = ENOENT;
ecf709
-        }
ecf709
-
ecf709
-        if (ret != EOK) {
ecf709
-            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup user %u@%s [%d]: %s\n",
ecf709
-                  uid, domain->name, ret, sss_strerror(ret));
ecf709
-        } else {
ecf709
-            *_user = res->msgs[0];
ecf709
-        }
ecf709
+        ret = ifp_users_get_from_cache(sbus_req, domain, key, _user);
ecf709
     }
ecf709
 
ecf709
     if (ret == EOK || ret == ENOENT) {
ecf709
-        if (_uid != NULL) {
ecf709
-            *_uid = uid;
ecf709
-        }
ecf709
-
ecf709
         if (_domain != NULL) {
ecf709
             *_domain = domain;
ecf709
         }
ecf709
+    } else if (ret != EOK) {
ecf709
+        DEBUG(SSSDBG_OP_FAILURE, "Unable to retrieve user from cache\n");
ecf709
     }
ecf709
 
ecf709
     return ret;
ecf709
@@ -1000,7 +1039,7 @@ static void ifp_users_get_as_string(struct sbus_request *sbus_req,
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, ifp_ctx, NULL, &domain, &msg;;
ecf709
+    ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &msg;;
ecf709
     if (ret != EOK) {
ecf709
         return;
ecf709
     }
ecf709
@@ -1034,7 +1073,7 @@ static void ifp_users_get_name(struct sbus_request *sbus_req,
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, ifp_ctx, NULL, &domain, &msg;;
ecf709
+    ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &msg;;
ecf709
     if (ret != EOK) {
ecf709
         return;
ecf709
     }
ecf709
@@ -1072,7 +1111,7 @@ static void ifp_users_get_as_uint32(struct sbus_request *sbus_req,
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, ifp_ctx, NULL, &domain, &msg;;
ecf709
+    ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &msg;;
ecf709
     if (ret != EOK) {
ecf709
         return;
ecf709
     }
ecf709
@@ -1100,7 +1139,7 @@ int ifp_users_user_update_groups_list(struct sbus_request *sbus_req,
ecf709
         return ERR_INTERNAL;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, data, NULL, &domain, &user);
ecf709
+    ret = ifp_users_user_get(sbus_req, data, &domain, &user);
ecf709
     if (ret != EOK) {
ecf709
         return ret;
ecf709
     }
ecf709
@@ -1113,7 +1152,7 @@ int ifp_users_user_update_groups_list(struct sbus_request *sbus_req,
ecf709
 
ecf709
     req = cache_req_initgr_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx,
ecf709
                                         ctx->rctx->ncache, 0,
ecf709
-                                        CACHE_REQ_POSIX_DOM, domain->name,
ecf709
+                                        CACHE_REQ_ANY_DOM, domain->name,
ecf709
                                         username);
ecf709
     if (req == NULL) {
ecf709
         return ENOMEM;
ecf709
@@ -1235,7 +1274,7 @@ void ifp_users_user_get_groups(struct sbus_request *sbus_req,
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, ifp_ctx, NULL, &domain, &user);
ecf709
+    ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &user);
ecf709
     if (ret != EOK) {
ecf709
         return;
ecf709
     }
ecf709
@@ -1268,7 +1307,7 @@ void ifp_users_user_get_groups(struct sbus_request *sbus_req,
ecf709
     for (i = 0; i < res->count; i++) {
ecf709
         gid = sss_view_ldb_msg_find_attr_as_uint64(domain, res->msgs[i],
ecf709
                                                    SYSDB_GIDNUM, 0);
ecf709
-        if (gid == 0) {
ecf709
+        if (gid == 0 && domain->type == DOM_TYPE_POSIX) {
ecf709
             continue;
ecf709
         }
ecf709
 
ecf709
@@ -1293,11 +1332,12 @@ void ifp_users_user_get_extra_attributes(struct sbus_request *sbus_req,
ecf709
 {
ecf709
     struct ifp_ctx *ifp_ctx;
ecf709
     struct sss_domain_info *domain;
ecf709
+    struct ldb_message *base_user;
ecf709
+    const char *name;
ecf709
     struct ldb_message **user;
ecf709
     struct ldb_message_element *el;
ecf709
     struct ldb_dn *basedn;
ecf709
     size_t count;
ecf709
-    uid_t uid;
ecf709
     const char *filter;
ecf709
     const char **extra;
ecf709
     hash_table_t *table;
ecf709
@@ -1322,7 +1362,7 @@ void ifp_users_user_get_extra_attributes(struct sbus_request *sbus_req,
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, data, &uid, &domain, NULL);
ecf709
+    ret = ifp_users_user_get(sbus_req, data, &domain, &base_user);
ecf709
     if (ret != EOK) {
ecf709
         return;
ecf709
     }
ecf709
@@ -1333,9 +1373,15 @@ void ifp_users_user_get_extra_attributes(struct sbus_request *sbus_req,
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
-    filter = talloc_asprintf(sbus_req, "(&(%s=%s)(%s=%u))",
ecf709
+    name = ldb_msg_find_attr_as_string(base_user, SYSDB_NAME, NULL);
ecf709
+    if (name == NULL) {
ecf709
+        DEBUG(SSSDBG_CRIT_FAILURE, "A user with no name\n");
ecf709
+        return;
ecf709
+    }
ecf709
+
ecf709
+    filter = talloc_asprintf(sbus_req, "(&(%s=%s)(%s=%s))",
ecf709
                              SYSDB_OBJECTCLASS, SYSDB_USER_CLASS,
ecf709
-                             SYSDB_UIDNUM, uid);
ecf709
+                             SYSDB_NAME, name);
ecf709
     if (filter == NULL) {
ecf709
         DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf() failed\n");
ecf709
         return;
ecf709
@@ -1351,7 +1397,7 @@ void ifp_users_user_get_extra_attributes(struct sbus_request *sbus_req,
ecf709
     }
ecf709
 
ecf709
     if (count == 0) {
ecf709
-        DEBUG(SSSDBG_TRACE_FUNC, "User %u not found!\n", uid);
ecf709
+        DEBUG(SSSDBG_TRACE_FUNC, "User %s not found!\n", name);
ecf709
         return;
ecf709
     } else if (count > 1) {
ecf709
         DEBUG(SSSDBG_CRIT_FAILURE, "More than one entry found!\n");
ecf709
@@ -1421,7 +1467,7 @@ int ifp_cache_object_store_user(struct sbus_request *sbus_req,
ecf709
     struct ldb_message *user;
ecf709
     errno_t ret;
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, data, NULL, &domain, &user);
ecf709
+    ret = ifp_users_user_get(sbus_req, data, &domain, &user);
ecf709
     if (ret != EOK) {
ecf709
         error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
ecf709
                                "user [%d]: %s\n", ret, sss_strerror(ret));
ecf709
@@ -1440,7 +1486,7 @@ int ifp_cache_object_remove_user(struct sbus_request *sbus_req,
ecf709
     struct ldb_message *user;
ecf709
     errno_t ret;
ecf709
 
ecf709
-    ret = ifp_users_user_get(sbus_req, data, NULL, &domain, &user);
ecf709
+    ret = ifp_users_user_get(sbus_req, data, &domain, &user);
ecf709
     if (ret != EOK) {
ecf709
         error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
ecf709
                                "user [%d]: %s\n", ret, sss_strerror(ret));
ecf709
diff --git a/src/responder/ifp/ifpsrv_cmd.c b/src/responder/ifp/ifpsrv_cmd.c
ecf709
index 118b5083b14bf5692c6fdd7ba90668fe514aa89d..d10f35e41dbb1623a0b9de37a4c43363cbefc1a3 100644
ecf709
--- a/src/responder/ifp/ifpsrv_cmd.c
ecf709
+++ b/src/responder/ifp/ifpsrv_cmd.c
ecf709
@@ -508,8 +508,12 @@ ifp_user_get_attr_lookup(struct tevent_req *subreq)
ecf709
         return;
ecf709
     }
ecf709
 
ecf709
+    /* IFP serves both POSIX and application domains. Requests that need
ecf709
+     * to differentiate between the two must be qualified
ecf709
+     */
ecf709
     subreq = cache_req_send(state, state->rctx->ev, state->rctx,
ecf709
-                            state->ncache, 0, CACHE_REQ_POSIX_DOM,
ecf709
+                            state->ncache, 0,
ecf709
+                            CACHE_REQ_ANY_DOM,
ecf709
                             state->domname, data);
ecf709
     if (subreq == NULL) {
ecf709
         tevent_req_error(req, ENOMEM);
ecf709
-- 
ecf709
2.9.3
ecf709