From d9f203e045c63c853ae60b47fb8013e92600c9f9 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mon, 19 Jan 2009 13:33:28 -0500 Subject: Refactoring the monitor code and SBUS utility functions. --- server/providers/data_provider.c | 33 ++++++++++--- server/providers/data_provider.h | 4 +- server/providers/data_provider_be.c | 70 +++++++++++++++++++++----- server/providers/dp_interfaces.h | 32 ++++++++++++ server/providers/dp_sbus.c | 98 +++++++++++++++++++++++++++++++++++++ server/providers/dp_sbus.h | 30 ++++++++++++ 6 files changed, 247 insertions(+), 20 deletions(-) create mode 100644 server/providers/dp_interfaces.h create mode 100644 server/providers/dp_sbus.c create mode 100644 server/providers/dp_sbus.h (limited to 'server/providers') diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c index fd64525ee..e361dfc87 100644 --- a/server/providers/data_provider.c +++ b/server/providers/data_provider.c @@ -34,10 +34,11 @@ #include "confdb/confdb.h" #include "dbus/dbus.h" #include "sbus/sssd_dbus.h" -#include "sbus_interfaces.h" #include "util/btreemap.h" #include "data_provider.h" -#include "util/service_helpers.h" +#include "dp_interfaces.h" +#include "monitor/monitor_sbus.h" +#include "monitor/monitor_interfaces.h" struct dp_backend; struct dp_frontend; @@ -156,14 +157,32 @@ static int service_reload(DBusMessage *message, void *data, DBusMessage **r) { static int dp_monitor_init(struct dp_ctx *dpctx) { + int ret; + char *sbus_address; struct service_sbus_ctx *ss_ctx; + struct sbus_method_ctx *sm_ctx; /* Set up SBUS connection to the monitor */ - ss_ctx = sssd_service_sbus_init(dpctx, dpctx->ev, dpctx->cdb, - mon_sbus_methods, NULL); - if (ss_ctx == NULL) { - DEBUG(0, ("Could not initialize D-BUS.\n")); - return ENOMEM; + ret = monitor_get_sbus_address(dpctx, dpctx->cdb, &sbus_address); + if (ret != EOK) { + DEBUG(0, ("Could not locate monitor address.\n")); + 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, + NULL /* Private Data */, + NULL /* Destructor */, + &ss_ctx); + if (ret != EOK) { + DEBUG(0, ("Failed to connect to monitor services.\n")); + return ret; } /* Set up DP-specific listeners */ diff --git a/server/providers/data_provider.h b/server/providers/data_provider.h index a7311e5ee..382b1fb09 100644 --- a/server/providers/data_provider.h +++ b/server/providers/data_provider.h @@ -32,8 +32,8 @@ #include "confdb/confdb.h" #include "dbus/dbus.h" #include "sbus/sssd_dbus.h" -#include "sbus_interfaces.h" -#include "util/service_helpers.h" +#include "sbus/sbus_client.h" +#include "providers/dp_interfaces.h" #define DATA_PROVIDER_VERSION 0x0001 #define DATA_PROVIDER_SERVICE_NAME "dp" diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c index ba9ea466c..a669564be 100644 --- a/server/providers/data_provider_be.c +++ b/server/providers/data_provider_be.c @@ -35,10 +35,11 @@ #include "db/sysdb.h" #include "dbus/dbus.h" #include "sbus/sssd_dbus.h" -#include "sbus_interfaces.h" #include "util/btreemap.h" #include "providers/dp_backend.h" -#include "util/service_helpers.h" +#include "providers/dp_sbus.h" +#include "monitor/monitor_sbus.h" +#include "monitor/monitor_interfaces.h" typedef int (*be_init_fn_t)(TALLOC_CTX *, struct be_mod_ops **, void **); @@ -286,20 +287,35 @@ done: * sbus channel to the monitor daemon */ static int mon_cli_init(struct be_ctx *ctx) { + int ret; + char *sbus_address; struct service_sbus_ctx *ss_ctx; + struct sbus_method_ctx *sm_ctx; - /* Set up SBUS connection to the monitor */ - ss_ctx = sssd_service_sbus_init(ctx, ctx->ev, ctx->cdb, - mon_sbus_methods, NULL); - if (ss_ctx == NULL) { - DEBUG(0, ("Could not initialize D-BUS.\n")); - return ENOMEM; + /* Set up SBUS connection to the monitor */ + ret = monitor_get_sbus_address(ctx, ctx->cdb, &sbus_address); + if (ret != EOK) { + DEBUG(0, ("Could not locate monitor address.\n")); + return ret; } - ctx->ss_ctx = ss_ctx; + ret = monitor_init_sbus_methods(ctx, mon_sbus_methods, &sm_ctx); + if (ret != EOK) { + DEBUG(0, ("Could not initialize SBUS methods.\n")); + return ret; + } - /* attach be context to the connection */ - sbus_conn_set_private_data(ss_ctx->scon_ctx, ctx); + ret = sbus_client_init(ctx, ctx->ev, + sbus_address, sm_ctx, + ctx /* Private Data */, + NULL /* Destructor */, + &ss_ctx); + if (ret != EOK) { + DEBUG(0, ("Failed to connect to monitor services.\n")); + return ret; + } + + ctx->ss_ctx = ss_ctx; return EOK; } @@ -308,6 +324,38 @@ static int mon_cli_init(struct be_ctx *ctx) * sbus channel to the data provider daemon */ static int be_cli_init(struct be_ctx *ctx) { + int ret; + char *sbus_address; + struct service_sbus_ctx *ss_ctx; + struct sbus_method_ctx *sm_ctx; + + /* Set up SBUS connection to the data provider */ + ret = dp_get_sbus_address(ctx, ctx->cdb, &sbus_address); + if (ret != EOK) { + DEBUG(0, ("Could not locate data provider address.\n")); + return ret; + } + + ret = dp_init_sbus_methods(ctx, mon_sbus_methods, &sm_ctx); + if (ret != EOK) { + DEBUG(0, ("Could not initialize SBUS methods.\n")); + return ret; + } + + ret = sbus_client_init(ctx, ctx->ev, + sbus_address, sm_ctx, + ctx /* Private Data */, + NULL /* Destructor */, + &ss_ctx); + if (ret != EOK) { + DEBUG(0, ("Failed to connect to data provider services.\n")); + return ret; + } + + ctx->ss_ctx = ss_ctx; + + return EOK; + return dp_sbus_cli_init(ctx, ctx->ev, ctx->cdb, be_methods, ctx, NULL, &ctx->dp_ctx); diff --git a/server/providers/dp_interfaces.h b/server/providers/dp_interfaces.h new file mode 100644 index 000000000..8d85eb36d --- /dev/null +++ b/server/providers/dp_interfaces.h @@ -0,0 +1,32 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher 2009 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef DP_INTERFACES_H_ +#define DP_INTERFACES_H_ + +/* Data Provider */ + +#define DATA_PROVIDER_INTERFACE "org.freeipa.sssd.dataprovider" +#define DATA_PROVIDER_PATH "/org/freeipa/sssd/dataprovider" + +#define DP_METHOD_CHECK_ONLINE "isOnline" + +#endif /* DP_INTERFACES_H_ */ diff --git a/server/providers/dp_sbus.c b/server/providers/dp_sbus.c new file mode 100644 index 000000000..f6fc12ffe --- /dev/null +++ b/server/providers/dp_sbus.c @@ -0,0 +1,98 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher 2009 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "util/util.h" +#include "confdb/confdb.h" +#include "sbus/sssd_dbus.h" +#include "providers/data_provider.h" +#include "providers/dp_sbus.h" +#include "providers/dp_interfaces.h" + +int dp_get_sbus_address(TALLOC_CTX *mem_ctx, struct confdb_ctx *confdb, char **address) +{ + int ret; + char *default_address; + + *address = NULL; + default_address = talloc_asprintf(mem_ctx, "unix:path=%s/%s", + PIPE_PATH, DATA_PROVIDER_PIPE); + if (default_address == NULL) { + return ENOMEM; + } + + if (confdb == NULL) { + /* If the confdb isn't specified, fall to the default */ + *address = default_address; + talloc_steal(mem_ctx, default_address); + ret = EOK; + goto done; + } + + ret = confdb_get_string(confdb, mem_ctx, + "config/services/dp", "sbusAddress", + default_address, address); + +done: + talloc_free(default_address); + 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 new file mode 100644 index 000000000..f21001f93 --- /dev/null +++ b/server/providers/dp_sbus.h @@ -0,0 +1,30 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher 2009 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef DP_SBUS_H_ +#define DP_SBUS_H_ + +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_ */ -- cgit