Programming Assignment 1B
Version 1.0
Version 1.1 - added name of executable
Version 1.2 - Changed min number of keys per user from 0 to 1, changed all example keys to uppercase
|
CS370: Operating Systems
|
DUE DATE:
10:00 pm
Friday February 7th, 2014
Programming Assignment 1B: Memory Management
- The purpose of this assignment is
to remind you of (or introduce you to)
data structures and memory management in C,
including structs, malloc(), free(),
and the use of pointers.
- Description of Task
For this assignment, you will be creating a program called keymanage
that uses a look-up table to manage 256-bit encryption keys for specific users.
- These keys will be represented as 64 hex digits (64 X 4 = 256).
- Each key is associated with one and only one user.
- The key must be represented by all 256 bits (i.e. explicit leading
zeroes).
- Each user may have from 1 to MAX_KEYS keys, where MAX_KEYS is a
constant defined to 16.
Each user is represented by their UID.
- UIDs are is a 16-bit identifier represented as a decimal number.
- (Hint: if UID is a 16-bit identifier, what is MAX_UIDS set to?)
- UIDs may have both explicit and implicit leading zeroes (i.e. 13 = 013).
The lookup table will be a 1-dimensional array of pointers.
- The lookup table is indexed by the UID.
- The table is created at initialization by malloc'ing the space
necessary for the table. (See hint above)
- Each slot should be initialized to null.
- When a user is added to the table, a space corresponding to
the size of the struct that will hold his key information is malloc'ed
and a pointer to
that space is placed at the appropriate location in the lookup table.
- The struct will hold up to MAX_KEYS keys, and whatever other information
is necessary to manage the keys.
Requirements of Task
- Read in an input file in the form:
UID KEY
The file is terminated by an end-of-file. Since it is assumed that
you created this file, you may assume no blank lines, the UIDs are
valid, and there
are no duplicate KEYs. This file should be called ValidKeys.txt.
-
If the file ValidKeys.txt does not exist, you should create it when
processing the END command. The file should only be created if the commands
generated a valid entry.
- If the actions of the commands result in no valid entries left
to be written, ValidKeys.txt should be removed.
- If the file ValidKeys.txt does not exist, if you get a command before
the first add, print out an error message and continue processing.
-
Once you have read in the input file, you should then read in a set
of commands from standard input. These commands should be of one of the
following forms.
ADD,UID,KEY
DELETE,UID,KEY
DELETE,UID
VALIDATE,UID,KEY
PRINT,UID
PRINT,ALL
END
- You should perform all pertinent error checking (i.e. valid command,
valid UID, valid key, etc.) Running edge conditions, testing for memory
leaks and invalid input
will be a part of the grading scripts. If you encounter an error, an
appropriate error message should be written to stderr and you should
continue processing. All error messages should be written to stderr.
-
ADD,UID,KEY
This command should add the key associated with the user to the
structure, checking to make sure the key does not already exist, that this
key puts them over their limit of 16, etc. If the user's slot in the table
is set to null, you should malloc the appropriate amount of space and
set the pointer in the lookup table accordingly.
- DELETE,UID,KEY
This command should delete the key from the users space. If this is the
only key the user had, the user space should be free'ed and the pointer
to the space in the lookup table set to null.
- VALIDATE,UID,KEY
This command prints a valid or not valid message based on the existance
of the requested key in the database.
- DELETE,UID
This commmand should delete all keys associated with a user by freeing
the user space associated with UID and setting the space in the lookup
table to null.
- PRINT,UID
This command should print all the keys associated with a user, one per line,
in sorted order.
Output should look exactly as below.
- PRINT,ALL
This command should print all the keys in the database - one per line.
Include the associated UID with each key. The keys should be printed
in sorted order, first by UID, and second by key. Output should look exactly
as below.
- END
This command should rewrite the data file ValidKeys.txt based on the current
information and exit.
Example:
A ValidKeys.txt file that looks like:
421 0123456789ABCDEF0123456789ABCDE00123456789ABCDEF0123456789ABCDE0
422 0123456789ABCDEF0123456789ABCDE10123456789ABCDEF0123456789ABCDE1
423 0123456789ABCDEF0123456789ABCDE20123456789ABCDEF0123456789ABCDE2
423 0123456789ABCDEF0123456789ABCDE30123456789ABCDEF0123456789ABCDE3
and executes the following commands:
ADD,422,0123456789ABCDEF0123456789ABCDE40123456789ABCDEF0123456789ABCDE4
DELETE,423,0123456789ABCDEF0123456789ABCDE30123456789ABCDEF0123456789ABCDE3
DELETE,421
VALIDATE,422,0123456789ABCDEF0123456789ABCDE40123456789ABCDEF0123456789ABCDE4
VALIDATE,423,0123456789ABCDEF0123456789ABCDE30123456789ABCDEF0123456789ABCDE3
PRINT,422
PRINT,ALL
END
would print:
The key submitted for user 422 is valid.
The key submitted for user 423 is invalid.
The keys for user 422 are:
422 0123456789ABCDEF0123456789ABCDE10123456789ABCDEF0123456789ABCDE1
422 0123456789ABCDEF0123456789ABCDE40123456789ABCDEF0123456789ABCDE4
The keys for all users are:
422 0123456789ABCDEF0123456789ABCDE10123456789ABCDEF0123456789ABCDE1
422 0123456789ABCDEF0123456789ABCDE40123456789ABCDEF0123456789ABCDE4
423 0123456789ABCDEF0123456789ABCDE20123456789ABCDEF0123456789ABCDE2
and result in a ValidKeys.txt file that looks like:
422 0123456789ABCDEF0123456789ABCDE10123456789ABCDEF0123456789ABCDE1
422 0123456789ABCDEF0123456789ABCDE40123456789ABCDEF0123456789ABCDE4
423 0123456789ABCDEF0123456789ABCDE20123456789ABCDEF0123456789ABCDE2
- What to Submit
The program files should be well documented with both data dictionaries
and logic flow descriptions.
Your makefile should perform a make target, a make clean
and a make all. Name the executables per the requirements .
-
make target will create the tar file containing the .c file(s),
.h file(s), and Makefile.
-
make all will compile your program(s) according to the specifications
of the assignment.
-
make clean will remove any .o file(s), executables, and tar files in
directory.
- Perform a make target and submit the tar file containing your
.c file(s), .h file(s), and Makefile
using the RamCT assignment submission page.
- You are required to work alone on this lab.
This is Programming Assignment 1B.
Late Policy
- Click here for the class policy on submitting
late assignments.
Copyright © 2001-2014: Colorado State University for CS370.
All rights reserved.