[SSSD] [PATCH] Pass sdap_id_ctx to online check from IPA provider

Jakub Hrozek jhrozek at redhat.com
Mon Dec 19 15:10:34 UTC 2011


Patch attached.
-------------- next part --------------
From 91a950a1a0e56d34cb73123a1fd890cdf0791ed9 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Mon, 19 Dec 2011 14:59:59 +0100
Subject: [PATCH] Pass sdap_id_ctx to online check from IPA provider

---
 src/providers/ipa/ipa_id.c       |   10 ++++++
 src/providers/ipa/ipa_id.h       |    3 ++
 src/providers/ipa/ipa_init.c     |    2 +-
 src/providers/ldap/ldap_common.h |    2 +
 src/providers/ldap/ldap_id.c     |   57 ++++++++++++++++++++++++++-----------
 5 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/src/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c
index a014c9f2095298e375e96c2bc39e7b5c98dee879..7302a8da07fc2f521e7269e7b08ea9ac2cff9050 100644
--- a/src/providers/ipa/ipa_id.c
+++ b/src/providers/ipa/ipa_id.c
@@ -321,3 +321,13 @@ static void ipa_account_info_netgroups_done(struct tevent_req *req)
 
     ipa_account_info_complete(breq, dp_error, ret, "Netgroup lookup failed");
 }
+
+void ipa_check_online(struct be_req *be_req)
+{
+    struct ipa_id_ctx *ipa_ctx;
+
+    ipa_ctx = talloc_get_type(be_req->be_ctx->bet_info[BET_ID].pvt_bet_data,
+                              struct ipa_id_ctx);
+
+    return sdap_do_online_check(be_req, ipa_ctx->sdap_id_ctx);
+}
diff --git a/src/providers/ipa/ipa_id.h b/src/providers/ipa/ipa_id.h
index aa2dfe7fd0dfa23d452f9765e2040e663224267c..04a6c2b8aaad024e55a71af39d486bd863313524 100644
--- a/src/providers/ipa/ipa_id.h
+++ b/src/providers/ipa/ipa_id.h
@@ -45,4 +45,7 @@ int ipa_get_netgroups_recv(struct tevent_req *req,
                            TALLOC_CTX *mem_ctx,
                            size_t *reply_count,
                            struct sysdb_attrs ***reply);
+
+void ipa_check_online(struct be_req *be_req);
+
 #endif
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 57b4180cc25ad044b3c7dd2c61afc8c34f0eb4b8..ec1b8380983e0708d6f2b35f71cd1fb1ed6ce243 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -41,7 +41,7 @@ struct ipa_options *ipa_options = NULL;
 struct bet_ops ipa_id_ops = {
     .handler = ipa_account_info_handler,
     .finalize = NULL,
-    .check_online = sdap_check_online
+    .check_online = ipa_check_online
 };
 
 struct bet_ops ipa_auth_ops = {
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
index d7aa71ab5b76bd011a928af019aa23b3a8289896..e6bb8b6a181debfee7511684d7ab29c951c89979 100644
--- a/src/providers/ldap/ldap_common.h
+++ b/src/providers/ldap/ldap_common.h
@@ -69,6 +69,8 @@ struct sdap_auth_ctx {
 };
 
 void sdap_check_online(struct be_req *breq);
+void sdap_do_online_check(struct be_req *be_req, struct sdap_id_ctx *ctx);
+
 /* id */
 void sdap_account_info_handler(struct be_req *breq);
 void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx);
diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c
index a1984cefd457f91a84d59879f17c0fe41448817b..feac63b67215e39494fbbe9c64096e31746101d7 100644
--- a/src/providers/ldap/ldap_id.c
+++ b/src/providers/ldap/ldap_id.c
@@ -666,36 +666,57 @@ static void sdap_check_online_done(struct tevent_req *req);
 void sdap_check_online(struct be_req *be_req)
 {
     struct sdap_id_ctx *ctx;
-    struct tevent_req *req;
 
     ctx = talloc_get_type(be_req->be_ctx->bet_info[BET_ID].pvt_bet_data,
                           struct sdap_id_ctx);
 
+    return sdap_do_online_check(be_req, ctx);
+}
+
+struct sdap_online_check_ctx {
+    struct be_req *be_req;
+    struct sdap_id_ctx *id_ctx;
+};
+
+void sdap_do_online_check(struct be_req *be_req, struct sdap_id_ctx *ctx)
+{
+    struct tevent_req *req;
+    struct sdap_online_check_ctx *check_ctx;
+    errno_t ret;
+
+    check_ctx = talloc_zero(be_req, struct sdap_online_check_ctx);
+    if (!check_ctx) {
+        ret = ENOMEM;
+        DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed\n"));
+        goto fail;
+    }
+    check_ctx->id_ctx = ctx;
+    check_ctx->be_req = be_req;
+
     req = sdap_cli_connect_send(be_req, be_req->be_ctx->ev, ctx->opts,
                                 be_req->be_ctx, ctx->service, false,
                                 CON_TLS_DFL, false);
     if (req == NULL) {
         DEBUG(1, ("sdap_cli_connect_send failed.\n"));
-        goto done;
+        ret = EIO;
+        goto fail;
     }
-    tevent_req_set_callback(req, sdap_check_online_done, be_req);
+    tevent_req_set_callback(req, sdap_check_online_done, check_ctx);
 
     return;
-done:
-    sdap_handler_done(be_req, DP_ERR_FATAL, 0, NULL);
+fail:
+    sdap_handler_done(be_req, DP_ERR_FATAL, ret, NULL);
 }
 
 static void sdap_check_online_done(struct tevent_req *req)
 {
-    struct be_req *be_req = tevent_req_callback_data(req, struct be_req);
+    struct sdap_online_check_ctx *check_ctx = tevent_req_callback_data(req,
+                                        struct sdap_online_check_ctx);
     int ret;
     int dp_err = DP_ERR_FATAL;
     bool can_retry;
-    struct sdap_id_ctx *ctx;
     struct sdap_server_opts *srv_opts;
-
-    ctx = talloc_get_type(be_req->be_ctx->bet_info[BET_ID].pvt_bet_data,
-                          struct sdap_id_ctx);
+    struct be_req *be_req;
 
     ret = sdap_cli_connect_recv(req, NULL, &can_retry, NULL, &srv_opts);
     talloc_zfree(req);
@@ -707,20 +728,22 @@ static void sdap_check_online_done(struct tevent_req *req)
     } else {
         dp_err = DP_ERR_OK;
 
-        if (!ctx->srv_opts) {
+        if (!check_ctx->id_ctx->srv_opts) {
             srv_opts->max_user_value = 0;
             srv_opts->max_group_value = 0;
-        } else if (strcmp(srv_opts->server_id, ctx->srv_opts->server_id) == 0
+        } else if (strcmp(srv_opts->server_id, check_ctx->id_ctx->srv_opts->server_id) == 0
                    && srv_opts->supports_usn
-                   && ctx->srv_opts->last_usn > srv_opts->last_usn) {
-            ctx->srv_opts->max_user_value = 0;
-            ctx->srv_opts->max_group_value = 0;
-            ctx->srv_opts->last_usn = srv_opts->last_usn;
+                   && check_ctx->id_ctx->srv_opts->last_usn > srv_opts->last_usn) {
+            check_ctx->id_ctx->srv_opts->max_user_value = 0;
+            check_ctx->id_ctx->srv_opts->max_group_value = 0;
+            check_ctx->id_ctx->srv_opts->last_usn = srv_opts->last_usn;
         }
 
-        sdap_steal_server_opts(ctx, &srv_opts);
+        sdap_steal_server_opts(check_ctx->id_ctx, &srv_opts);
     }
 
+    be_req = check_ctx->be_req;
+    talloc_free(check_ctx);
     sdap_handler_done(be_req, dp_err, 0, NULL);
 }
 
-- 
1.7.7.4



More information about the sssd-devel mailing list