From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11399 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Sedich Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH v4] Add RES_OPTIONS support for resolv.conf options overriding Date: Mon, 05 Jun 2017 20:33:15 +0000 Message-ID: References: <20170430205258.4806-1-stefan.sedich@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a1146939847038305513c6af7" X-Trace: blaine.gmane.org 1496694821 9566 195.159.176.226 (5 Jun 2017 20:33:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Jun 2017 20:33:41 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11412-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jun 05 22:33:38 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dHyh0-0002Ei-0C for gllmg-musl@m.gmane.org; Mon, 05 Jun 2017 22:33:38 +0200 Original-Received: (qmail 32086 invoked by uid 550); 5 Jun 2017 20:33:39 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 32041 invoked from network); 5 Jun 2017 20:33:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=hvALXIj0dzgFOmIlj5I5YuyfcCJLWULqANXm+INg03c=; b=YUpnMUXrwWn01GlNBJ1D7XicjOxkv2FoWb8CHnT8nrghqQE/1VmTwDR8p3HnA5ktg2 cT7Uj0y4NhFa/r4XvlN9+R8tgozKHKm0F5ezJRHZN4HRKOjZCmvkkSvTRmI2ow3N3Gi1 7e/h8WIgJ2p/BqkBDEwcoIGDut7E5JCIiHQ1QVisjVGJ+ErlUNVXurkZMt9h3V6MnzR2 Cc8DVyUUeG1YNx3pccoGaU4vZAWcs/NXBmls7N7t3Utdz13qxsnoWRK0CYPjTIycG8uQ woftJEk3B3Ulr35fkfEooe6JXERuYq1WfsHWpa2sgJBQMFQIJkDtsqsDfw+MQwB4CV9g q2Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=hvALXIj0dzgFOmIlj5I5YuyfcCJLWULqANXm+INg03c=; b=XeGH2esltoKN7M/tpQv6gCWCiI29gHxWAHKWN1/MbmMfTeGZXPRlG7bz5X4ZSXfZRm i1lI804Ip2QYS09856V/EGQjZCe8uD0CqusULaQERHatXcZccE2r9NtsF1l0YopBYggt OXoiWzLuVapW9PgUDThL93UEL0Eiw2xrvHgC9EClou39Sg+u1dn1zKTj0Ah/ZH+dB0xk ZPaLjaxMu70UJMnI8VTGhYNbigmwYq28lz7PNnd/8mQC3VEQWjhLoeQOjpyhuoC63QxB 17gFPh0qIFklSaJ0a3Mx6ZXw31rRtKW79Dz36tDQfreKVWK/yEBIuRCYyaVv8tvcglqq 3w7g== X-Gm-Message-State: AODbwcBhzps0yQm/cspw915KSsnhE4nZChd8hefMcxkbqOcJGJ7IezSd 8nUHjjho1NwrADGPg/WGLoVBIR3xxzdW X-Received: by 10.28.24.202 with SMTP id 193mr9532580wmy.125.1496694806478; Mon, 05 Jun 2017 13:33:26 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:11399 Archived-At: --001a1146939847038305513c6af7 Content-Type: text/plain; charset="UTF-8" Bumping this one up, was there any interest in merging in the addition of supporting RES_OPTIONS for now? can then discuss further if the parsing should be improved as per the rest of the thread, I would love to at least get RES_OPTIONS in for now :)! - Stefan On Sun, Apr 30, 2017 at 1:54 PM Stefan Sedich wrote: > Submitting final version of this patch, if we have any activity around > deciding it we want to parse the options more strictly they can be > addressed separately. > > > > - Stefan > > On Sun, Apr 30, 2017 at 1:53 PM Stefan Sedich > wrote: > >> 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 >> --- >> Changed in v4: >> - apply feedback from Alexander >> >> src/network/resolvconf.c | 48 >> ++++++++++++++++++++++++++++++------------------ >> 1 file changed, 30 insertions(+), 18 deletions(-) >> >> diff --git a/src/network/resolvconf.c b/src/network/resolvconf.c >> index 4c3e4c4b..16ca395f 100644 >> --- a/src/network/resolvconf.c >> +++ b/src/network/resolvconf.c >> @@ -5,6 +5,30 @@ >> #include >> #include >> >> +void __parse_resolv_opts(struct resolvconf *conf, const 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,10 @@ no_resolv_conf: >> >> conf->nns = nns; >> >> + if (!libc.secure) { >> + const char *opts = getenv("RES_OPTIONS"); >> + if (opts) __parse_resolv_opts(conf, opts); >> + } >> + >> return 0; >> } >> -- >> 2.11.0 >> >> --001a1146939847038305513c6af7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Bumping this one up, was there any interest in merging in = the addition of supporting RES_OPTIONS for now? can then discuss further if= the parsing should be improved as per the rest of the thread, I would love= to at least get RES_OPTIONS in for now :)!



