Skip to content

Commit b3fd817

Browse files
committed
Merge branch 'develop'
2 parents ea5a144 + af30b99 commit b3fd817

9 files changed

Lines changed: 150 additions & 75 deletions

File tree

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
* 2019-04-03: Version 0.2.6
2+
* Windows: use appropriate system and user configuration directories.
3+
* Windows: replace references to C:\Program Files with %PROGRAMFILES%.
4+
* Windows: use location of stubby.bat to find stubby.exe and stubby.yml.
5+
16
* 2019-01-11: Version 0.2.5
7+
* Fix builds on Windows.
28
* RFE getdnsapi/getdns#408: Document trust_anchors_backoff_time
39
in stubby.yml.example. Thanks Jonathan Underwood
410
* RFE #148: Document tls_ciphersuites, tls_cipher_list, tls_min_version

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AC_PREREQ([2.68])
2-
AC_INIT([Stubby], [0.2.5], [[email protected]])
2+
AC_INIT([Stubby], [0.2.6], [[email protected]])
33
AC_CANONICAL_TARGET
44
AM_INIT_AUTOMAKE
55
AC_CONFIG_SRCDIR([src/stubby.c])

macos/stubby-setdns-macos.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ usage () {
4848
RESET=0
4949
LIST=0
5050
SERVERS="127.0.0.1 ::1"
51-
OS_X=`uname -a | grep -c 'Darwin'`
51+
OS_X=$(uname -a | grep -c 'Darwin')
5252

5353
while getopts ":rlh" opt; do
5454
case $opt in
@@ -69,9 +69,9 @@ fi
6969

7070
if [[ $LIST -eq 1 ]]; then
7171
echo "** Current DNS settings **"
72-
networksetup -listallnetworkservices 2>/dev/null | grep -v '*' | while read x ; do
73-
RESULT=`networksetup -getdnsservers "$x"`
74-
RESULT=`echo $RESULT`
72+
networksetup -listallnetworkservices 2>/dev/null | grep -v '\*' | while read -r x ; do
73+
RESULT=$(networksetup -getdnsservers "$x")
74+
RESULT=$(echo $RESULT)
7575
printf '%-30s %s\n' "$x:" "$RESULT"
7676
done
7777
exit 1
@@ -84,13 +84,12 @@ fi
8484

8585
if [[ $RESET -eq 1 ]]; then
8686
SERVERS="empty"
87-
echo "Setting DNS servers to '"$SERVERS"' - the system will use default DNS service."
87+
echo "Setting DNS servers to $SERVERS - the system will use default DNS service."
8888
else
89-
echo "Setting DNS servers to '"$SERVERS"' - the system will use Stubby if it is running."
89+
echo "Setting DNS servers to $SERVERS - the system will use Stubby if it is running."
9090
fi
9191

9292
### Set the DNS settings via networksetup ###
93-
networksetup -listallnetworkservices 2>/dev/null | grep -v '*' | while read x ; do
93+
networksetup -listallnetworkservices 2>/dev/null | grep -v '\*' | while read -r x ; do
9494
networksetup -setdnsservers "$x" $SERVERS
95-
done
96-
95+
done

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ stubby_SOURCES = stubby.c yaml/convert_yaml_to_json.c sldns/sbuffer.c
66
else
77
stubby_SOURCES = stubby.c
88
endif
9-
AM_CPPFLAGS = -DSTUBBYCONFDIR=\"$(sysconfdir)/stubby\" -DRUNSTATEDIR=\"$(runstatedir)\"
9+
AM_CPPFLAGS = -DSTUBBYCONFDIR='"$(sysconfdir)/stubby"' -DRUNSTATEDIR='"$(runstatedir)"'

src/stubby.c

Lines changed: 89 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
#include <errno.h>
3333
#include <limits.h>
3434
#include <assert.h>
35-
#if !defined(STUBBY_ON_WINDOWS) && !defined(GETDNS_ON_WINDOWS)
35+
#if defined(STUBBY_ON_WINDOWS) || defined(GETDNS_ON_WINDOWS)
36+
#include <shlobj.h>
37+
#else
38+
#include <pwd.h>
3639
#include <unistd.h>
3740
#endif
3841
#include <signal.h>
@@ -62,7 +65,17 @@ getdns_yaml2dict(const char *str, getdns_dict **dict)
6265
}
6366
#endif
6467

