summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/nss/nsssrv.c57
-rw-r--r--server/nss/nsssrv.h8
-rw-r--r--server/providers/data_provider.c54
-rw-r--r--server/providers/data_provider.h8
-rw-r--r--server/sbus/sssd_dbus.h2
-rw-r--r--server/server.mk1
-rw-r--r--server/util/service_helpers.c99
-rw-r--r--server/util/service_helpers.h39
8 files changed, 168 insertions, 100 deletions
diff --git a/server/nss/nsssrv.c b/server/nss/nsssrv.c
index d66fe90c..fff563d0 100644
--- a/server/nss/nsssrv.c
+++ b/server/nss/nsssrv.c
@@ -39,6 +39,7 @@
#include "sbus/sssd_dbus.h"
#include "sbus_interfaces.h"
#include "util/btreemap.h"
+#include "util/service_helpers.h"
static int provide_identity(DBusMessage *message, void *data, DBusMessage **r);
static int reply_ping(DBusMessage *message, void *data, DBusMessage **r);
@@ -245,53 +246,21 @@ static int reply_ping(DBusMessage *message, void *data, DBusMessage **r)
static int nss_sbus_init(struct nss_ctx *nctx)
{
- struct nss_sbus_ctx *ns_ctx;
- DBusConnection *dbus_conn;
- char *sbus_address;
- int ret;
-
- ret = confdb_get_string(nctx->cdb, nctx,
- "config/services/monitor", "sbusAddress",
- DEFAULT_SBUS_ADDRESS, &sbus_address);
- if (ret != EOK) {
- return ret;
+ struct service_sbus_ctx *ss_ctx;
+
+ /* Set up SBUS connection to the monitor */
+ ss_ctx = sssd_service_sbus_init(nctx, nctx->ev, nctx->cdb,
+ provide_identity,
+ reply_ping);
+ if (ss_ctx == NULL) {
+ DEBUG(0, ("Could not initialize D-BUS.\n"));
+ return ENOMEM;
}
- ns_ctx = talloc(nctx, struct nss_sbus_ctx);
- if (!ns_ctx) {
- return ENOMEM;
- }
- ns_ctx->ev = nctx->ev;
-
- ret = sbus_new_connection(ns_ctx, ns_ctx->ev,
- sbus_address,
- &ns_ctx->scon_ctx, NULL);
- if (ret != EOK) {
- talloc_free(ns_ctx);
- return ret;
- }
-
- dbus_conn = sbus_get_connection(ns_ctx->scon_ctx);
-
- /* set up handler for service methods */
- ns_ctx->sm_ctx = talloc_zero(ns_ctx, struct sbus_method_ctx);
- if (!ns_ctx->sm_ctx) {
- talloc_free(ns_ctx);
- return ENOMEM;
- }
- ns_ctx->sm_ctx->interface = talloc_strdup(ns_ctx->sm_ctx,
- SERVICE_INTERFACE);
- ns_ctx->sm_ctx->path = talloc_strdup(ns_ctx->sm_ctx,
- SERVICE_PATH);
- if (!ns_ctx->sm_ctx->interface || !ns_ctx->sm_ctx->path) {
- talloc_free(ns_ctx);
- return ENOMEM;
- }
- ns_ctx->sm_ctx->methods = nss_sbus_methods;
- ns_ctx->sm_ctx->message_handler = sbus_message_handler;
- sbus_conn_add_method_ctx(ns_ctx->scon_ctx, ns_ctx->sm_ctx);
+ /* Set up NSS-specific listeners */
+ /* None currently used */
- nctx->ns_ctx = ns_ctx;
+ nctx->ss_ctx = ss_ctx;
return EOK;
}
diff --git a/server/nss/nsssrv.h b/server/nss/nsssrv.h
index cf07ad49..28949879 100644
--- a/server/nss/nsssrv.h
+++ b/server/nss/nsssrv.h
@@ -35,12 +35,6 @@
struct nss_ldb_ctx;
struct getent_ctx;
-struct nss_sbus_ctx {
- struct event_context *ev;
- struct sbus_method_ctx *sm_ctx;
- struct sbus_conn_ctx *scon_ctx;
-};
-
struct nss_ctx {
struct event_context *ev;
struct fd_event *lfde;
@@ -48,7 +42,7 @@ struct nss_ctx {
struct nss_ldb_ctx *lctx;
struct confdb_ctx *cdb;
char *sock_name;
- struct nss_sbus_ctx *ns_ctx;
+ struct service_sbus_ctx *ss_ctx;
struct btreemap *domain_map;
};
diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c
index 565581a8..7adcbf6a 100644
--- a/server/providers/data_provider.c
+++ b/server/providers/data_provider.c
@@ -39,6 +39,7 @@
#include "sbus_interfaces.h"
#include "util/btreemap.h"
#include "data_provider.h"
+#include "util/service_helpers.h"
static int provide_identity(DBusMessage *message, void *data, DBusMessage **r);
static int reply_ping(DBusMessage *message, void *data, DBusMessage **r);
@@ -86,52 +87,21 @@ static int reply_ping(DBusMessage *message, void *data, DBusMessage **r)
static int dp_monitor_init(struct dp_ctx *dpctx)
{
- struct dp_sbus_ctx *sbus_ctx;
- DBusConnection *dbus_conn;
- char *sbus_address;
- int ret;
-
- ret = confdb_get_string(dpctx->cdb, dpctx,
- "config/services/monitor", "sbusAddress",
- DEFAULT_SBUS_ADDRESS, &sbus_address);
- if (ret != EOK) {
- return ret;
- }
-
- sbus_ctx = talloc(dpctx, struct dp_sbus_ctx);
- if (!sbus_ctx) {
+ struct service_sbus_ctx *ss_ctx;
+
+ /* Set up SBUS connection to the monitor */
+ ss_ctx = sssd_service_sbus_init(dpctx, dpctx->ev, dpctx->cdb,
+ provide_identity,
+ reply_ping);
+ if (ss_ctx == NULL) {
+ DEBUG(0, ("Could not initialize D-BUS.\n"));
return ENOMEM;
}
- sbus_ctx->ev = dpctx->ev;
- ret = sbus_new_connection(sbus_ctx, sbus_ctx->ev,
- sbus_address,
- &sbus_ctx->scon_ctx, NULL);
- if (ret != EOK) {
- talloc_free(sbus_ctx);
- return ret;
- }
- dbus_conn = sbus_get_connection(sbus_ctx->scon_ctx);
-
- /* set up handler for service methods */
- sbus_ctx->sm_ctx = talloc_zero(sbus_ctx, struct sbus_method_ctx);
- if (!sbus_ctx->sm_ctx) {
- talloc_free(sbus_ctx);
- return ENOMEM;
- }
- sbus_ctx->sm_ctx->interface = talloc_strdup(sbus_ctx->sm_ctx,
- SERVICE_INTERFACE);
- sbus_ctx->sm_ctx->path = talloc_strdup(sbus_ctx->sm_ctx,
- SERVICE_PATH);
- if (!sbus_ctx->sm_ctx->interface || !sbus_ctx->sm_ctx->path) {
- talloc_free(sbus_ctx);
- return ENOMEM;
- }
- sbus_ctx->sm_ctx->methods = mon_sbus_methods;
- sbus_ctx->sm_ctx->message_handler = sbus_message_handler;
- sbus_conn_add_method_ctx(sbus_ctx->scon_ctx, sbus_ctx->sm_ctx);
+ /* Set up DP-specific listeners */
+ /* None currently used */
- dpctx->sbus_ctx = sbus_ctx;
+ dpctx->ss_ctx = ss_ctx;
return EOK;
}
diff --git a/server/providers/data_provider.h b/server/providers/data_provider.h
index 366cd6f6..7ed796ac 100644
--- a/server/providers/data_provider.h
+++ b/server/providers/data_provider.h
@@ -50,17 +50,11 @@ struct dp_module {
void *pvt_data;
};
-struct dp_sbus_ctx {
- struct event_context *ev;
- struct sbus_method_ctx *sm_ctx;
- struct sbus_conn_ctx *scon_ctx;
-};
-
struct dp_ctx {
struct event_context *ev;
struct confdb_ctx *cdb;
struct ldb_context *ldb;
- struct dp_sbus_ctx *sbus_ctx;
+ struct service_sbus_ctx *ss_ctx;
struct dp_module **modules;
};
diff --git a/server/sbus/sssd_dbus.h b/server/sbus/sssd_dbus.h
index 94447a6e..75567ac0 100644
--- a/server/sbus/sssd_dbus.h
+++ b/server/sbus/sssd_dbus.h
@@ -24,6 +24,8 @@
struct sbus_conn_ctx;
+#include "dbus/dbus.h"
+
typedef int (*sbus_msg_handler_fn)(DBusMessage *, void *, DBusMessage **);
/*
diff --git a/server/server.mk b/server/server.mk
index 1196cc56..b8cf51d4 100644
--- a/server/server.mk
+++ b/server/server.mk
@@ -7,6 +7,7 @@ SERVER_OBJ = \
util/become_daemon.o \
util/memory.o \
util/btreemap.o \
+ util/service_helpers.o \
confdb/confdb.o \
nss/nsssrv.o \
nss/nsssrv_packet.o \
diff --git a/server/util/service_helpers.c b/server/util/service_helpers.c
new file mode 100644
index 00000000..9f16d9b1
--- /dev/null
+++ b/server/util/service_helpers.c
@@ -0,0 +1,99 @@
+/*
+ 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 "events.h"
+#include "sbus/sssd_dbus.h"
+#include "confdb/confdb.h"
+#include "service_helpers.h"
+#include "sbus_interfaces.h"
+
+/*
+ * 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,
+ sbus_msg_handler_fn get_identity,
+ sbus_msg_handler_fn ping)
+{
+ struct service_sbus_ctx *ss_ctx;
+ struct sbus_method_ctx *sm_ctx;
+ TALLOC_CTX *ctx;
+ char *sbus_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;
+
+ ret = confdb_get_string(cdb, ctx,
+ "config/services/monitor", "sbusAddress",
+ DEFAULT_SBUS_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,
+ NULL);
+ 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 */
+ sm_ctx->methods = talloc_array(sm_ctx, struct sbus_method, 3);
+ if (sm_ctx->methods == NULL) goto error;
+
+ /* Handle getIdentity */
+ sm_ctx->methods[0].method = SERVICE_METHOD_IDENTITY;
+ sm_ctx->methods[0].fn = get_identity;
+
+ /* Handle ping */
+ sm_ctx->methods[1].method = SERVICE_METHOD_PING;
+ sm_ctx->methods[1].fn = ping;
+
+ /* Terminate the list */
+ sm_ctx->methods[2].method = NULL;
+ sm_ctx->methods[2].fn = NULL;
+
+ 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
new file mode 100644
index 00000000..6435ead5
--- /dev/null
+++ b/server/util/service_helpers.h
@@ -0,0 +1,39 @@
+/*
+ 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,
+ sbus_msg_handler_fn get_identity,
+ sbus_msg_handler_fn ping);
+
+#endif /*SERVICE_HELPERS_H_*/