summaryrefslogtreecommitdiff
path: root/server/providers
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/providers
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/providers')
-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
5 files changed, 51 insertions, 130 deletions
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_ */