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).

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os14-1-data-1.txt

mode 754
mode rw-r-----
umask 022 file
umask 027 dir
umask 077 file
What your program must print for os14-1-data-1.txt
mode 754 = 754 = rwxr-xr--
mode rw-r----- = 640 = rw-r-----
umask 022 file -> 644 rw-r--r--
umask 027 dir -> 750 rwxr-x---
umask 077 file -> 600 rw-------

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os14-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content os14-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

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.