THINK FIRST·CODE LATER

← All labs

Unix permission checker

Problem

Process commands until the end of input:

  • mode M — M is octal (754) or symbolic (rwxr-xr--, 9 characters). Print mode 754 = 754 = rwxr-xr-- (the input, the 3-digit octal, the symbolic form).
  • umask U file|dir — the new object's mode = base & ~U (base 666 for files, 777 for directories). Print umask 022 file -> 644 rw-r--r--.
  • check user groups owner fileGroup mode op — groups is a comma-separated list, op is r, w or x. If the user is root: r and w are always allowed, x only if at least one x bit is set — print … -> ALLOWED (root bypasses permissions) or, for x, (root, needs some x bit). Otherwise select one class: owner if user = owner, else group if fileGroup is in groups, else other; print ben w on ana:staff rw-r----- -> DENIED (group class).

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.