diff options
Diffstat (limited to 'server/responder/common/responder_dp.c')
-rw-r--r-- | server/responder/common/responder_dp.c | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/server/responder/common/responder_dp.c b/server/responder/common/responder_dp.c index 163dadf4..076b1543 100644 --- a/server/responder/common/responder_dp.c +++ b/server/responder/common/responder_dp.c @@ -6,148 +6,9 @@ #include "responder/common/responder.h" #include "providers/data_provider.h" #include "sbus/sbus_client.h" -#include "providers/dp_sbus.h" - -struct sss_dp_pvt_ctx { - struct resp_ctx *rctx; - struct sbus_interface *intf; - - uint16_t cli_type; - uint16_t cli_version; - const char *cli_name; - const char *cli_domain; - - time_t last_retry; - int retries; -}; hash_table_t *dp_requests = NULL; -static int sss_dp_conn_destructor(void *data); -static void sss_dp_reconnect(struct tevent_context *ev, - struct tevent_timer *te, - struct timeval tv, void *data); - -static void sss_dp_conn_reconnect(struct sss_dp_pvt_ctx *pvt) -{ - struct resp_ctx *rctx; - struct tevent_timer *te; - struct timeval tv; - char *sbus_address; - time_t now; - int ret; - - now = time(NULL); - - /* reset retry if last reconnect was > 60 sec. ago */ - if (pvt->last_retry + 60 < now) pvt->retries = 0; - if (pvt->retries >= 3) { - DEBUG(4, ("Too many reconnect retries! Giving up\n")); - return; - } - - pvt->last_retry = now; - pvt->retries++; - - rctx = pvt->rctx; - - ret = dp_get_sbus_address(rctx, rctx->cdb, &sbus_address); - if (ret != EOK) { - DEBUG(0, ("Could not locate data provider address.\n")); - return; - } - - ret = sbus_client_init(rctx, rctx->ev, sbus_address, - pvt->intf, &rctx->dp_conn, - sss_dp_conn_destructor, pvt); - - if (ret == EOK) { - /* Identify ourselves to the data provider */ - ret = dp_common_send_id(rctx->dp_conn, - pvt->cli_type, pvt->cli_version, - pvt->cli_name, pvt->cli_domain); - if (ret != EOK) { - DEBUG(0, ("Failed to identify to the data provider!\n")); - } - } - - if (ret != EOK) { - DEBUG(4, ("Failed to reconnect [%d(%s)]!\n", ret, strerror(ret))); - - tv.tv_sec = now +5; - tv.tv_usec = 0; - te = tevent_add_timer(rctx->ev, rctx, tv, sss_dp_reconnect, pvt); - if (te == NULL) { - DEBUG(4, ("Failed to add timed event! Giving up\n")); - } else { - DEBUG(4, ("Retrying in 5 seconds\n")); - } - } -} - -static void sss_dp_reconnect(struct tevent_context *ev, - struct tevent_timer *te, - struct timeval tv, void *data) -{ - struct sss_dp_pvt_ctx *pvt; - - pvt = talloc_get_type(data, struct sss_dp_pvt_ctx); - - sss_dp_conn_reconnect(pvt); -} - -int sss_dp_conn_destructor(void *data) -{ - struct sss_dp_pvt_ctx *pvt; - struct sbus_connection *conn; - - conn = talloc_get_type(data, struct sbus_connection); - if (!conn) return 0; - - /* if this is a regular disconnect just quit */ - if (sbus_conn_disconnecting(conn)) return 0; - - pvt = talloc_get_type(sbus_conn_get_private_data(conn), - struct sss_dp_pvt_ctx); - if (pvt) return 0; - - sss_dp_conn_reconnect(pvt); - - return 0; -} - -int sss_dp_init(struct resp_ctx *rctx, struct sbus_interface *dp_intf, - uint16_t cli_type, uint16_t cli_version, - const char *cli_name, const char *cli_domain) -{ - int ret; - struct sss_dp_pvt_ctx *pvt; - - pvt = talloc_zero(rctx, struct sss_dp_pvt_ctx); - if (!pvt) return ENOMEM; - - pvt->rctx = rctx; - pvt->intf = dp_intf; - pvt->cli_type = cli_type; - pvt->cli_version = cli_version; - pvt->cli_name = talloc_strdup(pvt, cli_name); - if (!pvt->cli_name) return ENOMEM; - pvt->cli_domain = talloc_strdup(pvt, cli_domain); - if (!pvt->cli_domain) return ENOMEM; - - /* Create a hash table to handle queued update requests */ - ret = hash_create(10, &dp_requests, NULL); - if (ret != HASH_SUCCESS) { - fprintf(stderr, "cannot create hash table (%s)\n", hash_error_string(ret)); - talloc_zfree(pvt); - return EIO; - } - - sss_dp_conn_reconnect(pvt); - - return EOK; -} - struct sss_dp_req; struct sss_dp_callback { |