interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / agora / observer-check.om

776 lines · 13764 bytes Raw Blame History
1note Captured-output oracle, not a collector or authorization to touch production.
2note Compose om2, json.om, policy.om, observer-check.om with omega-mv e5b32567.
3note All raw argv fields are bounded to 4095 bytes. Private expectations are runtime inputs.
4note Exit 0 predicate PASS, 1 REFUSE, 2 PENDING never readiness, 90 bad CLI/capacity.
5note Modes and mutation contract are in the operator's local replay input table.
6global ob_buf uchar 262144
7text ob_unit "unit"
8text ob_snap "snapshot"
9text ob_ps "ps"
10text ob_jour "journal"
11text ob_extra "state"
12text ob_exec "exec"
13text ob_anc "ancestors"
14text ob_pid "MainPID"
15text ob_user "User"
16text ob_group "Group"
17text ob_allow "IPAddressAllow"
18text ob_deny "IPAddressDeny"
19text ob_frag "FragmentPath"
20text ob_drop "DropInPaths"
21text ob_actk "ActiveState"
22text ob_sub "SubState"
23text ob_cg "ControlGroup"
24text ob_acct "IPAccounting"
25text ob_run "running"
26text ob_yes "yes"
27text ob_act "active"
28text ob_exkey "ExecStart"
29text ob_path "path="
30text ob_argv "argv[]="
31text ob_epid "pid="
32text ob_list "LISTEN"
33text ob_owner "pid="
34text ob_pre "(agora)"
35text ob_sexec "/usr/lib/systemd/systemd-executor"
36text ob_peer "0.0.0.0:*"
37text ob_root "root"
38text ob_jpid "_PID"
39text ob_juid "_UID"
40text ob_jgid "_GID"
41text ob_jexe "_EXE"
42text ob_junit "_SYSTEMD_UNIT"
43text ob_jmsg "MESSAGE"
44text ob_jtime "__REALTIME_TIMESTAMP"
45text ob_jcmd "_CMDLINE"
46
47fn ob_ws c uchar to bool
48ret or eq c 32 and ge c 9 le c 13
49end
50fn ob_at idx ulong to ulong
51ret mul idx 4096
52end
53fn ob_len p ulong to ulong
54for i ulong 4096
55if eq get ob_buf add p i 0
56ret i
57end
58end
59ret 4096
60end
61fn ob_trim p ulong to ulong
62while ob_ws get ob_buf p bound 4096
63p = add p 1
64end
65ret p
66end
67fn ob_size p ulong to ulong
68n = ob_len p
69while gt n 0 bound 4096
70if not ob_ws get ob_buf sub add p n 1
71break
72end
73n = sub n 1
74end
75ret n
76end
77fn ob_eq a ulong b ulong to bool
78a = ob_trim a
79b = ob_trim b
80n = ob_size a
81if ne n ob_size b
82ret false
83end
84for i ulong n
85if ne get ob_buf add a i get ob_buf add b i
86ret false
87end
88end
89ret true
90end
91fn ob_text p ulong t view uchar * to bool
92p = ob_trim p
93if ne ob_size p len t
94ret false
95end
96for i ulong len t
97if ne get ob_buf add p i get t i
98ret false
99end
100end
101ret true
102end
103fn ob_copy p ulong n ulong dst ulong to ulong
104if gt n 4095
105exit 90
106end
107for i ulong n
108put ob_buf add dst i get ob_buf add p i
109end
110put ob_buf add dst n 0
111ret dst
112end
113fn ob_num p ulong to long
114p = ob_trim p
115n = ob_size p
116if or eq n 0 gt n 18
117ret -1
118end
119v = long 0
120for i ulong n
121c = get ob_buf add p i
122if or lt c 48 gt c 57
123ret -1
124end
125v = add mul v 10 long sub c 48
126end
127ret v
128end
129note Token extraction preserves raw input; each token uses its own scratch slot.
130fn ob_tok p ulong wanted ulong to ulong
131p = ob_trim p
132for k ulong 16
133s = p
134while ne get ob_buf p 0 bound 4096
135if ob_ws get ob_buf p
136break
137end
138p = add p 1
139end
140if eq k wanted
141ret ob_copy s sub p s ob_at add 40 wanted
142end
143p = ob_trim p
144end
145exit 90
146end
147fn ob_count p ulong to ulong
148p = ob_trim p
149n = ulong 0
150while ne get ob_buf p 0 bound 4096
151n = add n 1
152while ne get ob_buf p 0 bound 4096
153if ob_ws get ob_buf p
154break
155end
156p = add p 1
157end
158p = ob_trim p
159end
160ret n
161end
162note Exact key, one occurrence, arbitrary property ordering; duplicate keys refuse.
163fn ob_lineq start ulong stop ulong key view uchar * to bool
164if le sub stop start len key
165ret false
166end
167for i ulong len key
168if ne get ob_buf add start i get key i
169ret false
170end
171end
172ret eq get ob_buf add start len key 61
173end
174fn ob_field raw ulong key view uchar * to ulong
175p = raw
176found = false
177dst = ob_at 58
178put ob_buf dst 0
179while ne get ob_buf p 0 bound 4096
180s = p
181while ne get ob_buf p 0 bound 4096
182if eq get ob_buf p 10
183break
184end
185p = add p 1
186end
187if ob_lineq s p key
188if found
189exit 1
190end
191found = true
192s = add add s len key 1
193r = ob_copy s sub p s dst
194end
195if eq get ob_buf p 10
196p = add p 1
197end
198end
199if not found
200exit 1
201end
202ret dst
203end
204fn ob_prop key view uchar * expected ulong to bool
205ret ob_eq ob_field ob_at 2 key ob_at expected
206end
207fn ob_to_po src ulong dst ulong to void
208n = ob_size src
209if gt n 4095
210exit 90
211end
212for i ulong n
213put po_buf add dst i get ob_buf add src i
214end
215put po_buf add dst n 0
216end
217fn ob_policy to bool
218ob_to_po ob_field ob_at 2 ob_allow 0
219ob_to_po ob_field ob_at 2 ob_deny 4096
220ob_to_po ob_at 6 8192
221ob_to_po ob_at 7 12288
222ret po_check 0 4096 8192 12288
223end
224fn ob_unitcheck to int
225if ne argcnt 10
226ret 90
227end
228if le ob_num ob_at 3 0
229ret 1
230end
231if ne ob_num ob_field ob_at 2 ob_pid ob_num ob_at 3
232ret 1
233end
234if not ob_prop ob_user 4
235ret 1
236end
237if not ob_prop ob_group 5
238ret 1
239end
240if not ob_prop ob_frag 8
241ret 1
242end
243if not ob_prop ob_drop 9
244ret 1
245end
246if not ob_policy
247ret 1
248end
249ret 0
250end
251fn ob_statecheck to int
252if ne argcnt 4
253ret 90
254end
255if not ob_text ob_field ob_at 2 ob_actk ob_act
256ret 1
257end
258if not ob_text ob_field ob_at 2 ob_sub ob_run
259ret 1
260end
261if not ob_text ob_field ob_at 2 ob_acct ob_yes
262ret 1
263end
264if not ob_prop ob_cg 3
265ret 1
266end
267ret 0
268end
269note ss -H -ltnp has exactly one nonempty LISTEN row. Queue sizes and fd are not identity.
270note Require the exact local endpoint token and one actual pid= owner, not substring PID matches.
271fn ob_isown p ulong to bool
272if ne get ob_buf p 112
273ret false
274end
275if ne get ob_buf add p 1 105
276ret false
277end
278if ne get ob_buf add p 2 100
279ret false
280end
281ret eq get ob_buf add p 3 61
282end
283fn ob_ownr p ulong raw ulong to long
284if eq p raw
285exit 1
286end
287if ne get ob_buf sub p 1 44
288exit 1
289end
290q = add p 4
291s = q
292while and ge get ob_buf q 48 le get ob_buf q 57 bound 4096
293q = add q 1
294end
295if ne get ob_buf q 44
296exit 1
297end
298q = ob_copy s sub q s ob_at 57
299ret ob_num q
300end
301fn ob_socket raw ulong pid ulong endpoint ulong to int
302p = ob_trim raw
303if eq get ob_buf p 0
304ret 2
305end
306if ne ob_count raw 6
307ret 1
308end
309if not ob_text ob_tok p 0 ob_list
310ret 1
311end
312if not ob_eq ob_tok p 3 endpoint
313ret 1
314end
315owner = long -1
316while ne get ob_buf p 0 bound 4096
317if eq get ob_buf p 10
318q = ob_trim add p 1
319if ne get ob_buf q 0
320ret 1
321end
322end
323if ob_isown p
324if ne owner -1
325ret 1
326end
327owner = ob_ownr p raw
328end
329p = add p 1
330end
331if ne owner ob_num pid
332ret 1
333end
334if le owner 0
335ret 1
336end
337ret 0
338end
339fn ob_creds raw ulong uid ulong gid ulong to bool
340if ne ob_count raw 2
341ret false
342end
343if ne ob_num ob_tok raw 0 ob_num uid
344ret false
345end
346ret eq ob_num ob_tok raw 1 ob_num gid
347end
348fn ob_validcreds raw ulong uid ulong gid ulong to bool
349if ob_creds raw uid gid
350ret true
351end
352if ne ob_count raw 2
353ret false
354end
355if ne ob_num ob_tok raw 0 0
356ret false
357end
358v = ob_num ob_tok raw 1
359ret or eq v 0 eq v ob_num gid
360end
361fn ob_pssame a ulong b ulong to bool
362if ne ob_num ob_tok a 0 ob_num ob_tok b 0
363ret false
364end
365ret eq ob_num ob_tok a 1 ob_num ob_tok b 1
366end
367note snapshot PID MAIN_BEFORE EXE_BEFORE PS_BEFORE SS EXE_AFTER PS_AFTER MAIN_AFTER EXE UID GID ENDPOINT ELAPSED LIMIT.
368note Captured elapsed/limit are compared as data, never against the replay machine's current clock.
369note A single ownerless socket row during a recognized exec transition is pending only.
370fn ob_anon raw ulong endpoint ulong to bool
371if ne ob_count raw 5
372ret false
373end
374if not ob_text ob_tok raw 0 ob_list
375ret false
376end
377if lt ob_num ob_tok raw 1 0
378ret false
379end
380if lt ob_num ob_tok raw 2 0
381ret false
382end
383if not ob_eq ob_tok raw 3 endpoint
384ret false
385end
386if not ob_text ob_tok raw 4 ob_peer
387ret false
388end
389p = ob_trim raw
390while ne get ob_buf p 0 bound 4096
391if eq get ob_buf p 10
392if ne get ob_buf ob_trim add p 1 0
393ret false
394end
395end
396p = add p 1
397end
398ret true
399end
400
401fn ob_snapshot to int
402if ne argcnt 16
403ret 90
404end
405if or le ob_num ob_at 11 0 le ob_num ob_at 12 0
406ret 1
407end
408if or eq ob_size ob_at 10 0 eq ob_size ob_at 13 0
409ret 1
410end
411if le ob_num ob_at 2 0
412ret 1
413end
414if ne ob_num ob_at 2 ob_num ob_at 3
415ret 1
416end
417if ne ob_num ob_at 2 ob_num ob_at 9
418ret 1
419end
420if or lt ob_num ob_at 14 0 le ob_num ob_at 15 0
421ret 1
422end
423if ge ob_num ob_at 14 ob_num ob_at 15
424ret 1
425end
426if or eq ob_size ob_at 4 0 eq ob_size ob_at 7 0
427ret 1
428end
429if not ob_validcreds ob_at 5 ob_at 11 ob_at 12
430ret 1
431end
432if not ob_validcreds ob_at 8 ob_at 11 ob_at 12
433ret 1
434end
435owned = ob_socket ob_at 6 ob_at 2 ob_at 13
436if eq owned 1
437if ob_text ob_at 4 ob_sexec
438if ob_eq ob_at 7 ob_at 10
439if ob_creds ob_at 8 ob_at 11 ob_at 12
440if ob_anon ob_at 6 ob_at 13
441ret 2
442end
443end
444end
445end
446ret 1
447end
448if not ob_eq ob_at 4 ob_at 7
449ret 2
450end
451if not ob_pssame ob_at 5 ob_at 8
452ret 2
453end
454if not ob_eq ob_at 7 ob_at 10
455if eq owned 0
456ret 1
457end
458ret 2
459end
460if not ob_creds ob_at 8 ob_at 11 ob_at 12
461ret 1
462end
463ret owned
464end
465note Legacy ps display supplies no /proc proof. Only root/root/(agora) is recognized as pre-exec PENDING.
466fn ob_pscheck to int
467if ne argcnt 7
468ret 90
469end
470if ne ob_num ob_tok ob_at 2 0 ob_num ob_at 3
471ret 1
472end
473if le ob_num ob_at 3 0
474ret 1
475end
476if eq ob_count ob_at 2 4
477if ob_text ob_tok ob_at 2 1 ob_root
478if ob_text ob_tok ob_at 2 2 ob_root
479if ob_text ob_tok ob_at 2 3 ob_pre
480ret 2
481end
482end
483end
484end
485if not ob_eq ob_tok ob_at 2 1 ob_at 4
486ret 1
487end
488if not ob_eq ob_tok ob_at 2 2 ob_at 5
489ret 1
490end
491note Compare args from the fourth token onwards, preserving internal spaces.
492p = ob_trim ob_at 2
493for i ulong 3
494while ne get ob_buf p 0 bound 4096
495if ob_ws get ob_buf p
496break
497end
498p = add p 1
499end
500p = ob_trim p
501end
502if not ob_eq p ob_at 6
503ret 1
504end
505ret 0
506end
507note ExecStart runtime timestamps/status formatting is not executable identity.
508note Parse only exact semicolon-delimited path, argv[] and pid fields, require each once.
509fn ob_execfield raw ulong key view uchar * to ulong
510p = ob_trim raw
511if eq get ob_buf p 123
512p = ob_trim add p 1
513end
514found = false
515dst = ob_at 59
516put ob_buf dst 0
517while ne get ob_buf p 0 bound 4096
518s = p
519while ne get ob_buf p 0 bound 4096
520if eq get ob_buf p 59
521break
522end
523p = add p 1
524end
525same = ge sub p s len key
526if same
527for i ulong len key
528if ne get ob_buf add s i get key i
529same = false
530end
531end
532end
533if same
534if found
535exit 1
536end
537found = true
538v = add s len key
539r = ob_copy v sub p v dst
540end
541if eq get ob_buf p 59
542p = ob_trim add p 1
543end
544end
545if not found
546exit 1
547end
548ret dst
549end
550fn ob_execcheck to int
551if ne argcnt 6
552ret 90
553end
554raw = ob_field ob_at 2 ob_exkey
555if not ob_eq ob_execfield raw ob_path ob_at 3
556ret 1
557end
558if not ob_eq ob_execfield raw ob_argv ob_at 4
559ret 1
560end
561if ne ob_num ob_execfield raw ob_epid ob_num ob_at 5
562ret 1
563end
564ret 0
565end
566note Journal JSON is parsed by the existing strict native reader. Duplicated keys refuse.
567fn ob_jval src view uchar * off ulong to ulong
568outbuf = new uchar 4096 0
569n = js_sget src off outbuf
570if or lt n 0 gt n 4095
571exit 1
572end
573dst = ob_at 60
574for i ulong ulong n
575if eq get outbuf i 0
576exit 1
577end
578put ob_buf add dst i get outbuf i
579end
580put ob_buf add dst ulong n 0
581ret dst
582end
583fn ob_jfield src view uchar * tape view uint * key view uchar * to ulong
584k = js_first tape 0
585found = false
586dst = ob_at 60
587put ob_buf dst 0
588while ne k jsnone bound 4096
589if js_streq src js_off tape k key
590if found
591exit 1
592end
593found = true
594if ne js_type tape add k 1 jsstr
595exit 1
596end
597dst = ob_jval src js_off tape add k 1
598end
599k = js_mnext tape k
600end
601if not found
602exit 1
603end
604ret dst
605end
606note journal JSON EXPECT_PID UID GID EXE UNIT MESSAGE CMDLINE MIN_REALTIME MAX_REALTIME.
607note A journal PASS proves provenance of that historical message only, never socket readiness.
608fn ob_journal to int
609src = new uchar 4096 0
610tape = new uint 4096 0
611if ne argcnt 12
612ret 90
613end
614n = ob_len ob_at 2
615for i ulong n
616put src i get ob_buf add ob_at 2 i
617end
618r = js_init tape 4096 16
619if lt r 0
620ret 1
621end
622r = js_parse src tape n
623if lt r 0
624ret 1
625end
626if ne js_type tape 0 jsobj
627ret 1
628end
629if ne ob_num ob_jfield src tape ob_jpid ob_num ob_at 3
630ret 1
631end
632if ne ob_num ob_jfield src tape ob_juid ob_num ob_at 4
633ret 1
634end
635if ne ob_num ob_jfield src tape ob_jgid ob_num ob_at 5
636ret 1
637end
638if not ob_eq ob_jfield src tape ob_jexe ob_at 6
639ret 1
640end
641if not ob_eq ob_jfield src tape ob_junit ob_at 7
642ret 1
643end
644if not ob_eq ob_jfield src tape ob_jmsg ob_at 8
645ret 1
646end
647if not ob_eq ob_jfield src tape ob_jcmd ob_at 9
648ret 1
649end
650stamp = ob_num ob_jfield src tape ob_jtime
651lo = ob_num ob_at 10
652hi = ob_num ob_at 11
653if or le lo 0 lt hi lo
654ret 1
655end
656if or lt stamp lo gt stamp hi
657ret 1
658end
659ret 0
660end
661note Ancestor policy is collected with show options before --, one or two explicitly selected units.
662note Empty allow/deny properties must each occur once per blank-delimited unit record.
663fn ob_blank start ulong stop ulong to bool
664while lt start stop bound 4096
665if not ob_ws get ob_buf start
666ret false
667end
668start = add start 1
669end
670ret true
671end
672fn ob_ancrow start ulong stop ulong mask ulong to ulong
673if ob_lineq start stop ob_allow
674if ne and mask 1 0
675exit 1
676end
677start = add add start len ob_allow 1
678if not ob_blank start stop
679exit 1
680end
681ret or mask 1
682end
683if ob_lineq start stop ob_deny
684if ne and mask 2 0
685exit 1
686end
687start = add add start len ob_deny 1
688if not ob_blank start stop
689exit 1
690end
691ret or mask 2
692end
693exit 1
694end
695fn ob_eol p ulong to ulong
696while and ne get ob_buf p 0 ne get ob_buf p 10 bound 4096
697p = add p 1
698end
699ret p
700end
701fn ob_anccheck to int
702if ne argcnt 4
703ret 90
704end
705want = ob_num ob_at 3
706if or lt want 1 gt want 2
707ret 1
708end
709p = ob_at 2
710mask = ulong 0
711records = ulong 0
712while ne get ob_buf p 0 bound 4096
713s = p
714p = ob_eol p
715if ob_blank s p
716if ne mask 0
717if ne mask 3
718ret 1
719end
720records = add records 1
721mask = ulong 0
722end
723else
724mask = ob_ancrow s p mask
725end
726if eq get ob_buf p 10
727p = add p 1
728end
729end
730if ne mask 0
731if ne mask 3
732ret 1
733end
734records = add records 1
735end
736if ne long records want
737ret 1
738end
739ret 0
740end
741fn main to int
742if or lt argcnt 2 gt argcnt 32
743ret 90
744end
745for i ulong ulong sub argcnt 1
746idx = add i 1
747p = ob_at idx
748n = argread idx ob_buf p 4095
749if or lt n 0 ge n 4095
750ret 90
751end
752put ob_buf add p ulong n 0
753end
754if ob_text ob_at 1 ob_unit
755ret ob_unitcheck
756end
757if ob_text ob_at 1 ob_snap
758ret ob_snapshot
759end
760if ob_text ob_at 1 ob_ps
761ret ob_pscheck
762end
763if ob_text ob_at 1 ob_jour
764ret ob_journal
765end
766if ob_text ob_at 1 ob_extra
767ret ob_statecheck
768end
769if ob_text ob_at 1 ob_exec
770ret ob_execcheck
771end
772if ob_text ob_at 1 ob_anc
773ret ob_anccheck
774end
775ret 90
776end