8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina Pavel Březina <pbrezina@redhat.com>
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina Copyright (C) 2014 Red Hat
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina This program is free software; you can redistribute it and/or modify
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina it under the terms of the GNU General Public License as published by
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina the Free Software Foundation; either version 3 of the License, or
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina (at your option) any later version.
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina This program is distributed in the hope that it will be useful,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina GNU General Public License for more details.
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina You should have received a copy of the GNU General Public License
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
62ebed8582285bd24efba92b9a06366511507946Pavel Březina#define PATH_MONITOR IFP_PATH_COMPONENTS "/monitor"
62ebed8582285bd24efba92b9a06366511507946Pavel Březina#define PATH_RESPONDERS IFP_PATH_COMPONENTS "/Responders"
62ebed8582285bd24efba92b9a06366511507946Pavel Březina#define PATH_BACKENDS IFP_PATH_COMPONENTS "/Backends"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char * const *svc = get_known_services();
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return false;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic bool backend_exists(struct confdb_ctx *confdb, const char *name)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_list_all_domain_names(NULL, confdb, &names);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return false;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return false;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic errno_t check_and_get_component_from_path(TALLOC_CTX *mem_ctx,
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(mem_ctx, path, PATH_RESPONDERS);
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(mem_ctx, path, PATH_BACKENDS);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic errno_t list_responders(TALLOC_CTX *mem_ctx,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char ***_list,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char * const *svc = get_known_services();
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina list = talloc_array(mem_ctx, const char*, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num; i++) {
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina list[i] = sbus_opath_compose(list, PATH_RESPONDERS, svc[i]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic errno_t list_backends(TALLOC_CTX *mem_ctx,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char ***_list,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_list_all_domain_names(tmp_ctx, confdb, &names);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina list = talloc_array(tmp_ctx, const char*, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num; i++) {
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina list[i] = sbus_opath_compose(list, PATH_BACKENDS, names[i]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_list_components(struct sbus_request *dbus_req, void *data)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_responders(dbus_req, &responders, &num_responders);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_backends(dbus_req, ctx->rctx->cdb, &backends, &num_backends);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina result = talloc_array(dbus_req, const char*, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num_responders; i++) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina result[i + 1] = talloc_steal(result, responders[i]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num_backends; i++) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina result[i + num_responders + 1] = talloc_steal(result, backends[i]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_ListComponents_finish(dbus_req, result, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_list_responders(struct sbus_request *dbus_req, void *data)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_responders(dbus_req, &result, &num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_ListResponders_finish(dbus_req, result, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_list_backends(struct sbus_request *dbus_req, void *data)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_backends(dbus_req, ctx->rctx->cdb, &result, &num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_ListBackends_finish(dbus_req, result, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_find_monitor(struct sbus_request *dbus_req, void *data)
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_FindMonitor_finish(dbus_req, PATH_MONITOR);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_find_responder_by_name(struct sbus_request *dbus_req,
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina result = sbus_opath_compose(dbus_req, PATH_RESPONDERS, arg_name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, NULL);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_FindResponderByName_finish(dbus_req, result);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_find_backend_by_name(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (backend_exists(ctx->rctx->cdb, arg_name)) {
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina result = sbus_opath_compose(dbus_req, PATH_BACKENDS, arg_name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, NULL);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_FindBackendByName_finish(dbus_req, result);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_name(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **_out)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_debug_level(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina confdb_path = talloc_asprintf(dbus_req, CONFDB_SERVICE_PATH_TMPL, name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina confdb_path = talloc_asprintf(dbus_req, CONFDB_DOMAIN_PATH_TMPL, name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_get_int(ctx->rctx->cdb, confdb_path,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_SERVICE_DEBUG_LEVEL, SSSDBG_DEFAULT, &level);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unable to retrieve configuration option"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_enabled(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_get_string_as_list(ctx->rctx->cdb, dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unable to retrieve configuration option"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_type(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **_out)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_backend_get_providers(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char ***_out,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina static const char *providers[] = {CONFDB_DOMAIN_ID_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num_providers = sizeof(providers) / sizeof(providers[0]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(tmp_ctx, ctx->rctx->cdb,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina confdb_path = talloc_asprintf(tmp_ctx, CONFDB_DOMAIN_PATH_TMPL, name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina out = talloc_zero_array(tmp_ctx, const char*, num_providers);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num_providers; i++) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_get_string(ctx->rctx->cdb, tmp_ctx, confdb_path,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina out[j] = talloc_asprintf(out, "%s=%s", providers[i], value);