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

Colorado State University

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.

Each user is represented by their UID.

The lookup table will be a 1-dimensional array of pointers.


Requirements of Task

  1. 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.
  2. 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.
  3. If the actions of the commands result in no valid entries left to be written, ValidKeys.txt should be removed.
  4. 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.
  5. 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

  6. 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.
  7. 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.
  8. 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.
  9. VALIDATE,UID,KEY
    This command prints a valid or not valid message based on the existance of the requested key in the database.
  10. 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.
  11. 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.
  12. 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.
  13. 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 .

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.