summaryrefslogtreecommitdiffstats
path: root/server/responder/common
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2009-08-17 04:29:47 -0400
committerStephen Gallagher <sgallagh@redhat.com>2009-08-17 09:39:01 -0400
commitc0f3393d4ab923e2eedab0fad88a864e2aae9fc9 (patch)
tree1a31b6e55879396897441545ac5d0278e7371c49 /server/responder/common
parent7385f34a3c8c68cf0f87d64e55e0ca44f46fdeaa (diff)
downloadsssd-c0f3393d4ab923e2eedab0fad88a864e2aae9fc9.tar.gz
sssd-c0f3393d4ab923e2eedab0fad88a864e2aae9fc9.tar.xz
sssd-c0f3393d4ab923e2eedab0fad88a864e2aae9fc9.zip
Fix reconnection code
Remove redundant reconnection code that was interfeering with the sbus reconnection code. Consolidate include files for sbus relates operations. Make pamsrv code similar to nsssrv code.
Diffstat (limited to 'server/responder/common')
-rw-r--r--server/responder/common/responder.h5
-rw-r--r--server/responder/common/responder_common.c36
-rw-r--r--server/responder/common/responder_dp.c139
3 files changed, 35 insertions, 145 deletions
diff --git a/server/responder/common/responder.h b/server/responder/common/responder.h
index 5510bf200..59a58a5c5 100644
--- a/server/responder/common/responder.h
+++ b/server/responder/common/responder.h
@@ -123,11 +123,6 @@ void sss_cmd_done(struct cli_ctx *cctx, void *freectx);
int sss_cmd_get_version(struct cli_ctx *cctx);
struct cli_protocol_version *register_cli_protocol_version(void);
-/* responder_dp.c */
-int sss_dp_init(struct resp_ctx *rctx, struct sbus_interface *intf,
- uint16_t cli_type, uint16_t cli_version,
- const char *cli_name, const char *cli_domain);
-
#define SSS_DP_USER 1
#define SSS_DP_GROUP 2
#define SSS_DP_INITGROUPS 3
diff --git a/server/responder/common/responder_common.c b/server/responder/common/responder_common.c
index cf06c3ca1..f1030c04e 100644
--- a/server/responder/common/responder_common.c
+++ b/server/responder/common/responder_common.c
@@ -39,7 +39,6 @@
#include "responder/common/responder.h"
#include "responder/common/responder_packet.h"
#include "providers/data_provider.h"
-#include "monitor/monitor_sbus.h"
#include "monitor/monitor_interfaces.h"
#include "sbus/sbus_client.h"
@@ -318,6 +317,41 @@ static int sss_monitor_init(struct resp_ctx *rctx,
return EOK;
}
+static int sss_dp_init(struct resp_ctx *rctx,
+ struct sbus_interface *intf,
+ uint16_t cli_type, uint16_t cli_version,
+ const char *cli_name, const char *cli_domain)
+{
+ char *sbus_address;
+ int ret;
+
+ /* Set up SBUS connection to the monitor */
+ ret = dp_get_sbus_address(rctx, rctx->cdb, &sbus_address);
+ if (ret != EOK) {
+ DEBUG(0, ("Could not locate DP address.\n"));
+ return ret;
+ }
+
+ ret = sbus_client_init(rctx, rctx->ev, sbus_address,
+ intf, &rctx->dp_conn,
+ NULL, NULL);
+ if (ret != EOK) {
+ DEBUG(0, ("Failed to connect to monitor services.\n"));
+ return ret;
+ }
+
+ /* Identify ourselves to the DP */
+ ret = dp_common_send_id(rctx->dp_conn,
+ cli_type, cli_version,
+ cli_name, cli_domain);
+ if (ret != EOK) {
+ DEBUG(0, ("Failed to identify to the DP!\n"));
+ return ret;
+ }
+
+ return EOK;
+}
+
/* create a unix socket and listen to it */
static int set_unix_socket(struct resp_ctx *rctx)
{
diff --git a/server/responder/common/responder_dp.c b/server/responder/common/responder_dp.c
index 163dadf4a..076b15432 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 {