summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2009-08-05 14:11:12 -0400
committerStephen Gallagher <sgallagh@redhat.com>2009-08-10 09:42:20 -0400
commit11c621b5ee1a0cdc27610f8b172017764acc285e (patch)
tree181c9079440367711c66d7281fc0aecb458fee77 /server
parentf1e4471551aa74015579bff0b64735cc9b085b74 (diff)
downloadsssd-11c621b5ee1a0cdc27610f8b172017764acc285e.tar.gz
sssd-11c621b5ee1a0cdc27610f8b172017764acc285e.tar.bz2
sssd-11c621b5ee1a0cdc27610f8b172017764acc285e.zip
Simplify interfaces initialization
Make as much as possible static, and remove use of talloc_reference and allocation/deallocation of memory when not necessary. Fix also responder use of rctx->conn, was mistakenly used for both monitor and dp connections.
Diffstat (limited to 'server')
-rw-r--r--server/monitor/monitor.c64
-rw-r--r--server/monitor/monitor_interfaces.h23
-rw-r--r--server/monitor/monitor_sbus.c35
-rw-r--r--server/monitor/monitor_sbus.h2
-rw-r--r--server/providers/data_provider.c76
-rw-r--r--server/providers/data_provider_be.c59
-rw-r--r--server/providers/dp_backend.h3
-rw-r--r--server/providers/dp_sbus.c41
-rw-r--r--server/providers/dp_sbus.h2
-rw-r--r--server/responder/common/responder.h12
-rw-r--r--server/responder/common/responder_common.c30
-rw-r--r--server/responder/common/responder_dp.c24
-rw-r--r--server/responder/nss/nsssrv.c39
-rw-r--r--server/responder/nss/nsssrv.h2
-rw-r--r--server/responder/nss/nsssrv_dp.c12
-rw-r--r--server/responder/pam/pamsrv.c39
-rw-r--r--server/responder/pam/pamsrv.h2
-rw-r--r--server/responder/pam/pamsrv_dp.c26
-rw-r--r--server/sbus/sbus_client.c9
-rw-r--r--server/sbus/sbus_client.h2
-rw-r--r--server/sbus/sssd_dbus.h28
-rw-r--r--server/sbus/sssd_dbus_connection.c137
-rw-r--r--server/sbus/sssd_dbus_private.h6
-rw-r--r--server/sbus/sssd_dbus_server.c11
24 files changed, 267 insertions, 417 deletions
diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c
index 7a27c4ec..81012071 100644
--- a/server/monitor/monitor.c
+++ b/server/monitor/monitor.c
@@ -171,45 +171,33 @@ static int dbus_get_monitor_version(DBusMessage *message,
}
struct sbus_method monitor_methods[] = {
- { MONITOR_METHOD_VERSION, dbus_get_monitor_version},
- {NULL, NULL}
+ { MON_SRV_METHOD_VERSION, dbus_get_monitor_version },
+ { NULL, NULL }
+};
+
+struct sbus_interface monitor_server_interface = {
+ MONITOR_DBUS_INTERFACE,
+ MONITOR_DBUS_PATH,
+ SBUS_DEFAULT_VTABLE,
+ monitor_methods,
+ NULL
};
/* monitor_dbus_init
* Set up the monitor service as a D-BUS Server */
static int monitor_dbus_init(struct mt_ctx *ctx)
{
- struct sbus_method_ctx *sd_ctx;
char *monitor_address;
int ret;
- sd_ctx = talloc_zero(ctx, struct sbus_method_ctx);
- if (!sd_ctx) {
- return ENOMEM;
- }
-
- monitor_address = talloc_asprintf(sd_ctx, "unix:path=%s/%s",
+ monitor_address = talloc_asprintf(ctx, "unix:path=%s/%s",
PIPE_PATH, SSSD_SERVICE_PIPE);
if (!monitor_address) {
- talloc_free(sd_ctx);
- return ENOMEM;
- }
-
- /* Set up globally-available D-BUS methods */
- sd_ctx->interface = talloc_strdup(sd_ctx, MONITOR_DBUS_INTERFACE);
- if (!sd_ctx->interface) {
- talloc_free(sd_ctx);
- return ENOMEM;
- }
- sd_ctx->path = talloc_strdup(sd_ctx, MONITOR_DBUS_PATH);
- if (!sd_ctx->path) {
- talloc_free(sd_ctx);
return ENOMEM;
}
- sd_ctx->methods = monitor_methods;
- sd_ctx->message_handler = sbus_message_handler;
- ret = sbus_new_server(ctx, ctx->ev, monitor_address, sd_ctx,
+ ret = sbus_new_server(ctx, ctx->ev,
+ monitor_address, &monitor_server_interface,
&ctx->sbus_srv, dbus_service_init, ctx);
talloc_free(monitor_address);
@@ -464,9 +452,9 @@ static int monitor_shutdown_service(struct mt_svc *svc)
/* Construct a shutdown message */
msg = dbus_message_new_method_call(NULL,
- SERVICE_PATH,
- SERVICE_INTERFACE,
- SERVICE_METHOD_SHUTDOWN);
+ MONITOR_PATH,
+ MONITOR_INTERFACE,
+ MON_CLI_METHOD_SHUTDOWN);
if (!msg) {
DEBUG(0,("Out of memory?!\n"));
monitor_kill_service(svc);
@@ -581,8 +569,8 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal)
dbus_conn = sbus_get_connection(svc->mt_conn->conn);
msg = dbus_message_new_method_call(NULL,
- SERVICE_PATH,
- SERVICE_INTERFACE,
+ MONITOR_PATH,
+ MONITOR_INTERFACE,
svc_signal);
if (!msg) {
DEBUG(0,("Out of memory?!\n"));
@@ -610,11 +598,11 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal)
static int service_signal_reload(struct mt_svc *svc)
{
- return service_signal(svc, SERVICE_METHOD_RELOAD);
+ return service_signal(svc, MON_CLI_METHOD_RELOAD);
}
static int service_signal_dns_reload(struct mt_svc *svc)
{
- return service_signal(svc, SERVICE_METHOD_RES_INIT);
+ return service_signal(svc, MON_CLI_METHOD_RES_INIT);
}
static int check_domain_ranges(struct sss_domain_info *domains)
@@ -1823,9 +1811,9 @@ static int dbus_service_init(struct sbus_connection *conn, void *data)
* for all services
*/
msg = dbus_message_new_method_call(NULL,
- SERVICE_PATH,
- SERVICE_INTERFACE,
- SERVICE_METHOD_IDENTITY);
+ MONITOR_PATH,
+ MONITOR_INTERFACE,
+ MON_CLI_METHOD_IDENTITY);
if (msg == NULL) {
DEBUG(0,("Out of memory?!\n"));
talloc_free(conn);
@@ -1970,9 +1958,9 @@ static int service_send_ping(struct mt_svc *svc)
* for all services
*/
msg = dbus_message_new_method_call(NULL,
- SERVICE_PATH,
- SERVICE_INTERFACE,
- SERVICE_METHOD_PING);
+ MONITOR_PATH,
+ MONITOR_INTERFACE,
+ MON_CLI_METHOD_PING);
if (!msg) {
DEBUG(0,("Out of memory?!\n"));
talloc_free(svc->mt_conn->conn);
diff --git a/server/monitor/monitor_interfaces.h b/server/monitor/monitor_interfaces.h
index 05d1bb41..5c58066d 100644
--- a/server/monitor/monitor_interfaces.h
+++ b/server/monitor/monitor_interfaces.h
@@ -25,20 +25,19 @@
#define MONITOR_DBUS_INTERFACE "org.freedesktop.sssd.monitor"
#define MONITOR_DBUS_PATH "/org/freedesktop/sssd/monitor"
-/* Monitor Methods */
-#define MONITOR_METHOD_VERSION "getVersion"
+/* Monitor SRV Methods */
+#define MON_SRV_METHOD_VERSION "getVersion"
+/*** Monitor Interface ***/
-/*** Services ***/
+#define MONITOR_PATH "/org/freedesktop/sssd/service"
+#define MONITOR_INTERFACE "org.freedesktop.sssd.service"
-#define SERVICE_PATH "/org/freedesktop/sssd/service"
-#define SERVICE_INTERFACE "org.freedesktop.sssd.service"
-
-/* Service Methods */
-#define SERVICE_METHOD_IDENTITY "getIdentity"
-#define SERVICE_METHOD_PING "ping"
-#define SERVICE_METHOD_RELOAD "reloadConfig"
-#define SERVICE_METHOD_SHUTDOWN "shutDown"
-#define SERVICE_METHOD_RES_INIT "resInit"
+/* Monitor CLI Methods */
+#define MON_CLI_METHOD_IDENTITY "getIdentity"
+#define MON_CLI_METHOD_PING "ping"
+#define MON_CLI_METHOD_RELOAD "reloadConfig"
+#define MON_CLI_METHOD_SHUTDOWN "shutDown"
+#define MON_CLI_METHOD_RES_INIT "resInit"
#define SSSD_SERVICE_PIPE "private/sbus-monitor"
diff --git a/server/monitor/monitor_sbus.c b/server/monitor/monitor_sbus.c
index 5d49f003..817b42ae 100644
--- a/server/monitor/monitor_sbus.c
+++ b/server/monitor/monitor_sbus.c
@@ -54,38 +54,3 @@ done:
return ret;
}
-int monitor_init_sbus_methods(TALLOC_CTX *mem_ctx,
- struct sbus_method *methods,
- struct sbus_method_ctx **sm_ctx)
-{
- struct sbus_method_ctx *method_ctx;
- int ret;
-
- method_ctx = talloc_zero(mem_ctx, struct sbus_method_ctx);
- if (!method_ctx) {
- ret = ENOMEM;
- goto fail;
- }
-
- method_ctx->interface = talloc_strdup(method_ctx, SERVICE_INTERFACE);
- if (method_ctx->interface == NULL) {
- ret = ENOMEM;
- goto fail;
- }
-
- method_ctx->path = talloc_strdup(method_ctx, SERVICE_PATH);
- if (method_ctx->path == NULL) {
- ret = ENOMEM;
- goto fail;
- }
-
- method_ctx->methods = methods;
- method_ctx->message_handler = sbus_message_handler;
-
- *sm_ctx = method_ctx;
- return EOK;
-
-fail:
- talloc_free(method_ctx);
- return ret;
-}
diff --git a/server/monitor/monitor_sbus.h b/server/monitor/monitor_sbus.h
index 5e110ab8..bc36e88e 100644
--- a/server/monitor/monitor_sbus.h
+++ b/server/monitor/monitor_sbus.h
@@ -24,7 +24,5 @@
int monitor_get_sbus_address(TALLOC_CTX *mem_ctx, struct confdb_ctx *confdb,
char **address);
-int monitor_init_sbus_methods(TALLOC_CTX *mem_ctx, struct sbus_method *methods,
- struct sbus_method_ctx **sm_ctx);
#endif /* MONITOR_SBUS_H_ */
diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c
index c844f644..b9529254 100644
--- a/server/providers/data_provider.c
+++ b/server/providers/data_provider.c
@@ -89,23 +89,39 @@ static int service_pong(DBusMessage *message, struct sbus_connection *conn);
static int service_reload(DBusMessage *message, struct sbus_connection *conn);
static int service_res_init(DBusMessage *message, struct sbus_connection *conn);
-struct sbus_method mon_sbus_methods[] = {
- { SERVICE_METHOD_IDENTITY, service_identity },
- { SERVICE_METHOD_PING, service_pong },
- { SERVICE_METHOD_RELOAD, service_reload },
- { SERVICE_METHOD_RES_INIT, service_res_init },
+struct sbus_method monitor_dp_methods[] = {
+ { MON_CLI_METHOD_IDENTITY, service_identity },
+ { MON_CLI_METHOD_PING, service_pong },
+ { MON_CLI_METHOD_RELOAD, service_reload },
+ { MON_CLI_METHOD_RES_INIT, service_res_init },
{ NULL, NULL }
};
+struct sbus_interface monitor_dp_interface = {
+ MONITOR_INTERFACE,
+ MONITOR_PATH,
+ SBUS_DEFAULT_VTABLE,
+ monitor_dp_methods,
+ NULL
+};
+
static int dp_get_account_info(DBusMessage *message, struct sbus_connection *conn);
static int dp_pamhandler(DBusMessage *message, struct sbus_connection *conn);
-struct sbus_method dp_sbus_methods[] = {
+struct sbus_method dp_methods[] = {
{ DP_SRV_METHOD_GETACCTINFO, dp_get_account_info },
{ DP_SRV_METHOD_PAMHANDLER, dp_pamhandler },
{ NULL, NULL }
};
+struct sbus_interface dp_interface = {
+ DATA_PROVIDER_INTERFACE,
+ DATA_PROVIDER_PATH,
+ SBUS_DEFAULT_VTABLE,
+ dp_methods,
+ NULL
+};
+
struct dp_request {
/* reply message to send when request is done */
DBusMessage *reply;
@@ -195,7 +211,6 @@ static int service_res_init(DBusMessage *message, struct sbus_connection *conn)
static int dp_monitor_init(struct dp_ctx *dpctx)
{
struct sbus_connection *conn;
- struct sbus_method_ctx *sm_ctx;
char *sbus_address;
int ret;
@@ -206,14 +221,8 @@ static int dp_monitor_init(struct dp_ctx *dpctx)
return ret;
}
- ret = monitor_init_sbus_methods(dpctx, mon_sbus_methods, &sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return ret;
- }
-
ret = sbus_client_init(dpctx, dpctx->ev, sbus_address,
- sm_ctx, &conn,
+ &monitor_dp_interface, &conn,
NULL, NULL);
if (ret != EOK) {
DEBUG(0, ("Failed to connect to monitor services.\n"));
@@ -990,59 +999,32 @@ static int dp_frontend_destructor(void *ctx)
* Set up the monitor service as a D-BUS Server */
static int dp_srv_init(struct dp_ctx *dpctx)
{
- TALLOC_CTX *tmp_ctx;
- struct sbus_method_ctx *sd_ctx;
char *dpbus_address;
char *default_dp_address;
int ret;
- tmp_ctx = talloc_new(dpctx);
- if (tmp_ctx == NULL) {
- return ENOMEM;
- }
-
DEBUG(3, ("Initializing Data Provider D-BUS Server\n"));
- default_dp_address = talloc_asprintf(tmp_ctx, "unix:path=%s/%s",
+ default_dp_address = talloc_asprintf(dpctx, "unix:path=%s/%s",
PIPE_PATH, DATA_PROVIDER_PIPE);
if (default_dp_address == NULL) {
ret = ENOMEM;
goto done;
}
- ret = confdb_get_string(dpctx->cdb, tmp_ctx,
+ ret = confdb_get_string(dpctx->cdb, dpctx,
DP_CONF_ENTRY, "dpbusAddress",
default_dp_address, &dpbus_address);
if (ret != EOK) goto done;
- sd_ctx = talloc_zero(tmp_ctx, struct sbus_method_ctx);
- if (!sd_ctx) {
- ret = ENOMEM;
- goto done;
- }
-
- /* Set up globally-available D-BUS methods */
- sd_ctx->interface = talloc_strdup(sd_ctx, DATA_PROVIDER_INTERFACE);
- if (!sd_ctx->interface) {
- ret = ENOMEM;
- goto done;
- }
- sd_ctx->path = talloc_strdup(sd_ctx, DATA_PROVIDER_PATH);
- if (!sd_ctx->path) {
- ret = ENOMEM;
- goto done;
- }
- sd_ctx->methods = dp_sbus_methods;
- sd_ctx->message_handler = sbus_message_handler;
-
- ret = sbus_new_server(dpctx, dpctx->ev, dpbus_address, sd_ctx,
- &dpctx->sbus_srv, dbus_dp_init, dpctx);
+ ret = sbus_new_server(dpctx, dpctx->ev, dpbus_address,
+ &dp_interface, &dpctx->sbus_srv,
+ dbus_dp_init, dpctx);
if (ret != EOK) {
goto done;
}
- talloc_steal(dpctx, sd_ctx);
done:
- talloc_free(tmp_ctx);
+ talloc_free(default_dp_address);
return ret;
}
diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c
index ecd20ad9..872c9d76 100644
--- a/server/providers/data_provider_be.c
+++ b/server/providers/data_provider_be.c
@@ -58,13 +58,21 @@ static int service_identity(DBusMessage *message, struct sbus_connection *conn);
static int service_pong(DBusMessage *message, struct sbus_connection *conn);
static int service_res_init(DBusMessage *message, struct sbus_connection *conn);
-struct sbus_method mon_sbus_methods[] = {
- { SERVICE_METHOD_IDENTITY, service_identity },
- { SERVICE_METHOD_PING, service_pong },
- { SERVICE_METHOD_RES_INIT, service_res_init },
+struct sbus_method monitor_be_methods[] = {
+ { MON_CLI_METHOD_IDENTITY, service_identity },
+ { MON_CLI_METHOD_PING, service_pong },
+ { MON_CLI_METHOD_RES_INIT, service_res_init },
{ NULL, NULL }
};
+struct sbus_interface monitor_be_interface = {
+ MONITOR_INTERFACE,
+ MONITOR_PATH,
+ SBUS_DEFAULT_VTABLE,
+ monitor_be_methods,
+ NULL
+};
+
static int be_identity(DBusMessage *message, struct sbus_connection *conn);
static int be_check_online(DBusMessage *message, struct sbus_connection *conn);
static int be_get_account_info(DBusMessage *message, struct sbus_connection *conn);
@@ -78,6 +86,14 @@ struct sbus_method be_methods[] = {
{ NULL, NULL }
};
+struct sbus_interface be_interface = {
+ DATA_PROVIDER_INTERFACE,
+ DATA_PROVIDER_PATH,
+ SBUS_DEFAULT_VTABLE,
+ be_methods,
+ NULL
+};
+
static struct bet_data bet_data[] = {
{BET_NULL, NULL, NULL},
{BET_ID, "provider", "sssm_%s_init"},
@@ -681,20 +697,8 @@ static int mon_cli_init(struct be_ctx *ctx)
return ret;
}
- ret = monitor_init_sbus_methods(ctx, mon_sbus_methods, &ctx->mon_sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return ret;
- }
-
- /* FIXME: remove this */
- if (talloc_reference(ctx, ctx->mon_sm_ctx) == NULL) {
- DEBUG(0, ("Failed to take memory reference\n"));
- return ENOMEM;
- }
-
ret = sbus_client_init(ctx, ctx->ev, sbus_address,
- ctx->mon_sm_ctx, &ctx->mon_conn,
+ &monitor_be_interface, &ctx->mon_conn,
NULL, ctx);
if (ret != EOK) {
DEBUG(0, ("Failed to connect to monitor services.\n"));
@@ -720,14 +724,8 @@ static int be_cli_init(struct be_ctx *ctx)
return ret;
}
- ret = dp_init_sbus_methods(ctx, be_methods, &ctx->dp_sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return ret;
- }
-
ret = sbus_client_init(ctx, ctx->ev, sbus_address,
- ctx->dp_sm_ctx, &ctx->dp_conn,
+ &be_interface, &ctx->dp_conn,
NULL, ctx);
if (ret != EOK) {
DEBUG(0, ("Failed to connect to monitor services.\n"));
@@ -758,19 +756,6 @@ static void be_cli_reconnect_init(struct sbus_connection *conn, int status, void
/* Did we reconnect successfully? */
if (status == SBUS_RECONNECT_SUCCESS) {
- /* Add the methods back to the new connection */
- ret = sbus_conn_add_method_ctx(be_ctx->dp_conn,
- be_ctx->dp_sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not re-add methods on reconnection.\n"));
- ret = be_finalize(be_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Finalizing back-end failed with error [%d] [%s]", ret, strerror(ret)));
- be_shutdown(NULL, ret, NULL);
- }
- return;
- }
-
DEBUG(1, ("Reconnected to the Data Provider.\n"));
return;
}
diff --git a/server/providers/dp_backend.h b/server/providers/dp_backend.h
index f05a5420..987e5365 100644
--- a/server/providers/dp_backend.h
+++ b/server/providers/dp_backend.h
@@ -70,10 +70,7 @@ struct be_ctx {
const char *identity;
const char *conf_path;
- struct sbus_method_ctx *mon_sm_ctx;
struct sbus_connection *mon_conn;
-
- struct sbus_method_ctx *dp_sm_ctx;
struct sbus_connection *dp_conn;
struct loaded_be loaded_be[BET_MAX];
diff --git a/server/providers/dp_sbus.c b/server/providers/dp_sbus.c
index 22be6c84..f34822d5 100644
--- a/server/providers/dp_sbus.c
+++ b/server/providers/dp_sbus.c
@@ -57,44 +57,3 @@ done:
return ret;
}
-int dp_init_sbus_methods(TALLOC_CTX *mem_ctx, struct sbus_method *methods,
- struct sbus_method_ctx **sm_ctx)
-{
- int ret;
- TALLOC_CTX *tmp_ctx;
- struct sbus_method_ctx *method_ctx;
-
- tmp_ctx = talloc_new(mem_ctx);
- if (tmp_ctx == NULL) {
- return ENOMEM;
- }
-
- method_ctx = talloc_zero(tmp_ctx, struct sbus_method_ctx);
- if (method_ctx == NULL) {
- ret = ENOMEM;
- goto done;
- }
-
- method_ctx->interface = talloc_strdup(method_ctx, DATA_PROVIDER_INTERFACE);
- if (method_ctx->interface == NULL) {
- ret = ENOMEM;
- goto done;
- }
-
- method_ctx->path = talloc_strdup(method_ctx, DATA_PROVIDER_PATH);
- if (method_ctx->path == NULL) {
- ret = ENOMEM;
- goto done;
- }
-
- method_ctx->methods = methods;
- method_ctx->message_handler = sbus_message_handler;
-
- *sm_ctx = method_ctx;
- talloc_steal(mem_ctx, method_ctx);
- ret = EOK;
-
-done:
- talloc_free(tmp_ctx);
- return ret;
-}
diff --git a/server/providers/dp_sbus.h b/server/providers/dp_sbus.h
index f21001f9..f3f54223 100644
--- a/server/providers/dp_sbus.h
+++ b/server/providers/dp_sbus.h
@@ -24,7 +24,5 @@
int dp_get_sbus_address(TALLOC_CTX *mem_ctx, struct confdb_ctx *confdb,
char **address);
-int dp_init_sbus_methods(TALLOC_CTX *mem_ctx, struct sbus_method *methods,
- struct sbus_method_ctx **sm_ctx);
#endif /* DP_SBUS_H_ */
diff --git a/server/responder/common/responder.h b/server/responder/common/responder.h
index 5bde42ac..0f090831 100644
--- a/server/responder/common/responder.h
+++ b/server/responder/common/responder.h
@@ -64,16 +64,14 @@ struct resp_ctx {
const char *sock_name;
const char *priv_sock_name;
- struct sbus_connection *conn;
- struct sbus_method_ctx *sm_ctx;
+ struct sbus_connection *mon_conn;
+ struct sbus_connection *dp_conn;
struct sss_domain_info *domains;
- struct sbus_method *sss_sbus_methods;
struct sss_cmd_table *sss_cmds;
const char *sss_pipe_name;
const char *confdb_service_path;
- struct sbus_method *dp_methods;
struct sss_names_ctx *names;
@@ -100,12 +98,12 @@ struct sss_cmd_table {
int sss_process_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct confdb_ctx *cdb,
- struct sbus_method sss_sbus_methods[],
struct sss_cmd_table sss_cmds[],
const char *sss_pipe_name,
const char *sss_priv_pipe_name,
const char *confdb_service_path,
- struct sbus_method dp_methods[],
+ struct sbus_interface *dp_intf,
+ struct sbus_interface *monitor_intf,
struct resp_ctx **responder_ctx);
int sss_parse_name(TALLOC_CTX *memctx,
@@ -119,7 +117,7 @@ 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_method dp_methods[]);
+int sss_dp_init(struct resp_ctx *rctx, struct sbus_interface *intf);
#define NSS_DP_USER 1
#define NSS_DP_GROUP 2
diff --git a/server/responder/common/responder_common.c b/server/responder/common/responder_common.c
index c8e5d818..f3df7c65 100644
--- a/server/responder/common/responder_common.c
+++ b/server/responder/common/responder_common.c
@@ -285,7 +285,8 @@ static void accept_fd_handler(struct tevent_context *ev,
return;
}
-static int sss_sbus_init(struct resp_ctx *rctx)
+static int sss_monitor_init(struct resp_ctx *rctx,
+ struct sbus_interface *intf)
{
char *sbus_address;
int ret;
@@ -297,21 +298,8 @@ static int sss_sbus_init(struct resp_ctx *rctx)
return ret;
}
- ret = monitor_init_sbus_methods(rctx, rctx->sss_sbus_methods,
- &rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return ret;
- }
-
- /* FIXME: remove this */
- if (talloc_reference(rctx, rctx->sm_ctx) == NULL) {
- DEBUG(0, ("Failed to take memory reference\n"));
- return ENOMEM;
- }
-
ret = sbus_client_init(rctx, rctx->ev, sbus_address,
- rctx->sm_ctx, &rctx->conn,
+ intf, &rctx->mon_conn,
NULL, NULL);
if (ret != EOK) {
DEBUG(0, ("Failed to connect to monitor services.\n"));
@@ -455,12 +443,12 @@ failed:
int sss_process_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct confdb_ctx *cdb,
- struct sbus_method sss_sbus_methods[],
struct sss_cmd_table sss_cmds[],
const char *sss_pipe_name,
const char *sss_priv_pipe_name,
const char *confdb_service_path,
- struct sbus_method dp_methods[],
+ struct sbus_interface *dp_intf,
+ struct sbus_interface *monitor_intf,
struct resp_ctx **responder_ctx)
{
struct resp_ctx *rctx;
@@ -473,12 +461,10 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
}
rctx->ev = ev;
rctx->cdb = cdb;
- rctx->sss_sbus_methods = sss_sbus_methods;
rctx->sss_cmds = sss_cmds;
rctx->sock_name = sss_pipe_name;
rctx->priv_sock_name = sss_priv_pipe_name;
rctx->confdb_service_path = confdb_service_path;
- rctx->dp_methods = dp_methods;
ret = confdb_get_domains(rctx->cdb, rctx, &rctx->domains);
if (ret != EOK) {
@@ -486,18 +472,18 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
return ret;
}
- ret = sss_sbus_init(rctx);
+ ret = sss_monitor_init(rctx, monitor_intf);
if (ret != EOK) {
DEBUG(0, ("fatal error setting up message bus\n"));
return ret;
}
- ret = sss_dp_init(rctx, rctx->dp_methods);
+ ret = sss_dp_init(rctx, dp_intf);
if (ret != EOK) {
DEBUG(0, ("fatal error setting up backend connector\n"));
return ret;
}
- else if (!rctx->conn) {
+ else if (!rctx->dp_conn) {
DEBUG(0, ("Data Provider is not yet available. Retrying.\n"));
return EIO;
}
diff --git a/server/responder/common/responder_dp.c b/server/responder/common/responder_dp.c
index 547cb272..dc810fd9 100644
--- a/server/responder/common/responder_dp.c
+++ b/server/responder/common/responder_dp.c
@@ -10,7 +10,7 @@
struct sss_dp_pvt_ctx {
struct resp_ctx *rctx;
- struct sbus_method *methods;
+ struct sbus_interface *intf;
time_t last_retry;
int retries;
};
@@ -49,20 +49,8 @@ static void sss_dp_conn_reconnect(struct sss_dp_pvt_ctx *pvt)
return;
}
- ret = dp_init_sbus_methods(rctx, pvt->methods, &rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return;
- }
-
- /* FIXME: remove this */
- if (talloc_reference(rctx, rctx->sm_ctx) == NULL) {
- DEBUG(0, ("Failed to take memory reference\n"));
- return;
- }
-
ret = sbus_client_init(rctx, rctx->ev, sbus_address,
- rctx->sm_ctx, &rctx->conn,
+ pvt->intf, &rctx->dp_conn,
sss_dp_conn_destructor, pvt);
if (ret != EOK) {
DEBUG(4, ("Failed to reconnect [%d(%s)]!\n", ret, strerror(ret)));
@@ -109,7 +97,7 @@ int sss_dp_conn_destructor(void *data)
return 0;
}
-int sss_dp_init(struct resp_ctx *rctx, struct sbus_method *dp_methods)
+int sss_dp_init(struct resp_ctx *rctx, struct sbus_interface *dp_intf)
{
struct sss_dp_pvt_ctx *pvt;
@@ -117,7 +105,7 @@ int sss_dp_init(struct resp_ctx *rctx, struct sbus_method *dp_methods)
if (!pvt) return ENOMEM;
pvt->rctx = rctx;
- pvt->methods = dp_methods;
+ pvt->intf = dp_intf;
sss_dp_conn_reconnect(pvt);
@@ -243,12 +231,12 @@ int nss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *memctx,
* in some pathological cases it may happen that nss starts up before
* dp connection code is actually able to establish a connection.
*/
- if (!rctx->conn) {
+ if (!rctx->dp_conn) {
DEBUG(1, ("The Data Provider connection is not available yet!"
" This maybe a bug, it shouldn't happen!\n"));
return EIO;
}
- dbus_conn = sbus_get_connection(rctx->conn);
+ dbus_conn = sbus_get_connection(rctx->dp_conn);
/* create the message */
msg = dbus_message_new_method_call(NULL,
diff --git a/server/responder/nss/nsssrv.c b/server/responder/nss/nsssrv.c
index d104c7c8..248d5384 100644
--- a/server/responder/nss/nsssrv.c
+++ b/server/responder/nss/nsssrv.c
@@ -57,12 +57,20 @@ static int service_pong(DBusMessage *message, struct sbus_connection *conn);
static int service_reload(DBusMessage *message, struct sbus_connection *conn);
static int service_res_init(DBusMessage *message, struct sbus_connection *conn);
-struct sbus_method nss_sbus_methods[] = {
- {SERVICE_METHOD_IDENTITY, service_identity},
- {SERVICE_METHOD_PING, service_pong},
- {SERVICE_METHOD_RELOAD, service_reload},
- {SERVICE_METHOD_RES_INIT, service_res_init},
- {NULL, NULL}
+struct sbus_method monitor_nss_methods[] = {
+ { MON_CLI_METHOD_IDENTITY, service_identity },
+ { MON_CLI_METHOD_PING, service_pong },
+ { MON_CLI_METHOD_RELOAD, service_reload },
+ { MON_CLI_METHOD_RES_INIT, service_res_init },
+ { NULL, NULL }
+};
+
+struct sbus_interface monitor_nss_interface = {
+ MONITOR_INTERFACE,
+ MONITOR_PATH,
+ SBUS_DEFAULT_VTABLE,
+ monitor_nss_methods,
+ NULL
};
static int service_identity(DBusMessage *message, struct sbus_connection *conn)
@@ -252,19 +260,10 @@ static void nss_shutdown(struct resp_ctx *rctx)
static void nss_dp_reconnect_init(struct sbus_connection *conn, int status, void *pvt)
{
- int ret;
struct resp_ctx *rctx = talloc_get_type(pvt, struct resp_ctx);
/* Did we reconnect successfully? */
if (status == SBUS_RECONNECT_SUCCESS) {
- /* Add the methods back to the new connection */
- ret = sbus_conn_add_method_ctx(rctx->conn,
- rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not re-add methods on reconnection.\n"));
- nss_shutdown(rctx);
- }
-
DEBUG(1, ("Reconnected to the Data Provider.\n"));
return;
}
@@ -280,7 +279,7 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct confdb_ctx *cdb)
{
- struct sbus_method *nss_dp_methods;
+ struct sbus_interface *nss_dp_interface;
struct sss_cmd_table *nss_cmds;
struct nss_ctx *nctx;
int ret, max_retries;
@@ -297,15 +296,15 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
return ret;
}
- nss_dp_methods = get_nss_dp_methods();
+ nss_dp_interface = get_nss_dp_interface();
nss_cmds = get_nss_cmds();
ret = sss_process_init(nctx, ev, cdb,
- nss_sbus_methods,
nss_cmds,
SSS_NSS_SOCKET_NAME, NULL,
NSS_SRV_CONFIG,
- nss_dp_methods,
+ nss_dp_interface,
+ &monitor_nss_interface,
&nctx->rctx);
if (ret != EOK) {
return ret;
@@ -327,7 +326,7 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
return ret;
}
- sbus_reconnect_init(nctx->rctx->conn,
+ sbus_reconnect_init(nctx->rctx->dp_conn,
max_retries,
nss_dp_reconnect_init, nctx->rctx);
diff --git a/server/responder/nss/nsssrv.h b/server/responder/nss/nsssrv.h
index cbbb9cc6..f79d056c 100644
--- a/server/responder/nss/nsssrv.h
+++ b/server/responder/nss/nsssrv.h
@@ -68,7 +68,7 @@ struct nss_packet;
int nss_cmd_execute(struct cli_ctx *cctx);
/* from nsssrv_dp.c */
-struct sbus_method *get_nss_dp_methods(void);
+struct sbus_interface *get_nss_dp_interface(void);
struct sss_cmd_table *get_nss_cmds(void);
#endif /* __NSSSRV_H__ */
diff --git a/server/responder/nss/nsssrv_dp.c b/server/responder/nss/nsssrv_dp.c
index 7150a594..92a2d441 100644
--- a/server/responder/nss/nsssrv_dp.c
+++ b/server/responder/nss/nsssrv_dp.c
@@ -66,7 +66,15 @@ static struct sbus_method nss_dp_methods[] = {
{ NULL, NULL }
};
-struct sbus_method *get_nss_dp_methods(void)
+struct sbus_interface nss_dp_interface = {
+ DATA_PROVIDER_INTERFACE,
+ DATA_PROVIDER_PATH,
+ SBUS_DEFAULT_VTABLE,
+ nss_dp_methods,
+ NULL
+};
+
+struct sbus_interface *get_nss_dp_interface(void)
{
- return nss_dp_methods;
+ return &nss_dp_interface;
}
diff --git a/server/responder/pam/pamsrv.c b/server/responder/pam/pamsrv.c
index cd423714..48286ecd 100644
--- a/server/responder/pam/pamsrv.c
+++ b/server/responder/pam/pamsrv.c
@@ -60,12 +60,20 @@ static int service_pong(DBusMessage *message, struct sbus_connection *conn);
static int service_reload(DBusMessage *message, struct sbus_connection *conn);
static int service_res_init(DBusMessage *message, struct sbus_connection *conn);
-struct sbus_method sss_sbus_methods[] = {
- {SERVICE_METHOD_IDENTITY, service_identity},
- {SERVICE_METHOD_PING, service_pong},
- {SERVICE_METHOD_RELOAD, service_reload},
- {SERVICE_METHOD_RES_INIT, service_res_init},
- {NULL, NULL}
+struct sbus_method monitor_pam_methods[] = {
+ { MON_CLI_METHOD_IDENTITY, service_identity },
+ { MON_CLI_METHOD_PING, service_pong },
+ { MON_CLI_METHOD_RELOAD, service_reload },
+ { MON_CLI_METHOD_RES_INIT, service_res_init },
+ { NULL, NULL }
+};
+
+struct sbus_interface monitor_pam_interface = {
+ MONITOR_INTERFACE,
+ MONITOR_PATH,
+ SBUS_DEFAULT_VTABLE,
+ monitor_pam_methods,
+ NULL
};
static int service_identity(DBusMessage *message, struct sbus_connection *conn)
@@ -142,19 +150,10 @@ static int service_reload(DBusMessage *message, struct sbus_connection *conn) {
static void pam_dp_reconnect_init(struct sbus_connection *conn, int status, void *pvt)
{
- int ret;
struct resp_ctx *rctx = talloc_get_type(pvt, struct resp_ctx);
/* Did we reconnect successfully? */
if (status == SBUS_RECONNECT_SUCCESS) {
- /* Add the methods back to the new connection */
- ret = sbus_conn_add_method_ctx(rctx->conn,
- rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not re-add methods on reconnection.\n"));
- pam_shutdown(rctx);
- }
-
DEBUG(1, ("Reconnected to the Data Provider.\n"));
return;
}
@@ -190,7 +189,7 @@ static int pam_process_init(struct main_context *main_ctx,
return ret;
}
- sbus_reconnect_init(rctx->conn, max_retries,
+ sbus_reconnect_init(rctx->dp_conn, max_retries,
pam_dp_reconnect_init, rctx);
return EOK;
@@ -202,7 +201,7 @@ int main(int argc, const char *argv[])
poptContext pc;
struct main_context *main_ctx;
int ret;
- struct sbus_method *pam_dp_methods;
+ struct sbus_interface *pam_dp_interface;
struct sss_cmd_table *sss_cmds;
struct resp_ctx *rctx;
@@ -229,17 +228,17 @@ int main(int argc, const char *argv[])
ret = server_setup("sssd[pam]", 0, PAM_SRV_CONFIG, &main_ctx);
if (ret != EOK) return 2;
- pam_dp_methods = register_pam_dp_methods();
+ pam_dp_interface = get_pam_dp_interface();
sss_cmds = register_sss_cmds();
ret = sss_process_init(main_ctx,
main_ctx->event_ctx,
main_ctx->confdb_ctx,
- sss_sbus_methods,
sss_cmds,
SSS_PAM_SOCKET_NAME,
SSS_PAM_PRIV_SOCKET_NAME,
PAM_SRV_CONFIG,
- pam_dp_methods,
+ pam_dp_interface,
+ &monitor_pam_interface,
&rctx);
if (ret != EOK) return 3;
diff --git a/server/responder/pam/pamsrv.h b/server/responder/pam/pamsrv.h
index fa688fe1..1de1cee8 100644
--- a/server/responder/pam/pamsrv.h
+++ b/server/responder/pam/pamsrv.h
@@ -22,7 +22,7 @@ struct pam_auth_req {
void *data;
};
-struct sbus_method *register_pam_dp_methods(void);
+struct sbus_interface *get_pam_dp_interface(void);
struct sss_cmd_table *register_sss_cmds(void);
int pam_dp_send_req(struct pam_auth_req *preq, int timeout);
diff --git a/server/responder/pam/pamsrv_dp.c b/server/responder/pam/pamsrv_dp.c
index c7a536e8..c0a286b2 100644
--- a/server/responder/pam/pamsrv_dp.c
+++ b/server/responder/pam/pamsrv_dp.c
@@ -92,12 +92,12 @@ int pam_dp_send_req(struct pam_auth_req *preq, int timeout)
* in some pathological cases it may happen that nss starts up before
* dp connection code is actually able to establish a connection.
*/
- if (!preq->cctx->rctx->conn) {
+ if (!preq->cctx->rctx->dp_conn) {
DEBUG(1, ("The Data Provider connection is not available yet!"
" This maybe a bug, it shouldn't happen!\n"));
return EIO;
}
- dbus_conn = sbus_get_connection(preq->cctx->rctx->conn);
+ dbus_conn = sbus_get_connection(preq->cctx->rctx->dp_conn);
msg = dbus_message_new_method_call(NULL,
DP_CLI_PATH,
@@ -169,12 +169,20 @@ static int pam_dp_identity(DBusMessage *message, struct sbus_connection *conn)
return EOK;
}
-struct sbus_method *register_pam_dp_methods(void)
-{
- static struct sbus_method pam_dp_methods[] = {
- { DP_CLI_METHOD_IDENTITY, pam_dp_identity },
- { NULL, NULL }
- };
+static struct sbus_method pam_dp_methods[] = {
+ { DP_CLI_METHOD_IDENTITY, pam_dp_identity },
+ { NULL, NULL }
+};
+
+struct sbus_interface pam_dp_interface = {
+ DATA_PROVIDER_INTERFACE,
+ DATA_PROVIDER_PATH,
+ SBUS_DEFAULT_VTABLE,
+ pam_dp_methods,
+ NULL
+};
- return pam_dp_methods;
+struct sbus_interface *get_pam_dp_interface(void)
+{
+ return &pam_dp_interface;
}
diff --git a/server/sbus/sbus_client.c b/server/sbus/sbus_client.c
index 82021d6e..df5c0712 100644
--- a/server/sbus/sbus_client.c
+++ b/server/sbus/sbus_client.c
@@ -26,7 +26,7 @@
int sbus_client_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
const char *server_address,
- struct sbus_method_ctx *sm_ctx,
+ struct sbus_interface *intf,
struct sbus_connection **_conn,
sbus_conn_destructor_fn destructor,
void *conn_pvt_data)
@@ -39,12 +39,7 @@ int sbus_client_init(TALLOC_CTX *mem_ctx,
return EINVAL;
}
- ret = sbus_new_connection(mem_ctx, ev, server_address, &conn);
- if (ret != EOK) {
- goto fail;
- }
-
- ret = sbus_conn_add_method_ctx(conn, sm_ctx);
+ ret = sbus_new_connection(mem_ctx, ev, server_address, intf, &conn);
if (ret != EOK) {
goto fail;
}
diff --git a/server/sbus/sbus_client.h b/server/sbus/sbus_client.h
index bce8f821..742f8a10 100644
--- a/server/sbus/sbus_client.h
+++ b/server/sbus/sbus_client.h
@@ -28,7 +28,7 @@
int sbus_client_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
const char *server_address,
- struct sbus_method_ctx *sm_ctx,
+ struct sbus_interface *intf,
struct sbus_connection **_conn,
sbus_conn_destructor_fn destructor,
void *conn_pvt_data);
diff --git a/server/sbus/sssd_dbus.h b/server/sbus/sssd_dbus.h
index 6487ced6..ac02c444 100644
--- a/server/sbus/sssd_dbus.h
+++ b/server/sbus/sssd_dbus.h
@@ -59,15 +59,17 @@ enum {
#define DBUS_INTROSPECT_INTERFACE "org.freedesktop.DBus.Introspectable"
#define DBUS_INTROSPECT_METHOD "Introspect"
+#define SBUS_DEFAULT_VTABLE { NULL, sbus_message_handler, NULL, NULL, NULL, NULL }
+
struct sbus_method {
const char *method;
sbus_msg_handler_fn fn;
};
-struct sbus_method_ctx {
- char *interface;
- char *path;
- DBusObjectPathMessageFunction message_handler;
+struct sbus_interface {
+ const char *interface;
+ const char *path;
+ DBusObjectPathVTable vtable;
struct sbus_method *methods;
sbus_msg_handler_fn introspect_fn;
};
@@ -76,7 +78,7 @@ struct sbus_method_ctx {
int sbus_new_server(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
const char *address,
- struct sbus_method_ctx *ctx,
+ struct sbus_interface *intf,
struct sbus_connection **server,
sbus_server_conn_init_fn init_fn, void *init_pvt_data);
@@ -92,6 +94,7 @@ int sbus_new_server(TALLOC_CTX *mem_ctx,
int sbus_new_connection(TALLOC_CTX *ctx,
struct tevent_context *ev,
const char *address,
+ struct sbus_interface *intf,
struct sbus_connection **conn);
/* sbus_add_connection
@@ -106,11 +109,12 @@ int sbus_new_connection(TALLOC_CTX *ctx,
* connections, including those retrieved from
* dbus_bus_get
*/
-int sbus_add_connection(TALLOC_CTX *ctx,
- struct tevent_context *ev,
- DBusConnection *dbus_conn,
- struct sbus_connection **conn,
- int connection_type);
+int sbus_init_connection(TALLOC_CTX *ctx,
+ struct tevent_context *ev,
+ DBusConnection *dbus_conn,
+ struct sbus_interface *intf,
+ int connection_type,
+ struct sbus_connection **_conn);
void sbus_conn_set_destructor(struct sbus_connection *conn,
sbus_conn_destructor_fn destructor);
@@ -121,8 +125,8 @@ DBusConnection *sbus_get_connection(struct sbus_connection *conn);
void sbus_disconnect(struct sbus_connection *conn);
void sbus_conn_set_private_data(struct sbus_connection *conn, void *pvt_data);
void *sbus_conn_get_private_data(struct sbus_connection *conn);
-int sbus_conn_add_method_ctx(struct sbus_connection *conn,
- struct sbus_method_ctx *method_ctx);
+int sbus_conn_add_interface(struct sbus_connection *conn,
+ struct sbus_interface *intf);
bool sbus_conn_disconnecting(struct sbus_connection *conn);
/* max_retries < 0: retry forever
diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c
index f2435bfb..ab414da0 100644
--- a/server/sbus/sssd_dbus_connection.c
+++ b/server/sbus/sssd_dbus_connection.c
@@ -7,14 +7,14 @@
/* Types */
struct dbus_ctx_list;
-struct method_holder {
- struct method_holder *prev, *next;
+struct sbus_interface_p {
+ struct sbus_interface_p *prev, *next;
struct sbus_connection *conn;
- struct sbus_method_ctx *method_ctx;
- DBusObjectPathVTable *dbus_vtable;
+ struct sbus_interface *intf;
};
-static bool path_in_method_list(struct method_holder *list, const char *path);
+static bool path_in_interface_list(struct sbus_interface_p *list,
+ const char *path);
static void sbus_unreg_object_paths(struct sbus_connection *conn);
static int sbus_auto_reconnect(struct sbus_connection *conn);
@@ -56,8 +56,8 @@ static void sbus_dispatch(struct tevent_context *ev,
DEBUG(0, ("Cannot start auto-reconnection.\n"));
conn->reconnect_callback(conn,
- SBUS_RECONNECT_ERROR,
- conn->reconnect_pvt);
+ SBUS_RECONNECT_ERROR,
+ conn->reconnect_pvt);
return;
}
@@ -129,11 +129,12 @@ static int sbus_conn_set_fns(struct sbus_connection *conn);
* Set up a D-BUS connection to use the libevents mainloop
* for handling file descriptor and timed events
*/
-int sbus_add_connection(TALLOC_CTX *ctx,
- struct tevent_context *ev,
- DBusConnection *dbus_conn,
- struct sbus_connection **_conn,
- int connection_type)
+int sbus_init_connection(TALLOC_CTX *ctx,
+ struct tevent_context *ev,
+ DBusConnection *dbus_conn,
+ struct sbus_interface *intf,
+ int connection_type,
+ struct sbus_connection **_conn)
{
struct sbus_connection *conn;
int ret;
@@ -149,10 +150,16 @@ int sbus_add_connection(TALLOC_CTX *ctx,
ret = sbus_conn_set_fns(conn);
if (ret != EOK) {
talloc_free(conn);
+ return ret;
}
- *_conn = conn;
+ ret = sbus_conn_add_interface(conn, intf);
+ if (ret != EOK) {
+ talloc_free(conn);
+ return ret;
+ }
+ *_conn = conn;
return ret;
}
@@ -208,9 +215,10 @@ static int sbus_conn_set_fns(struct sbus_connection *conn)
}
int sbus_new_connection(TALLOC_CTX *ctx, struct tevent_context *ev,
- const char *address,
- struct sbus_connection **conn)
+ const char *address, struct sbus_interface *intf,
+ struct sbus_connection **_conn)
{
+ struct sbus_connection *conn;
DBusConnection *dbus_conn;
DBusError dbus_error;
int ret;
@@ -226,17 +234,18 @@ int sbus_new_connection(TALLOC_CTX *ctx, struct tevent_context *ev,
return EIO;
}
- ret = sbus_add_connection(ctx, ev, dbus_conn,
- conn, SBUS_CONN_TYPE_SHARED);
+ ret = sbus_init_connection(ctx, ev, dbus_conn, intf,
+ SBUS_CONN_TYPE_SHARED, &conn);
if (ret != EOK) {
/* FIXME: release resources */
}
/* Store the address for later reconnection */
- (*conn)->address = talloc_strdup((*conn), address);
+ conn->address = talloc_strdup(conn, address);
- dbus_connection_set_exit_on_disconnect((*conn)->dbus.conn, FALSE);
+ dbus_connection_set_exit_on_disconnect(conn->dbus.conn, FALSE);
+ *_conn = conn;
return ret;
}
@@ -364,7 +373,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
DBusMessage *message,
void *user_data)
{
- struct method_holder *ctx;
+ struct sbus_interface_p *intf_p;
const char *method;
const char *path;
const char *msg_interface;
@@ -375,7 +384,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
if (!user_data) {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
- ctx = talloc_get_type(user_data, struct method_holder);
+ intf_p = talloc_get_type(user_data, struct sbus_interface_p);
method = dbus_message_get_member(message);
DEBUG(9, ("Received SBUS method [%s]\n", method));
@@ -386,18 +395,18 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
/* Validate the D-BUS path */
- if (strcmp(path, ctx->method_ctx->path) != 0)
+ if (strcmp(path, intf_p->intf->path) != 0)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
/* Validate the method interface */
- if (strcmp(msg_interface, ctx->method_ctx->interface) == 0) {
+ if (strcmp(msg_interface, intf_p->intf->interface) == 0) {
found = 0;
- for (i = 0; ctx->method_ctx->methods[i].method != NULL; i++) {
- if (strcmp(method, ctx->method_ctx->methods[i].method) == 0) {
+ for (i = 0; intf_p->intf->methods[i].method != NULL; i++) {
+ if (strcmp(method, intf_p->intf->methods[i].method) == 0) {
found = 1;
- ret = ctx->method_ctx->methods[i].fn(message, ctx->conn);
+ ret = intf_p->intf->methods[i].fn(message, intf_p->conn);
if (ret != EOK) {
- return sbus_reply_internal_error(message, ctx->conn);
+ return sbus_reply_internal_error(message, intf_p->conn);
}
break;
}
@@ -407,7 +416,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
/* Reply DBUS_ERROR_UNKNOWN_METHOD */
DEBUG(1, ("No matching method found for %s.\n", method));
reply = dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD, NULL);
- sbus_conn_send_reply(ctx->conn, reply);
+ sbus_conn_send_reply(intf_p->conn, reply);
dbus_message_unref(reply);
}
}
@@ -418,13 +427,13 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
if (strcmp(msg_interface, DBUS_INTROSPECT_INTERFACE) == 0 &&
strcmp(method, DBUS_INTROSPECT_METHOD) == 0)
{
- if (ctx->method_ctx->introspect_fn) {
+ if (intf_p->intf->introspect_fn) {
/* If we have been asked for introspection data and we have
* an introspection function registered, user that.
*/
- ret = ctx->method_ctx->introspect_fn(message, ctx->conn);
+ ret = intf_p->intf->introspect_fn(message, intf_p->conn);
if (ret != EOK) {
- return sbus_reply_internal_error(message, ctx->conn);
+ return sbus_reply_internal_error(message, intf_p->conn);
}
}
}
@@ -438,49 +447,35 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
/* Adds a new D-BUS path message handler to the connection
* Note: this must be a unique path.
*/
-int sbus_conn_add_method_ctx(struct sbus_connection *conn,
- struct sbus_method_ctx *method_ctx)
+int sbus_conn_add_interface(struct sbus_connection *conn,
+ struct sbus_interface *intf)
{
- struct method_holder *mh;
+ struct sbus_interface_p *intf_p;
dbus_bool_t dbret;
const char *path;
- if (!conn || !method_ctx || !method_ctx->message_handler) {
+ if (!conn || !intf || !intf->vtable.message_function) {
return EINVAL;
}
- path = method_ctx->path;
+ path = intf->path;
- if (path_in_method_list(conn->method_list, path)) {
+ if (path_in_interface_list(conn->intf_list, path)) {
DEBUG(0, ("Cannot add method context with identical path.\n"));
return EINVAL;
}
- mh = talloc_zero(conn, struct method_holder);
- if (!mh) {
- return ENOMEM;
- }
- mh->conn = conn;
-
- /* Set up the vtable for the object path */
- mh->dbus_vtable = talloc_zero(conn, DBusObjectPathVTable);
- if (!mh->dbus_vtable) {
- talloc_free(mh);
- return ENOMEM;
- }
- mh->dbus_vtable->message_function = method_ctx->message_handler;
-
- mh->method_ctx = talloc_reference(mh, method_ctx);
- if (!mh->method_ctx) {
- /* talloc_reference only fails on insufficient memory */
- talloc_free(mh);
+ intf_p = talloc_zero(conn, struct sbus_interface_p);
+ if (!intf_p) {
return ENOMEM;
}
+ intf_p->conn = conn;
+ intf_p->intf = intf;
- DLIST_ADD(conn->method_list, mh);
+ DLIST_ADD(conn->intf_list, intf_p);
dbret = dbus_connection_register_object_path(conn->dbus.conn,
- path, mh->dbus_vtable, mh);
+ path, &intf->vtable, intf_p);
if (!dbret) {
DEBUG(0, ("Could not register object path to the connection.\n"));
return ENOMEM;
@@ -489,9 +484,10 @@ int sbus_conn_add_method_ctx(struct sbus_connection *conn,
return EOK;
}
-static bool path_in_method_list(struct method_holder *list, const char *path)
+static bool path_in_interface_list(struct sbus_interface_p *list,
+ const char *path)
{
- struct method_holder *iter;
+ struct sbus_interface_p *iter;
if (!list || !path) {
return false;
@@ -499,7 +495,7 @@ static bool path_in_method_list(struct method_holder *list, const char *path)
iter = list;
while (iter != NULL) {
- if (strcmp(iter->method_ctx->path, path) == 0) {
+ if (strcmp(iter->intf->path, path) == 0) {
return true;
}
iter = iter->next;
@@ -510,16 +506,12 @@ static bool path_in_method_list(struct method_holder *list, const char *path)
static void sbus_unreg_object_paths(struct sbus_connection *conn)
{
- struct method_holder *iter = conn->method_list;
- struct method_holder *purge;
+ struct sbus_interface_p *iter = conn->intf_list;
while (iter != NULL) {
dbus_connection_unregister_object_path(conn->dbus.conn,
- iter->method_ctx->path);
- DLIST_REMOVE(conn->method_list, iter);
- purge = iter;
+ iter->intf->path);
iter = iter->next;
- talloc_free(purge);
}
}
@@ -538,7 +530,7 @@ static void sbus_reconnect(struct tevent_context *ev,
struct timeval tv, void *data)
{
struct sbus_connection *conn;
- struct method_holder *mh;
+ struct sbus_interface_p *iter;
DBusError dbus_error;
dbus_bool_t dbret;
int ret;
@@ -559,17 +551,18 @@ static void sbus_reconnect(struct tevent_context *ev,
}
/* Re-register object paths */
- mh = conn->method_list;
- while (mh) {
+ iter = conn->intf_list;
+ while (iter) {
dbret = dbus_connection_register_object_path(conn->dbus.conn,
- mh->method_ctx->path,
- mh->dbus_vtable, mh);
+ iter->intf->path,
+ &iter->intf->vtable,
+ iter);
if (!dbret) {
DEBUG(0, ("Could not register object path.\n"));
dbus_connection_unref(conn->dbus.conn);
goto failed;
}
- mh = mh->next;
+ iter = iter->next;
}
/* Reset retries to 0 to resume dispatch processing */
diff --git a/server/sbus/sssd_dbus_private.h b/server/sbus/sssd_dbus_private.h
index 01eaf00d..79cae230 100644
--- a/server/sbus/sssd_dbus_private.h
+++ b/server/sbus/sssd_dbus_private.h
@@ -10,6 +10,8 @@ enum dbus_conn_type {
SBUS_CONNECTION
};
+struct sbus_interface_p;
+
struct sbus_connection {
struct tevent_context *ev;
@@ -24,7 +26,7 @@ struct sbus_connection {
void *pvt_data; /* Private data for this connection */
/* dbus tables and handlers */
- struct method_holder *method_list;
+ struct sbus_interface_p *intf_list;
/* reconnect settings */
int retries;
@@ -34,7 +36,7 @@ struct sbus_connection {
void *reconnect_pvt;
/* server related stuff */
- struct sbus_method_ctx *server_method;
+ struct sbus_interface *server_intf;
sbus_server_conn_init_fn srv_init_fn;
void *srv_init_data;
};
diff --git a/server/sbus/sssd_dbus_server.c b/server/sbus/sssd_dbus_server.c
index 8a123d6d..ef2de106 100644
--- a/server/sbus/sssd_dbus_server.c
+++ b/server/sbus/sssd_dbus_server.c
@@ -49,8 +49,9 @@ static void sbus_server_init_new_connection(DBusServer *dbus_server,
}
DEBUG(5,("Adding connection %lX.\n", conn));
- ret = sbus_add_connection(server, server->ev, dbus_conn,
- &conn, SBUS_CONN_TYPE_PRIVATE);
+ ret = sbus_init_connection(server, server->ev,
+ dbus_conn, server->server_intf,
+ SBUS_CONN_TYPE_PRIVATE, &conn);
if (ret != 0) {
dbus_connection_close(dbus_conn);
DEBUG(5,("Closing connection (failed setup)"));
@@ -61,8 +62,6 @@ static void sbus_server_init_new_connection(DBusServer *dbus_server,
DEBUG(5,("Got a connection\n"));
- sbus_conn_add_method_ctx(conn, server->server_method);
-
/*
* Initialize connection-specific features
* This may set a more detailed destructor, but
@@ -87,7 +86,7 @@ static void sbus_server_init_new_connection(DBusServer *dbus_server,
int sbus_new_server(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
const char *address,
- struct sbus_method_ctx *method,
+ struct sbus_interface *intf,
struct sbus_connection **_server,
sbus_server_conn_init_fn init_fn, void *init_pvt_data)
{
@@ -121,7 +120,7 @@ int sbus_new_server(TALLOC_CTX *mem_ctx,
server->ev = ev;
server->type = SBUS_SERVER;
server->dbus.server = dbus_server;
- server->server_method = method;
+ server->server_intf = intf;
server->srv_init_fn = init_fn;
server->srv_init_data = init_pvt_data;