8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina/*
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina Authors:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina Pavel Březina <pbrezina@redhat.com>
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina Copyright (C) 2014 Red Hat
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
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
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
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/>.
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina*/
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include <string.h>
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include <talloc.h>
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include <signal.h>
09641f85aae8fff72d0573394c40c8c3c002179aPavel Březina#include <errno.h>
09641f85aae8fff72d0573394c40c8c3c002179aPavel Březina#include <utime.h>
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include "config.h"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include "confdb/confdb.h"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include "util/util.h"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include "responder/common/responder.h"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include "responder/ifp/ifp_components.h"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
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
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaenum component_type {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina COMPONENT_MONITOR,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina COMPONENT_RESPONDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina COMPONENT_BACKEND
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina};
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic bool responder_exists(const char *name)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char * const *svc = get_known_services();
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int i;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; svc[i] != NULL; i++) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (strcmp(svc[i], name) == 0) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return true;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return false;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic bool backend_exists(struct confdb_ctx *confdb, const char *name)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char **names = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int i;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_list_all_domain_names(NULL, confdb, &names);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return false;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; names[i] != NULL; i++) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (strcmp(names[i], name) == 0) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return true;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return false;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic errno_t check_and_get_component_from_path(TALLOC_CTX *mem_ctx,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct confdb_ctx *confdb,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *path,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina enum component_type *_type,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char **_name)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina enum component_type type;
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina char *name = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (confdb == NULL || path == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return EINVAL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (strcmp(path, PATH_MONITOR) == 0) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina type = COMPONENT_MONITOR;
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = talloc_strdup(mem_ctx, "monitor");
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina if (name == NULL) {
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina ret = ENOMEM;
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina goto done;
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina } else {
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(mem_ctx, path, PATH_RESPONDERS);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (name != NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina type = COMPONENT_RESPONDER;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina } else {
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(mem_ctx, path, PATH_BACKENDS);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (name != NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina type = COMPONENT_BACKEND;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina } else {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EINVAL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (strchr(name, '/') != NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EINVAL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina switch (type) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_MONITOR:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina /* noop */
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_RESPONDER:
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina if (!responder_exists(name)) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = ENOENT;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_BACKEND:
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina if (!backend_exists(confdb, name)) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = ENOENT;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (_type != NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_type = type;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (_name != NULL) {
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina *_name = name;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EOK;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinadone:
c66420cb235934e3cbc3ee934c3c48afbb88bb9bPavel Březina if (ret != EOK) {
c66420cb235934e3cbc3ee934c3c48afbb88bb9bPavel Březina talloc_free(name);
c66420cb235934e3cbc3ee934c3c48afbb88bb9bPavel Březina }
c66420cb235934e3cbc3ee934c3c48afbb88bb9bPavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic errno_t list_responders(TALLOC_CTX *mem_ctx,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char ***_list,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int *_num)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **list = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char * const *svc = get_known_services();
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int i;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (num = 0; svc[num] != NULL; num++);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina list = talloc_array(mem_ctx, const char*, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (list == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = ENOMEM;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num; i++) {
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina list[i] = sbus_opath_compose(list, PATH_RESPONDERS, svc[i]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (list[i] == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = ENOMEM;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_num = num;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_list = list;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EOK;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinadone:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina talloc_free(list);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinastatic errno_t list_backends(TALLOC_CTX *mem_ctx,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct confdb_ctx *confdb,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char ***_list,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int *_num)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina TALLOC_CTX *tmp_ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **list = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char **names = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int i;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina tmp_ctx = talloc_new(NULL);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (tmp_ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return ENOMEM;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_list_all_domain_names(tmp_ctx, confdb, &names);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (num = 0; names[num] != NULL; num++);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina list = talloc_array(tmp_ctx, const char*, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (list == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = ENOMEM;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num; i++) {
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina list[i] = sbus_opath_compose(list, PATH_BACKENDS, names[i]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (list[i] == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = ENOMEM;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_num = num;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_list = talloc_steal(mem_ctx, list);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EOK;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinadone:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina talloc_free(tmp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_list_components(struct sbus_request *dbus_req, void *data)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DBusError *error = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **responders = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **backends = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **result = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num_responders;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num_backends;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int i;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EINVAL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_responders(dbus_req, &responders, &num_responders);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_backends(dbus_req, ctx->rctx->cdb, &backends, &num_backends);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina num = num_responders + num_backends + 1;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina result = talloc_array(dbus_req, const char*, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (result == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = ENOMEM;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina result[0] = PATH_MONITOR;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; i < num_responders; i++) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina result[i + 1] = talloc_steal(result, responders[i]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
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 }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EOK;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinadone:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina "%s", strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_ListComponents_finish(dbus_req, result, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_list_responders(struct sbus_request *dbus_req, void *data)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DBusError *error = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **result = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_responders(dbus_req, &result, &num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina "%s", strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_ListResponders_finish(dbus_req, result, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_list_backends(struct sbus_request *dbus_req, void *data)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DBusError *error = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **result = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = EINVAL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina goto done;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = list_backends(dbus_req, ctx->rctx->cdb, &result, &num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinadone:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina "%s", strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_ListBackends_finish(dbus_req, result, num);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_find_monitor(struct sbus_request *dbus_req, void *data)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_FindMonitor_finish(dbus_req, PATH_MONITOR);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_find_responder_by_name(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina void *data,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *arg_name)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DBusError *error = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *result = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (responder_exists(arg_name)) {
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina result = sbus_opath_compose(dbus_req, PATH_RESPONDERS, arg_name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (result == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, NULL);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina } else {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina "Responder \"%s\" does not exist", arg_name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_FindResponderByName_finish(dbus_req, result);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinaint ifp_find_backend_by_name(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina void *data,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *arg_name)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DBusError *error = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *result = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
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 "%s\n", strerror(EINVAL));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
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 if (result == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, NULL);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina } else {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina "Backend \"%s\" does not exist", arg_name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return sbus_request_fail_and_finish(dbus_req, error);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina return iface_ifp_FindBackendByName_finish(dbus_req, result);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_name(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina void *data,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **_out)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char *name = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina dbus_req->path, NULL, &name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret, strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = name;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_debug_level(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina void *data,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina uint32_t *_out)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *confdb_path = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char *name = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina enum component_type type;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int level;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = 0;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina dbus_req->path, &type, &name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret, strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina switch (type) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_MONITOR:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina confdb_path = CONFDB_MONITOR_CONF_ENTRY;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_RESPONDER:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina confdb_path = talloc_asprintf(dbus_req, CONFDB_SERVICE_PATH_TMPL, name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_BACKEND:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina confdb_path = talloc_asprintf(dbus_req, CONFDB_DOMAIN_PATH_TMPL, name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (confdb_path == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
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 if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unable to retrieve configuration option"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina "[%d]: %s\n", ret, strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = level;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_enabled(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina void *data,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina bool *_out)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *param = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char **values = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char *name = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina enum component_type type;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int i;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = false;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina dbus_req->path, &type, &name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret, strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina switch (type) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_MONITOR:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = true;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_RESPONDER:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina param = CONFDB_MONITOR_ACTIVE_SERVICES;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_BACKEND:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina param = CONFDB_MONITOR_ACTIVE_DOMAINS;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = confdb_get_string_as_list(ctx->rctx->cdb, dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_MONITOR_CONF_ENTRY, param, &values);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unable to retrieve configuration option"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina "[%d]: %s\n", ret, strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina for (i = 0; values[i] != NULL; i++) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (strcmp(values[i], name) == 0) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = true;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_component_get_type(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina void *data,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **_out)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina enum component_type type;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina dbus_req->path, &type, NULL);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret, strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina switch (type) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_MONITOR:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = "monitor";
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_RESPONDER:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = "responder";
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina case COMPONENT_BACKEND:
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = "backend";
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina break;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březinavoid ifp_backend_get_providers(struct sbus_request *dbus_req,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina void *data,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char ***_out,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int *_out_len)
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina{
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina TALLOC_CTX *tmp_ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina struct ifp_ctx *ctx = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char *confdb_path = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char *name = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina enum component_type type;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina const char **out = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina char *value = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina static const char *providers[] = {CONFDB_DOMAIN_ID_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_DOMAIN_AUTH_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_DOMAIN_ACCESS_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_DOMAIN_CHPASS_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_DOMAIN_SUDO_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_DOMAIN_AUTOFS_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_DOMAIN_SELINUX_PROVIDER,
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina CONFDB_DOMAIN_HOSTID_PROVIDER,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio CONFDB_DOMAIN_SUBDOMAINS_PROVIDER,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio CONFDB_DOMAIN_SESSION_PROVIDER};
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int num_providers = sizeof(providers) / sizeof(providers[0]);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina errno_t ret;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int i;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina int j;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = NULL;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out_len = 0;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina tmp_ctx = talloc_new(NULL);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (tmp_ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ctx == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret = check_and_get_component_from_path(tmp_ctx, ctx->rctx->cdb,
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina dbus_req->path, &type, &name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina ret, strerror(ret));
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (type != COMPONENT_BACKEND) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina confdb_path = talloc_asprintf(tmp_ctx, CONFDB_DOMAIN_PATH_TMPL, name);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (confdb_path == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina out = talloc_zero_array(tmp_ctx, const char*, num_providers);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (out == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina j = 0;
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 providers[i], NULL, &value);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (ret != EOK) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (value == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina continue;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina out[j] = talloc_asprintf(out, "%s=%s", providers[i], value);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina if (out[j] == NULL) {
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina j++;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina }
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out = talloc_steal(dbus_req, out);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina *_out_len = j;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina talloc_free(tmp_ctx);
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina return;
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina}