CS60 Homework 14 ---------------------------- Due Mon Nov 17 @ 1:00pm Chapters 9 and 12 in the Savitch Strings 'n Files -------------------- The task of this assignment is to build a simple UNIX passwd file reader and record holder. The program must create an object that can hold records that contain the information on each line of a standard UNIX passwd file. It must read a passwd file, one line at a time, and parse each line into it's 7 parts. After a new record is created, the read in tokens should be input into the record and the program should go to the next passwd file line. Once all passwd lines are read, the program must ask the user to input a username to search for in the read in records and if the username exists, must print out a formatted record with all of that user's information. The password file to use for this assignment is a fake UNIX passwd file that can be found on the webpage (passwd.fake). UNIX passwd file ------------------- UNIX passwd files contain all information about all users that are allowed to log into a UNIX system. Each line of a passwd file is set up like the following: username:passwd:uid:gid:realname:homedir:shell For example, the passwd entry for use 'dnurmi' may look like the following: dnurmi:up.hOoxZCfhUU:500:500:Nurmi:/home/dnurmi:/bin/gosh Notice that each field is separated by colons. Program Requirements ------------------------- 1.) Implement a class that has C++ strings for holding the following information: - username - realname - homedir - shell - password and two ints that hold the following: - uid - gid The class must at minimum support a way to initialize these member variables as well as a 'print' routine (or overloaded << operator) that will output the variables in the following manner: User Name: dnurmi Real Name: Nurmi Homedir: /home/dnurmi Shell: /bin/gosh Pass: up.hOoxZCfhUU UID: 500 GID: 500 2.) Your program must implement a file reader and line parser that opens a passwd file (given as a commandline argument), reads the lines one at a time, parses each line into it's seven parts, and creates a 'record' object which contains those parts. You may assume that there will be no more than 32 total lines in the file. HINT: use only C++ strings for this assignment. member functions such as 'find' and 'substr' are all you need to do the parsing. 3.) You program must implement a simple loop that asks the user for the username of a user, and searches it's record array for a record that contains the input username. If the input username is found, the record should be printed. Otherwise, the program should output nothing and ask for another username. This loop should continue until the user types 'exit'. Extra Credit (1pt) --------------------- Add the ability for your program, after a record has been found, to ask the user to input a password and check to see if the input passwd matches the encrypted passwd for that user. The function used to do this is called 'crypt' and is prototyped in a manpage. The cleartext passwords for the users in the 'fake' passwd file are as follows: root = ub3rg33k dnurmi = ub3rdORK bgates = OverLord sfanning = duuuuuur If the user inputs the correct password, the program should report success. Othwerwise, the program should report something quite rude. Turnin ---------------------- The turnin tag for this assignment is 'hw14' and should include your object header and code files, a typescript showing compilation and execution of the program, a Makefile, and an optional README containing special instructions for the grader. Sample Output ------------------- [nurmi@localhost hw14]$ ls Makefile hw14.cpp passwd.fake record.h crypter.c hw14.outline record.cpp typescript [nurmi@localhost hw14]$ make g++ -I./ -ansi -pedantic -c -o record.o record.cpp g++ -I./ -ansi -pedantic -c -o hw14.o hw14.cpp g++ record.o hw14.o -o hw14 [nurmi@localhost hw14]$ cat passwd.fake root:wrBQ4IFUFnrzQ:0:0:Root User:/root:/bin/bash dnurmi:up.hOoxZCfhUU:500:500:Nurmi:/home/dnurmi:/bin/gosh bgates:yjSKlk3/iEv.c:501:501:B. Gates:/home/bgates:/bin/noshell sfanning:ylRk2Z2lJwwNI:502:502:S. Fanning:/home/sfanning:/bin/csh [nurmi@localhost hw14]$ ./hw14 USAGE: ./hw14 [nurmi@localhost hw14]$ ./hw14 passwd.fake enter username to search for: dnurmi -------------------------------- User Name: dnurmi Real Name: Nurmi Homedir: /home/dnurmi Shell: /bin/gosh Pass: up.hOoxZCfhUU UID: 500 GID: 500 enter username to search for: fofofo enter username to search for: blah enter username to search for: root -------------------------------- User Name: root Real Name: Root User Homedir: /root Shell: /bin/bash Pass: wrBQ4IFUFnrzQ UID: 0 GID: 0 enter username to search for: exit [nurmi@localhost hw14]$ make clean rm -rf *.o *.a *~* hw14 [nurmi@localhost hw14]$ exit