fail_over_srv.c revision 77d165f0629966db65753a3aee84a8b4971673af
77d165f0629966db65753a3aee84a8b4971673afPavel Březina Pavel B??ezina <pbrezina@redhat.com>
77d165f0629966db65753a3aee84a8b4971673afPavel Březina Copyright (C) 2013 Red Hat
77d165f0629966db65753a3aee84a8b4971673afPavel Březina This program is free software; you can redistribute it and/or modify
77d165f0629966db65753a3aee84a8b4971673afPavel Březina it under the terms of the GNU General Public License as published by
77d165f0629966db65753a3aee84a8b4971673afPavel Březina the Free Software Foundation; either version 3 of the License, or
77d165f0629966db65753a3aee84a8b4971673afPavel Březina (at your option) any later version.
77d165f0629966db65753a3aee84a8b4971673afPavel Březina This program is distributed in the hope that it will be useful,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
77d165f0629966db65753a3aee84a8b4971673afPavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77d165f0629966db65753a3aee84a8b4971673afPavel Březina GNU General Public License for more details.
77d165f0629966db65753a3aee84a8b4971673afPavel Březina You should have received a copy of the GNU General Public License
77d165f0629966db65753a3aee84a8b4971673afPavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic void fo_discover_srv_done(struct tevent_req *subreq);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastruct tevent_req *fo_discover_srv_send(TALLOC_CTX *mem_ctx,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina req = tevent_req_create(mem_ctx, &state, struct fo_discover_srv_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, ("tevent_req_create() failed\n"));
77d165f0629966db65753a3aee84a8b4971673afPavel Březina subreq = resolv_discover_srv_send(state, ev, resolv_ctx, service,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina tevent_req_set_callback(subreq, fo_discover_srv_done, req);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic void fo_discover_srv_done(struct tevent_req *subreq)
77d165f0629966db65753a3aee84a8b4971673afPavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state = tevent_req_data(req, struct fo_discover_srv_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina DEBUG(SSSDBG_TRACE_FUNC, ("Got answer. Processing...\n"));
77d165f0629966db65753a3aee84a8b4971673afPavel Březina /* sort and store the answer */
77d165f0629966db65753a3aee84a8b4971673afPavel Březina ret = resolv_sort_srv_reply(state, &reply_list);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, ("Could not sort the answers from DNS "
77d165f0629966db65753a3aee84a8b4971673afPavel Březina for (record = reply_list; record != NULL; record = record->next) {
77d165f0629966db65753a3aee84a8b4971673afPavel Březina DEBUG(SSSDBG_TRACE_FUNC, ("Got %lu servers\n", state->num_servers));
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state->servers = talloc_array(state, struct fo_server_info,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state->servers[i].host = talloc_steal(state->servers, record->host);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinaerrno_t fo_discover_srv_recv(TALLOC_CTX *mem_ctx,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state = tevent_req_data(req, struct fo_discover_srv_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina *_dns_domain = talloc_steal(mem_ctx, state->dns_domain);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina *_servers = talloc_steal(mem_ctx, state->servers);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic void fo_resolve_srv_dns_domain_done(struct tevent_req *subreq);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic errno_t fo_resolve_srv_dns_discover(struct tevent_req *req);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic void fo_resolve_srv_dns_done(struct tevent_req *subreq);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinafo_resolve_srv_dns_ctx_init(TALLOC_CTX *mem_ctx,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina ctx = talloc_zero(mem_ctx, struct fo_resolve_srv_dns_ctx);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina ctx->sssd_domain = talloc_strdup(ctx, sssd_domain);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastruct tevent_req *fo_resolve_srv_dns_send(TALLOC_CTX *mem_ctx,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina struct fo_resolve_srv_dns_state *state = NULL;
77d165f0629966db65753a3aee84a8b4971673afPavel Březina req = tevent_req_create(mem_ctx, &state, struct fo_resolve_srv_dns_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, ("tevent_req_create() failed\n"));
77d165f0629966db65753a3aee84a8b4971673afPavel Březina ctx = talloc_get_type(pvt, struct fo_resolve_srv_dns_ctx);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina if (discovery_domain == NULL && ctx->detected_domain == NULL) {
77d165f0629966db65753a3aee84a8b4971673afPavel Březina /* we will try to detect proper discovery domain */
77d165f0629966db65753a3aee84a8b4971673afPavel Březina subreq = resolv_get_domain_send(state, state->ev, ctx->resolv_ctx,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina tevent_req_set_callback(subreq, fo_resolve_srv_dns_domain_done, req);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina /* we will use either provided or previously detected
77d165f0629966db65753a3aee84a8b4971673afPavel Březina * discovery domain */
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic void fo_resolve_srv_dns_domain_done(struct tevent_req *subreq)
77d165f0629966db65753a3aee84a8b4971673afPavel Březina struct fo_resolve_srv_dns_state *state = NULL;
77d165f0629966db65753a3aee84a8b4971673afPavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state = tevent_req_data(req, struct fo_resolve_srv_dns_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina ret = resolv_get_domain_recv(state->ctx, subreq,
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic errno_t fo_resolve_srv_dns_discover(struct tevent_req *req)
77d165f0629966db65753a3aee84a8b4971673afPavel Březina struct fo_resolve_srv_dns_state *state = NULL;
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state = tevent_req_data(req, struct fo_resolve_srv_dns_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina domains = talloc_zero_array(state, const char *, 3);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina /* we will use detected domain with SSSD domain as fallback */
77d165f0629966db65753a3aee84a8b4971673afPavel Březina domains[0] = talloc_strdup(domains, ctx->detected_domain);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina if (strcmp(ctx->detected_domain, ctx->sssd_domain) != 0) {
77d165f0629966db65753a3aee84a8b4971673afPavel Březina domains[1] = talloc_strdup(domains, ctx->sssd_domain);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina /* We will use only discovery domain that was provided via plugin
77d165f0629966db65753a3aee84a8b4971673afPavel Březina * interface. We don't have to dup here because it is already on
77d165f0629966db65753a3aee84a8b4971673afPavel Březina subreq = fo_discover_srv_send(state, state->ev, ctx->resolv_ctx,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina tevent_req_set_callback(subreq, fo_resolve_srv_dns_done, req);
77d165f0629966db65753a3aee84a8b4971673afPavel Březinastatic void fo_resolve_srv_dns_done(struct tevent_req *subreq)
77d165f0629966db65753a3aee84a8b4971673afPavel Březina struct fo_resolve_srv_dns_state *state = NULL;
77d165f0629966db65753a3aee84a8b4971673afPavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state = tevent_req_data(req, struct fo_resolve_srv_dns_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina ret = fo_discover_srv_recv(state, subreq, &state->dns_domain,
77d165f0629966db65753a3aee84a8b4971673afPavel Březinaerrno_t fo_resolve_srv_dns_recv(TALLOC_CTX *mem_ctx,
77d165f0629966db65753a3aee84a8b4971673afPavel Březina struct fo_resolve_srv_dns_state *state = NULL;
77d165f0629966db65753a3aee84a8b4971673afPavel Březina state = tevent_req_data(req, struct fo_resolve_srv_dns_state);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina *_primary_servers = talloc_steal(mem_ctx, state->servers);
77d165f0629966db65753a3aee84a8b4971673afPavel Březina /* backup servers are not supported by simple srv lookup */