1 /* dns-stuff.c - DNS related code including CERT RR (rfc-4398)
2 * Copyright (C) 2006 Free Software Foundation, Inc.
3 * Copyright (C) 2006, 2015 Werner Koch
5 * This file is part of GnuPG.
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of either
10 * - the GNU Lesser General Public License as published by the Free
11 * Software Foundation; either version 3 of the License, or (at
12 * your option) any later version.
16 * - the GNU General Public License as published by the Free
17 * Software Foundation; either version 2 of the License, or (at
18 * your option) any later version.
20 * or both in parallel, as here.
22 * This file is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, see <https://www.gnu.org/licenses/>.
30 #ifndef GNUPG_DIRMNGR_DNS_STUFF_H
31 #define GNUPG_DIRMNGR_DNS_STUFF_H
33 #ifdef HAVE_W32_SYSTEM
34 # ifdef HAVE_WINSOCK2_H
35 # include <winsock2.h>
39 # include <sys/types.h>
40 # include <sys/socket.h>
44 * Flags used with resolve_dns_addr.
46 #define DNS_NUMERICHOST 1 /* Force numeric output format. */
47 #define DNS_WITHBRACKET 2 /* Put brackets around numeric v6
51 * Constants for use with get_dns_cert.
53 #define DNS_CERTTYPE_ANY 0 /* Internal catch all type. */
54 /* Certificate types according to RFC-4398: */
55 #define DNS_CERTTYPE_PKIX 1 /* X.509 as per PKIX. */
56 #define DNS_CERTTYPE_SPKI 2 /* SPKI certificate. */
57 #define DNS_CERTTYPE_PGP 3 /* OpenPGP packet. */
58 #define DNS_CERTTYPE_IPKIX 4 /* The URL of an X.509 data object. */
59 #define DNS_CERTTYPE_ISPKI 5 /* The URL of an SPKI certificate. */
60 #define DNS_CERTTYPE_IPGP 6 /* The fingerprint
61 and URL of an OpenPGP packet. */
62 #define DNS_CERTTYPE_ACPKIX 7 /* Attribute Certificate. */
63 #define DNS_CERTTYPE_IACPKIX 8 /* The URL of an Attribute Certificate. */
64 #define DNS_CERTTYPE_URI 253 /* URI private. */
65 #define DNS_CERTTYPE_OID 254 /* OID private. */
66 /* Hacks for our implementation. */
67 #define DNS_CERTTYPE_RRBASE 1024 /* Base of special constants. */
68 #define DNS_CERTTYPE_RR61 (DNS_CERTTYPE_RRBASE + 61)
72 struct dns_addrinfo_s;
73 typedef struct dns_addrinfo_s *dns_addrinfo_t;
81 struct sockaddr addr[1];
87 unsigned short priority;
88 unsigned short weight;
95 /* Set verbosity and debug mode for this module. */
96 void set_dns_verbose (int verbose, int debug);
98 /* Set the Disable-IPv4 flag so that the name resolver does not return
100 void set_dns_disable_ipv4 (int yes);
102 /* Set the timeout for libdns requests to SECONDS. */
103 void set_dns_timeout (int seconds);
105 /* Calling this function with YES set to True forces the use of the
106 * standard resolver even if dirmngr has been built with support for
107 * an alternative resolver. */
108 void enable_standard_resolver (int yes);
110 /* Return true if the standard resolver is used. */
111 int standard_resolver_p (void);
113 /* Calling this function with YES switches libdns into recursive mode.
114 * It has no effect on the standard resolver. */
115 void enable_recursive_resolver (int yes);
117 /* Return true iff the recursive resolver is used. */
118 int recursive_resolver_p (void);
120 /* Put this module eternally into Tor mode. When called agained with
121 * NEW_CIRCUIT request a new TOR circuit for the next DNS query. */
122 void enable_dns_tormode (int new_circuit);
124 /* Change the default IP address of the nameserver to IPADDR. The
125 address needs to be a numerical IP address and will be used for the
126 next DNS query. Note that this is only used in Tor mode. */
127 void set_dns_nameserver (const char *ipaddr);
129 /* SIGHUP action handler for this module. */
130 void reload_dns_stuff (int force);
132 void free_dns_addrinfo (dns_addrinfo_t ai);
134 /* Function similar to getaddrinfo. */
135 gpg_error_t resolve_dns_name (const char *name, unsigned short port,
136 int want_family, int want_socktype,
137 dns_addrinfo_t *r_dai, char **r_canonname);
139 /* Function similar to getnameinfo. */
140 gpg_error_t resolve_dns_addr (const struct sockaddr *addr, int addrlen,
141 unsigned int flags, char **r_name);
143 /* Return true if NAME is a numerical IP address. */
144 int is_ip_address (const char *name);
146 /* Return true if NAME is an onion address. */
147 int is_onion_address (const char *name);
149 /* Get the canonical name for NAME. */
150 gpg_error_t get_dns_cname (const char *name, char **r_cname);
152 /* Return a CERT record or an arbitray RR. */
153 gpg_error_t get_dns_cert (const char *name, int want_certtype,
154 void **r_key, size_t *r_keylen,
155 unsigned char **r_fpr, size_t *r_fprlen,
158 /* Return an array of SRV records. */
159 gpg_error_t get_dns_srv (const char *name,
160 const char *service, const char *proto,
161 struct srventry **list, unsigned int *r_count);
164 #endif /*GNUPG_DIRMNGR_DNS_STUFF_H*/