diff options
author | Pavel Březina <pbrezina@redhat.com> | 2016-06-20 18:09:39 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2016-06-27 16:34:58 +0200 |
commit | bf83a0faacf16196ab9bd37dcf6190b4209ccaf7 (patch) | |
tree | d58616b69b4e5486e5261f1b38b90830d4a21b95 /src/providers | |
parent | 586fa3571753ab4a607d40fc31503fc0e8effd70 (diff) | |
download | sssd-bf83a0faacf16196ab9bd37dcf6190b4209ccaf7.tar.gz sssd-bf83a0faacf16196ab9bd37dcf6190b4209ccaf7.tar.xz sssd-bf83a0faacf16196ab9bd37dcf6190b4209ccaf7.zip |
DP: Add org.freedesktop.sssd.DataProvider.Failover
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/providers')
-rw-r--r-- | src/providers/backend.h | 23 | ||||
-rw-r--r-- | src/providers/data_provider/dp_iface.c | 6 | ||||
-rw-r--r-- | src/providers/data_provider/dp_iface.h | 5 | ||||
-rw-r--r-- | src/providers/data_provider/dp_iface.xml | 8 | ||||
-rw-r--r-- | src/providers/data_provider/dp_iface_failover.c | 66 | ||||
-rw-r--r-- | src/providers/data_provider/dp_iface_generated.c | 40 | ||||
-rw-r--r-- | src/providers/data_provider/dp_iface_generated.h | 16 | ||||
-rw-r--r-- | src/providers/data_provider_fo.c | 23 |
8 files changed, 163 insertions, 24 deletions
diff --git a/src/providers/backend.h b/src/providers/backend.h index ba0bc5927..305413660 100644 --- a/src/providers/backend.h +++ b/src/providers/backend.h @@ -50,7 +50,28 @@ struct be_resolv_ctx { enum restrict_family family_order; }; -struct be_failover_ctx; +struct be_svc_data { + struct be_svc_data *prev; + struct be_svc_data *next; + + const char *name; + struct fo_service *fo_service; + + struct fo_server *last_good_srv; + time_t last_status_change; + bool run_callbacks; + + struct be_svc_callback *callbacks; + struct fo_server *first_resolved; +}; + +struct be_failover_ctx { + struct fo_ctx *fo_ctx; + struct be_resolv_ctx *be_res; + + struct be_svc_data *svcs; + struct tevent_timer *primary_server_handler; +}; struct be_cb; diff --git a/src/providers/data_provider/dp_iface.c b/src/providers/data_provider/dp_iface.c index 7bd740ad6..1270c8b96 100644 --- a/src/providers/data_provider/dp_iface.c +++ b/src/providers/data_provider/dp_iface.c @@ -41,9 +41,15 @@ struct iface_dp_backend iface_dp_backend = { .IsOnline = dp_backend_is_online }; +struct iface_dp_failover iface_dp_failover = { + {&iface_dp_backend_meta, 0}, + .ListServices = dp_failover_list_services +}; + static struct sbus_iface_map dp_map[] = { { DP_PATH, &iface_dp.vtable }, { DP_PATH, &iface_dp_backend.vtable }, + { DP_PATH, &iface_dp_failover.vtable }, { NULL, NULL } }; diff --git a/src/providers/data_provider/dp_iface.h b/src/providers/data_provider/dp_iface.h index 8354b1d3a..76e623d21 100644 --- a/src/providers/data_provider/dp_iface.h +++ b/src/providers/data_provider/dp_iface.h @@ -64,4 +64,9 @@ errno_t dp_backend_is_online(struct sbus_request *sbus_req, void *dp_cli, const char *domain); +/* org.freedesktop.sssd.DataProvider.Failover */ +errno_t dp_failover_list_services(struct sbus_request *sbus_req, + void *dp_cli, + const char *domname); + #endif /* DP_IFACE_H_ */ diff --git a/src/providers/data_provider/dp_iface.xml b/src/providers/data_provider/dp_iface.xml index da16eb639..eab7fc0f1 100644 --- a/src/providers/data_provider/dp_iface.xml +++ b/src/providers/data_provider/dp_iface.xml @@ -16,6 +16,14 @@ </method> </interface> + <interface name="org.freedesktop.sssd.DataProvider.Failover"> + <annotation value="iface_dp_failover" name="org.freedesktop.DBus.GLib.CSymbol"/> + <method name="ListServices"> + <arg name="domain_name" type="s" direction="in" /> + <arg name="services" type="as" direction="out" /> + </method> + </interface> + <interface name="org.freedesktop.sssd.dataprovider"> <annotation value="iface_dp" name="org.freedesktop.DBus.GLib.CSymbol"/> <method name="pamHandler"> diff --git a/src/providers/data_provider/dp_iface_failover.c b/src/providers/data_provider/dp_iface_failover.c new file mode 100644 index 000000000..038791088 --- /dev/null +++ b/src/providers/data_provider/dp_iface_failover.c @@ -0,0 +1,66 @@ +/* + Authors: + Pavel Březina <pbrezina@redhat.com> + + Copyright (C) 2016 Red Hat + + 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 <talloc.h> +#include <tevent.h> + +#include "sbus/sssd_dbus.h" +#include "sbus/sssd_dbus_errors.h" +#include "providers/data_provider/dp_private.h" +#include "providers/data_provider/dp_iface.h" +#include "providers/backend.h" +#include "util/util.h" + +errno_t dp_failover_list_services(struct sbus_request *sbus_req, + void *dp_cli, + const char *domname) +{ + struct be_ctx *be_ctx; + struct be_svc_data *svc; + const char **services; + int num_services; + + be_ctx = dp_client_be(dp_cli); + + num_services = 0; + DLIST_FOR_EACH(svc, be_ctx->be_fo->svcs) { + num_services++; + } + + services = talloc_zero_array(sbus_req, const char *, num_services); + if (services == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n"); + return ENOMEM; + } + + num_services = 0; + DLIST_FOR_EACH(svc, be_ctx->be_fo->svcs) { + services[num_services] = talloc_strdup(services, svc->name); + if (services[num_services] == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n"); + talloc_free(services); + return ENOMEM; + } + num_services++; + } + + iface_dp_failover_ListServices_finish(sbus_req, services, num_services); + return EOK; +} diff --git a/src/providers/data_provider/dp_iface_generated.c b/src/providers/data_provider/dp_iface_generated.c index 388aa39d2..7b36fd8aa 100644 --- a/src/providers/data_provider/dp_iface_generated.c +++ b/src/providers/data_provider/dp_iface_generated.c @@ -92,6 +92,46 @@ const struct sbus_interface_meta iface_dp_backend_meta = { sbus_invoke_get_all, /* GetAll invoker */ }; +/* arguments for org.freedesktop.sssd.DataProvider.Failover.ListServices */ +const struct sbus_arg_meta iface_dp_failover_ListServices__in[] = { + { "domain_name", "s" }, + { NULL, } +}; + +/* arguments for org.freedesktop.sssd.DataProvider.Failover.ListServices */ +const struct sbus_arg_meta iface_dp_failover_ListServices__out[] = { + { "services", "as" }, + { NULL, } +}; + +int iface_dp_failover_ListServices_finish(struct sbus_request *req, const char *arg_services[], int len_services) +{ + return sbus_request_return_and_finish(req, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &arg_services, len_services, + DBUS_TYPE_INVALID); +} + +/* methods for org.freedesktop.sssd.DataProvider.Failover */ +const struct sbus_method_meta iface_dp_failover__methods[] = { + { + "ListServices", /* name */ + iface_dp_failover_ListServices__in, + iface_dp_failover_ListServices__out, + offsetof(struct iface_dp_failover, ListServices), + invoke_s_method, + }, + { NULL, } +}; + +/* interface info for org.freedesktop.sssd.DataProvider.Failover */ +const struct sbus_interface_meta iface_dp_failover_meta = { + "org.freedesktop.sssd.DataProvider.Failover", /* name */ + iface_dp_failover__methods, + NULL, /* no signals */ + NULL, /* no properties */ + sbus_invoke_get_all, /* GetAll invoker */ +}; + /* arguments for org.freedesktop.sssd.dataprovider.autofsHandler */ const struct sbus_arg_meta iface_dp_autofsHandler__in[] = { { "dp_flags", "u" }, diff --git a/src/providers/data_provider/dp_iface_generated.h b/src/providers/data_provider/dp_iface_generated.h index 28b018354..977ab3bae 100644 --- a/src/providers/data_provider/dp_iface_generated.h +++ b/src/providers/data_provider/dp_iface_generated.h @@ -19,6 +19,10 @@ #define IFACE_DP_BACKEND "org.freedesktop.sssd.DataProvider.Backend" #define IFACE_DP_BACKEND_ISONLINE "IsOnline" +/* constants for org.freedesktop.sssd.DataProvider.Failover */ +#define IFACE_DP_FAILOVER "org.freedesktop.sssd.DataProvider.Failover" +#define IFACE_DP_FAILOVER_LISTSERVICES "ListServices" + /* constants for org.freedesktop.sssd.dataprovider */ #define IFACE_DP "org.freedesktop.sssd.dataprovider" #define IFACE_DP_PAMHANDLER "pamHandler" @@ -64,6 +68,15 @@ struct iface_dp_backend { /* finish function for IsOnline */ int iface_dp_backend_IsOnline_finish(struct sbus_request *req, bool arg_status); +/* vtable for org.freedesktop.sssd.DataProvider.Failover */ +struct iface_dp_failover { + struct sbus_vtable vtable; /* derive from sbus_vtable */ + int (*ListServices)(struct sbus_request *req, void *data, const char *arg_domain_name); +}; + +/* finish function for ListServices */ +int iface_dp_failover_ListServices_finish(struct sbus_request *req, const char *arg_services[], int len_services); + /* vtable for org.freedesktop.sssd.dataprovider */ struct iface_dp { struct sbus_vtable vtable; /* derive from sbus_vtable */ @@ -103,6 +116,9 @@ extern const struct sbus_interface_meta iface_dp_client_meta; /* interface info for org.freedesktop.sssd.DataProvider.Backend */ extern const struct sbus_interface_meta iface_dp_backend_meta; +/* interface info for org.freedesktop.sssd.DataProvider.Failover */ +extern const struct sbus_interface_meta iface_dp_failover_meta; + /* interface info for org.freedesktop.sssd.dataprovider */ extern const struct sbus_interface_meta iface_dp_meta; diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c index 1e858c354..332174e34 100644 --- a/src/providers/data_provider_fo.c +++ b/src/providers/data_provider_fo.c @@ -34,29 +34,6 @@ struct be_svc_callback { void *private_data; }; -struct be_svc_data { - struct be_svc_data *prev; - struct be_svc_data *next; - - const char *name; - struct fo_service *fo_service; - - struct fo_server *last_good_srv; - time_t last_status_change; - bool run_callbacks; - - struct be_svc_callback *callbacks; - struct fo_server *first_resolved; -}; - -struct be_failover_ctx { - struct fo_ctx *fo_ctx; - struct be_resolv_ctx *be_res; - - struct be_svc_data *svcs; - struct tevent_timer *primary_server_handler; -}; - static const char *proto_table[] = { FO_PROTO_TCP, FO_PROTO_UDP, NULL }; int be_fo_is_srv_identifier(const char *server) |