590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek Pavel Březina <pbrezina@redhat.com>
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek Copyright (C) 2014 Red Hat
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek This program is free software; you can redistribute it and/or modify
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek it under the terms of the GNU General Public License as published by
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek (at your option) any later version.
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek This program is distributed in the hope that it will be useful,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek GNU General Public License for more details.
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek You should have received a copy of the GNU General Public License
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina#include "responder/common/data_provider/rdp.h"
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina#include "providers/data_provider/dp_responder_iface.h"
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina#define RETURN_DOM_PROP_AS_STRING(dbus_req, pvt_data, out, property) do { \
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina __dom = get_domain_info_from_req((dbus_req), (pvt_data)); \
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozekstatic void ifp_list_domains_process(struct tevent_req *req);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozekint ifp_list_domains(struct sbus_request *dbus_req,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek ifp_ctx = talloc_get_type(data, struct ifp_ctx);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Invalid ifp context!");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek return sbus_request_fail_and_finish(dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek return sbus_request_fail_and_finish(dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek req = sss_dp_get_domains_send(ireq, ifp_ctx->rctx, false, NULL);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek return sbus_request_finish(ireq->dbus_req, NULL);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek tevent_req_set_callback(req, ifp_list_domains_process, ireq);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozekstatic void ifp_list_domains_process(struct tevent_req *req)
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek ireq = tevent_req_callback_data(req, struct ifp_req);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(ireq->dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Failed to refresh domain objects\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek sbus_request_fail_and_finish(ireq->dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek ret = sysdb_master_domain_update(ireq->ifp_ctx->rctx->domains);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(ireq->dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Failed to refresh subdomain list\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek sbus_request_fail_and_finish(ireq->dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek paths = talloc_zero_array(ireq, const char *, num_domains);
62ebed8582285bd24efba92b9a06366511507946Pavel Březina p = sbus_opath_compose(ireq, IFP_PATH_DOMAINS, dom->name);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Could not create path for dom %s, skipping\n", dom->name);
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina ret = iface_ifp_ListDomains_finish(ireq->dbus_req, paths, num_domains);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Could not finish request!\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozekstatic void ifp_find_domain_by_name_process(struct tevent_req *req);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozekint ifp_find_domain_by_name(struct sbus_request *dbus_req,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek ifp_ctx = talloc_get_type(data, struct ifp_ctx);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Invalid ifp context!");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek return sbus_request_fail_and_finish(dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek return sbus_request_fail_and_finish(dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek state = talloc_zero(ireq, struct ifp_get_domain_state);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek req = sss_dp_get_domains_send(ireq, ifp_ctx->rctx, false, NULL);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek tevent_req_set_callback(req, ifp_find_domain_by_name_process, state);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozekstatic void ifp_find_domain_by_name_process(struct tevent_req *req)
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek state = tevent_req_callback_data(req, struct ifp_get_domain_state);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(ireq->dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Failed to refresh domain objects\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek sbus_request_fail_and_finish(ireq->dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek ret = sysdb_master_domain_update(ireq->ifp_ctx->rctx->domains);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(ireq->dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Failed to refresh subdomain list\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek sbus_request_fail_and_finish(ireq->dbus_req, error);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek /* Reply with the domain that was asked for */
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek iter = get_next_domain(iter, SSS_GND_DESCEND)) {
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek if (strcasecmp(iter->name, state->name) == 0) {
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek error = sbus_error_new(ireq->dbus_req, DBUS_ERROR_FAILED,
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "No such domain\n");
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek sbus_request_fail_and_finish(ireq->dbus_req, error);
62ebed8582285bd24efba92b9a06366511507946Pavel Březina path = sbus_opath_compose(ireq, IFP_PATH_DOMAINS, iter->name);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek "Could not create path for domain %s, skipping\n", iter->name);
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina ret = iface_ifp_FindDomainByName_finish(ireq->dbus_req, path);
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Could not finish request!\n");
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinaget_domain_info_from_req(struct sbus_request *dbus_req, void *data)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(dbus_req, dbus_req->path,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina DEBUG(SSSDBG_TRACE_INTERNAL, "Looking for domain %s\n", name);
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek iter = get_next_domain(iter, SSS_GND_DESCEND)) {
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinastatic void get_server_list(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char ***_out,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina dom = get_domain_info_from_req(dbus_req, data);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina /* subdomains are not present in configuration */
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid ifp context!\n");
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina conf_path = talloc_asprintf(dbus_req, CONFDB_DOMAIN_PATH_TMPL, dom->name);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina /* TODO: replace hardcoded values with option names from the provider */
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina option = backup == false ? "ldap_uri" : "ldap_backup_uri";
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina } else if (strcasecmp(dom->provider, "ipa") == 0) {
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina option = backup == false ? "ipa_server" : "ipa_backup_server";
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina } else if (strcasecmp(dom->provider, "ad") == 0) {
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina option = backup == false ? "ad_server" : "ad_backup_server";
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina ret = confdb_get_string_as_list(ctx->rctx->cdb, dbus_req, conf_path,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina for (num_servers = 0; servers[num_servers] != NULL; num_servers++);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina out = talloc_zero_array(dbus_req, const char*, num_servers);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina for (i = 0; i < num_servers; i++) {
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_name(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char **_out)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina RETURN_DOM_PROP_AS_STRING(dbus_req, data, _out, name);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_provider(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char **_out)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina RETURN_DOM_PROP_AS_STRING(dbus_req, data, _out, provider);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_primary_servers(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char ***_out,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina get_server_list(dbus_req, data, _out, _out_len, false);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_backup_servers(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char ***_out,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina get_server_list(dbus_req, data, _out, _out_len, true);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_min_id(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina dom = get_domain_info_from_req(dbus_req, data);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_max_id(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina dom = get_domain_info_from_req(dbus_req, data);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_realm(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char **_out)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina RETURN_DOM_PROP_AS_STRING(dbus_req, data, _out, realm);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_forest(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char **_out)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina RETURN_DOM_PROP_AS_STRING(dbus_req, data, _out, forest);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_login_format(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char **_out)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina RETURN_DOM_PROP_AS_STRING(dbus_req, data, _out, names->re_pattern);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_fqdn_format(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char **_out)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina RETURN_DOM_PROP_AS_STRING(dbus_req, data, _out, names->fq_fmt);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_enumerable(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina dom = get_domain_info_from_req(dbus_req, data);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_use_fqdn(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina dom = get_domain_info_from_req(dbus_req, data);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_subdomain(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina dom = get_domain_info_from_req(dbus_req, data);
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březinavoid ifp_dom_get_parent_domain(struct sbus_request *dbus_req,
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina const char **_out)
d387c4608dbd3ca056e18e85313ef51aac146fd2Pavel Březina dom = get_domain_info_from_req(dbus_req, data);
62ebed8582285bd24efba92b9a06366511507946Pavel Březina *_out = sbus_opath_compose(dbus_req, IFP_PATH_DOMAINS,
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březinaint ifp_domains_domain_is_online(struct sbus_request *sbus_req,
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina dom = get_domain_info_from_req(sbus_req, data);
a06e23c0bcf0c8669a29b801876aca8aac422931Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
a06e23c0bcf0c8669a29b801876aca8aac422931Pavel Březina "Unknown domain");
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina rdp_message_send_and_reply(sbus_req, ifp_ctx->rctx, dom, DP_PATH,
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březinaint ifp_domains_domain_list_services(struct sbus_request *sbus_req,
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina dom = get_domain_info_from_req(sbus_req, data);
a06e23c0bcf0c8669a29b801876aca8aac422931Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
a06e23c0bcf0c8669a29b801876aca8aac422931Pavel Březina "Unknown domain");
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina rdp_message_send_and_reply(sbus_req, ifp_ctx->rctx, dom, DP_PATH,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinaint ifp_domains_domain_active_server(struct sbus_request *sbus_req,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina dom = get_domain_info_from_req(sbus_req, data);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina "Unknown domain");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina rdp_message_send_and_reply(sbus_req, ifp_ctx->rctx, dom, DP_PATH,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinaint ifp_domains_domain_list_servers(struct sbus_request *sbus_req,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina dom = get_domain_info_from_req(sbus_req, data);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina "Unknown domain");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina rdp_message_send_and_reply(sbus_req, ifp_ctx->rctx, dom, DP_PATH,
c6cf752337f5977ce3753b7113dc1a2342c86319Pavel Březinaint ifp_domains_domain_refresh_access_rules(struct sbus_request *sbus_req,
c6cf752337f5977ce3753b7113dc1a2342c86319Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
c6cf752337f5977ce3753b7113dc1a2342c86319Pavel Březina dom = get_domain_info_from_req(sbus_req, data);
c6cf752337f5977ce3753b7113dc1a2342c86319Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
c6cf752337f5977ce3753b7113dc1a2342c86319Pavel Březina "Unknown domain");