cybersecurity · intermediate · ~15 min · safe pentest lab

Owner permission bits

Extract the owner permission triad.

Challenge

Extract the owner's permission triad from a Unix mode. A mode packs owner/group/other as three octal digits; the owner is the top one.

Task

Implement int owner_perms(int mode) that returns the owner's rwx bits: (mode >> 6) & 7.

Input

  • mode: a Unix permission mode (octal), e.g. 0755. The grader passes fixed values.

Output

Returns int: the owner's 3-bit permission value (0..7).

Example

owner_perms(0755)   ->   7   (rwx)
owner_perms(0644)   ->   6   (rw-)

Edge cases

  • Only the owner triad is returned; group/other bits are masked out.

Rules

  • Shift right 6 and mask with 7.

Input format

A Unix permission mode (octal int).

Output format

An int: the owner's rwx bits (0..7).

Constraints

Return (mode >> 6) & 7.

Starter code

int owner_perms(int mode) {
    /* TODO */
    return 0;
}

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