From de38bb8f2f04dcefbbe4a998c9bd8532c844bcc0 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mon, 26 Jan 2009 16:01:26 -0500 Subject: Preliminary support for enabling InfoPipe to listen on the D-BUS system bus. It will connect and authenticate successfully (using the included D-BUS policy file installed in the correct /etc directory. Does not yet listen for requests. --- server/Makefile.in | 10 ++- server/conf_macros.m4 | 14 ++++ server/configure.ac | 1 + server/infopipe/infopipe.c | 14 +++- server/infopipe/infopipe.h | 1 + server/infopipe/org.freeipa.sssd.infopipe.conf | 22 +++++++ server/infopipe/sysbus.c | 89 ++++++++++++++++++++++++++ server/infopipe/sysbus.h | 33 ++++++++++ server/server.mk | 3 +- 9 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 server/infopipe/org.freeipa.sssd.infopipe.conf create mode 100644 server/infopipe/sysbus.c create mode 100644 server/infopipe/sysbus.h (limited to 'server') diff --git a/server/Makefile.in b/server/Makefile.in index 656be8a6e..0206b372f 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -61,7 +61,10 @@ OBJS = $(SERVER_OBJ) @LIBREPLACEOBJ@ $(EXTRA_OBJ) headers = +DBUS_SYSBUS_POLICY_DIR = @sysbuspath@ + LIBEXECBINS = sbin/sssd_nss sbin/sssd_dp sbin/sssd_be sbin/sssd_info sbin/sssd_pk +DBUS_SYSBUS_POLICIES = infopipe/org.freeipa.sssd.infopipe.conf BINS = sbin/sssd $(LIBEXECBINS) SOLIBS = lib/libsss_proxy.$(SHLIBEXT) @@ -90,10 +93,10 @@ distclean:: clean realdistclean:: distclean rm -f configure config.h.in -install:: all installdirs installheaders installlibs installbin +install:: all installdirs installheaders installlibs installbin installsupport installdirs:: - mkdir -p $(DESTDIR)$(includedir) $(DESTDIR)$(libdir) $(DESTDIR)$(sbindir) + mkdir -p $(DESTDIR)$(includedir) $(DESTDIR)$(libdir) $(DESTDIR)$(sbindir) $(DBUS_SYSBUS_POLICY_DIR) installheaders:: installdirs ifneq (x$(headers), x) @@ -107,4 +110,7 @@ endif installbin:: installdirs +installsupport:: installdirs + cp $(DBUS_SYSBUS_POLICIES) $(DBUS_SYSBUS_POLICY_DIR) + include $(srvdir)/server.mk diff --git a/server/conf_macros.m4 b/server/conf_macros.m4 index 9aac02c5b..33290d892 100644 --- a/server/conf_macros.m4 +++ b/server/conf_macros.m4 @@ -57,3 +57,17 @@ AC_DEFUN(WITH_PIPE_PATH, AC_SUBST(pipepath) AC_DEFINE_UNQUOTED(PIPE_PATH, "$pipepath", [Where to store pipe files for the SSSD interconnects]) ]) + +AC_DEFUN(WITH_DBUS_SYSBUS_PATH, + [ AC_ARG_WITH([dbus-sysbus-path], + [AC_HELP_STRING([--with-dbus-sysbus-path=PATH], + [Where to store policy files for the D-BUS system bus [/etc/dbus-1/system.d]] + ) + ] + ) + sysbuspath="/etc/dbus-1/system.d" + if test x"$with_dbus_sysbus_path" != x; then + sysbuspath=$with_dbus_sysbus_path + fi + AC_SUBST(sysbuspath) + ]) diff --git a/server/configure.ac b/server/configure.ac index 94c057f42..54dedd9d8 100644 --- a/server/configure.ac +++ b/server/configure.ac @@ -37,6 +37,7 @@ WITH_DB_PATH WITH_PLUGIN_PATH WITH_PID_PATH WITH_PIPE_PATH +WITH_DBUS_SYSBUS_PATH m4_include(pkg.m4) m4_include(libpopt.m4) diff --git a/server/infopipe/infopipe.c b/server/infopipe/infopipe.c index 14e0354f0..81541d82d 100644 --- a/server/infopipe/infopipe.c +++ b/server/infopipe/infopipe.c @@ -24,15 +24,22 @@ #include "popt.h" #include "infopipe.h" #include "util/util.h" +#include "sbus/sssd_dbus.h" #include "sbus/sbus_client.h" #include "monitor/monitor_sbus.h" #include "monitor/monitor_interfaces.h" +#include "infopipe/sysbus.h" struct infp_ctx { struct event_context *ev; struct confdb_ctx *cdb; struct service_sbus_ctx *ss_ctx; - struct sbus_srv_ctx *sbus_srv; + struct sysbus_ctx *sysbus; +}; + +struct sbus_method infp_methods[] = { + { SYSBUS_GET_PARAM, sysbus_get_param }, + { NULL, NULL } }; static int service_identity(DBusMessage *message, void *data, DBusMessage **r) @@ -142,10 +149,15 @@ static int infp_process_init(TALLOC_CTX *mem_ctx, infp_ctx->ev = ev; infp_ctx->cdb = cdb; + /* Connect to the monitor */ ret = infp_monitor_init(infp_ctx); if (ret != EOK) { DEBUG(0, ("Fatal error setting up monitor bus\n")); } + + /* Connect to the D-BUS system bus */ + ret = sysbus_init(infp_ctx, &infp_ctx->sysbus, infp_methods); + return ret; } diff --git a/server/infopipe/infopipe.h b/server/infopipe/infopipe.h index c888b1daf..259729aae 100644 --- a/server/infopipe/infopipe.h +++ b/server/infopipe/infopipe.h @@ -22,6 +22,7 @@ #ifndef INFOPIPE_H_ #define INFOPIPE_H_ +#define INFOPIPE_DBUS_NAME "org.freeipa.sssd.infopipe" #define INFOPIPE_VERSION 0x0001 #define INFOPIPE_SERVICE_NAME "infp" diff --git a/server/infopipe/org.freeipa.sssd.infopipe.conf b/server/infopipe/org.freeipa.sssd.infopipe.conf new file mode 100644 index 000000000..e33eb30c7 --- /dev/null +++ b/server/infopipe/org.freeipa.sssd.infopipe.conf @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/server/infopipe/sysbus.c b/server/infopipe/sysbus.c new file mode 100644 index 000000000..2c28bacc7 --- /dev/null +++ b/server/infopipe/sysbus.c @@ -0,0 +1,89 @@ +/* + SSSD + + SystemBus 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 "talloc.h" +#include "tevent.h" +#include "util/util.h" +#include "dbus/dbus.h" +#include "sbus/sssd_dbus.h" +#include "sysbus.h" +#include "infopipe/infopipe.h" + +struct sysbus_ctx { + DBusConnection *conn; + struct sbus_method_ctx *method_ctx_list; + void *pvt_data; +}; + +static int sysbus_destructor(TALLOC_CTX *ctx) { + struct sysbus_ctx *system_bus = talloc_get_type(ctx, struct sysbus_ctx); + dbus_connection_unref(system_bus->conn); + return EOK; +} + +int sysbus_init(TALLOC_CTX *mem_ctx, struct sysbus_ctx **sysbus, struct sbus_method *methods) +{ + DBusError dbus_error; + struct sysbus_ctx *system_bus; + int ret; + + system_bus = talloc_zero(mem_ctx, struct sysbus_ctx); + if (system_bus == NULL) { + return ENOMEM; + } + + dbus_error_init(&dbus_error); + + /* Connect to the well-known system bus */ + system_bus->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error); + if (system_bus->conn == NULL) { + DEBUG(0, ("Failed to connect to D-BUS system bus.\n")); + talloc_free(system_bus); + return EIO; + } + dbus_connection_set_exit_on_disconnect(system_bus->conn, FALSE); + talloc_set_destructor((TALLOC_CTX *)system_bus, + sysbus_destructor); + + ret = dbus_bus_request_name(system_bus->conn, + INFOPIPE_DBUS_NAME, + /* We want exclusive access */ + DBUS_NAME_FLAG_DO_NOT_QUEUE, + &dbus_error + ); + if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + /* We were unable to register on the system bus */ + DEBUG(0, ("Unable to request name on the system bus. Error: %s\n", dbus_error.message)); + talloc_free(system_bus); + return EIO; + } + + DEBUG(1, ("Listening on %s\n", INFOPIPE_DBUS_NAME)); + + *sysbus = system_bus; + return EOK; +} + +int sysbus_get_param(DBusMessage *message, void *data, DBusMessage **r) { + /* TODO: remove this */ + DEBUG(0, ("Received message. Printing this garbage.\n")); + return EOK; +} diff --git a/server/infopipe/sysbus.h b/server/infopipe/sysbus.h new file mode 100644 index 000000000..f47219b7a --- /dev/null +++ b/server/infopipe/sysbus.h @@ -0,0 +1,33 @@ +/* + SSSD + + SystemBus 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 SYSBUS_H_ +#define SYSBUS_H_ + +#define SYSBUS_GET_PARAM "getParam" + +struct sysbus_ctx; + +int sysbus_init(TALLOC_CTX *mem_ctx, struct sysbus_ctx **sysbus, struct sbus_method *methods); + +int sysbus_get_param(DBusMessage *message, void *data, DBusMessage **r); + +#endif /* SYSBUS_H_ */ diff --git a/server/server.mk b/server/server.mk index 54f9629ac..58a49e593 100644 --- a/server/server.mk +++ b/server/server.mk @@ -32,7 +32,8 @@ NSSSRV_OBJ = \ nss/nsssrv_dp.o INFOPIPE_OBJ = \ - infopipe/infopipe.o + infopipe/infopipe.o \ + infopipe/sysbus.o POLKIT_OBJ = \ polkit/sssd_polkit.o -- cgit