From 90117ef21c23361d8b2fa346516fa24105219e8c Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Tue, 10 Mar 2015 12:48:16 +0100
Subject: [PATCH] SDAP: Make simple bind timeout configurable

Resolves:
https://fedorahosted.org/sssd/ticket/1501

Reuse the value of sdap_opt_timeout to set a longer bind timeout for
user authentication, ID connection authentication and authentication
during IPA migration mode.

Reviewed-by: Pavel Reichl <preichl@redhat.com>

diff --git a/src/providers/ipa/ipa_auth.c b/src/providers/ipa/ipa_auth.c
index eb62f02..82ccffd 100644
--- a/src/providers/ipa/ipa_auth.c
+++ b/src/providers/ipa/ipa_auth.c
@@ -378,7 +378,7 @@ static void ipa_migration_flag_connect_done(struct tevent_req *req)
     password.length = state->pd->authtok_size;
 
     req = sdap_auth_send(state, state->ev, state->sh, NULL, NULL, dn,
-                         "password", password);
+                         "password", password, dp_opt_get_int(state->ipa_auth_ctx->sdap_auth_ctx->opts->basic,SDAP_OPT_TIMEOUT));
     if (req == NULL) {
         DEBUG(SSSDBG_OP_FAILURE, ("sdap_auth_send failed.\n"));
         goto done;
diff --git a/src/providers/ldap/ldap_auth.c b/src/providers/ldap/ldap_auth.c
index f161d30..05a317a 100644
--- a/src/providers/ldap/ldap_auth.c
+++ b/src/providers/ldap/ldap_auth.c
@@ -629,7 +629,7 @@ static void auth_connect_done(struct tevent_req *subreq)
 
     subreq = sdap_auth_send(state, state->ev, state->sh,
                             NULL, NULL, state->dn,
-                            "password", state->password);
+                            "password", state->password, dp_opt_get_int(state->ctx->opts->basic,SDAP_OPT_TIMEOUT));
     if (!subreq) {
         tevent_req_error(req, ENOMEM);
         return;
diff --git a/src/providers/ldap/sdap_async.h b/src/providers/ldap/sdap_async.h
index 8c16d94..81bc66f 100644
--- a/src/providers/ldap/sdap_async.h
+++ b/src/providers/ldap/sdap_async.h
@@ -109,7 +109,8 @@ struct tevent_req *sdap_auth_send(TALLOC_CTX *memctx,
                                   const char *sasl_user,
                                   const char *user_dn,
                                   const char *authtok_type,
-                                  struct dp_opt_blob authtok);
+                                  struct dp_opt_blob authtok,
+                                  int simple_bind_timeout);
 
 int sdap_auth_recv(struct tevent_req *req,
                    TALLOC_CTX *memctx,
@@ -129,7 +130,8 @@ struct tevent_req *sdap_exop_modify_passwd_send(TALLOC_CTX *memctx,
                                                 struct sdap_handle *sh,
                                                 char *user_dn,
                                                 char *password,
-                                                char *new_password);
+                                                char *new_password,
+                                                int timeout);
 int sdap_exop_modify_passwd_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                                  enum sdap_result *result,
                                  char **user_error_msg);
diff --git a/src/providers/ldap/sdap_async_connection.c b/src/providers/ldap/sdap_async_connection.c
index bb1cdab..b5a6be3 100644
--- a/src/providers/ldap/sdap_async_connection.c
+++ b/src/providers/ldap/sdap_async_connection.c
@@ -457,6 +457,7 @@ static void simple_bind_done(struct sdap_op *op,
 static struct tevent_req *simple_bind_send(TALLOC_CTX *memctx,
                                            struct tevent_context *ev,
                                            struct sdap_handle *sh,
+                                           int timeout,
                                            const char *user_dn,
                                            struct berval *pw)
 {
@@ -516,9 +517,8 @@ static struct tevent_req *simple_bind_send(TALLOC_CTX *memctx,
         if (ret) goto fail;
     }
 
-    /* FIXME: get timeouts from configuration, for now 5 secs. */
     ret = sdap_op_add(state, ev, sh, msgid,
-                      simple_bind_done, req, 5, &state->op);
+                      simple_bind_done, req, timeout, &state->op);
     if (ret) {
         DEBUG(1, ("Failed to set up operation!\n"));
         goto fail;
@@ -1104,7 +1104,8 @@ struct tevent_req *sdap_auth_send(TALLOC_CTX *memctx,
                                   const char *sasl_user,
                                   const char *user_dn,
                                   const char *authtok_type,
-                                  struct dp_opt_blob authtok)
+                                  struct dp_opt_blob authtok,
+                                  int simple_bind_timeout)
 {
     struct tevent_req *req, *subreq;
     struct sdap_auth_state *state;
@@ -1137,7 +1138,7 @@ struct tevent_req *sdap_auth_send(TALLOC_CTX *memctx,
         }
     } else {
         state->is_sasl = false;
-        subreq = simple_bind_send(state, ev, sh, user_dn, &state->pw);
+        subreq = simple_bind_send(state, ev, sh, simple_bind_timeout, user_dn, &state->pw);
         if (!subreq) {
             tevent_req_error(req, ENOMEM);
             return tevent_req_post(req, ev);
@@ -1631,7 +1632,8 @@ static void sdap_cli_auth_step(struct tevent_req *req)
                             dp_opt_get_string(state->opts->basic,
                                                SDAP_DEFAULT_AUTHTOK_TYPE),
                             dp_opt_get_blob(state->opts->basic,
-                                                    SDAP_DEFAULT_AUTHTOK));
+                                                    SDAP_DEFAULT_AUTHTOK),
+                            dp_opt_get_int(state->opts->basic,SDAP_OPT_TIMEOUT));
     if (!subreq) {
         tevent_req_error(req, ENOMEM);
         return;
-- 
2.14.2