65-
#define STUBBYPIDFILE RUNSTATEDIR"/stubby.pid"
68+
static char *make_config_file_path(const char *dir, const char *fname)
69+
{
70+
int reslen = strlen(dir) + strlen(fname) + 1;
71+
char *res = malloc(reslen);
72+
73+
if (res == NULL)
74+
return NULL;
75+
76+
snprintf(res, reslen, "%s%s", dir, fname);
77+
return res;
78+
}
6679

6780
#if defined(STUBBY_ON_WINDOWS) || defined(GETDNS_ON_WINDOWS)
6881
#define DEBUG_ON(...) do { \
@@ -78,7 +91,31 @@ getdns_yaml2dict(const char *str, getdns_dict **dict)
7891
fprintf(stderr, "[%s.%.6d] ", buf_dEbUgSyM, (int)tv_dEbUgSyM.tv_usec); \
7992
fprintf(stderr, __VA_ARGS__); \
8093
} while (0)
94+
95+
static char *folder_config_file(int csidl)
96+
{
97+
TCHAR szPath[MAX_PATH];
98+
99+
if (!SUCCEEDED(SHGetFolderPath(NULL,
100+
csidl | CSIDL_FLAG_CREATE, NULL, 0, szPath)))
101+
return NULL;
102+
103+
return make_config_file_path(szPath, "\\Stubby\\stubby.yml");
104+
}
105+
106+
// %APPDATA%/Stubby/stubby.yml.
107+
char *home_config_file()
108+
{
109+
return folder_config_file(CSIDL_APPDATA);
110+
}
111+
112+
char *system_config_file()
113+
{
114+
return folder_config_file(CSIDL_PROGRAM_FILES);
115+
}
81116
#else
117+
#define STUBBYPIDFILE RUNSTATEDIR"/stubby.pid"
118+
82119
#define DEBUG_ON(...) do { \
83120
struct timeval tv_dEbUgSyM; \
84121
struct tm tm_dEbUgSyM; \
@@ -90,6 +127,20 @@ getdns_yaml2dict(const char *str, getdns_dict **dict)
90127
fprintf(stderr, "[%s.%.6d] ", buf_dEbUgSyM, (int)tv_dEbUgSyM.tv_usec); \
91128
fprintf(stderr, __VA_ARGS__); \
92129
} while (0)
130+
131+
char *home_config_file()
132+
{
133+
struct passwd *p = getpwuid(getuid());
134+
char *home = p ? p->pw_dir : getenv("HOME");
135+
if (!home)
136+
return NULL;
137+
return make_config_file_path(home, "/.stubby.yml");
138+
}
139+
140+
char *system_config_file()
141+
{
142+
return make_config_file_path(STUBBYCONFDIR, "/stubby.yml");
143+
}
93144
#endif
94145
#define DEBUG_OFF(...) do {} while (0)
95146

