chiark / gitweb /
build: Enable gcc warnings to detect non-portable code.
[gnupg2.git] / dirmngr / dns-stuff.h
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
4  *
5  * This file is part of GnuPG.
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of either
9  *
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.
13  *
14  * or
15  *
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.
19  *
20  * or both in parallel, as here.
21  *
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.
26  *
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/>.
29  */
30 #ifndef GNUPG_DIRMNGR_DNS_STUFF_H
31 #define GNUPG_DIRMNGR_DNS_STUFF_H
32
33 #ifdef HAVE_W32_SYSTEM
34 # ifdef HAVE_WINSOCK2_H
35 #  include <winsock2.h>
36 # endif
37 # include <windows.h>
38 #else
39 # include <sys/types.h>
40 # include <sys/socket.h>
41 #endif
42
43 /*
44  * Flags used with resolve_dns_addr.
45  */
46 #define DNS_NUMERICHOST        1  /* Force numeric output format.  */
47 #define DNS_WITHBRACKET        2  /* Put brackets around numeric v6
48                                      addresses.  */
49
50 /*
51  * Constants for use with get_dns_cert.
52  */
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)
69
70
71
72 struct dns_addrinfo_s;
73 typedef struct dns_addrinfo_s *dns_addrinfo_t;
74 struct dns_addrinfo_s
75 {
76   dns_addrinfo_t next;
77   int family;
78   int socktype;
79   int protocol;
80   int addrlen;
81   struct sockaddr addr[1];
82 };
83
84
85 struct srventry
86 {
87   unsigned short priority;
88   unsigned short weight;
89   unsigned short port;
90   int run_count;
91   char target[1025];
92 };
93
94
95 /* Set verbosity and debug mode for this module. */
96 void set_dns_verbose (int verbose, int debug);
97
98 /* Set the timeout for libdns requests to SECONDS.  */
99 void set_dns_timeout (int seconds);
100
101 /* Calling this function with YES set to True forces the use of the
102  * standard resolver even if dirmngr has been built with support for
103  * an alternative resolver.  */
104 void enable_standard_resolver (int yes);
105
106 /* Return true if the standard resolver is used.  */
107 int standard_resolver_p (void);
108
109 /* Calling this function with YES switches libdns into recursive mode.
110  * It has no effect on the standard resolver.  */
111 void enable_recursive_resolver (int yes);
112
113 /* Return true iff the recursive resolver is used.  */
114 int recursive_resolver_p (void);
115
116 /* Calling this function switches the DNS code into Tor mode if
117    possibe.  Return 0 on success.  */
118 gpg_error_t enable_dns_tormode (int new_circuit);
119
120 /* Change the default IP address of the nameserver to IPADDR.  The
121    address needs to be a numerical IP address and will be used for the
122    next DNS query.  Note that this is only used in Tor mode.  */
123 void set_dns_nameserver (const char *ipaddr);
124
125 /* SIGHUP action handler for this module.  */
126 void reload_dns_stuff (int force);
127
128 void free_dns_addrinfo (dns_addrinfo_t ai);
129
130 /* Function similar to getaddrinfo.  */
131 gpg_error_t resolve_dns_name (const char *name, unsigned short port,
132                               int want_family, int want_socktype,
133                               dns_addrinfo_t *r_dai, char **r_canonname);
134
135 /* Function similar to getnameinfo.  */
136 gpg_error_t resolve_dns_addr (const struct sockaddr *addr, int addrlen,
137                               unsigned int flags, char **r_name);
138
139 /* Return true if NAME is a numerical IP address.  */
140 int is_ip_address (const char *name);
141
142 /* Return true if NAME is an onion address.  */
143 int is_onion_address (const char *name);
144
145 /* Get the canonical name for NAME.  */
146 gpg_error_t get_dns_cname (const char *name, char **r_cname);
147
148 /* Return a CERT record or an arbitray RR.  */
149 gpg_error_t get_dns_cert (const char *name, int want_certtype,
150                           void **r_key, size_t *r_keylen,
151                           unsigned char **r_fpr, size_t *r_fprlen,
152                           char **r_url);
153
154 /* Return an array of SRV records.  */
155 gpg_error_t get_dns_srv (const char *name,
156                          struct srventry **list, unsigned int *r_count);
157
158
159 #endif /*GNUPG_DIRMNGR_DNS_STUFF_H*/