2 dnl ### NSC -- Zone File Generator
3 dnl ### (c) 1997--2011 Martin Mares <mj@ucw.cz>
5 dnl ### Usage: m4 -DVERS=path-to-version-file nsc.m4 domain-source-files >zone-file
6 dnl ### or: m4 -DHASHING nsc.m4 domain-source-files | md5sum
12 ifdef(`HASHING', `define(`VERSION',`YYYYMMDDNN')', `
14 ifdef(`VERS',`',`nsc_fatal_error(`VERS macro not defined')')
16 define(TODAY_CODE, translit(esyscmd(`date +"%Y%m%d"'),`
19 # Backward compatibility with NSC 2.x version files
20 ifdef(`last_today_code', `define(`LAST_TODAY_CODE',last_today_code)undefine(`last_today_code')')
21 ifdef(`subver_num', `define(`SUBVER_NUM',subver_num)undefine(`subver_num')')
22 ifelse(TODAY_CODE, LAST_TODAY_CODE, `', `define(`SUBVER_NUM',1)')
23 syscmd(echo >VERS "`define'(`LAST_TODAY_CODE',TODAY_CODE) `define'(`SUBVER_NUM',incr(SUBVER_NUM))")
24 ifelse(eval(SUBVER_NUM > 99),1,`nsc_fatal_error(`Too many zone changes in a single day, you must tweak 'VERS` manually')')
25 define(`VERSION',TODAY_CODE`'format(`%02d', SUBVER_NUM))
31 define(nsc_set_name, `define(`CURRENT_NAME', nsc_corr_dot($1))define(`PRINT_NAME', CURRENT_NAME)')
32 define(nsc_emit_name, `ifdef(`PRINT_NAME', `PRINT_NAME`'undefine(`PRINT_NAME')', `')')
33 define(nsc_abs_name, `ifelse(CURRENT_NAME, translit(CURRENT_NAME,.,:), CURRENT_NAME.CURRENT_DOMAIN, CURRENT_NAME)')
38 ifelse(CURRENT_DOMAIN,@,`',$ORIGIN CURRENT_DOMAIN)
40 nsc_emit_name `SOA' nsc_corr_dot(NSNAME) MAINTNAME (
41 VERSION REFRESH RETRY EXPIRE MINTTL )')
42 define(SOA, `ifdef(`CURRENT_DOMAIN',`ifdef(`REVERSE_MODE',,`nsc_fatal_error(`SOA record defined twice')')')dnl
43 define(`CURRENT_DOMAIN',ifelse($1,@,@,$1.))dnl
44 nsc_set_name(CURRENT_DOMAIN)dnl
45 ifdef(`REVERSE_MODE',,`nsc_SOA')')
49 define(REVERSE, `divert(-1)
50 define(`REVERSE_MODE', `')
52 define(`REVNET6', nsc_revblock6($1))
54 define(`REVNET', `$1.')
55 define(`REVLOW', `$2')
56 define(`REVHIGH', `$3')
65 define(nsc_auto_PTR4, `dnl
67 ifelse(REVNET, substr($1, 0, len(REVNET)), `
68 define(`REVX', substr($1, len(REVNET)))
70 `nsc_mk_PTR(nsc_revaddr(REVX), $2)',
72 ifelse(eval((REVX >= REVLOW) && (REVX <= REVHIGH)), 1, `nsc_mk_PTR(REVX, $2)')
78 define(nsc_auto_PTR6, `dnl
80 define(`REVA', nsc_revaddr6($1))
81 ifelse(REVNET6, substr(REVA, eval(63-len(REVNET6))), `
82 nsc_mk_PTR(substr(REVA, 0, eval(62-len(REVNET6))), $2)
89 define(nsc_AONLY, `nsc_emit_name nsc_if_v6($1,`AAAA nsc_norm_v6($1)',``A' $1')
91 define(nsc_A, `nsc_if_v6($1,`nsc_auto_PTR6',`nsc_auto_PTR4')($1,nsc_abs_name)nsc_AONLY($1)')
92 define(ADDR, `nsc_iterate(`nsc_A', $@)dnl')
93 define(DADDR, `nsc_iterate(`nsc_AONLY', $@)dnl')
97 define(H, `nsc_set_name($1)nsc_iterate(`nsc_A', shift($@))dnl')
98 define(DH, `nsc_set_name($1)nsc_iterate(`nsc_AONLY', shift($@))dnl')
100 # Subdomain specification and glue records
102 define(D, `nsc_set_name($1)dnl')
103 define(GLUE, `DH($@)')
107 define(nsc_NS, `nsc_emit_name `NS' nsc_corr_dot($1)
109 define(NS, `nsc_iterate(`nsc_NS', $@)dnl')
113 define(nsc_MX, `nsc_emit_name `MX' nsc_corr_dot($1)
115 define(MX, `nsc_iterate(`nsc_MX', $@)dnl')
119 define(HI, `nsc_emit_name HINFO "$1" "$2"')
123 define(nsc_ALIAS, `$1 `CNAME' CURRENT_NAME
125 define(ALIAS, `nsc_iterate(`nsc_ALIAS', $@)nsc_set_name(CURRENT_NAME)dnl')
129 define(TXT, `nsc_emit_name `TXT' "$1"')
131 # RP (responsible person) records
133 define(RP, `nsc_emit_name `RP' nsc_corr_dot($1) nsc_corr_dot($2)')
137 define(SRV, `_`'$1`'._`'$2`'.CURRENT_NAME `SRV' $3 $4 $5 nsc_corr_dot($6)`'nsc_set_name(CURRENT_NAME)')
141 define(CNAME, `$1 `CNAME' nsc_corr_dot($2)')
143 # Explicit PTR records
145 define(PTR, `$1 `PTR' nsc_corr_dot($2)')
147 # Shortcut for classless reverse delegation of a block
149 define(REVBLOCK, `nsc_forloop(`i', $2, $3, `i' `CNAME' `i'.$1
155 define(nsc_cleanup, `ifdef(`DISABLE_LOCALHOST',,`
156 ; Added automatically (required by RFC 1912)
157 localhost A 127.0.0.1
159 m4wrap(`nsc_cleanup')
162 `;;;' Primary zone file
163 `;;;' Generated by NSCVER (nsc.m4) on ifdef(`HASHING', ``CURRENT_DATE'', `CURRENT_DATE')
164 `;;;' Please do not edit manually
165 `;;;' `VERSION': VERSION