Assignment title: Information


Project 1: A Simple Unix Shell Design and implement a simple UNIX shell program using the grammar specified in the later part of this section. Please allow for at least 100 commands in a command line and at least 1000 arguments in each command.

In addition to the above, the following are required:

1. Reconfigurable shell prompt (default %) The shell must have a shell built-in command prompt for changing the current prompt. For example, type the following command % prompt john$ should change the shell prompt to john$, i.e., the second token of the command.

2. The shell built-in command pwd This command prints the current directory (also known as working directory) of the shell process.

3. Directory walk This command is similar to that provided by the Bash built-in command cd. In particular, typing the command without a path should set the current directory of the shell to the home directory of the user.

4. Wildcard characters If a token contains wildcard characters * or ? the token is treated as a filename. The wildcard characters in such a token indicate to the shell that the filename must be expanded. For example the command % ls *.c may be expanded to ls ex1.c ex2.c ex3.c if there are three matching files ex1.c ex2.c ex3.c in the current directory. You may implement this feature using the C function glob.

5. Standard input and output redirections > and < For example: % ls -lt > foo would redirect the standard output of process ls -lt to file foo. Similarly in the following command, % cat < foo the standard input of process cat is redirected to file foo.

6. Shell pipeline | For example: % ls -lt | more the standard output of process ls -lt is connected to the standard input of process more via a pipe.

7. Background job execution For example: % xterm & The commannd line starts command xterm in the background (i.e., the shell will not wait for the process to terminate and you can type in the next command immediately). The following command line % sleep 20 & ps -l starts command sleep 20 and immediately execute command ps -l without waiting for command sleep 20 to finish first.

8. Sequential job execution For example the command line % sleep 20 ; ps -l starts command sleep 20 first, and wait for it to finish, then execute command ps -l.

9. The shell built-in command exit Use the built-in command exit to terminate the shell program. The behaviour of the above commands (except prompt) should be as close to those of the Bash shell as possible. In addition, your shell should not be terminated by CTRL-C or CTRL-\.

Finally you must not use any existing shell program to implement your shell (for example by calling a shell through the function system). That would defeat the purpose of this project. In the above, commands such as ls, cat, grep, sleep, ps and xterm are used as examples to illustrate the use of your shell program. However your shell must be able to handle any command or executable program. Note the commands prompt, pwd, cd and exit should be implemented as shell builtins, not as external commands.

The syntax and behaviour of the built-in commands pwd, cd and exit should be similar to the corresponding commands under Bash shell. A major part of this shell is a command line parser. Please read the this note for suggestions on implementing the parser. Definition of Command Line Syntax The following is the formal definition of the command line syntax for the shell, defined in Extended BNF:

< command line > ::= < job > | < job > '&' | < job > '&' < command line > | < job > ';' | < job > ';' < command line > < job > ::= < command >

| < job > '|' < command > < command > ::= < simple command > | < simple command > '<' < filename > | < simple command > '>' < filename > < simple command > ::= < pathname >

| < simple command > < token > An informal definition plus additional explanations of the syntax is given below:

1. A command line consists of one or several jobs separated by the special character "&" and/or ";". The last job may be followed by the character "&" or ";". If a job is followed by the character "&", then it should be executed in the background. 2. A job consists of one or more commands separated by pipeline characters "|";

3. A command is either a simple command or a simple command followed by an input redirection (< filename) or an output redirection (> filename); 4. A simple command consists of a single pathname followed by zero or more tokens;

5. The following five characters are the special characters: &, ;, |, < , > ; 6. The white space characters are defined to be the space character and the tab character;

7. A token is either a special character or a string that does not contain space characters or special characters. In this project we do not consider quoted strings. Therefore if single quote or double quote characters appear in a string, they are treated just like any other non-special characters without its usually special meaning;

8. Tokens must be separated by one or more white spaces; 9. A pathname is either a file name, or an absolute pathname, or a relative pathname.

Examples of pathnames are grep, /usr/bin/grep, bin/grep and ./grep; 10. A command line must end with a newline character.

1. You have forgotten the root password for a system. How do you reset the root password? Give three methods: one using sudo, one booting into runlevel one and the third using a rescue disk. How do you stop any other users from using these same techniques to crack the system?

2. Try the unofficial practice L101 quiz at http://www.penguintutor.com/quiz/index.php Keep trying till you score above 70%, and then print out your results page. You can make use of the web and a runnng Linux system to try to answer the questions

3. My router keeps a log of intrusion attempts. The log contains lines like log - http://cict.bhtafe.edu.au/subjects/ict213/assignments/log.txt

Mar 24 01:17:30 user alert kernel: Intrusion -> TCP packet from [ppp0] 108.162.231.167:19756 to 192.168.1.101:80

I would like to know which of my services are being attacked, and which hosts are most heavily involved in attacks. My external IP is 60.241.205.167 and my internal network is 192.168.1.0/24. I want to know 1. Which IP addresses are attacking me

2. Which ports on my hosts are being attacked To do this, 3. What command will print just the lines containing the string "user alert kernel" from the log? 4. What command will read these lines from standard input and just print the "Attack IP:port" segment?

5. What command will remove the ":port" from these lines? 6. What commands will sort the list of attack IP addresses and tell me the top ten addresses? 7. For each of these ten, attempt a reverse lookup to see if their host names are accessible

8. What command(s) will print the "My IP:port" segments from the log? 9. What command(s) will tell me the most frequently attacked IP address and port?

4. You are setting up some Linux machines to be used as "point of sale" terminals. When someone logs in the point-of-sale application should run, occupying the whole screen with no window decorations. How do you configure the machine to do this? (For simplicity, use just an editor application as the "point-of-sale application"). Show which configuration files you have used and their contents, and attach a screen shot of the application.

5. Summarise the arguments for and against systemd in about two paragraphs.