Due: Mon Apr 9 11:59 pm
No late submissions accepted.
Assignment by Michael Chang, Julie Zelenski, and Chris Gregg
The goal for this week is for you to acclimate to working in the unix environment. This means configuring your setup and practicing until you are comfortable in the environment and can successfully build and run programs using unix tools.
Once you have your basics established, we have a few small tasks for you to complete and submit for the assignment proper.
Coming up to speed on unix
Depending on your prior experience, getting to a good level of comfort with unix might take a complete crash course or only a quick refresher.
CS107 instructor Chris Gregg has prepared a nice library of videos on key unix topics intended for a CS107 audience. Follow the link to "Getting help -> Unix reference" at the top of this web page to see the list of available topics. Scan the list to identify those topics you are unfamiliar with and look into those entries to learn more.
We think the videos are pretty nifty -- live demonstration of using the commands while having someone talk you through it, but we also provide written materials if you'd rather read than watch. You're free to do one or the other (or both!). Be sure to follow along and try out commands for yourself to get practice.
Our unix materials will be available all quarter and you can return to them at any time during CS107 to be introduced to a command or get a refresher on a topic. You are also welcome to seek out any materials that you find helpful to your learning.
Before you move on the assignment itself, double-check that you are comfortable with these unix basics:
- Log into myth
- Manage files, navigate filesystem
- Did you create a cs107 directory to hold and organize your work?
- Can you find the code being demoed in lecture?
- Edit files, configure your editor
- You should be able to create a new file, edit its contents, save, and exit.
- Working with the shell and unix commands
- If you encounter a command that is new to you, how can you get more information about it?
- Have you tried using tab-completion to avoid manually typing long commands/paths?
- Do you know how to retrieve/re-issue previous commands from your shell history?
Clone the assignment starter
CS107 assignments are distributed as Git repositories. When starting a CS107 assignment, you get a copy of the starter files by "cloning" from your class repo. Change into the directory where you are keeping your CS107 work and clone assign0 with this command:
git clone /afs/ir/class/cs107/repos/assign0/$USER assign0
If you attempt to clone and receive an error that the "repository does not exist":
- double-check for typos in the path. The path needs to be typed just as shown above. This includes the odd-looking $USER at end, which is a environment variable that expands into your username automatically.
- be sure you are logged into myth
If you confirm you are on a myth system and your correctly-typed repo path is not available, this indicates that you were not on the Axess enrollment list at the time we created the student repos. Drop an email to
email@example.com and tell us your username and we can manually set up a repo for you. Please make sure to enroll in Axess so we will create future repos for you automatically.
Once you have your clone, take a look at the starter files. The
readme.txt file is an ordinary text file where you will answer questions for the assignment. The
custom_tests files are used to build and test the triangle program.
The starter project also contains two subdirectories:
samples which is a symbolic link to the shared directory
tools which links to the
submit programs. (Further information about symlinks). Note that the shared directories are not editable by you, so you will not be able to create, edit, or delete files with these directories.
1. Enrollment confirmation
In order to complete your enrollment in CS107, you must confirm your availability to attend the exams and accept the course Honor Code policy.
readme.txt file in your editor now and edit as appropriate.
2. Intruder detection activity
For this activity, you will investigate a simulated break-in and answer the questions that are posed below. Your answers are to be typed into your
readme.txt file. For each, briefly describe (in 1-2 sentences) how you arrived at that answer and what unix commands you used.
Situation: An intruder had broken into your dorm's unix-based server and deleted most of files! Fortunately, there is a backup of the server contents, but before restoring the files, you'd like to know who the intruder was and what they did. With your newly-developed unix skills, you are just the expert to help investigate.
The key files are available in the directory
samples/server_files, which you can access within your cloned
The first thing you want to determine is the username of the intruder. The server is used by many different users. Each user has a home directory under
home/. For example, the home directory for the user
bob would be the path
home/bob. The file
users.list contains a list of all the authorized users. In an uncompromised system, each home directory would correspond to a user on the authorized list and vice versa. The intruder is not an authorized user and they gained illicit access by inserting their own home directory onto the system. This means there is one home directory that doesn't belong and your job is to find it.
Manually cross-comparing the users.list to the directory contents could work, but would be tedious. Instead what unix commands can you use to help? Hint: If you need to create a temporary file, you won't be able to create it inside
samples/server_files. Your home directory is a good place for these files and files there can easily be accessed via, e.g.
- What is the username of the intruder?
Now that you know the intruder's username, you will examine the files in intruder's home directory to learn what they were up to. Though the intruder tried to delete all the home directory files as part of covering their tracks, you can see that these supposedly empty directories are still taking up space. Perhaps something interesting was overlooked?
Take a closer look to find out what files have been left behind. Open each of the files in the intruder's home directory to see their contents.
- There is one file in the intruder's home directory that provides critical information about their activities. What file is that and what does it contain?
You believe that the intruder used
sudo to execute some commands as a privileged user. You want to identify those commands, but the file is rather long to comb through by hand. What unix command can you use to extract the information you seek?
- Which commands did the intruder execute using
Reiterating from above: when answering the intruder questions a/b/c above, be sure to include the details on how you figured out the answer and what unix commands you used along the way.
3. Simple C program
The final task of the assignment gives you practice using the unix development tools to edit, build, run, and test a simple C program.
In your assign0 folder, type
make. This will build the program named
triangle. Run the program to see what it does:
You should be rewarded with an ascii representation of Sierpinski's triangle - cool! Try to run
$ make make: Nothing to be done for `all'.
This isn't an error; it simply means that nothing has changed in the program's source, so there isn't anything to re-compile.
triangle.c in a text editor and change the value of the variable
main from 3 to 5. After you have saved the file, you must then use
make to re-build the program, and then you can run the newly built program to see the bigger triangle. If you forget to re-run
you will run the original version of the program that has not been updated.
The starter code uses a fixed constant for the number of levels to print. Your task is to extend the program to take an optional command-line argument that allows the user to dictate the number of levels. With no arguments
./triangle should default to a level 3 triangle, but if the user should also be able to run, say,
./triangle 4 or
./triangle 2 to control the number of levels. If given an unworkable number of levels (anything larger than 8 gets unwieldy and negative would be nonsensical), your program should reject it with a helpful and explanatory message that informs the user how to correct their error.
In order to complete this task, the program will need to convert the user's argument (supplied in string form) into an integer. The C library function
atoi can be used to do this. Review the man page (
man atoi) or look in your C reference to get acquainted with this function.
We'd also like to introduce you to the sanitycheck tool that you will use throughout CS107 as a testing aid. Please carefully read our instructions for using sanitycheck and try it out!
The default sanitycheck for assign0 has one simple test that validates the output of the triangle program when given no argument. The unmodified starter program code should pass this test. After you have extended the triangle program to accept an argument, the program should continue to pass the default sanitycheck, but you will need new tests to validate the argument-handling.
You extend sanitycheck to test additional cases by writing your own
custom_tests file. The starter project includes a sample
custom_tests. Open this file in your editor to see the format. Now consider what additional test cases are needed to fully vet the output of your new, improved triangle program. You will need at least two additional tests. Add those tests to
custom_tests and use these with sanitycheck to validate that your triangle program passes all tests.
Advice, hints, and common questions
Each assignment comes with a companion page of advice, hints, and answers to commonly asked questions. This assignment doesn't have as much material there as some others will, but for the later assignments, the advice page is an essential resource to review, especially for answering questions before you even realize you have them! Go to advice/FAQ page
The assignment is graded out of 20 points. Full credit will be awarded for reasonable answers to the questions in the
readme.txt file and a correct modification of
custom_tests. We expect everyone will earn all 20 points; go team!
Finish and submit
After you are finished with your work and have saved all your changes, you must follow the submit instructions to hand in your work.
We recommend you do a trial submit in advance of the deadline to familiarize yourself with the process and allow time to work through any snags. You can replace that submission with a subsequent one if desired.
No late submissions are accepted on this assignment. The deadline is firm without exception. This assignment is worth a very small number of points compared to other assignments, but don't miss this chance to snap up some quick points and start your quarter off right!
How did it go for you? Review the post-task self-check.