async_resolv.h revision eafbc66c2ff6365478e62a8df3fd005bf80e5c7b
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose/*
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose SSSD
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose Async resolver header
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose Authors:
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose Martin Nagy <mnagy@redhat.com>
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose Jakub Hrozek <jhrozek@redhat.com>
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose Copyright (C) Red Hat, Inc 2009
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose This program is free software; you can redistribute it and/or modify
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose it under the terms of the GNU General Public License as published by
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose the Free Software Foundation; either version 3 of the License, or
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose (at your option) any later version.
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose This program is distributed in the hope that it will be useful,
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose GNU General Public License for more details.
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose You should have received a copy of the GNU General Public License
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose*/
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose#ifndef __ASYNC_RESOLV_H__
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#define __ASYNC_RESOLV_H__
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozek
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozek#include <netdb.h>
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#include <ares.h>
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#include "config.h"
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#include "confdb/confdb.h"
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#ifndef RESOLV_DEFAULT_TTL
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#define RESOLV_DEFAULT_TTL 7200
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#endif /* RESOLV_DEFAULT_TTL */
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#ifndef RESOLV_DEFAULT_SRV_TTL
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#define RESOLV_DEFAULT_SRV_TTL 14400
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#endif /* RESOLV_DEFAULT_SRV_TTL */
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher#include "util/util.h"
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher/*
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher * An opaque structure which holds context for a module using the async
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher * resolver. Is should be used as a "local-global" variable - in sssd,
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher * every backend should have its own.
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher * Do NOT free the context until there are any pending resolv_ calls
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose */
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestruct resolv_ctx;
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Boseint resolv_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce int timeout, struct resolv_ctx **ctxp);
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikvoid resolv_reread_configuration(struct resolv_ctx *ctx);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorceconst char *resolv_strerror(int ares_code);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestruct resolv_hostent *
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Boseresolv_copy_hostent(TALLOC_CTX *mem_ctx, struct hostent *src);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestruct resolv_hostent *
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Boseresolv_copy_hostent_ares(TALLOC_CTX *mem_ctx, struct hostent *src,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose int family, void *ares_ttl_data,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose int num_ares_ttl_data);
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik/** Get host by name **/
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikenum host_database {
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik DB_FILES,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik DB_DNS,
4d09e8abf9f4306d3d6add88ee9100373c421c74Jakub Hrozek
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik DB_SENTINEL
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik};
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikenum restrict_family {
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik IPV4_ONLY,
4d09e8abf9f4306d3d6add88ee9100373c421c74Jakub Hrozek IPV4_FIRST,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik IPV6_ONLY,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik IPV6_FIRST
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose};
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose/* If resolv_hostent->family is AF_INET, then ipaddr points to
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose * struct in_addr, else if family is AF_INET6, ipaddr points to
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose * struct in6_addr
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik */
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikstruct resolv_addr {
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik uint8_t *ipaddr;
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik int ttl;
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose};
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorcestruct resolv_hostent {
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce char *name; /* official name of host */
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose char **aliases; /* alias list */
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose int family; /* host address type */
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose struct resolv_addr **addr_list; /* list of addresses */
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose};
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce/* The default database order */
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorceextern enum host_database default_host_dbs[];
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorcestruct tevent_req *resolv_gethostbyname_send(TALLOC_CTX *mem_ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce struct tevent_context *ev,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce struct resolv_ctx *ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce const char *name,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce enum restrict_family family_order,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce enum host_database *db);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorceint resolv_gethostbyname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce int *status, int *timeouts,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce struct resolv_hostent **rhostent);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorcechar *
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorceresolv_get_string_address_index(TALLOC_CTX *mem_ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce struct resolv_hostent *hostent,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce unsigned int addrindex);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorcechar *
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorceresolv_get_string_ptr_address(TALLOC_CTX *mem_ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce int family, uint8_t *address);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce#define resolv_get_string_address(mem_ctx, hostent) \
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce resolv_get_string_address_index(mem_ctx, hostent, 0)
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorcestruct sockaddr_storage *
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorceresolv_get_sockaddr_address_index(TALLOC_CTX *mem_ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce struct resolv_hostent *hostent,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce int port, int addrindex);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce#define resolv_get_sockaddr_address(mem_ctx, rhostent, port) \
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce resolv_get_sockaddr_address_index(mem_ctx, rhostent, port, 0)
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce/** Get SRV record **/
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorcestruct tevent_req *resolv_getsrv_send(TALLOC_CTX *mem_ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce struct tevent_context *ev,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce struct resolv_ctx *ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce const char *query);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikint resolv_getsrv_recv(TALLOC_CTX *mem_ctx,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik struct tevent_req *req,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik int *status,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik int *timeouts,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik struct ares_srv_reply **reply_list,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik uint32_t *ttl);
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik/* This is an implementation of section "Usage rules" of RFC 2782 */
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikint
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikresolv_sort_srv_reply(struct ares_srv_reply **reply);
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik/** Get TXT record **/
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikstruct tevent_req *resolv_gettxt_send(TALLOC_CTX *mem_ctx,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik struct tevent_context *ev,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik struct resolv_ctx *ctx,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce const char *query);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikint resolv_gettxt_recv(TALLOC_CTX *mem_ctx,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik struct tevent_req *req,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik int *status,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik int *timeouts,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik struct ares_txt_reply **reply_list);
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik/** Utils **/
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikstruct tevent_req *
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnikresolv_get_domain_send(TALLOC_CTX *mem_ctx,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik struct tevent_context *ev,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose struct resolv_ctx *resolv_ctx,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose const char *hostname,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce enum host_database *host_dbs,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose enum restrict_family family_order);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Boseerrno_t resolv_get_domain_recv(TALLOC_CTX *mem_ctx,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose struct tevent_req *req,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose char **_dns_domain);
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorcestruct tevent_req *
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Boseresolv_discover_srv_send(TALLOC_CTX *mem_ctx,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose struct tevent_context *ev,
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose struct resolv_ctx *resolv_ctx,
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose const char *service,
de9fa0156b6cad1c824803283f15dfc360fb3f64Stephen Gallagher const char *protocol,
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozek const char **discovery_domains);
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozek
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozekerrno_t resolv_discover_srv_recv(TALLOC_CTX *mem_ctx,
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozek struct tevent_req *req,
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozek struct ares_srv_reply **_reply_list,
bd09ead65cded3207cf228c44a31bbc87c2979bdJakub Hrozek uint32_t *_ttl,
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik char **_dns_domain);
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose#endif /* __ASYNC_RESOLV_H__ */
1b18a3fc310932e5afcdaa4bb401c8d368e79c0bSumit Bose