Program 2

Due Date: May 6, 2004
100 Points


This program asks you to determine whether a user can access a file.

Program Function

You are to write a program that takes the name of a user or a group and a file name. The program prints the access permissions that the user has over the file. The permissions for a file are read, write, and execute. The permissions for a directory are list (read), alter (write), and search (execute).

Command Syntax

Your program must be named perm, and must accept the following command-line syntax:

perm [ -p ] [ -g ] user_or_group_name filename

where user_or_group_name is the name of the user or group, and filename is the name of the file to be checked.

If the -p option is given, the program is to print the access permissions for each component in the filename.

If the -g option is given, the user_or_group_name is to be considered a group name, and if no such group exists an error is to be given. If it is omitted, the user_or_group_name is assumed to be a user name unless no such user exists, in which case it is taken to be a group name.

Output

Your program is to print the information in the following form when the -p option is not given:

user bishop can read and execute the file /bin/sh

or

group staff can read, write, and execute the file /tmp/xyzzy

If the -p option is given, the output should look like:

user bishop can list and search the directory /bin
user bishop can read and execute the file /bin/sh
or
group staff can list, alter, and search the directory /tmp
group staff can read, write, and execute the file /tmp/xyzzy

What To Turn In

Turn in your fully commented source code and a Makefile bundled into a tar(1) file. When unpacked, the tar file should create a directory called pr2 that contains the program and the Makefile The Makefile should be constructed so that the grader can cd into the newly-created directory, type

make
and then invoke perm as described above. If the grader has to do anything more, you will lose points!

Extra Credit

For group access, check each member of the group to determine if any of them is the owner of the file. Print that user's access separately.


Here is a PDF version of this document.