async_resolv_utils.c revision bf54fbed126ec3d459af40ea370ffadacd31c76d
d98fdd80331e93cd698281341360a3ce3e30afbePavel Březina Pavel Březina <pbrezina@redhat.com>
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina Copyright (C) 2013 Red Hat
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina This program is free software; you can redistribute it and/or modify
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina it under the terms of the GNU General Public License as published by
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina the Free Software Foundation; either version 3 of the License, or
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina (at your option) any later version.
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina This program is distributed in the hope that it will be useful,
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina GNU General Public License for more details.
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina You should have received a copy of the GNU General Public License
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březinastatic void resolv_get_domain_done(struct tevent_req *subreq);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina /* use system hostname */
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina ret = gethostname(system_hostname, HOST_NAME_MAX);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "gethostname() failed: [%d]: %s\n",
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina state->hostname = talloc_strdup(state, hostname);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Host name is: %s\n", state->hostname);
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina subreq = resolv_gethostbyname_send(state, ev, resolv_ctx, state->hostname,
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina tevent_req_set_callback(subreq, resolv_get_domain_done, req);
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březinastatic void resolv_get_domain_done(struct tevent_req *subreq)
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina state = tevent_req_data(req, struct resolv_get_domain_state);
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina ret = resolv_gethostbyname_recv(subreq, req, &resolv_status,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not get fully qualified name for host name %s "
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina "error [%d]: %s, resolver returned: [%d]: %s\n",
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina state->hostname, ret, strerror(ret), resolv_status,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "The FQDN is: %s\n", rhostent->name);
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina state->fqdn = talloc_steal(state, rhostent->name);
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březinaerrno_t resolv_get_domain_recv(TALLOC_CTX *mem_ctx,
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina state = tevent_req_data(req, struct resolv_get_domain_state);
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina if (domptr == NULL || (*(domptr+1) == '\0')) {
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina /* If the FQDN did not contain a dot or the dot was the last character
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina * (broken DNS server perhaps) */
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina *_dns_domain = talloc_strdup(mem_ctx, dns_domain);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březinastatic errno_t resolv_discover_srv_next_domain(struct tevent_req *req);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březinastatic void resolv_discover_srv_done(struct tevent_req *subreq);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březinastruct tevent_req *resolv_discover_srv_send(TALLOC_CTX *mem_ctx,
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina struct resolv_discover_srv_state *state = NULL;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina if (resolv_ctx == NULL || service == NULL || protocol == NULL
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březinastatic errno_t resolv_discover_srv_next_domain(struct tevent_req *req)
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina struct resolv_discover_srv_state *state = NULL;
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina state = tevent_req_data(req, struct resolv_discover_srv_state);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina domain = state->discovery_domains[state->domain_index];
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina query = talloc_asprintf(state, "_%s._%s.%s", state->service,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "SRV resolution of service '%s'. Will use DNS "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "discovery domain '%s'\n", state->service, domain);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina tevent_req_set_callback(subreq, resolv_discover_srv_done, req);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březinastatic void resolv_discover_srv_done(struct tevent_req *subreq)
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina struct resolv_discover_srv_state *state = NULL;
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina state = tevent_req_data(req, struct resolv_discover_srv_state);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = resolv_getsrv_recv(state, subreq, &status, NULL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "SRV query failed [%d]: %s\n",
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina /* continue with next discovery domain */
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina /* there are no more domains to try */
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina /* critical error when fetching SRV record */
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březinaerrno_t resolv_discover_srv_recv(TALLOC_CTX *mem_ctx,
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina struct resolv_discover_srv_state *state = NULL;
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina state = tevent_req_data(req, struct resolv_discover_srv_state);
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina /* domain_index now points to selected domain + 1 */
673d4c1932fa4ab1496499207d8627970d0b7561Pavel Březina state->discovery_domains[state->domain_index - 1]);