cybersecurity · intermediate · ~15 min

Score a setuid program against the 5-item checklist

Mechanise an audit checklist.

Challenge

Score a setuid program against a fixed 5-item hardening checklist by counting how many checks pass.

Task

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 start
  • f3 = uses geteuid for auth decisions, not getuid
  • f4 = uses openat + O_NOFOLLOW for file access
  • f5 = does not call system/popen

Input

  • f1..f5: five flags the grader provides. Treat each as a boolean (any non-zero counts as 1).

Output

Returns the count of passing checks, an int in 0..5.

Example

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

Edge cases

  • All zero: returns 0. All one: returns 5.

Why this matters

Auditing setuid programs is rote — 5 items. Mechanising the score makes you fast.

Input format

Five boolean flags f1..f5 (1 = check passes, 0 = fails).

Output format

The count of passing checks, an int in 0..5.

Constraints

Normalise each flag to 0/1 and sum.

Starter code

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; }

Common mistakes

Treating any non-zero as 1 (we want strict 0/1).

Edge cases to handle

All zero. All one. Any combination.

Complexity

O(1).

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.