cybersecurity · intermediate · ~15 min
Mechanise an audit checklist.
Score a setuid program against a fixed 5-item hardening checklist by counting how many checks pass.
Implement int setuid_score(int f1, int f2, int f3, int f4, int f5) that returns the number of passing checks (0..5). Each argument is a boolean (1 = the check passes, 0 = it fails):
f1 = environment scrubbed (clearenv called)f2 = fds 0/1/2 confirmed open at startf3 = uses geteuid for auth decisions, not getuidf4 = uses openat + O_NOFOLLOW for file accessf5 = does not call system/popenf1..f5: five flags the grader provides. Treat each as a boolean (any non-zero counts as 1).Returns the count of passing checks, an int in 0..5.
setuid_score(1,1,1,1,1) -> 5
setuid_score(0,0,0,0,0) -> 0
setuid_score(1,0,1,0,1) -> 3
setuid_score(0,1,0,1,0) -> 2
Auditing setuid programs is rote — 5 items. Mechanising the score makes you fast.
Five boolean flags f1..f5 (1 = check passes, 0 = fails).
The count of passing checks, an int in 0..5.
Normalise each flag to 0/1 and sum.
int setuid_score(int f1, int f2, int f3, int f4, int f5) { /* TODO */ (void)f1; (void)f2; (void)f3; (void)f4; (void)f5; return 0; }
Treating any non-zero as 1 (we want strict 0/1).
All zero. All one. Any combination.
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.