From nobody Wed May 15 10:10:26 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VfTW61rXhz5KcNW; Wed, 15 May 2024 10:10:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VfTW61CSWz4k6P; Wed, 15 May 2024 10:10:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715767826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=d0zu9zaT2iZcR+DHHhZ7kIaum8Px8GBMw0Z+YSxKHB8=; b=EdcZOVpRKm6iTOu6w3Vr2zz7eG8UgwLCqV/IqyTlVDZRON8CNDSy2lzM+Nl4qog6xQSb+y IpJ53JlAq3SQ3wfkz3yHlss8gLYidr3UpuK+jevRBDUB0wHhVUXJ3/BRHRwrT9lt1MjLU4 mzLkcdAaHbV6O07ua+WJdqtFeckQ0YV7/sF18hxqjUZvyGMZPnWAyUZxiimphr0gY5adjx HKxGao9YFclFMfaWVBBYKj2A5avYjBgjvTPJp7DijVCrpzbbgvQF09TCnbpEtgY02CRevi LbmysXJqK23VYk3H8rdLg39vNCyKlYHnyZ1nY8++syyAj07VnvloDEPX16czyA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715767826; a=rsa-sha256; cv=none; b=FL24iARERxsiWbHp3u4+wbzhkkJZezDy4UC9xTB9HLLeQcbcbGE4rl87B5hhJgfbq31coG 1RysAVSqNYMoKavoG84nhxcynFsOG173PfRYjk+qAzaPsTEVthtiiCIIFmMoKYYkJBhTZ2 cuz2zh37XUUGFz5yUrzip7z+GqQln0q7V13iBVUzNrvYRS+k8EMu8k/NcfHDMbZ7VZUJJp apuL+31OILBCr8pfw/0Syt99vcTazEZgABLbiE550eBqFI8EaWOwdLn1uGxSRD1voWXnVi qWpGrDt6l7CCR0n+CZLhhObQJIDXjNiegaBHE9UVFG9t2zuNw+bfJVEVOopiKw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715767826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=d0zu9zaT2iZcR+DHHhZ7kIaum8Px8GBMw0Z+YSxKHB8=; b=Dcl62eK6UnsYM1y/Gsi6S0jviiM5um/Z3QhxhtocLw84IBkPSRl3BMy/grKHBy+pgVL6Co kWBHZ7xK4qxloi0ukCEsZQNSFh3h7FC0YbHFWfYKsM5zWM78mrK5wF7klD/ACfflGp013o J0INyrP2TNXoU4qC9Q1L990G06QEbCMUua24fAONe8U3IJXxKdVWyGPVV6zraUDKmhOlv+ CamWr/iX7agWmD88Dpgu3Z5vX7lyMd+OiPFmd2BD1cmah22Wg9uXh6WhK5BSGiSBGguWWn IzLR7p5cFZWIlY8l/udcAfp/+7kzZh06rpmlfjWxgSYi4HGcKQ5yJlxWXCMMXA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VfTW60qPnz19dS; Wed, 15 May 2024 10:10:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44FAAQiM070841; Wed, 15 May 2024 10:10:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44FAAQ5c070838; Wed, 15 May 2024 10:10:26 GMT (envelope-from git) Date: Wed, 15 May 2024 10:10:26 GMT Message-Id: <202405151010.44FAAQ5c070838@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 154ad8e0f88f - main - Revert "Issue #237 : Resolver uses nameserver commented out in /etc/resolv.conf" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 154ad8e0f88ffc07b6d06686f53bfc22927d3ad8 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=154ad8e0f88ffc07b6d06686f53bfc22927d3ad8 commit 154ad8e0f88ffc07b6d06686f53bfc22927d3ad8 Author: Dag-Erling Smørgrav AuthorDate: 2024-05-15 10:10:20 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-15 10:10:20 +0000 Revert "Issue #237 : Resolver uses nameserver commented out in /etc/resolv.conf" This reverts commit b5fb1f44ed435fa25fe3de87c9b9ee6c0aad5125. --- contrib/ldns/parse.c | 35 ++++--------------------------- contrib/ldns/resolver.c | 55 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/contrib/ldns/parse.c b/contrib/ldns/parse.c index af8b2c1321b2..9698ba71e881 100644 --- a/contrib/ldns/parse.c +++ b/contrib/ldns/parse.c @@ -27,14 +27,9 @@ ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit) return ldns_fget_token_l(f, token, delim, limit, NULL); } -enum file_type2parse { - zone_file_type, resolv_conf_file_type -}; - -static ldns_status -ldns_fget_token_l_st_file_type(FILE *f, char **token, size_t *limit, - bool fixed, const char *delim, int *line_nr, - enum file_type2parse file_type) +ldns_status +ldns_fget_token_l_st(FILE *f, char **token, size_t *limit, bool fixed + , const char *delim, int *line_nr) { int c, prev_c; int p; /* 0 -> no parentheses seen, >0 nr of ( seen */ @@ -103,9 +98,7 @@ ldns_fget_token_l_st_file_type(FILE *f, char **token, size_t *limit, } /* do something with comments ; */ - if ((c == ';' - || (c == '#' && file_type == resolv_conf_file_type)) - && quoted == 0) { + if (c == ';' && quoted == 0) { if (prev_c != '\\') { com = 1; } @@ -222,26 +215,6 @@ tokenread: return i == 0 ? LDNS_STATUS_SYNTAX_EMPTY : LDNS_STATUS_OK; } -ldns_status -ldns_fget_token_l_st(FILE *f, char **token, size_t *limit, bool fixed - , const char *delim, int *line_nr) -{ - return ldns_fget_token_l_st_file_type( - f, token, limit, fixed, delim, line_nr, zone_file_type); -} - -ssize_t -ldns_fget_token_l_resolv_conf(FILE *f, char *token, const char *delim, - size_t limit, int *line_nr) -{ - if (limit == 0) - limit = LDNS_MAX_LINELEN; - if (ldns_fget_token_l_st_file_type(f, &token, &limit, true, delim, - line_nr, resolv_conf_file_type)) - return -1; - else - return (ssize_t)strlen(token); -} ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr) diff --git a/contrib/ldns/resolver.c b/contrib/ldns/resolver.c index 4b398abb4418..f9ec65a55966 100644 --- a/contrib/ldns/resolver.c +++ b/contrib/ldns/resolver.c @@ -761,8 +761,6 @@ ldns_resolver_new_frm_fp(ldns_resolver **res, FILE *fp) return ldns_resolver_new_frm_fp_l(res, fp, NULL); } -ssize_t ldns_fget_token_l_resolv_conf(FILE *f, char *token, const char *delim, - size_t limit, int *line_nr); ldns_status ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) { @@ -777,7 +775,7 @@ ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) #endif ssize_t gtr, bgtr; ldns_buffer *b; - int lnr = 0; + int lnr = 0, oldline; FILE* myfp = fp; if(!line_nr) line_nr = &lnr; @@ -811,18 +809,36 @@ ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) gtr = 1; word[0] = 0; + oldline = *line_nr; expect = LDNS_RESOLV_KEYWORD; while (gtr > 0) { + /* check comments */ + if (word[0] == '#') { + word[0]='x'; + if(oldline == *line_nr) { + /* skip until end of line */ + int c; + do { + c = fgetc(myfp); + } while(c != EOF && c != '\n'); + if(c=='\n') (*line_nr)++; + } + /* and read next to prepare for further parsing */ + oldline = *line_nr; + continue; + } + oldline = *line_nr; switch(expect) { case LDNS_RESOLV_KEYWORD: /* keyword */ - gtr = ldns_fget_token_l_resolv_conf(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); + gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); if (gtr != 0) { + if(word[0] == '#') continue; for(i = 0; i < LDNS_RESOLV_KEYWORDS; i++) { if (strcasecmp(keyword[i], word) == 0) { /* chosen the keyword and * expect values carefully - */ + */ expect = i; break; } @@ -840,12 +856,16 @@ ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) break; case LDNS_RESOLV_DEFDOMAIN: /* default domain dname */ - gtr = ldns_fget_token_l_resolv_conf(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); + gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); if (gtr == 0) { if(!fp) fclose(myfp); ldns_resolver_deep_free(r); return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR; } + if(word[0] == '#') { + expect = LDNS_RESOLV_KEYWORD; + continue; + } tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, word); if (!tmp) { if(!fp) fclose(myfp); @@ -859,12 +879,16 @@ ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) break; case LDNS_RESOLV_NAMESERVER: /* NS aaaa or a record */ - gtr = ldns_fget_token_l_resolv_conf(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); + gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); if (gtr == 0) { if(!fp) fclose(myfp); ldns_resolver_deep_free(r); return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR; } + if(word[0] == '#') { + expect = LDNS_RESOLV_KEYWORD; + continue; + } if(strchr(word, '%')) { /* snip off interface labels, * fe80::222:19ff:fe31:4222%eth0 */ @@ -887,7 +911,7 @@ ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) break; case LDNS_RESOLV_SEARCH: /* search list domain dname */ - gtr = ldns_fget_token_l_resolv_conf(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr); + gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr); b = LDNS_MALLOC(ldns_buffer); if(!b) { ldns_resolver_deep_free(r); @@ -905,6 +929,10 @@ ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) bgtr = ldns_bget_token(b, word, LDNS_PARSE_NORMAL, (size_t) gtr + 1); while (bgtr > 0) { gtr -= bgtr; + if(word[0] == '#') { + expect = LDNS_RESOLV_KEYWORD; + break; + } tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, word); if (!tmp) { ldns_resolver_deep_free(r); @@ -926,23 +954,28 @@ ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr) } break; case LDNS_RESOLV_SORTLIST: - gtr = ldns_fget_token_l_resolv_conf(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr); + gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr); /* sortlist not implemented atm */ expect = LDNS_RESOLV_KEYWORD; break; case LDNS_RESOLV_OPTIONS: - gtr = ldns_fget_token_l_resolv_conf(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr); + gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr); /* options not implemented atm */ expect = LDNS_RESOLV_KEYWORD; break; case LDNS_RESOLV_ANCHOR: /* a file containing a DNSSEC trust anchor */ - gtr = ldns_fget_token_l_resolv_conf(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); + gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr); if (gtr == 0) { ldns_resolver_deep_free(r); if(!fp) fclose(myfp); return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR; } + if(word[0] == '#') { + expect = LDNS_RESOLV_KEYWORD; + continue; + } + #ifdef HAVE_SSL tmp_rr = ldns_read_anchor_file(word); (void) ldns_resolver_push_dnssec_anchor(r, tmp_rr);