code wiki / _hdl_build / nx_pub_audit_run.nx
nx_pub_audit_run.nx source
↩ module page · 78 lines · 4505 B
1// nx_pub_audit_run.nx -- R7b: run the no-bypass LAW audit over the REAL source tree to produce the MIGRATION
2// WORKLIST. Walks runtime/ + runtime/_hdl_build/ (sovereign getdents64 via nx_dirent), runs pub_audit_file on
3// each .nx, and reports every file that references the raw transport (nx_aw_send/nx_aw_push) yet is NOT part of
4// the sanctioned publisher/transport family (allowlisted by prefix: nx_aw_, nx_pub, nx_url, nx_synced, nx_hostctl).
5// Read-only (no migration here -- migration touches sibling files and is operator-coordinated). Emits the worklist
6// to knowledge/publish/bypass_worklist.txt + stdout with a count. license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_publisher.nx"
9import "nx_dirent.nx"
10const K_MAGIC_131072: i64 = 131072
11
12func aw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func an(v: i64) -> i64 { var m: i64=v; if m<0{aw("-" 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 }
14func rep(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); sys_write(fd,s,n); return 0 }
15
16func ax_starts(s: *u8, pfx: *u8) -> i64 { var i: i64=0; while pfx[i]!=(0 as u8){ if s[i]!=pfx[i]{ return 0 } i=i+1 } return 1 }
17// sanctioned to reference the transport (the publisher + transport/control/verify family).
18func ax_allowed(name: *u8) -> i64 {
19 if ax_starts(name, "nx_aw_" as *u8) == 1 { return 1 }
20 if ax_starts(name, "nx_pub" as *u8) == 1 { return 1 }
21 if ax_starts(name, "nx_url" as *u8) == 1 { return 1 }
22 if ax_starts(name, "nx_synced" as *u8) == 1 { return 1 }
23 if ax_starts(name, "nx_hostctl" as *u8) == 1 { return 1 }
24 return 0
25}
26func ax_ends_nx(name: *u8) -> i64 {
27 var l: i64 = 0; while name[l]!=(0 as u8){ l=l+1 }
28 if l < 4 { return 0 }
29 if name[l-3]==(46 as u8) { if name[l-2]==(110 as u8) { if name[l-1]==(120 as u8) { return 1 } } }
30 return 0
31}
32
33// scan one directory. st[0]=files scanned, st[1]=bypass violations. prints + writes each violation.
34func ax_scan(dirpath: *u8, repfd: i64, st: *i64) -> i64 {
35 let fd: i64 = nx_openat(NX_AT_FDCWD, dirpath, NX_O_RDONLY | NX_O_DIRECTORY, 0)
36 if fd < 0 { return 0 }
37 let buf: *u8 = sys_mmap(K_MAGIC_131072)
38 let dr: *NxDirent = sys_mmap(NX_DIRENT_BYTES) as *NxDirent
39 var more: i64 = 1
40 while more == 1 {
41 let n: i64 = nx_dirent_read(fd, buf, K_MAGIC_131072)
42 if n <= 0 { more = 0 } else {
43 var off: i64 = 0
44 while off < n {
45 let nextoff: i64 = nx_dirent_iter(buf, off, n, dr)
46 if nextoff <= off { off = n } else {
47 if ax_ends_nx(dr.name) == 1 {
48 st[0] = st[0] + 1
49 let full: *u8 = sys_mmap(800); pub_join(dirpath, dr.name, full)
50 if pub_audit_call_strict(full, ax_allowed(dr.name)) == 1 {
51 st[1] = st[1] + 1
52 rep(repfd, " BYPASS -> migrate to pub_submit: " as *u8); rep(repfd, full); rep(repfd, "\n" as *u8)
53 }
54 }
55 off = nextoff
56 }
57 }
58 }
59 }
60 sys_close(fd)
61 return 0
62}
63
64func main() -> i64 {
65 aw("=== NX-PUBLISHER STRICT BYPASS AUDIT (real-tree scan, ALL live-touching primitives -> migration worklist) ===\n" as *u8)
66 let d: *u8 = "knowledge/publish" as *u8; __syscall(83, d as i64, 493, 0, 0, 0, 0)
67 let repfd: i64 = sys_openat_wr("knowledge/publish/bypass_worklist.txt" as *u8, 0x1a4)
68 let st: *i64 = sys_mmap(32); st[0]=0; st[1]=0
69 rep(repfd, "# NISHI PUBLISHER -- direct-publish bypass worklist (migrate each to pub_submit)\n" as *u8)
70 ax_scan("runtime" as *u8, repfd, st)
71 ax_scan("runtime/_hdl_build" as *u8, repfd, st)
72 aw(" scanned .nx files="); an(st[0]); aw(" BYPASS violations (workstreams to migrate)="); an(st[1]); aw("\n")
73 aw(" worklist -> knowledge/publish/bypass_worklist.txt\n" as *u8)
74 if repfd >= 0 { sys_close(repfd) }
75 // honest verdict: this is a REPORT (read-only). GREEN just means the scan ran (found >=0 files).
76 if st[0] > 0 { aw("AUDIT-RUN verdict=GREEN (tree scanned; worklist emitted)\n" as *u8); sys_exit(0); return 0 }
77 aw("AUDIT-RUN verdict=RED (no files scanned -- dir open failed?)\n" as *u8); sys_exit(1); return 1
78}