This assignment is a test of filename parsing and confinement mechanisms. The basic task is simple: read a series of lines, each of which contains two filenames. Copy the first file to the second. The input format is dead simple, too: the two names are separated by EXACTLY one blank. Thus, there cannot be be any blanks, newlines, or NUL characters in either file name. You not only need not check for strange characters, except as outlined below, you MUST NOT do so. Here's the catch: the the input file has to be verified to ensure that it is within the "document root", per the configuration file described below. The output file must be within the designated output area, again per the configuration file. You MUST use some sort of confinement mechanism (I strongly recommend using the chroot() system call) to ensure that the output file location is properly restricted. You may NOT use any other form of parsing or validation on the output file. Note that if you do use chroot(), your program must be executed as root or must be setuid root -- that's perfectly acceptable. Since you've already learned to write privileged programs, you need not worry about checking permissions, etc., on the input or output files; that's not what this assignment is about. The program has to read a configuration file. It's perfectly acceptable to have a default filename compiled in; however, your program MUST accept the syntax hwcopy -c configfile All of the input/output pairs are read from stdin. (If you want to specify a list of files to read on the command line, you're welcome to, but that's not required.) The configuration file has three types of lines: document root, output area, and alias. Since this file is notionally prepared by the system administrator, you don't have to worry about it having dangerous input (though it's always a good idea to give proper error messages for bad input). The lines in it look like this: DocumentRoot directory-name OutputArea directory-name Alias /name/ directory-name DocumentRoot and OutputArea may appear only once; Alias may appear many times. You may set a reasonable upper bound on the number of Alias lines your program accepts, and on the length of the different filenames. OutputArea is simple enough: all file output must be to something underneath that directory. DocumentRoot seems simple -- all input must be underneath it -- but that's modified by the Alias commands. The Alias commands let you pretend that some other parts of the file system are underneath the document root. (This is similar to the way web servers behave; see the October 31 lecture for details.) The "name" field, which must be surrounded by / characters, gives the pathname relative to document root that is mapped to something else. Thus, if the configuration file contains DocumentRoot /home/smb2132/input Alias /foo/ /tmp/abc Alias /bar/ /etc a request to read /foo/x.y is legal and would actually read /tmp/abc/x.y and a request for /bar/passwd would read /etc/passwd. (Note that all input and output filenames are relative to the document root and output areas. Thus, an input file of /abc and abc are both /home/smb2132/input/abc.) Because the input area is not a tree, you probably can't use chroot() (though if you find a good way to do it, by all means do so). You MUST handle things like .. and . in filenames.