>From e510dbbb83b75982ce755cc27d8754875832aa3a Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Fri, 1 Aug 2014 12:22:21 +0100
Subject: [PATCH 4/9] SDAP: refactor sdap_access_filter_done

As preparation for ticket #2364 move code from sdap_access_filter_done()
into sdap_access_done() to make its reuse possible and thus avoid code
duplication.
---
 src/providers/ldap/sdap_access.c | 41 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/providers/ldap/sdap_access.c b/src/providers/ldap/sdap_access.c
index e54f4e0d5d13d72e8cb38bd1c827ea2f52e7dcef..68633643f7430c26885a78d2903e7a4dd636e1d5 100644
--- a/src/providers/ldap/sdap_access.c
+++ b/src/providers/ldap/sdap_access.c
@@ -60,8 +60,11 @@ static struct tevent_req *sdap_access_filter_send(TALLOC_CTX *mem_ctx,
                                              struct sdap_id_conn_ctx *conn,
                                              const char *username,
                                              struct ldb_message *user_entry);
+
 static errno_t sdap_access_filter_recv(struct tevent_req *req);
 
+static errno_t sdap_access_subreq_recv(struct tevent_req *req);
+
 static errno_t sdap_account_expired(struct sdap_access_ctx *access_ctx,
                                     struct pam_data *pd,
                                     struct ldb_message *user_entry);
@@ -219,14 +222,14 @@ static errno_t check_next_rule(struct sdap_access_req_ctx *state,
     return ret;
 }
 
-static void sdap_access_filter_done(struct tevent_req *subreq)
+static void sdap_access_done(struct tevent_req *subreq)
 {
     errno_t ret;
     struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
     struct sdap_access_req_ctx *state =
             tevent_req_data(req, struct sdap_access_req_ctx);
 
-    ret = sdap_access_filter_recv(subreq);
+    ret = sdap_access_subreq_recv(subreq);
     talloc_zfree(subreq);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Error retrieving access check result.\n");
@@ -249,6 +252,11 @@ static void sdap_access_filter_done(struct tevent_req *subreq)
     }
 }
 
+static void sdap_access_filter_done(struct tevent_req *subreq)
+{
+    sdap_access_done(subreq);
+}
+
 errno_t sdap_access_recv(struct tevent_req *req)
 {
     TEVENT_REQ_RETURN_ON_ERROR(req);
@@ -256,7 +264,6 @@ errno_t sdap_access_recv(struct tevent_req *req)
     return EOK;
 }
 
-
 #define SHADOW_EXPIRE_MSG "Account expired according to shadow attributes"
 
 static errno_t sdap_account_expired_shadow(struct pam_data *pd,
@@ -644,6 +651,10 @@ static errno_t sdap_account_expired(struct sdap_access_ctx *access_ctx,
     return ret;
 }
 
+enum sdap_access_control_type {
+    SDAP_ACCESS_CONTROL_FILTER,
+};
+
 struct sdap_access_filter_req_ctx {
     const char *username;
     const char *filter;
@@ -656,6 +667,7 @@ struct sdap_access_filter_req_ctx {
     struct sss_domain_info *domain;
     bool cached_access;
     char *basedn;
+    enum sdap_access_control_type ac_type;
 };
 
 static errno_t sdap_access_filter_decide_offline(struct tevent_req *req);
@@ -696,6 +708,7 @@ static struct tevent_req *sdap_access_filter_send(TALLOC_CTX *mem_ctx,
     state->ev = ev;
     state->access_ctx = access_ctx;
     state->domain = domain;
+    state->ac_type = SDAP_ACCESS_CONTROL_FILTER;
 
     DEBUG(SSSDBG_TRACE_FUNC,
           "Performing access filter check for user [%s]\n", username);
@@ -772,6 +785,27 @@ done:
     return req;
 }
 
+static errno_t sdap_access_subreq_recv(struct tevent_req *req)
+{
+    struct sdap_access_filter_req_ctx *state;
+    errno_t ret;
+
+    state = tevent_req_data(req, struct sdap_access_filter_req_ctx);
+
+    switch(state->ac_type) {
+    case SDAP_ACCESS_CONTROL_FILTER:
+        ret = sdap_access_filter_recv(req);
+        break;
+    default:
+        ret = EINVAL;
+        DEBUG(SSSDBG_MINOR_FAILURE, "Unknown access control type: %d.",
+              state->ac_type);
+        break;
+    }
+
+    return ret;
+}
+
 static errno_t sdap_access_filter_decide_offline(struct tevent_req *req)
 {
     struct sdap_access_filter_req_ctx *state =
@@ -956,7 +990,6 @@ static errno_t sdap_access_filter_recv(struct tevent_req *req)
     return EOK;
 }
 
-
 #define AUTHR_SRV_MISSING_MSG "Authorized service attribute missing, " \
                               "access denied"
 #define AUTHR_SRV_DENY_MSG "Access denied by authorized service attribute"
-- 
1.9.3

