From 8ee88613458f9f6249e03d6dfdd2c79e549ffd81 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 27 Jun 2020 18:23:35 +0200 Subject: [PATCH] Relative names with dots are now allowed if the dots are escaped --- README | 5 ++--- TODO | 1 - cf.dist/example.com | 3 ++- m4/dnslib.m4 | 7 ++++--- m4/nsc.m4 | 18 +++++++++--------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README b/README index 529020e..2733214 100644 --- a/README +++ b/README @@ -194,9 +194,8 @@ output with your own records. All host or domain names are either names relative to the current domain with no dots inside or absolute names (in this case, NSC automatically -ensures that the trailing dot is present in the resource records). Relative -names with dots are not supported, but they are rare and you can always write -them as absolute anyway. +ensures that the trailing dot is present in the resource records). If you +really need a relative name with dots, escape all dots as "\.". Your menu: diff --git a/TODO b/TODO index 0845c7c..ba839b3 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ freebsd: don't use `-f' in hostname - Update or delete nsc.lsm -- do we still need root.cache? diff --git a/cf.dist/example.com b/cf.dist/example.com index b5e900c..6a57551 100644 --- a/cf.dist/example.com +++ b/cf.dist/example.com @@ -26,10 +26,11 @@ RP(admin.example.com, text) H(ns1, 10.0.0.1) H(ns2, 10.1.0.1) H(mail, 10.0.0.2) +H(name\.with\.dots, 10.0.0.3) ; A web server with several aliases and MX records -H(www, 10.0.0.3) +H(www, 10.0.0.4) ALIAS(fairytales, scifi, horror) MX(0 mail.example.com) diff --git a/m4/dnslib.m4 b/m4/dnslib.m4 index 414aa65..5997262 100644 --- a/m4/dnslib.m4 +++ b/m4/dnslib.m4 @@ -28,10 +28,11 @@ define(nsc_file_name, `translit($1,/,@)') define(nsc_revIPa, `ifelse($#, 1, `$1', `nsc_revIPa(shift($@)).$1')') define(nsc_revaddr, `nsc_revIPa(translit($1, `.', `,'))') -# Fix up dots in a name: if the name is not simple (i.e., it contains at least one dot), -# ensure that it ends with a dot. +# Fix up dots in a name: If the name is not simple (i.e., it contains at least one unescaped +# dot), ensure that it ends with a dot. Then unescape all escaped dots (\.). -define(nsc_corr_dot, `ifelse(substr($1,decr(len($1))),.,$1,$1`'ifelse(index($1,.),-1,,.))') +define(nsc_name, `nsc_unescape_name(ifelse(substr($1,decr(len($1))),.,$1,$1`'ifelse(regexp($1,`[^\\]\.'),-1,,.)))') +define(nsc_unescape_name,`patsubst(`$1',\\\.,.)') # Normalize IPv6 address diff --git a/m4/nsc.m4 b/m4/nsc.m4 index cf7a81d..8a94bc2 100644 --- a/m4/nsc.m4 +++ b/m4/nsc.m4 @@ -28,9 +28,9 @@ define(`VERSION',TODAY_CODE`'format(`%02d', SUBVER_NUM)) # Record names -define(nsc_set_name, `define(`CURRENT_NAME', nsc_corr_dot($1))define(`PRINT_NAME', CURRENT_NAME)') +define(nsc_set_name, `define(`CURRENT_NAME', nsc_name($1))define(`PRINT_NAME', CURRENT_NAME)') define(nsc_emit_name, `ifdef(`PRINT_NAME', `PRINT_NAME`'undefine(`PRINT_NAME')', `')') -define(nsc_abs_name, `ifelse(CURRENT_NAME, translit(CURRENT_NAME,.,:), CURRENT_NAME.CURRENT_DOMAIN, CURRENT_NAME)') +define(nsc_abs_name, `ifelse(regexp(CURRENT_NAME,\.$),-1,CURRENT_NAME.CURRENT_DOMAIN,CURRENT_NAME)') define(nsc_abs_name_nodot, `define(`nsc_tmp', nsc_abs_name)substr(nsc_tmp,0,decr(len(nsc_tmp)))') # SOA record @@ -38,7 +38,7 @@ define(nsc_abs_name_nodot, `define(`nsc_tmp', nsc_abs_name)substr(nsc_tmp,0,decr define(nsc_SOA, ` ifelse(CURRENT_DOMAIN,@,`',$ORIGIN CURRENT_DOMAIN) $TTL MINTTL -nsc_emit_name `SOA' nsc_corr_dot(NSNAME) MAINTNAME ( +nsc_emit_name `SOA' nsc_name(NSNAME) MAINTNAME ( VERSION REFRESH RETRY EXPIRE MINTTL )') define(SOA, `ifdef(`CURRENT_DOMAIN',`ifdef(`REVERSE_MODE',,`nsc_fatal_error(`SOA record defined twice')')')dnl define(`CURRENT_DOMAIN',ifelse($1,@,@,$1.))dnl @@ -105,13 +105,13 @@ define(GLUE, `DH($@)') # NS record -define(nsc_NS, `nsc_emit_name `NS' nsc_corr_dot($1) +define(nsc_NS, `nsc_emit_name `NS' nsc_name($1) ') define(NS, `nsc_iterate(`nsc_NS', $@)dnl') # MX record -define(nsc_MX, `nsc_emit_name `MX' nsc_corr_dot($1) +define(nsc_MX, `nsc_emit_name `MX' nsc_name($1) ') define(MX, `nsc_iterate(`nsc_MX', $@)dnl') @@ -131,19 +131,19 @@ define(TXT, `nsc_emit_name `TXT' "$1"') # RP (responsible person) records -define(RP, `nsc_emit_name `RP' nsc_corr_dot($1) nsc_corr_dot($2)') +define(RP, `nsc_emit_name `RP' nsc_name($1) nsc_name($2)') # SRV records -define(SRV, `_`'$1`'._`'$2`'.CURRENT_NAME `SRV' $3 $4 $5 nsc_corr_dot($6)`'nsc_set_name(CURRENT_NAME)') +define(SRV, `_`'$1`'._`'$2`'.CURRENT_NAME `SRV' $3 $4 $5 nsc_name($6)`'nsc_set_name(CURRENT_NAME)') # CNAME records -define(CNAME, `$1 `CNAME' nsc_corr_dot($2)') +define(CNAME, `$1 `CNAME' nsc_name($2)') # Explicit PTR records -define(PTR, `$1 `PTR' nsc_corr_dot($2)') +define(PTR, `$1 `PTR' nsc_name($2)') # DS records (DNSSEC keys for subdomains) -- 2.39.2