summaryrefslogtreecommitdiff
path: root/server/responder
diff options
context:
space:
mode:
Diffstat (limited to 'server/responder')
-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
-rw-r--r--server/responder/nss/nsssrv.c40
-rw-r--r--server/responder/pam/pamsrv.c100
-rw-r--r--server/responder/pam/pamsrv.h2
-rw-r--r--server/responder/pam/pamsrv_cmd.c2
-rw-r--r--server/responder/pam/pamsrv_dp.c1
8 files changed, 116 insertions, 209 deletions
diff --git a/server/responder/common/responder.h b/server/responder/common/responder.h
index 5510bf20..59a58a5c 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 cf06c3ca..f1030c04 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 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 {
diff --git a/server/responder/nss/nsssrv.c b/server/responder/nss/nsssrv.c
index 456c6292..a896ef31 100644
--- a/server/responder/nss/nsssrv.c
+++ b/server/responder/nss/nsssrv.c
@@ -41,7 +41,6 @@
#include "util/btreemap.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"
@@ -186,35 +185,44 @@ static void nss_shutdown(struct resp_ctx *rctx)
exit(0);
}
+static struct sbus_method nss_dp_methods[] = {
+ { NULL, NULL }
+};
-static void nss_dp_reconnect_init(struct sbus_connection *conn, int status, void *pvt)
+struct sbus_interface nss_dp_interface = {
+ DP_CLI_INTERFACE,
+ DP_CLI_PATH,
+ SBUS_DEFAULT_VTABLE,
+ nss_dp_methods,
+ NULL
+};
+
+
+static void nss_dp_reconnect_init(struct sbus_connection *conn,
+ int status, void *pvt)
{
struct resp_ctx *rctx = talloc_get_type(pvt, struct resp_ctx);
+ int ret;
/* Did we reconnect successfully? */
if (status == SBUS_RECONNECT_SUCCESS) {
DEBUG(1, ("Reconnected to the Data Provider.\n"));
- return;
+
+ /* Identify ourselves to the data provider */
+ ret = dp_common_send_id(conn,
+ DP_CLI_FRONTEND,
+ DATA_PROVIDER_VERSION,
+ "NSS", "");
+ /* all fine */
+ if (ret == EOK) return;
}
- /* Handle failure */
+ /* Failed to reconnect */
DEBUG(0, ("Could not reconnect to data provider.\n"));
/* Kill the backend and let the monitor restart it */
nss_shutdown(rctx);
}
-static struct sbus_method nss_dp_methods[] = {
- { NULL, NULL }
-};
-
-struct sbus_interface nss_dp_interface = {
- DP_CLI_INTERFACE,
- DP_CLI_PATH,
- SBUS_DEFAULT_VTABLE,
- nss_dp_methods,
- NULL
-};
-
int nss_process_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct confdb_ctx *cdb)
diff --git a/server/responder/pam/pamsrv.c b/server/responder/pam/pamsrv.c
index 6f92eb96..c751528f 100644
--- a/server/responder/pam/pamsrv.c
+++ b/server/responder/pam/pamsrv.c
@@ -40,7 +40,6 @@
#include "util/btreemap.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"
#include "responder/pam/pamsrv.h"
@@ -78,14 +77,43 @@ static int service_reload(DBusMessage *message, struct sbus_connection *conn) {
return monitor_common_pong(message, conn);
}
+static void pam_shutdown(struct resp_ctx *rctx)
+{
+ /* TODO: Do clean-up here */
+
+ /* Nothing left to do but exit() */
+ exit(0);
+}
+
+static struct sbus_method pam_dp_methods[] = {
+ { NULL, NULL }
+};
+
+struct sbus_interface pam_dp_interface = {
+ DP_CLI_INTERFACE,
+ DP_CLI_PATH,
+ SBUS_DEFAULT_VTABLE,
+ pam_dp_methods,
+ NULL
+};
+
+
static void pam_dp_reconnect_init(struct sbus_connection *conn, int status, void *pvt)
{
struct resp_ctx *rctx = talloc_get_type(pvt, struct resp_ctx);
+ int ret;
/* Did we reconnect successfully? */
if (status == SBUS_RECONNECT_SUCCESS) {
DEBUG(1, ("Reconnected to the Data Provider.\n"));
- return;
+
+ /* Identify ourselves to the data provider */
+ ret = dp_common_send_id(conn,
+ DP_CLI_FRONTEND,
+ DATA_PROVIDER_VERSION,
+ "PAM", "");
+ /* all fine */
+ if (ret == EOK) return;
}
/* Handle failure */
@@ -94,20 +122,32 @@ static void pam_dp_reconnect_init(struct sbus_connection *conn, int status, void
pam_shutdown(rctx);
}
-static void pam_shutdown(struct resp_ctx *rctx)
-{
- /* TODO: Do clean-up here */
-
- /* Nothing left to do but exit() */
- exit(0);
-}
-
-
-static int pam_process_init(struct main_context *main_ctx,
- struct resp_ctx *rctx)
+static int pam_process_init(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct confdb_ctx *cdb)
{
+ struct sss_cmd_table *pam_cmds;
+ struct resp_ctx *rctx;
int ret, max_retries;
+ pam_cmds = get_pam_cmds();
+ ret = sss_process_init(mem_ctx, ev, cdb,
+ pam_cmds,
+ SSS_PAM_SOCKET_NAME,
+ SSS_PAM_PRIV_SOCKET_NAME,
+ PAM_SRV_CONFIG,
+ PAM_SBUS_SERVICE_NAME,
+ PAM_SBUS_SERVICE_VERSION,
+ &monitor_pam_interface,
+ DP_CLI_FRONTEND,
+ DATA_PROVIDER_VERSION,
+ "PAM", "",
+ &pam_dp_interface,
+ &rctx);
+ if (ret != EOK) {
+ return ret;
+ }
+
/* Enable automatic reconnection to the Data Provider */
/* FIXME: "retries" is too generic, either get it from a global config
@@ -125,26 +165,12 @@ static int pam_process_init(struct main_context *main_ctx,
return EOK;
}
-static struct sbus_method pam_dp_methods[] = {
- { NULL, NULL }
-};
-
-struct sbus_interface pam_dp_interface = {
- DP_CLI_INTERFACE,
- DP_CLI_PATH,
- SBUS_DEFAULT_VTABLE,
- pam_dp_methods,
- NULL
-};
-
int main(int argc, const char *argv[])
{
int opt;
poptContext pc;
struct main_context *main_ctx;
int ret;
- struct sss_cmd_table *sss_cmds;
- struct resp_ctx *rctx;
struct poptOption long_options[] = {
POPT_AUTOHELP
@@ -175,27 +201,11 @@ int main(int argc, const char *argv[])
DEBUG(2, ("Could not set up to exit when parent process does\n"));
}
- sss_cmds = register_sss_cmds();
- ret = sss_process_init(main_ctx,
+ ret = pam_process_init(main_ctx,
main_ctx->event_ctx,
- main_ctx->confdb_ctx,
- sss_cmds,
- SSS_PAM_SOCKET_NAME,
- SSS_PAM_PRIV_SOCKET_NAME,
- PAM_SRV_CONFIG,
- PAM_SBUS_SERVICE_NAME,
- PAM_SBUS_SERVICE_VERSION,
- &monitor_pam_interface,
- DP_CLI_FRONTEND,
- DATA_PROVIDER_VERSION,
- "PAM", "",
- &pam_dp_interface,
- &rctx);
+ main_ctx->confdb_ctx);
if (ret != EOK) return 3;
- ret = pam_process_init(main_ctx, rctx);
- if (ret != EOK) return 4;
-
/* loop on main */
server_loop(main_ctx);
diff --git a/server/responder/pam/pamsrv.h b/server/responder/pam/pamsrv.h
index 67261157..00b36586 100644
--- a/server/responder/pam/pamsrv.h
+++ b/server/responder/pam/pamsrv.h
@@ -22,7 +22,7 @@ struct pam_auth_req {
void *data;
};
-struct sss_cmd_table *register_sss_cmds(void);
+struct sss_cmd_table *get_pam_cmds(void);
int pam_dp_send_req(struct pam_auth_req *preq, int timeout);
diff --git a/server/responder/pam/pamsrv_cmd.c b/server/responder/pam/pamsrv_cmd.c
index 39d71bb4..12625509 100644
--- a/server/responder/pam/pamsrv_cmd.c
+++ b/server/responder/pam/pamsrv_cmd.c
@@ -809,7 +809,7 @@ struct cli_protocol_version *register_cli_protocol_version(void)
return pam_cli_protocol_version;
}
-struct sss_cmd_table *register_sss_cmds(void)
+struct sss_cmd_table *get_pam_cmds(void)
{
static struct sss_cmd_table sss_cmds[] = {
{SSS_GET_VERSION, sss_cmd_get_version},
diff --git a/server/responder/pam/pamsrv_dp.c b/server/responder/pam/pamsrv_dp.c
index 3696d3d6..7ea2b7e4 100644
--- a/server/responder/pam/pamsrv_dp.c
+++ b/server/responder/pam/pamsrv_dp.c
@@ -29,7 +29,6 @@
#include "responder/common/responder_packet.h"
#include "providers/data_provider.h"
#include "sbus/sbus_client.h"
-#include "providers/dp_sbus.h"
#include "responder/pam/pamsrv.h"
static void pam_dp_process_reply(DBusPendingCall *pending, void *ptr)