summaryrefslogtreecommitdiff
path: root/server/responder/nss/nsssrv_dp.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/responder/nss/nsssrv_dp.c')
-rw-r--r--server/responder/nss/nsssrv_dp.c123
1 files changed, 7 insertions, 116 deletions
diff --git a/server/responder/nss/nsssrv_dp.c b/server/responder/nss/nsssrv_dp.c
index d4406e40..0668a5b5 100644
--- a/server/responder/nss/nsssrv_dp.c
+++ b/server/responder/nss/nsssrv_dp.c
@@ -93,7 +93,7 @@ static void nss_dp_send_acct_callback(DBusPendingCall *pending, void *ptr)
talloc_free(ndp_req);
}
-int nss_dp_send_acct_req(struct nss_ctx *nctx, TALLOC_CTX *memctx,
+int nss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *memctx,
nss_dp_callback_t callback, void *callback_ctx,
int timeout, const char *domain, int type,
const char *opt_name, uint32_t opt_id)
@@ -139,11 +139,10 @@ int nss_dp_send_acct_req(struct nss_ctx *nctx, TALLOC_CTX *memctx,
filter = talloc_strdup(memctx, "name=*");
}
if (!filter) {
- talloc_free(nctx);
return ENOMEM;
}
- conn = sbus_get_connection(nctx->dp_ctx->scon_ctx);
+ conn = sbus_get_connection(rctx->dp_ctx->scon_ctx);
/* create the message */
msg = dbus_message_new_method_call(NULL,
@@ -198,8 +197,8 @@ int nss_dp_send_acct_req(struct nss_ctx *nctx, TALLOC_CTX *memctx,
gettimeofday(&tv, NULL);
tv.tv_sec += timeout/1000;
tv.tv_usec += (timeout%1000) * 1000;
- ndp_req->te = tevent_add_timer(nctx->ev, memctx, tv,
- nss_dp_send_acct_timeout, ndp_req);
+ ndp_req->te = tevent_add_timer(rctx->ev, memctx, tv,
+ nss_dp_send_acct_timeout, ndp_req);
/* Set up the reply handler */
dbus_pending_call_set_notify(pending_reply,
@@ -314,120 +313,12 @@ static int nss_dp_identity(DBusMessage *message, struct sbus_conn_ctx *sconn)
return EOK;
}
-struct sbus_method nss_dp_methods[] = {
+static struct sbus_method nss_dp_methods[] = {
{ DP_CLI_METHOD_IDENTITY, nss_dp_identity },
{ NULL, NULL }
};
-struct nss_dp_pvt_ctx {
- struct nss_ctx *nctx;
- struct sbus_method *methods;
- time_t last_retry;
- int retries;
-};
-
-static int nss_dp_conn_destructor(void *data);
-static void nss_dp_reconnect(struct tevent_context *ev,
- struct tevent_timer *te,
- struct timeval tv, void *data);
-
-static void nss_dp_conn_reconnect(struct nss_dp_pvt_ctx *pvt)
-{
- struct nss_ctx *nctx;
- struct tevent_timer *te;
- struct timeval tv;
- struct sbus_method_ctx *sm_ctx;
- 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++;
-
- nctx = pvt->nctx;
-
- ret = dp_get_sbus_address(nctx, nctx->cdb, &sbus_address);
- if (ret != EOK) {
- DEBUG(0, ("Could not locate data provider address.\n"));
- return;
- }
-
- ret = dp_init_sbus_methods(nctx, pvt->methods, &sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return;
- }
-
- ret = sbus_client_init(nctx, nctx->ev,
- sbus_address, sm_ctx,
- pvt, nss_dp_conn_destructor,
- &nctx->dp_ctx);
- 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(nctx->ev, nctx, tv, nss_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 nss_dp_reconnect(struct tevent_context *ev,
- struct tevent_timer *te,
- struct timeval tv, void *data)
-{
- struct nss_dp_pvt_ctx *pvt;
-
- pvt = talloc_get_type(data, struct nss_dp_pvt_ctx);
-
- nss_dp_conn_reconnect(pvt);
-}
-
-int nss_dp_conn_destructor(void *data)
-{
- struct nss_dp_pvt_ctx *pvt;
- struct sbus_conn_ctx *scon;
-
- scon = talloc_get_type(data, struct sbus_conn_ctx);
- if (!scon) return 0;
-
- /* if this is a regular disconnect just quit */
- if (sbus_conn_disconnecting(scon)) return 0;
-
- pvt = talloc_get_type(sbus_conn_get_private_data(scon),
- struct nss_dp_pvt_ctx);
- if (pvt) return 0;
-
- nss_dp_conn_reconnect(pvt);
-
- return 0;
-}
-
-int nss_dp_init(struct nss_ctx *nctx)
+struct sbus_method *get_nss_dp_methods(void)
{
- struct nss_dp_pvt_ctx *pvt;
-
- pvt = talloc_zero(nctx, struct nss_dp_pvt_ctx);
- if (!pvt) return ENOMEM;
-
- pvt->nctx = nctx;
- pvt->methods = nss_dp_methods;
-
- nss_dp_conn_reconnect(pvt);
-
- return EOK;
+ return nss_dp_methods;
}
-