code wiki / _hdl_build / nx_pub_dns_gate.nx
nx_pub_dns_gate.nx source
↩ module page · 37 lines · 2998 B
1// nx_pub_dns_gate.nx -- pub_dns proof: the publisher emits a well-formed, persistent domain->endpoint wiring directive
2// for hosting to apply (the public-domain cutover is NOT a fragile daemon-swap). File-based. license_tier: ORIGINAL expect_exit: 0
3import "nx_syscalls.nx"
4import "nx_publisher.nx"
5import "nx_runpath.nx"
6
7func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
8func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
9func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 }
10func g_unlink(path: *u8) -> i64 { __syscall(87, path as i64, 0, 0, 0, 0, 0); return 0 }
11func file_has(path: *u8, needle: *u8) -> i64 { let lp: *i64 = sys_mmap(8) as *i64; let d: *u8 = sys_read_file(path, lp); if (d as i64)==0 { return 0 } return pub_substr(d, lp[0], needle) }
12
13func main() -> i64 {
14 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
15 g_w("=== NX-PUB-DNS GATE (publisher emits the public-domain wiring directive) ===\n" as *u8)
16 let wsid: *u8 = sys_mmap(64); rp_wsid(wsid); rp_ensure(wsid)
17 let D: *u8 = sys_mmap(512); rp_path(wsid, "pdns" as *u8, D); __syscall(83, D as i64, 493, 0, 0, 0, 0)
18
19 let buf: *u8 = sys_mmap(512)
20 let n: i64 = pub_dns_config("nishifamily.com" as *u8, "192.168.8.240" as *u8, 443, buf)
21 let well_formed: i64 = ((pub_substr(buf, n, "nishifamily.com" as *u8)==1) as i64) & ((pub_substr(buf, n, "192.168.8.240" as *u8)==1) as i64) & ((pub_substr(buf, n, "port=443" as *u8)==1) as i64) & ((pub_substr(buf, n, "proto=https" as *u8)==1) as i64)
22
23 let conf: *u8 = sys_mmap(700); pub_join(D, "dns.conf" as *u8, conf); g_unlink(conf)
24 pub_dns_emit("nishifamily.com" as *u8, "192.168.8.240" as *u8, 443, conf)
25 let persisted: i64 = ((file_has(conf, "nishifamily.com" as *u8)==1) as i64) & ((file_has(conf, "192.168.8.240" as *u8)==1) as i64)
26 let wrong_port_absent: i64 = (pub_substr(buf, n, "port=8080" as *u8)==0) as i64
27
28 g_w(" config='" as *u8); g_w(buf); g_w("'\n" as *u8)
29 g_row("pub_dns emits a well-formed directive (domain + host + port=443 + proto=https)" as *u8, well_formed, pass)
30 g_row("emitted config persists to disk + reads back (for hosting to apply)" as *u8, persisted, pass)
31 g_row("LIAR-KILL: the directive carries the REAL port (443), not a wrong one (8080)" as *u8, wrong_port_absent, pass)
32 g_w(" NOTE: applying the DNS A-record / proxy is hosting-coordinated (operator-gated); the publisher EMITS it.\n" as *u8)
33
34 g_w("NX-PUB-DNS rows=3 pass=" as *u8); g_n(pass[0])
35 if pass[0]==3 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
36 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
37}