From a9714955317988004becfe6218db3cf51e627609 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Thu, 19 Feb 2009 14:34:00 -0500 Subject: [PATCH] Adding initial framework for the InfoPipe --- server/infopipe/infopipe.c | 42 +++- server/infopipe/infopipe.h | 83 ++++++- server/infopipe/infopipe_groups.c | 54 ++++ server/infopipe/infopipe_users.c | 59 +++++ .../org.freeipa.sssd.infopipe.Introspect.xml | 275 ++++++++++++++++++++ server/infopipe/org.freeipa.sssd.infopipe.conf | 16 +- server/infopipe/sysbus.c | 158 ----------- server/infopipe/sysbus.h | 35 --- server/sbus/sssd_dbus.h | 5 + server/sbus/sssd_dbus_connection.c | 28 ++- server/server.mk | 6 +- server/util/sysbus.c | 166 ++++++++++++ server/util/sysbus.h | 35 +++ 13 files changed, 740 insertions(+), 222 deletions(-) create mode 100644 server/infopipe/infopipe_groups.c create mode 100644 server/infopipe/infopipe_users.c create mode 100644 server/infopipe/org.freeipa.sssd.infopipe.Introspect.xml delete mode 100644 server/infopipe/sysbus.c delete mode 100644 server/infopipe/sysbus.h create mode 100644 server/util/sysbus.c create mode 100644 server/util/sysbus.h diff --git a/server/infopipe/infopipe.c b/server/infopipe/infopipe.c index a0654c4..f7986a6 100644 --- a/server/infopipe/infopipe.c +++ b/server/infopipe/infopipe.c @@ -22,13 +22,14 @@ #include #include #include "popt.h" -#include "infopipe.h" #include "util/util.h" +#include "util/btreemap.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" +#include "util/sysbus.h" +#include "infopipe.h" struct infp_ctx { struct event_context *ev; @@ -37,11 +38,6 @@ struct infp_ctx { struct sysbus_ctx *sysbus; }; -struct sbus_method infp_methods[] = { - { SYSBUS_READ_ATTR, sysbus_get_param }, - { NULL, NULL } -}; - static int service_identity(DBusMessage *message, void *data, DBusMessage **r) { dbus_uint16_t version = INFOPIPE_VERSION; @@ -134,12 +130,26 @@ static int infp_monitor_init(struct infp_ctx *infp_ctx) return EOK; } +struct sbus_method infp_methods[] = { + INFP_USER_METHODS + INFP_GROUP_METHODS + { NULL, NULL } +}; + +int infp_introspect(DBusMessage *message, void *data, DBusMessage **r) +{ + /* Return the Introspection XML */ + + /* TODO: actually return the file */ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + static int infp_process_init(TALLOC_CTX *mem_ctx, struct event_context *ev, struct confdb_ctx *cdb) { struct infp_ctx *infp_ctx; - struct DBusConnection *conn; int ret; infp_ctx = talloc_zero(mem_ctx, struct infp_ctx); @@ -158,15 +168,29 @@ static int infp_process_init(TALLOC_CTX *mem_ctx, } /* Connect to the D-BUS system bus and set up methods */ - ret = sysbus_init(infp_ctx, &infp_ctx->sysbus, infp_ctx->ev, INFOPIPE_DBUS_NAME, infp_methods); + ret = sysbus_init(infp_ctx, &infp_ctx->sysbus, + infp_ctx->ev, INFOPIPE_DBUS_NAME, + INFOPIPE_INTERFACE, INFOPIPE_PATH, + infp_methods, infp_introspect); if (ret != EOK) { DEBUG(0, ("Failed to connect to the system message bus\n")); return EIO; } + /* Add the infp_ctx to the sbus_conn_ctx private data + * so we can pass it into message handler functions + */ + sbus_conn_set_private_data(sysbus_get_sbus_conn(infp_ctx->sysbus), infp_ctx); + return ret; } +int infp_check_permissions(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + int main(int argc, const char *argv[]) { int opt; diff --git a/server/infopipe/infopipe.h b/server/infopipe/infopipe.h index dcd3e4f..8492c1b 100644 --- a/server/infopipe/infopipe.h +++ b/server/infopipe/infopipe.h @@ -22,10 +22,87 @@ #ifndef INFOPIPE_H_ #define INFOPIPE_H_ -#define INFOPIPE_DBUS_NAME "org.freeipa.sssd.infopipe" -#define INFOPIPE_INTERFACE "org.freeipa.sssd.infopipe" -#define INFOPIPE_PATH "/org/freeipa/sssd/infopipe" +#define INFOPIPE_DBUS_NAME "org.freeipa.sssd.infopipe1" +#define INFOPIPE_INTERFACE "org.freeipa.sssd.infopipe1" +#define INFOPIPE_PATH "/org/freeipa/sssd/infopipe1" #define INFOPIPE_VERSION 0x0001 #define INFOPIPE_SERVICE_NAME "infp" +/* InfoPipe Methods + * NOTE: Any changes to the method names and arguments for these calls + * must also be updated in the org.freeipa.sssd.infopipe.Introspect.xml + * or clients may not behave properly. + */ + +/********************************************************** + * Introspection Methods (from infopipe.c) * + **********************************************************/ + +/* This function must be exposed through the + * org.freedesktop.DBus.Introspectable interface + */ +#define INFP_INTROSPECT "Introspect" +int infp_introspect(DBusMessage *message, void *data, DBusMessage **r); + +/********************************************************** + * Permission Methods (from infopipe.c) * + **********************************************************/ +#define INFP_CHECK_PERMISSIONS "CheckPermissions1" +int infp_check_permissions(DBusMessage *message, void *data, DBusMessage **r); + +/********************************************************** + * User Methods (from infopipe_users.c) * + **********************************************************/ +#define INFP_USERS_GET_CACHED "GetCachedUsers1" +int infp_users_get_cached(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_USERS_CREATE "CreateUser1" +int infp_users_create(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_USERS_DELETE "DeleteUser1" +int infp_users_delete(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_USERS_GET_ATTR "GetUserAttributes1" +int infp_users_get_attr(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_USERS_SET_ATTR "SetUserAttributes1" +int infp_users_set_attr(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_USERS_SET_UID "Set_YouReallyDoNotWantToUseThisFunction_UserUID1" +int infp_users_set_uid(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_USER_METHODS \ + {INFP_USERS_GET_CACHED, infp_users_get_cached}, \ + {INFP_USERS_CREATE, infp_users_create}, \ + {INFP_USERS_DELETE, infp_users_delete}, \ + {INFP_USERS_GET_ATTR, infp_users_get_attr}, \ + {INFP_USERS_SET_ATTR, infp_users_set_attr}, \ + {INFP_USERS_SET_UID, infp_users_set_uid}, + +/********************************************************** + * Group Methods (from infopipe_groups.c) * + **********************************************************/ + +#define INFP_GROUPS_CREATE "CreateGroup1" +int infp_groups_create(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_GROUPS_DELETE "DeleteGroup1" +int infp_groups_delete(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_GROUPS_ADD_MEMBERS "AddGroupMembers1" +int infp_groups_add_members(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_GROUPS_REMOVE_MEMBERS "RemoveGroupMembers1" +int infp_groups_remove_members(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_GROUPS_SET_GID "Set_YouReallyDoNotWantToUseThisFunction_GroupGID1" +int infp_groups_set_gid(DBusMessage *message, void *data, DBusMessage **r); + +#define INFP_GROUP_METHODS \ + {INFP_GROUPS_CREATE, infp_groups_create}, \ + {INFP_GROUPS_DELETE, infp_groups_delete}, \ + {INFP_GROUPS_ADD_MEMBERS, infp_groups_add_members}, \ + {INFP_GROUPS_REMOVE_MEMBERS, infp_groups_remove_members}, \ + {INFP_GROUPS_SET_GID, infp_groups_set_gid}, + #endif /* INFOPIPE_H_ */ diff --git a/server/infopipe/infopipe_groups.c b/server/infopipe/infopipe_groups.c new file mode 100644 index 0000000..4b9cfc2 --- /dev/null +++ b/server/infopipe/infopipe_groups.c @@ -0,0 +1,54 @@ +/* + SSSD + + InfoPipe + + 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 +#include "util/util.h" +#include "infopipe.h" + +int infp_groups_create(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_groups_delete(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_groups_add_members(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_groups_remove_members(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_groups_set_gid(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} diff --git a/server/infopipe/infopipe_users.c b/server/infopipe/infopipe_users.c new file mode 100644 index 0000000..632e624 --- /dev/null +++ b/server/infopipe/infopipe_users.c @@ -0,0 +1,59 @@ +/* + SSSD + + InfoPipe + + 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 +#include "util/util.h" +#include "infopipe.h" + +int infp_users_get_cached(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_users_create(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_users_delete(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_users_get_attr(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_users_set_attr(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} + +int infp_users_set_uid(DBusMessage *message, void *data, DBusMessage **r) +{ + *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + return EOK; +} diff --git a/server/infopipe/org.freeipa.sssd.infopipe.Introspect.xml b/server/infopipe/org.freeipa.sssd.infopipe.Introspect.xml new file mode 100644 index 0000000..5c50cfe --- /dev/null +++ b/server/infopipe/org.freeipa.sssd.infopipe.Introspect.xml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/infopipe/org.freeipa.sssd.infopipe.conf b/server/infopipe/org.freeipa.sssd.infopipe.conf index 8b3c760..b9ca558 100644 --- a/server/infopipe/org.freeipa.sssd.infopipe.conf +++ b/server/infopipe/org.freeipa.sssd.infopipe.conf @@ -8,21 +8,15 @@ - - + + - + + within the InfoPipe Daemon. --> - - - - + diff --git a/server/infopipe/sysbus.c b/server/infopipe/sysbus.c deleted file mode 100644 index 1422eb2..0000000 --- a/server/infopipe/sysbus.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - 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 { - struct sbus_conn_ctx *sconn; - struct sbus_method_ctx *sm_ctx; - 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(sbus_get_connection(system_bus->sconn)); - return EOK; -} - -static int sysbus_init_methods(TALLOC_CTX *mem_ctx, struct sysbus_ctx *sysbus, 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) { - return ENOMEM; - } - - method_ctx = talloc_zero(tmp_ctx, struct sbus_method_ctx); - if (!method_ctx) { - ret = ENOMEM; - goto done; - } - - method_ctx->interface = talloc_strdup(method_ctx, INFOPIPE_INTERFACE); - if (method_ctx->interface == NULL) { - ret = ENOMEM; - goto done; - } - - method_ctx->path = talloc_strdup(method_ctx, INFOPIPE_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; -} - -int sysbus_init(TALLOC_CTX *mem_ctx, struct sysbus_ctx **sysbus, - struct event_context *ev, const char *dbus_name, - struct sbus_method *methods) -{ - DBusError dbus_error; - DBusConnection *conn; - 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 */ - conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error); - if (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(conn, FALSE); - talloc_set_destructor((TALLOC_CTX *)system_bus, - sysbus_destructor); - - ret = dbus_bus_request_name(conn, - 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)); - - /* Integrate with TEvent loop */ - ret = sbus_add_connection(system_bus, ev, conn, &system_bus->sconn, SBUS_CONN_TYPE_SHARED); - if (ret != EOK) { - DEBUG(0, ("Could not integrate D-BUS into mainloop.\n")); - talloc_free(system_bus); - return ret; - } - - /* Set up methods */ - ret = sysbus_init_methods(system_bus, system_bus, methods, &system_bus->sm_ctx); - if (ret != EOK) { - talloc_free(system_bus); - return ret; - } - - ret = sbus_conn_add_method_ctx(system_bus->sconn, system_bus->sm_ctx); - if (ret != EOK) { - talloc_free(system_bus); - return ret; - } - - *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; -} - -DBusConnection *sysbus_get_dbus_conn(struct sysbus_ctx *sysbus) { - return sbus_get_connection(sysbus->sconn); -} diff --git a/server/infopipe/sysbus.h b/server/infopipe/sysbus.h deleted file mode 100644 index 00e36cc..0000000 --- a/server/infopipe/sysbus.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - 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_READ_ATTR "ReadAttribute" - -struct sysbus_ctx; - -int sysbus_init(TALLOC_CTX *mem_ctx, struct sysbus_ctx **sysbus, - struct event_context *ev, const char *dbus_name, - struct sbus_method *methods); - -int sysbus_get_param(DBusMessage *message, void *data, DBusMessage **r); - -#endif /* SYSBUS_H_ */ diff --git a/server/sbus/sssd_dbus.h b/server/sbus/sssd_dbus.h index ea48fb8..c75bbc9 100644 --- a/server/sbus/sssd_dbus.h +++ b/server/sbus/sssd_dbus.h @@ -48,6 +48,10 @@ enum { SBUS_CONN_TYPE_SHARED }; +/* Special interface and method for D-BUS introspection */ +#define DBUS_INTROSPECT_INTERFACE "org.freedesktop.DBus.Introspectable" +#define DBUS_INTROSPECT_METHOD "Introspect" + struct sbus_method { const char *method; sbus_msg_handler_fn fn; @@ -59,6 +63,7 @@ struct sbus_method_ctx { char *path; DBusObjectPathMessageFunction message_handler; struct sbus_method *methods; + sbus_msg_handler_fn introspect_fn; }; struct sbus_message_handler_ctx { diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c index 601ca00..d02dc6c 100644 --- a/server/sbus/sssd_dbus_connection.c +++ b/server/sbus/sssd_dbus_connection.c @@ -499,12 +499,12 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, if (!method || !path || !msg_interface) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - /* Validate the method interface */ - if (strcmp(msg_interface, ctx->method_ctx->interface) != 0) + /* Validate the D-BUS path */ + if (strcmp(path, ctx->method_ctx->path) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - /* Validate the D-BUS path */ - if (strcmp(path, ctx->method_ctx->path) == 0) { + /* Validate the method interface */ + if (strcmp(msg_interface, ctx->method_ctx->interface) == 0) { found = 0; for (i = 0; ctx->method_ctx->methods[i].method != NULL; i++) { if (strcmp(method, ctx->method_ctx->methods[i].method) == 0) { @@ -521,6 +521,24 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, reply = dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD, NULL); } } + else { + /* Special case: check for Introspection request + * This is usually only useful for system bus connections + */ + if (strcmp(msg_interface, DBUS_INTROSPECT_INTERFACE) == 0 && + strcmp(method, DBUS_INTROSPECT_METHOD) == 0) + { + if (ctx->method_ctx->introspect_fn) { + /* If we have been asked for introspection data and we have + * an introspection function registered, user that. + */ + ret = ctx->method_ctx->introspect_fn(message, ctx, &reply); + if (ret != EOK) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + else + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } DEBUG(5, ("Method %s complete. Reply was %ssent.\n", method, reply?"":"not ")); @@ -548,6 +566,7 @@ int sbus_conn_add_method_ctx(struct sbus_conn_ctx *dct_ctx, } if (_method_list_contains_path(dct_ctx->method_ctx_list, method_ctx)) { + DEBUG(0, ("Cannot add method context with identical path.\n")); return EINVAL; } @@ -579,6 +598,7 @@ int sbus_conn_add_method_ctx(struct sbus_conn_ctx *dct_ctx, dbret = dbus_connection_register_object_path(dct_ctx->conn, method_ctx->path, connection_vtable, msg_handler_ctx); if (!dbret) { + DEBUG(0, ("Could not register object path to the connection.\n")); return ENOMEM; } diff --git a/server/server.mk b/server/server.mk index 4832f00..53801fb 100644 --- a/server/server.mk +++ b/server/server.mk @@ -4,6 +4,7 @@ UTIL_OBJ = \ util/server.o \ util/memory.o \ util/btreemap.o \ + util/sysbus.o \ monitor/monitor_sbus.o \ providers/dp_sbus.o \ sbus/sssd_dbus_common.o \ @@ -35,7 +36,8 @@ NSSSRV_OBJ = \ INFOPIPE_OBJ = \ infopipe/infopipe.o \ - infopipe/sysbus.o + infopipe/infopipe_users.o \ + infopipe/infopipe_groups.o POLKIT_OBJ = \ polkit/sssd_polkit.o @@ -75,4 +77,4 @@ lib/memberof.$(SHLIBEXT): $(MEMBEROF_OBJ) #Tests tests/sysdb-tests: $(SYSDB_TEST_OBJ) $(UTIL_OBJ) lib/libsysdb.$(SHLIBEXT) - $(CC) -o tests/sysdb-tests $(SYSDB_TEST_OBJ) $(UTIL_OBJ) -lsysdb $(LDFLAGS) $(LIBS) $(CHECK_LIBS) \ No newline at end of file + $(CC) -o tests/sysdb-tests $(SYSDB_TEST_OBJ) $(UTIL_OBJ) -lsysdb $(LDFLAGS) $(LIBS) $(CHECK_LIBS) diff --git a/server/util/sysbus.c b/server/util/sysbus.c new file mode 100644 index 0000000..a6b352f --- /dev/null +++ b/server/util/sysbus.c @@ -0,0 +1,166 @@ +/* + 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 { + struct sbus_conn_ctx *sconn; + struct sbus_method_ctx *service_methods; + 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(sbus_get_connection(system_bus->sconn)); + return EOK; +} + +static int sysbus_init_methods(TALLOC_CTX *mem_ctx, + struct sysbus_ctx *sysbus, + const char *interface, + const char *path, + struct sbus_method *methods, + sbus_msg_handler_fn introspect_method, + 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) { + return ENOMEM; + } + + method_ctx = talloc_zero(tmp_ctx, struct sbus_method_ctx); + if (!method_ctx) { + ret = ENOMEM; + goto done; + } + + method_ctx->interface = talloc_strdup(method_ctx, interface); + if (method_ctx->interface == NULL) { + ret = ENOMEM; + goto done; + } + + method_ctx->path = talloc_strdup(method_ctx, path); + if (method_ctx->path == NULL) { + ret = ENOMEM; + goto done; + } + + method_ctx->methods = methods; + method_ctx->introspect_fn = introspect_method; + 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; +} + +int sysbus_init(TALLOC_CTX *mem_ctx, struct sysbus_ctx **sysbus, + struct event_context *ev, const char *dbus_name, + const char *interface, const char *path, + struct sbus_method *methods, + sbus_msg_handler_fn introspect_method) +{ + DBusError dbus_error; + DBusConnection *conn; + 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 */ + conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error); + if (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(conn, FALSE); + talloc_set_destructor((TALLOC_CTX *)system_bus, + sysbus_destructor); + + ret = dbus_bus_request_name(conn, + 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", dbus_name)); + + /* Integrate with TEvent loop */ + ret = sbus_add_connection(system_bus, ev, conn, &system_bus->sconn, SBUS_CONN_TYPE_SHARED); + if (ret != EOK) { + DEBUG(0, ("Could not integrate D-BUS into mainloop.\n")); + talloc_free(system_bus); + return ret; + } + + /* Set up methods */ + ret = sysbus_init_methods(system_bus, system_bus, interface, path, + methods, introspect_method, + &system_bus->service_methods); + if (ret != EOK) { + DEBUG(0, ("Could not set up service methods.\n")); + talloc_free(system_bus); + return ret; + } + + ret = sbus_conn_add_method_ctx(system_bus->sconn, system_bus->service_methods); + if (ret != EOK) { + DEBUG(0, ("Could not add service methods to the connection.\n")); + talloc_free(system_bus); + return ret; + } + + *sysbus = system_bus; + return EOK; +} + +struct sbus_conn_ctx *sysbus_get_sbus_conn(struct sysbus_ctx *sysbus) +{ + return sysbus->sconn; +} diff --git a/server/util/sysbus.h b/server/util/sysbus.h new file mode 100644 index 0000000..f591365 --- /dev/null +++ b/server/util/sysbus.h @@ -0,0 +1,35 @@ +/* + 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_ + +struct sysbus_ctx; + +int sysbus_init(TALLOC_CTX *mem_ctx, struct sysbus_ctx **sysbus, + struct event_context *ev, const char *dbus_name, + const char *interface, const char *path, + struct sbus_method *methods, + sbus_msg_handler_fn introspect_method); + +struct sbus_conn_ctx *sysbus_get_sbus_conn(struct sysbus_ctx *sysbus); + +#endif /* SYSBUS_H_ */ -- 1.6.0.6