summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2010-05-21 12:35:10 +0200
committerSumit Bose <sbose@redhat.com>2010-05-21 12:35:10 +0200
commitb21119655e68cc31a345aa06e2b3936b822a5a4c (patch)
tree418b92d214da207e899df62fe019409adef0fcef
parentce8dee004c25f4fe74da7da7d7c2817fc130ff4e (diff)
downloadsssd-1-2-proxy.tar.gz
sssd-1-2-proxy.tar.xz
sssd-1-2-proxy.zip
Swap SBus client server role between proxy and proxy_childsssd-1-2-proxy
-rw-r--r--src/providers/proxy/proxy.c187
-rw-r--r--src/providers/proxy/proxy_child.c164
2 files changed, 167 insertions, 184 deletions
diff --git a/src/providers/proxy/proxy.c b/src/providers/proxy/proxy.c
index adf5c77af..421fbf670 100644
--- a/src/providers/proxy/proxy.c
+++ b/src/providers/proxy/proxy.c
@@ -35,6 +35,13 @@
#include "db/sysdb.h"
#include "providers/proxy/proxy.h"
+struct proxy_client {
+ struct proxy_auth_ctx *proxy_auth_ctx;
+ struct sbus_connection *conn;
+ struct tevent_timer *timeout;
+ bool initialized;
+};
+
struct proxy_nss_ops {
enum nss_status (*getpwnam_r)(const char *name, struct passwd *result,
char *buffer, size_t buflen, int *errnop);
@@ -78,15 +85,20 @@ struct proxy_auth_ctx {
char *pam_target;
struct proxy_auth_req *request_list;
bool pam_worker_running;
- struct sbus_connection *conn;
+ struct sbus_connection *sbus_srv;
int timeout_ms;
pid_t proxy_child_pid;
char *proxy_child_command;
struct tevent_signal *proxy_child_sige;
+ struct proxy_client *proxy_cli;
};
+static int client_registration(DBusMessage *message,
+ struct sbus_connection *conn);
+
static struct sbus_method proxy_methods[] = {
- { NULL, NULL }
+ { DP_METHOD_REGISTER, client_registration },
+ { NULL, NULL }
};
struct sbus_interface proxy_interface = {
@@ -378,7 +390,7 @@ static errno_t send_req_to_pam_child(struct proxy_auth_ctx *proxy_auth_ctx)
goto done;
}
- ret = sbus_conn_send(proxy_auth_ctx->conn, msg,
+ ret = sbus_conn_send(proxy_auth_ctx->proxy_cli->conn, msg,
proxy_auth_ctx->timeout_ms, process_proxy_child_reply,
proxy_auth_ctx, NULL);
@@ -2692,24 +2704,131 @@ done:
return ret;
}
-static void proxy_reconnect_init(struct sbus_connection *conn, int status,
- void *pvt)
+static int client_registration(DBusMessage *message,
+ struct sbus_connection *conn)
{
- struct proxy_auth_ctx *proxy_auth_ctx = talloc_get_type(pvt,
- struct proxy_auth_ctx);
- int ret;
+ dbus_uint16_t version = DATA_PROVIDER_VERSION;
+ struct proxy_client *proxy_cli;
+ DBusMessage *reply;
+ DBusError dbus_error;
+ dbus_uint16_t cli_ver;
+ char *cli_name;
+ dbus_bool_t dbret;
+ void *data;
+
+ data = sbus_conn_get_private_data(conn);
+ proxy_cli = talloc_get_type(data, struct proxy_client);
+ if (!proxy_cli) {
+ DEBUG(0, ("Connection holds no valid init data\n"));
+ return EINVAL;
+ }
+
+ /* First thing, cancel the timeout */
+ DEBUG(4, ("Cancel proxy client ID timeout [%p]\n", proxy_cli->timeout));
+ talloc_zfree(proxy_cli->timeout);
+
+ dbus_error_init(&dbus_error);
+
+ dbret = dbus_message_get_args(message, &dbus_error,
+ DBUS_TYPE_UINT16, &cli_ver,
+ DBUS_TYPE_STRING, &cli_name,
+ DBUS_TYPE_INVALID);
+ if (!dbret) {
+ DEBUG(1, ("Failed to parse message, killing connection\n"));
+ if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
+ sbus_disconnect(conn);
+ /* FIXME: should we just talloc_zfree(conn) ? */
+ return EIO;
+ }
+
+ if (strcasecmp(cli_name, "PROXY") != 0) {
+ DEBUG(1, ("Unknown client! [%s]\n", cli_name));
+ }
- if (status == SBUS_RECONNECT_SUCCESS) {
- DEBUG(1, ("Reconnected to the Data Provider.\n"));
+ DEBUG(4, ("Added proxy client [%s]\n", cli_name));
- ret = dp_common_send_id(proxy_auth_ctx->conn, DATA_PROVIDER_VERSION,
- "PROXY");
- if (ret == EOK) return;
+ /* reply that all is ok */
+ reply = dbus_message_new_method_return(message);
+ if (!reply) {
+ DEBUG(0, ("Dbus Out of memory!\n"));
+ return ENOMEM;
}
- DEBUG(0, ("Could not reconnect to proxy child.\n"));
+ dbret = dbus_message_append_args(reply,
+ DBUS_TYPE_UINT16, &version,
+ DBUS_TYPE_INVALID);
+ if (!dbret) {
+ DEBUG(0, ("Failed to build dbus reply\n"));
+ dbus_message_unref(reply);
+ sbus_disconnect(conn);
+ return EIO;
+ }
+
+ /* send reply back */
+ sbus_conn_send_reply(conn, reply);
+ dbus_message_unref(reply);
+
+ proxy_cli->initialized = true;
+ return EOK;
+}
+
+static void init_timeout(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval t, void *ptr)
+{
+ struct proxy_client *proxy_cli;
+
+ DEBUG(2, ("Client timed out before Identification [%p]!\n", te));
+
+ proxy_cli = talloc_get_type(ptr, struct proxy_client);
+
+ sbus_disconnect(proxy_cli->conn);
+ talloc_zfree(proxy_cli);
}
+static int proxy_client_init(struct sbus_connection *conn, void *data)
+{
+ struct proxy_auth_ctx *proxy_auth_ctx;
+ struct proxy_client *proxy_cli;
+ struct timeval tv;
+
+ proxy_auth_ctx = talloc_get_type(data, struct proxy_auth_ctx);
+
+ /* hang off this memory to the connection so that when the connection
+ * is freed we can potentially call a destructor */
+
+ proxy_cli = talloc_zero(conn, struct proxy_client);
+ if (!proxy_cli) {
+ DEBUG(0,("Out of memory?!\n"));
+ talloc_zfree(conn);
+ return ENOMEM;
+ }
+ proxy_cli->proxy_auth_ctx = proxy_auth_ctx;
+ proxy_cli->conn = conn;
+ proxy_cli->initialized = false;
+
+ /* 5 seconds should be plenty */
+ tv = tevent_timeval_current_ofs(5, 0);
+
+ proxy_cli->timeout = tevent_add_timer(proxy_auth_ctx->be->ev, proxy_cli,
+ tv, init_timeout, proxy_cli);
+ if (!proxy_cli->timeout) {
+ DEBUG(0,("Out of memory?!\n"));
+ talloc_zfree(conn);
+ return ENOMEM;
+ }
+ DEBUG(4, ("Set-up proxy client ID timeout [%p]\n", proxy_cli->timeout));
+
+ /* Attach the client context to the connection context, so that it is
+ * always available when we need to manage the connection. */
+ sbus_conn_set_private_data(conn, proxy_cli);
+
+ proxy_auth_ctx->proxy_cli = proxy_cli;
+
+ return EOK;
+}
+
+
int sssm_proxy_auth_init(struct be_ctx *bectx,
struct bet_ops **ops, void **pvt_data)
{
@@ -2742,46 +2861,36 @@ int sssm_proxy_auth_init(struct be_ctx *bectx,
goto done;
}
- ctx->proxy_child_command = talloc_asprintf(ctx,
- "%s/proxy_child -d %d%s%s --domain %s",
- SSSD_LIBEXEC_PATH, debug_level,
- (debug_timestamps ? "" : " --debug-timestamps=0"),
- (debug_to_file ? " --debug-to-files" : ""),
- bectx->domain->name);
- if (ctx->proxy_child_command == NULL) {
+ sbus_address = talloc_asprintf(ctx, "unix:path=%s/%s_%s", PIPE_PATH,
+ PROXY_CHILD_PIPE, bectx->domain->name);
+ if (sbus_address == NULL) {
DEBUG(1, ("talloc_asprintf failed.\n"));
ret = ENOMEM;
goto done;
}
- ret = start_proxy_child(ctx);
+ ret = sbus_new_server(ctx, bectx->ev, sbus_address, &proxy_interface,
+ &ctx->sbus_srv, proxy_client_init, ctx);
if (ret != EOK) {
- DEBUG(1, ("start_proxy_child failed.\n"));
+ DEBUG(0, ("Could not set up sbus server.\n"));
goto done;
}
- sbus_address = talloc_asprintf(ctx, "unix:path=%s/%s_%s", PIPE_PATH,
- PROXY_CHILD_PIPE, bectx->domain->name);
- if (sbus_address == NULL) {
+ ctx->proxy_child_command = talloc_asprintf(ctx,
+ "%s/proxy_child -d %d%s%s --domain %s",
+ SSSD_LIBEXEC_PATH, debug_level,
+ (debug_timestamps ? "" : " --debug-timestamps=0"),
+ (debug_to_file ? " --debug-to-files" : ""),
+ bectx->domain->name);
+ if (ctx->proxy_child_command == NULL) {
DEBUG(1, ("talloc_asprintf failed.\n"));
ret = ENOMEM;
goto done;
}
- ret = sbus_client_init(ctx, bectx->ev, sbus_address,
- &proxy_interface, &ctx->conn,
- NULL, NULL);
- if (ret != EOK) {
- DEBUG(1, ("sbus_client_init failed.\n"));
- goto done;
- }
-
- sbus_reconnect_init(ctx->conn, 3, proxy_reconnect_init, ctx);
-
-
- ret = dp_common_send_id(ctx->conn, DATA_PROVIDER_VERSION, "PROXY");
+ ret = start_proxy_child(ctx);
if (ret != EOK) {
- DEBUG(0, ("dp_common_send_id failed.\n"));
+ DEBUG(1, ("start_proxy_child failed.\n"));
goto done;
}
diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c
index ba0894013..8f40db172 100644
--- a/src/providers/proxy/proxy_child.c
+++ b/src/providers/proxy/proxy_child.c
@@ -65,12 +65,9 @@ struct sbus_interface monitor_be_interface = {
NULL
};
-static int client_registration(DBusMessage *message,
- struct sbus_connection *conn);
static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn);
struct sbus_method pc_methods[] = {
- { DP_METHOD_REGISTER, client_registration },
{ DP_METHOD_PAMHANDLER, pc_pam_handler },
{ NULL, NULL }
};
@@ -91,15 +88,8 @@ struct pc_ctx {
const char *identity;
const char *conf_path;
struct sbus_connection *mon_conn;
- struct sbus_connection *sbus_srv;
- const char *pam_target;
-};
-
-struct pc_client {
- struct pc_ctx *pc_ctx;
struct sbus_connection *conn;
- struct tevent_timer *timeout;
- bool initialized;
+ const char *pam_target;
};
struct authtok_conv {
@@ -248,15 +238,15 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
{
DBusError dbus_error;
DBusMessage *reply;
- struct pc_client *pc_cli;
+ struct pc_ctx *pc_ctx;
dbus_bool_t ret;
void *user_data;
struct pam_data *pd = NULL;
user_data = sbus_conn_get_private_data(conn);
if (!user_data) return EINVAL;
- pc_cli = talloc_get_type(user_data, struct pc_client);
- if (!pc_cli) return EINVAL;
+ pc_ctx = talloc_get_type(user_data, struct pc_ctx);
+ if (!pc_ctx) return EINVAL;
reply = dbus_message_new_method_return(message);
if (!reply) {
@@ -267,14 +257,14 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
dbus_error_init(&dbus_error);
- ret = dp_unpack_pam_request(message, pc_cli, &pd, &dbus_error);
+ ret = dp_unpack_pam_request(message, pc_ctx, &pd, &dbus_error);
if (!ret) {
DEBUG(1,("Failed, to parse message!\n"));
return EIO;
}
pd->pam_status = PAM_SYSTEM_ERR;
- pd->domain = talloc_strdup(pd, pc_cli->pc_ctx->domain->name);
+ pd->domain = talloc_strdup(pd, pc_ctx->domain->name);
if (pd->domain == NULL) {
talloc_free(pd);
return ENOMEM;
@@ -283,7 +273,7 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
DEBUG(4, ("Got request with the following data\n"));
DEBUG_PAM_DATA(4, pd);
- ret = call_pam_stack(pc_cli->pc_ctx->pam_target, pd);
+ ret = call_pam_stack(pc_ctx->pam_target, pd);
if (ret != EOK) {
DEBUG(1, ("call_pam_stack failed.\n"));
}
@@ -306,129 +296,7 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
return EOK;
}
-static int client_registration(DBusMessage *message,
- struct sbus_connection *conn)
-{
- dbus_uint16_t version = DATA_PROVIDER_VERSION;
- struct pc_client *pc_cli;
- DBusMessage *reply;
- DBusError dbus_error;
- dbus_uint16_t cli_ver;
- char *cli_name;
- dbus_bool_t dbret;
- void *data;
-
- data = sbus_conn_get_private_data(conn);
- pc_cli = talloc_get_type(data, struct pc_client);
- if (!pc_cli) {
- DEBUG(0, ("Connection holds no valid init data\n"));
- return EINVAL;
- }
-
- /* First thing, cancel the timeout */
- DEBUG(4, ("Cancel DP ID timeout [%p]\n", pc_cli->timeout));
- talloc_zfree(pc_cli->timeout);
-
- dbus_error_init(&dbus_error);
-
- dbret = dbus_message_get_args(message, &dbus_error,
- DBUS_TYPE_UINT16, &cli_ver,
- DBUS_TYPE_STRING, &cli_name,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(1, ("Failed to parse message, killing connection\n"));
- if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
- sbus_disconnect(conn);
- /* FIXME: should we just talloc_zfree(conn) ? */
- return EIO;
- }
-
- if (strcasecmp(cli_name, "PROXY") != 0) {
- DEBUG(1, ("Unknown client! [%s]\n", cli_name));
- }
-
- DEBUG(4, ("Added Frontend client [%s]\n", cli_name));
-
- /* reply that all is ok */
- reply = dbus_message_new_method_return(message);
- if (!reply) {
- DEBUG(0, ("Dbus Out of memory!\n"));
- return ENOMEM;
- }
-
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &version,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(0, ("Failed to build dbus reply\n"));
- dbus_message_unref(reply);
- sbus_disconnect(conn);
- return EIO;
- }
-
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
-
- pc_cli->initialized = true;
- return EOK;
-}
-
-static void init_timeout(struct tevent_context *ev,
- struct tevent_timer *te,
- struct timeval t, void *ptr)
-{
- struct pc_client *pc_cli;
-
- DEBUG(2, ("Client timed out before Identification [%p]!\n", te));
-
- pc_cli = talloc_get_type(ptr, struct pc_client);
-
- sbus_disconnect(pc_cli->conn);
- talloc_zfree(pc_cli);
-}
-
-static int proxy_child_client_init(struct sbus_connection *conn, void *data)
-{
- struct pc_ctx *pc_ctx;
- struct pc_client *pc_cli;
- struct timeval tv;
-
- pc_ctx = talloc_get_type(data, struct pc_ctx);
-
- /* hang off this memory to the connection so that when the connection
- * is freed we can potentially call a destructor */
-
- pc_cli = talloc_zero(conn, struct pc_client);
- if (!pc_cli) {
- DEBUG(0,("Out of memory?!\n"));
- talloc_zfree(conn);
- return ENOMEM;
- }
- pc_cli->pc_ctx = pc_ctx;
- pc_cli->conn = conn;
- pc_cli->initialized = false;
-
- /* 5 seconds should be plenty */
- tv = tevent_timeval_current_ofs(5, 0);
-
- pc_cli->timeout = tevent_add_timer(pc_ctx->ev, pc_cli,
- tv, init_timeout, pc_cli);
- if (!pc_cli->timeout) {
- DEBUG(0,("Out of memory?!\n"));
- talloc_zfree(conn);
- return ENOMEM;
- }
- DEBUG(4, ("Set-up Backend ID timeout [%p]\n", pc_cli->timeout));
-
- /* Attach the client context to the connection context, so that it is
- * always available when we need to manage the connection. */
- sbus_conn_set_private_data(conn, pc_cli);
-
- return EOK;
-}
-
-static int proxy_child_srv_init(struct pc_ctx *ctx)
+static int proxy_cli_init(struct pc_ctx *ctx)
{
char *sbus_address;
int ret;
@@ -441,11 +309,17 @@ static int proxy_child_srv_init(struct pc_ctx *ctx)
return ENOMEM;
}
- ret = sbus_new_server(ctx, ctx->ev, sbus_address,
- &pc_interface, &ctx->sbus_srv,
- proxy_child_client_init, ctx);
+ ret = sbus_client_init(ctx, ctx->ev, sbus_address,
+ &pc_interface, &ctx->conn,
+ NULL, ctx);
+ if (ret != EOK) {
+ DEBUG(1, ("sbus_client_init failed.\n"));
+ return ret;
+ }
+
+ ret = dp_common_send_id(ctx->conn, DATA_PROVIDER_VERSION, "PROXY");
if (ret != EOK) {
- DEBUG(0, ("Could not set up sbus server.\n"));
+ DEBUG(0, ("dp_common_send_id failed.\n"));
return ret;
}
@@ -526,7 +400,7 @@ int proxy_child_process_init(TALLOC_CTX *mem_ctx, const char *domain,
return ret;
}
- ret = proxy_child_srv_init(ctx);
+ ret = proxy_cli_init(ctx);
if (ret != EOK) {
DEBUG(0, ("fatal error setting up server bus\n"));
return ret;