- Stefan

On Sun, Apr 30, 2017 at 1:54 PM Stefan Sedich <stefan.sedich@gmail.com> wrote:
Submitting final version = of this patch, if we have any activity around deciding it we want to parse = the options more strictly they can be addressed separately.



- Stefan

On Sun, Apr 30, 2017 at= 1:53 PM Stefan Sedich <stefan.sedich@gmail.com> wrote:
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
---
Changed in v4:
=C2=A0 - apply feedback from Alexander

=C2=A0src/network/resolvconf.c | 48 ++++++++++++++++++++++++++++++---------= ---------
=C2=A01 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/network/resolvconf.c b/src/network/resolvconf.c
index 4c3e4c4b..16ca395f 100644
--- a/src/network/resolvconf.c
+++ b/src/network/resolvconf.c
@@ -5,6 +5,30 @@
=C2=A0#include <string.h>
=C2=A0#include <netinet/in.h>

+void __parse_resolv_opts(struct resolvconf *conf, const char *opts)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0char *p, *z;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D strstr(opts, "ndots:");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (p && isdigit(p[6])) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p +=3D 6;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long x =3D= strtoul(p, &z, 10);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (z !=3D p) conf-= >ndots =3D x > 15 ? 15 : x;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D strstr(opts, "attempts:");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (p && isdigit(p[9])) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p +=3D 9;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long x =3D= strtoul(p, &z, 10);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (z !=3D p) conf-= >attempts =3D x > 10 ? 10 : x;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D strstr(opts, "timeout:");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (p && (isdigit(p[8]) || p[8]=3D=3D&#= 39;.')) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p +=3D 8;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long x =3D= strtoul(p, &z, 10);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (z !=3D p) conf-= >timeout =3D x > 60 ? 60 : x;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+}
+
=C2=A0int __get_resolv_conf(struct resolvconf *conf, char *search, size_t s= earch_sz)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 char line[256];
@@ -38,24 +62,7 @@ int __get_resolv_conf(struct resolvconf *conf, char *sea= rch, size_t search_sz)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 continue;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!strncmp(line, = "options", 7) && isspace(line[7])) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0p =3D strstr(line, "ndots:");
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0if (p && isdigit(p[6])) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p +=3D 6;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long x =3D strtoul(p, &z= , 10);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (z !=3D p) conf->ndots =3D x &g= t; 15 ? 15 : x;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0}
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0p =3D strstr(line, "attempts:");
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0if (p && isdigit(p[9])) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p +=3D 9;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long x =3D strtoul(p, &z= , 10);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (z !=3D p) conf->attempts =3D x= > 10 ? 10 : x;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0}
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0p =3D strstr(line, "timeout:");
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0if (p && (isdigit(p[8]) || p[8]=3D=3D'.')) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p +=3D 8;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long x =3D strtoul(p, &z= , 10);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (z !=3D p) conf->timeout =3D x = > 60 ? 60 : x;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0__parse_resolv_opts(conf, line);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 continue;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!strncmp(line, = "nameserver", 10) && isspace(line[10])) {
@@ -89,5 +96,10 @@ no_resolv_conf:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 conf->nns =3D nns;

+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!libc.secure) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const char *opts = =3D getenv("RES_OPTIONS");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (opts) __parse_r= esolv_opts(conf, opts);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0;
=C2=A0}
--
2.11.0

--001a1146939847038305513c6af7--