@@ -126,6 +177,8 @@ static void stubby_local_log(void *userarg, uint64_t system,
126177
void
127178
print_usage(FILE *out)
128179
{
180+
char *home_conf_fn = home_config_file();
181+
char *system_conf_fn = system_config_file();
129182
fprintf(out, "usage: " STUBBY_PACKAGE " [<option> ...] \\\n");
130183
fprintf(out, "\t-C\t<filename>\n");
131184
fprintf(out, "\t\tRead settings from config file <filename>\n");
@@ -135,16 +188,16 @@ print_usage(FILE *out)
135188
fprintf(out, "\t\tspecified on the command line.)\n");
136189
fprintf(out, "\t\tBy default, the configuration file location is obtained\n");
137190
fprintf(out, "\t\tby looking for YAML files in the following order:\n");
138-
fprintf(out, "\t\t\t\"%s/.stubby.yml\"\n", getenv("HOME"));
139-
fprintf(out, "\t\t\t\"%s/stubby.yml\"\n", STUBBYCONFDIR);
140-
fprintf(out, "\t\tAn default file (Using Strict mode) is installed as\n");
141-
fprintf(out, "\t\t\t\"%s/stubby.yml\"\n", STUBBYCONFDIR);
191+
fprintf(out, "\t\t\t\"%s\"\n", home_conf_fn);
192+
fprintf(out, "\t\t\t\"%s\"\n", system_conf_fn);
193+
fprintf(out, "\t\tA default file (Using Strict mode) is installed as\n");
194+
fprintf(out, "\t\t\t\"%s\"\n", system_conf_fn);
142195
#if !defined(STUBBY_ON_WINDOWS) && !defined(GETDNS_ON_WINDOWS)
143196
fprintf(out, "\t-g\tRun stubby in background (default is foreground)\n");
144197
#endif
145198
fprintf(out, "\t-h\tPrint this help\n");
146199
fprintf(out, "\t-i\tValidate and print the configuration only. Useful to validate config file\n");
147-
fprintf(out, "\t\t\tcontents. Note: does not attempt to bind to the listen addresses.\n");
200+
fprintf(out, "\t\tcontents. Note: does not attempt to bind to the listen addresses.\n");
148201
fprintf(out, "\t-l\tEnable logging of all logs (same as -v 7)\n");
149202
fprintf(out, "\t-v\tSpecify logging level (overrides -l option). Values are\n");
150203
fprintf(out, "\t\t\t0: EMERG - %s\n", GETDNS_LOG_EMERG_TEXT);
@@ -156,6 +209,8 @@ print_usage(FILE *out)
156209
fprintf(out, "\t\t\t6: INFO - %s\n", GETDNS_LOG_INFO_TEXT);
157210
fprintf(out, "\t\t\t7: DEBUG - %s\n", GETDNS_LOG_DEBUG_TEXT);
158211
fprintf(out, "\t-V\tPrint the " STUBBY_PACKAGE " version\n");
212+
free(home_conf_fn);
213+
free(system_conf_fn);
159214
}
160215

161216
void
@@ -702,9 +757,9 @@ void stubby_local_log(void *userarg, uint64_t system,
702757
int
703758
main(int argc, char **argv)
704759
{
705-
char home_stubby_conf_fn_spc[1024], *home_stubby_conf_fn = NULL;
760+
char *conf_fn;
706761
const char *custom_config_fn = NULL;
707-
int fn_sz;
762+
int found_conf = 0;
708763
int print_api_info = 0;
709764
int log_connections = 0;
710765
getdns_return_t r;
@@ -771,48 +826,36 @@ main(int argc, char **argv)
771826
return r;
772827
}
773828
} else {
774-
fn_sz = snprintf( home_stubby_conf_fn_spc
775-
, sizeof(home_stubby_conf_fn_spc)
776-
, "%s/.stubby.yml"
777-
, getenv("HOME")
778-
);
779-
780-
if (fn_sz > 0 && fn_sz < (int)sizeof(home_stubby_conf_fn_spc))
781-
home_stubby_conf_fn = home_stubby_conf_fn_spc;
782-
783-
else if (fn_sz > 0) {
784-
if (!(home_stubby_conf_fn = malloc(fn_sz + 1)) ||
785-
snprintf( home_stubby_conf_fn, fn_sz
786-
, "%s/.stubby.yml", getenv("HOME")) != fn_sz) {
787-
if (home_stubby_conf_fn) {
788-
free(home_stubby_conf_fn);
789-
home_stubby_conf_fn = NULL;
790-
}
791-
}
829+
conf_fn = home_config_file();
830+
if (!conf_fn) {
831+
fprintf(stderr, "Error getting user config file");
832+
exit(EXIT_FAILURE);
792833
}
793-
if (home_stubby_conf_fn &&
794-
(r = parse_config_file(home_stubby_conf_fn))) {
795-
if (r != GETDNS_RETURN_IO_ERROR)
834+
r = parse_config_file(conf_fn);
835+
if (r == GETDNS_RETURN_GOOD)
836+
found_conf = 1;
837+
else if (r != GETDNS_RETURN_IO_ERROR)
838+
fprintf( stderr, "Error parsing config file "
839+
"\"%s\": %s\n", conf_fn
840+
, _getdns_strerror(r));
841+
free(conf_fn);
842+
if (!found_conf) {
843+
conf_fn = system_config_file();
844+
if (!conf_fn) {
845+
fprintf(stderr, "Error getting system config file");
846+
exit(EXIT_FAILURE);
847+
}
848+
r = parse_config_file(conf_fn);
849+
if (r == GETDNS_RETURN_GOOD)
850+
found_conf = 1;
851+
else if (r != GETDNS_RETURN_IO_ERROR)
796852
fprintf( stderr, "Error parsing config file "
797-
"\"%s\": %s\n", home_stubby_conf_fn
853+
"\"%s\": %s\n", conf_fn
798854
, _getdns_strerror(r));
799-
if (home_stubby_conf_fn != home_stubby_conf_fn_spc)
800-
free(home_stubby_conf_fn);
801-
home_stubby_conf_fn = NULL;
855+
free(conf_fn);
802856
}
803-
if (!home_stubby_conf_fn &&
804-
(r = parse_config_file(STUBBYCONFDIR"/stubby.yml"))) {
805-
if (r != GETDNS_RETURN_IO_ERROR) {
806-
fprintf( stderr, "Error parsing config file \"%s\": %s\n"
807-
, STUBBYCONFDIR"/stubby.yml"
808-
, _getdns_strerror(r));
809-
}
857+
if (!found_conf)
810858
fprintf(stderr, "WARNING: No Stubby config file found... using minimal default config (Opportunistic Usage)\n");
811-
}
812-
if (home_stubby_conf_fn &&
813-
home_stubby_conf_fn != home_stubby_conf_fn_spc) {
814-
free(home_stubby_conf_fn);
815-
}
816859
}
817860
if ((r = getdns_context_set_resolution_type(context, GETDNS_RESOLUTION_STUB))) {
818861
fprintf( stderr, "Error while trying to configure stubby for "

stubby.yml.example

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ edns_client_subnet_private : 1
6565
############################# CONNECTION SETTINGS ##############################
6666
# Set to 1 to instruct stubby to distribute queries across all available name
6767
# servers - this will use multiple simultaneous connections which can give
68-
# better performance is most (but not all) cases.
68+
# better performance in most (but not all) cases.
6969
# Set to 0 to treat the upstreams below as an ordered list and use a single
7070
# upstream until it becomes unavailable, then use the next one.
7171
round_robin_upstreams: 1
7272

73-
# EDNS0 option for keepalive idle timeout in ms as specified in
73+
# EDNS0 option for keepalive idle timeout in milliseconds as specified in
7474
# https://tools.ietf.org/html/rfc7828
7575
# This keeps idle TLS connections open to avoid the overhead of opening a new
7676
# connection for every query.
@@ -84,16 +84,16 @@ idle_timeout: 10000
8484
# individual upstream after failures under normal circumstances (default 3600)
8585
# tls_backoff_time: 300
8686

87-
# Specify where the location for CA certificates for verification purposes are
88-
# located.
87+
# Specify the location for CA certificates used for verification purposes are
88+
# located - this overrides the OS specific default location.
8989
# tls_ca_path: "/etc/ssl/certs/"
9090

9191
# Limit the total number of outstanding queries permitted
9292
# limit_outstanding_queries: 100
9393

94-
# Specify the timeout on getting a response to an individual request
95-
# (default 5s)
96-
# timeout: 1
94+
# Specify the timeout in milliseconds on getting a response to an individual
95+
# request (default 5000)
96+
# timeout: 1000
9797

9898
# Set the acceptable ciphers for DNS over TLS. With OpenSSL 1.1.1 this list is
9999
# for TLS1.2 and older only. Ciphers for TLS1.3 should be set with the
@@ -132,8 +132,9 @@ listen_addresses:
132132
# Stubby tries to fetch and validate the DNSSEC root trust anchor on the fly
133133
# when needed (Zero configuration DNSSEC), but only if it can store then
134134
# somewhere. The default location to store these files is the ".getdns"
135-
# subdirectory in the user's home directory. If there is no home directory, or
136-
# the .getdns subdirectory could not be created (or is not present), Stubby
135+
# subdirectory in the user's home directory on Unixes, and the %appdata%\getdns
136+
# directory on Windows. If there is no home directory, or
137+
# the required subdirectory could not be created (or is not present), Stubby
137138
# will fall back to the current working directory to try to store the
138139
# trust-anchor files.
139140
#
@@ -223,8 +224,7 @@ upstream_recursive_servers:
223224
## Quad 9 'secure' service - Filters, does DNSSEC, doesn't send ECS
224225
# - address_data: 9.9.9.9
225226
# tls_auth_name: "dns.quad9.net"
226-
## Quad 9 'insecure' service - No filtering, does DNSSEC, may send ECS (it is
227-
## unclear if it honours the edns_client_subnet_private request from stubby)
227+
## Quad 9 'insecure' service - No filtering, no DNSSEC, doesn't send ECS
228228
# - address_data: 9.9.9.10
229229
# tls_auth_name: "dns.quad9.net"
230230
## Cloudflare 1.1.1.1 and 1.0.0.1
@@ -249,6 +249,16 @@ upstream_recursive_servers:
249249
# tls_auth_name: "dns.google"
250250
# - address_data: 8.8.4.4
251251
# tls_auth_name: "dns.google"
252+
## Adguard Default servers
253+
# - address_data: 176.103.130.130
254+
# tls_auth_name: "dns.adguard.com"
255+
# - address_data: 176.103.130.131
256+
# tls_auth_name: "dns.adguard.com"
257+
## Adguard Family Protection servers
258+
# - address_data: 176.103.130.132
259+
# tls_auth_name: "dns-family.adguard.com"
260+
# - address_data: 176.103.130.134
261+
# tls_auth_name: "dns-family.adguard.com"
252262
### Test servers ###
253263
## A Surfnet/Sinodun server supporting TLS 1.2 and 1.3
254264
# - address_data: 145.100.185.18
@@ -350,6 +360,16 @@ upstream_recursive_servers:
350360
# tls_auth_name: "dns.google"
351361
# - address_data: 2001:4860:4860::8844
352362
# tls_auth_name: "dns.google"
363+
## Adguard Default servers
364+
# - address_data: 2a00:5a60::ad1:0ff
365+
# tls_auth_name: "dns.adguard.com"
366+
# - address_data: 2a00:5a60::ad2:0ff
367+
# tls_auth_name: "dns.adguard.com"
368+
## Adguard Family Protection servers
369+
# - address_data: 2a00:5a60::bad1:0ff
370+
# tls_auth_name: "dns-family.adguard.com"
371+
# - address_data: 2a00:5a60::bad2:0ff
372+
# tls_auth_name: "dns-family.adguard.com"
353373
### Test servers ###
354374
## The Uncensored DNS server
355375
# - address_data: 2a01:3a0:53:53::0

0 commit comments

Comments
 (0)