|
|
Message-Id: <20170425194557.8520-1-stefan.sedich@gmail.com>
Date: Tue, 25 Apr 2017 12:45:57 -0700
From: Stefan Sedich <stefan.sedich@...il.com>
To: musl@...ts.openwall.com
Cc: Stefan Sedich <stefan.sedich@...il.com>
Subject: [PATCH v3] Add RES_OPTIONS support for resolv.conf options overriding
Currently glibc supports using the RES_OPTIONS environment variable
to customize the resolv.conf options on a per-process basis, this
adds the same support to musl
---
Changes in v3:
- initialize res_opts_env
src/network/resolvconf.c | 49 ++++++++++++++++++++++++++++++------------------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/src/network/resolvconf.c b/src/network/resolvconf.c
index 4c3e4c4b..177c6877 100644
--- a/src/network/resolvconf.c
+++ b/src/network/resolvconf.c
@@ -5,6 +5,30 @@
#include <string.h>
#include <netinet/in.h>
+void __parse_resolv_opts(struct resolvconf *conf, char *opts)
+{
+ char *p, *z;
+
+ p = strstr(opts, "ndots:");
+ if (p && isdigit(p[6])) {
+ p += 6;
+ unsigned long x = strtoul(p, &z, 10);
+ if (z != p) conf->ndots = x > 15 ? 15 : x;
+ }
+ p = strstr(opts, "attempts:");
+ if (p && isdigit(p[9])) {
+ p += 9;
+ unsigned long x = strtoul(p, &z, 10);
+ if (z != p) conf->attempts = x > 10 ? 10 : x;
+ }
+ p = strstr(opts, "timeout:");
+ if (p && (isdigit(p[8]) || p[8]=='.')) {
+ p += 8;
+ unsigned long x = strtoul(p, &z, 10);
+ if (z != p) conf->timeout = x > 60 ? 60 : x;
+ }
+}
+
int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
{
char line[256];
@@ -38,24 +62,7 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
continue;
}
if (!strncmp(line, "options", 7) && isspace(line[7])) {
- p = strstr(line, "ndots:");
- if (p && isdigit(p[6])) {
- p += 6;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->ndots = x > 15 ? 15 : x;
- }
- p = strstr(line, "attempts:");
- if (p && isdigit(p[9])) {
- p += 9;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->attempts = x > 10 ? 10 : x;
- }
- p = strstr(line, "timeout:");
- if (p && (isdigit(p[8]) || p[8]=='.')) {
- p += 8;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->timeout = x > 60 ? 60 : x;
- }
+ __parse_resolv_opts(conf, line);
continue;
}
if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
@@ -89,5 +96,11 @@ no_resolv_conf:
conf->nns = nns;
+ char *res_opts_env = NULL;
+ if (!libc.secure) res_opts_env = getenv("RES_OPTIONS");
+ if (res_opts_env) {
+ __parse_resolv_opts(conf, res_opts_env);
+ }
+
return 0;
}
--
2.11.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.