diff options
-rw-r--r-- | server/configure.ac | 2 | ||||
-rw-r--r-- | server/monitor/monitor.c (renamed from server/monitor.c) | 4 | ||||
-rw-r--r-- | server/monitor/monitor.h (renamed from server/monitor.h) | 0 | ||||
-rw-r--r-- | server/monitor/monitor_interfaces.h (renamed from server/sbus_interfaces.h) | 7 | ||||
-rw-r--r-- | server/monitor/monitor_sbus.c | 97 | ||||
-rw-r--r-- | server/monitor/monitor_sbus.h | 30 | ||||
-rw-r--r-- | server/nss/nsssrv.c | 33 | ||||
-rw-r--r-- | server/nss/nsssrv_dp.c | 23 | ||||
-rw-r--r-- | server/providers/data_provider.c | 33 | ||||
-rw-r--r-- | server/providers/data_provider.h | 4 | ||||
-rw-r--r-- | server/providers/data_provider_be.c | 70 | ||||
-rw-r--r-- | server/providers/dp_interfaces.h | 32 | ||||
-rw-r--r-- | server/providers/dp_sbus.c | 98 | ||||
-rw-r--r-- | server/providers/dp_sbus.h | 30 | ||||
-rw-r--r-- | server/sbus/sbus_client.c | 79 | ||||
-rw-r--r-- | server/sbus/sbus_client.h | 42 | ||||
-rw-r--r-- | server/server.mk | 7 | ||||
-rw-r--r-- | server/util/service_helpers.c | 91 | ||||
-rw-r--r-- | server/util/service_helpers.h | 39 |
19 files changed, 547 insertions, 174 deletions
diff --git a/server/configure.ac b/server/configure.ac index 0d02fae8..ddf9d47b 100644 --- a/server/configure.ac +++ b/server/configure.ac @@ -12,7 +12,7 @@ AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""]) AC_DEFUN([SMB_EXT_LIB], [echo -n ""]) AC_DEFUN([SMB_ENABLE], [echo -n ""]) AC_INIT(ldb, 0.9.2) -AC_CONFIG_SRCDIR([monitor.c]) +AC_CONFIG_SRCDIR([autogen.sh]) AC_LIBREPLACE_ALL_CHECKS diff --git a/server/monitor.c b/server/monitor/monitor.c index 36904791..75742eab 100644 --- a/server/monitor.c +++ b/server/monitor/monitor.c @@ -30,10 +30,10 @@ #include "tevent.h" #include "util/util.h" #include "confdb/confdb.h" -#include "monitor.h" +#include "monitor/monitor.h" #include "dbus/dbus.h" #include "sbus/sssd_dbus.h" -#include "sbus_interfaces.h" +#include "monitor/monitor_interfaces.h" /* ping time cannot be less then once every few seconds or the * monitor will get crazy hammering children with messages */ diff --git a/server/monitor.h b/server/monitor/monitor.h index 8899c51a..8899c51a 100644 --- a/server/monitor.h +++ b/server/monitor/monitor.h diff --git a/server/sbus_interfaces.h b/server/monitor/monitor_interfaces.h index 0a3fe7a8..1b91c25a 100644 --- a/server/sbus_interfaces.h +++ b/server/monitor/monitor_interfaces.h @@ -40,10 +40,3 @@ #define SERVICE_METHOD_RELOAD "reloadConfig" #define SSSD_SERVICE_PIPE "private/sbus-monitor" - -/* Data Provider */ - -#define DATA_PROVIDER_INTERFACE "org.freeipa.sssd.dataprovider" -#define DATA_PROVIDER_PATH "/org/freeipa/sssd/dataprovider" - -#define DP_METHOD_CHECK_ONLINE "isOnline" diff --git a/server/monitor/monitor_sbus.c b/server/monitor/monitor_sbus.c new file mode 100644 index 00000000..7a9c8b09 --- /dev/null +++ b/server/monitor/monitor_sbus.c @@ -0,0 +1,97 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + +#include "util/util.h" +#include "confdb/confdb.h" +#include "sbus/sssd_dbus.h" +#include "monitor/monitor_sbus.h" +#include "monitor/monitor_interfaces.h" + +int monitor_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, SSSD_SERVICE_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/monitor", "sbusAddress", + default_address, address); + +done: + talloc_free(default_address); + return ret; +} + +int monitor_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, SERVICE_INTERFACE); + if (method_ctx->interface == NULL) { + ret = ENOMEM; + goto done; + } + + method_ctx->path = talloc_strdup(method_ctx, SERVICE_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/monitor/monitor_sbus.h b/server/monitor/monitor_sbus.h new file mode 100644 index 00000000..5e110ab8 --- /dev/null +++ b/server/monitor/monitor_sbus.h @@ -0,0 +1,30 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef MONITOR_SBUS_H_ +#define MONITOR_SBUS_H_ + +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/nss/nsssrv.c b/server/nss/nsssrv.c index 93a897a2..1c42c3c5 100644 --- a/server/nss/nsssrv.c +++ b/server/nss/nsssrv.c @@ -36,10 +36,11 @@ #include "confdb/confdb.h" #include "dbus/dbus.h" #include "sbus/sssd_dbus.h" -#include "sbus_interfaces.h" #include "util/btreemap.h" -#include "util/service_helpers.h" #include "providers/data_provider.h" +#include "monitor/monitor_sbus.h" +#include "monitor/monitor_interfaces.h" +#include "sbus/sbus_client.h" #define SSS_NSS_PIPE_NAME "nss" @@ -276,14 +277,32 @@ static int service_reload(DBusMessage *message, void *data, DBusMessage **r) { static int nss_sbus_init(struct nss_ctx *nctx) { + 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(nctx, nctx->ev, nctx->cdb, - nss_sbus_methods, NULL); - if (ss_ctx == NULL) { - DEBUG(0, ("Could not initialize D-BUS.\n")); - return ENOMEM; + ret = monitor_get_sbus_address(nctx, nctx->cdb, &sbus_address); + if (ret != EOK) { + DEBUG(0, ("Could not locate monitor address.\n")); + return ret; + } + + ret = monitor_init_sbus_methods(nctx, nss_sbus_methods, &sm_ctx); + if (ret != EOK) { + DEBUG(0, ("Could not initialize SBUS methods.\n")); + return ret; + } + + ret = sbus_client_init(nctx, nctx->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 NSS-specific listeners */ diff --git a/server/nss/nsssrv_dp.c b/server/nss/nsssrv_dp.c index 567f8e9b..d6aba556 100644 --- a/server/nss/nsssrv_dp.c +++ b/server/nss/nsssrv_dp.c @@ -24,6 +24,8 @@ #include "util/util.h" #include "nss/nsssrv.h" #include "providers/data_provider.h" +#include "sbus/sbus_client.h" +#include "providers/dp_sbus.h" struct nss_dp_req { nss_dp_callback_t callback; @@ -310,6 +312,8 @@ static void nss_dp_conn_reconnect(struct nss_dp_pvt_ctx *pvt) struct nss_ctx *nctx; struct timed_event *te; struct timeval tv; + struct sbus_method_ctx *sm_ctx; + char *sbus_address; time_t now; int ret; @@ -327,9 +331,21 @@ static void nss_dp_conn_reconnect(struct nss_dp_pvt_ctx *pvt) nctx = pvt->nctx; - ret = dp_sbus_cli_init(nctx, nctx->ev, nctx->cdb, - pvt->methods, pvt, - nss_dp_conn_destructor, + ret = dp_get_sbus_address(nctx, nctx->cdb, &sbus_address); + if (ret != EOK) { + DEBUG(0, ("Could not locate data provider address.\n")); + return; + } + + ret = dp_init_sbus_methods(nctx, pvt->methods, &sm_ctx); + if (ret != EOK) { + DEBUG(0, ("Could not initialize SBUS methods.\n")); + return; + } + + ret = sbus_client_init(nctx, nctx->ev, + sbus_address, sm_ctx, + pvt, nss_dp_conn_destructor, &nctx->dp_ctx); if (ret != EOK) { DEBUG(4, ("Failed to reconnect [%d(%s)]!\n", ret, strerror(ret))); @@ -379,7 +395,6 @@ int nss_dp_conn_destructor(void *data) int nss_dp_init(struct nss_ctx *nctx) { struct nss_dp_pvt_ctx *pvt; - int ret; pvt = talloc_zero(nctx, struct nss_dp_pvt_ctx); if (!pvt) return ENOMEM; diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c index fd64525e..e361dfc8 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 a7311e5e..382b1fb0 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 ba9ea466..a669564b 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 00000000..8d85eb36 --- /dev/null +++ b/server/providers/dp_interfaces.h @@ -0,0 +1,32 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + +#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 00000000..f6fc12ff --- /dev/null +++ b/server/providers/dp_sbus.c @@ -0,0 +1,98 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + +#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 00000000..f21001f9 --- /dev/null +++ b/server/providers/dp_sbus.h @@ -0,0 +1,30 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + +#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_ */ diff --git a/server/sbus/sbus_client.c b/server/sbus/sbus_client.c new file mode 100644 index 00000000..9b05b22a --- /dev/null +++ b/server/sbus/sbus_client.c @@ -0,0 +1,79 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + +#include "util/util.h" +#include "talloc.h" +#include "sbus_client.h" + +int sbus_client_init(TALLOC_CTX *mem_ctx, + struct event_context *ev, + const char *server_address, + struct sbus_method_ctx *sm_ctx, + void *conn_pvt_data, + sbus_conn_destructor_fn destructor, + struct service_sbus_ctx **srvs_ctx) +{ + int ret; + TALLOC_CTX *tmp_ctx; + struct service_sbus_ctx *ss_ctx; + + /* Validate input */ + if (server_address == NULL) { + return EINVAL; + } + + tmp_ctx = talloc_new(mem_ctx); + if (tmp_ctx == NULL) { + return ENOMEM; + } + + ss_ctx = talloc_zero(tmp_ctx, struct service_sbus_ctx); + if (ss_ctx == NULL) { + ret = ENOMEM; + goto done; + } + ss_ctx->ev = ev; + + ret = sbus_new_connection(ss_ctx, ss_ctx->ev, + server_address, &ss_ctx->scon_ctx, + destructor); + if (ret != EOK) goto done; + + ret = sbus_conn_add_method_ctx(ss_ctx->scon_ctx, sm_ctx); + if (ret != EOK) goto done; + ss_ctx->sm_ctx = sm_ctx; + if (talloc_reference(ss_ctx, sm_ctx) == NULL) { + ret = ENOMEM; + goto done; + } + + if(conn_pvt_data) { + sbus_conn_set_private_data(ss_ctx->scon_ctx, conn_pvt_data); + } + + talloc_steal(mem_ctx, ss_ctx); + *srvs_ctx = ss_ctx; + ret = EOK; + +done: + talloc_free(tmp_ctx); + return ret; +} diff --git a/server/sbus/sbus_client.h b/server/sbus/sbus_client.h new file mode 100644 index 00000000..ec61cb0f --- /dev/null +++ b/server/sbus/sbus_client.h @@ -0,0 +1,42 @@ +/* + SSSD + + Data Provider Helpers + + Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef SBUS_CLIENT_H_ +#define SBUS_CLIENT_H_ + +#include "tevent.h" +#include "sbus/sssd_dbus.h" + +struct service_sbus_ctx { + struct event_context *ev; + struct sbus_conn_ctx *scon_ctx; + struct sbus_method_ctx *sm_ctx; +}; + +int sbus_client_init(TALLOC_CTX *mem_ctx, + struct event_context *ev, + const char *server_address, + struct sbus_method_ctx *sm_ctx, + void *conn_pvt_data, + sbus_conn_destructor_fn destructor, + struct service_sbus_ctx **srvs_ctx); + +#endif /* SBUS_CLIENT_H_ */ diff --git a/server/server.mk b/server/server.mk index b77a1729..fd05c170 100644 --- a/server/server.mk +++ b/server/server.mk @@ -4,16 +4,17 @@ UTIL_OBJ = \ util/server.o \ util/memory.o \ util/btreemap.o \ - util/service_helpers.o \ + monitor/monitor_sbus.o \ + providers/dp_sbus.o \ sbus/sssd_dbus_common.o \ sbus/sssd_dbus_connection.o \ sbus/sssd_dbus_server.o \ - providers/dp_helpers.o \ + sbus/sbus_client.o \ confdb/confdb.o \ db/sysdb.o SERVER_OBJ = \ - monitor.o + monitor/monitor.o DP_OBJ = \ providers/data_provider.o diff --git a/server/util/service_helpers.c b/server/util/service_helpers.c deleted file mode 100644 index 9f07abd7..00000000 --- a/server/util/service_helpers.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - SSSD - - Service monitor - - Copyright (C) Stephen Gallagher 2008 - - 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 <http://www.gnu.org/licenses/>. - */ - -#include "util/util.h" -#include "talloc.h" -#include "sbus/sssd_dbus.h" -#include "confdb/confdb.h" -#include "service_helpers.h" -#include "sbus_interfaces.h" - -struct event_context; - -/* - * Set up an SBUS connection to the monitor - */ -struct service_sbus_ctx *sssd_service_sbus_init(TALLOC_CTX *mem_ctx, - struct event_context *ev, - struct confdb_ctx *cdb, - struct sbus_method *methods, - sbus_conn_destructor_fn destructor) -{ - struct service_sbus_ctx *ss_ctx; - struct sbus_method_ctx *sm_ctx; - TALLOC_CTX *ctx; - char *sbus_address; - char *default_monitor_address; - DBusConnection *conn; - int ret; - - ctx = talloc_new(mem_ctx); - if (ctx == NULL) goto error; - - ss_ctx = talloc_zero(ctx, struct service_sbus_ctx); - if (ss_ctx == NULL) return NULL; - - default_monitor_address = talloc_asprintf(ctx, "unix:path=%s/%s", - PIPE_PATH, SSSD_SERVICE_PIPE); - if (default_monitor_address == NULL) goto error; - - ret = confdb_get_string(cdb, ctx, - "config/services/monitor", "sbusAddress", - default_monitor_address, &sbus_address); - if (ret != EOK) goto error; - ss_ctx->ev = ev; - - ret = sbus_new_connection(ss_ctx, ss_ctx->ev, - sbus_address, &ss_ctx->scon_ctx, - destructor); - if (ret != EOK) goto error; - - conn = sbus_get_connection(ss_ctx->scon_ctx); - - /* set up handler for service methods */ - sm_ctx = talloc_zero(ss_ctx, struct sbus_method_ctx); - if (sm_ctx == NULL) goto error; - - sm_ctx->interface = talloc_strdup(sm_ctx, SERVICE_INTERFACE); - sm_ctx->path = talloc_strdup(sm_ctx, SERVICE_PATH); - if (!sm_ctx->interface || !sm_ctx->path) goto error; - - /* Set up required monitor methods and handlers */ - sm_ctx->methods = methods; - sm_ctx->message_handler = sbus_message_handler; - sbus_conn_add_method_ctx(ss_ctx->scon_ctx, sm_ctx); - - talloc_steal(mem_ctx,ss_ctx); - talloc_free(ctx); - return ss_ctx; - -error: - talloc_free(ctx); - return NULL; -} diff --git a/server/util/service_helpers.h b/server/util/service_helpers.h deleted file mode 100644 index 05777ea2..00000000 --- a/server/util/service_helpers.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - SSSD - - Service monitor - - Copyright (C) Stephen Gallagher 2008 - - 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 <http://www.gnu.org/licenses/>. - */ - -#ifndef SERVICE_HELPERS_H_ -#define SERVICE_HELPERS_H_ - -struct service_sbus_ctx { - struct event_context *ev; - struct sbus_conn_ctx *scon_ctx; -}; - -/* - * Set up an SBUS connection to the monitor - */ -struct service_sbus_ctx *sssd_service_sbus_init(TALLOC_CTX *mem_ctx, - struct event_context *ev, - struct confdb_ctx *cdb, - struct sbus_method *methods, - sbus_conn_destructor_fn destructor); - -#endif /*SERVICE_HELPERS_H_*/ |