_PASSWORD FILES_ by Trevor J. Pope Listing One /*************************************************************************/ /* File: passtest.c */ /* Password package - test program */ /* Simple test program to check the operation of the password package */ /* under unix. */ /* Copyright (C) 1994-5, Trevor J. Pope -- All rights reserved. */ /* License to copy and use this software is granted provided that this */ /* copyright notice is retained in any copies of any part of this */ /* software. */ /* No representations are made concerning either the merchantability */ /* of this software or the suitability of this software for any */ /* particular purpose. It is provided "as is" without express or */ /* implied warranty of any kind. */ /*************************************************************************/ /* Common library includes */ #include /* for file I/O */ #include /* for time functions */ #include /* for strcpy */ #include /* for errno etc */ /* Pull in the standard include for the package */ #include "Password.h" /*************************************************************************/ /* main() -- Entry point for the test program */ /* Passed : command line parameter list */ /*************************************************************************/ int main( int argc, char * argv[], char * env[] ) { int result; char option, optionString[80]; char userName[USER_NAME_LENGTH+1]; char userNumber[EMPLOYEE_NUMBER_LENGTH+1]; char accessString[ACCESS_RIGHTS_LENGTH+1]; char password[PASSWORD_LENGTH+1]; char superUserName[USER_NAME_LENGTH+1]; char superPassword[PASSWORD_LENGTH+1]; char newPassword[PASSWORD_LENGTH+1]; char passwordFileName[51]; char machineName[MACHINE_NAME_LENGTH+1]; char userDetails[USER_DETAILS_LENGTH]; /* Loop getting options and executing them until a quit is selected */ do { /* Show menu */ printf("\n\ Select: (i)nitialise (v)alidate (c)hange (a)add (d)elete\n\ (n)ew (u)sers (s)how (h)elp (q)uit : "); scanf( "%s", &optionString[0] ); option = optionString[0]; /* Act on option ... */ switch( (int)option ) { case 'i': { printf("\n initPassword - enter password file name :"); scanf("%s", passwordFileName ); result = initPassword( passwordFileName ); printf("\n initPassword() returned %s \n", &passReturnCodeStrings[result][0] ); break; } case 'v': { printf("\n validateUser - enter userName :"); scanf("%s", userName ); printf("\n validateUser - enter pass word :"); scanf("%s", password ); result = validateUser( userName, password, accessString ); if( result == PASS_OK ) { printf("validateUser() returned %s (Access level is %s )\n", &passReturnCodeStrings[result][0], accessString ); } else { printf("validateUser() returned %s \n", &passReturnCodeStrings[result][0] ); } break; } case 'c': { printf("\n changePassword - enter userName :"); scanf("%s", userName ); printf("\n changePassword - enter old pass word :"); scanf("%s", password ); printf("\n changePassword - enter new pass word :"); scanf("%s", newPassword ); result = changePassword( userName, password, newPassword ); printf("changePassword() returned %s \n", &passReturnCodeStrings[result][0] ); break; } case 'a': { printf("\n addUser - enter supervisor userName :"); scanf("%s", superUserName ); printf("\n addUser - enter supervisor password :"); scanf("%s", superPassword ); printf("\n addUser - enter new userName :"); scanf("%s", userName ); printf("\n addUser - enter new user number:"); scanf("%s", userNumber ); printf("\n addUser - enter new user rights :"); scanf("%s", accessString ); printf("\n addUser - enter new user password :"); scanf("%s", password ); result = addUser( superUserName, superPassword, userName, userNumber, accessString, password ); printf("addUser() returned %s \n", &passReturnCodeStrings[result][0] ); break; } case 'd': { printf("\n deleteUser - enter supervisor userName :"); scanf("%s", superUserName ); printf("\n deleteUser - enter supervisor password :"); scanf("%s", superPassword ); printf("\n addUser - enter userName to delete :"); scanf("%s", userName ); result = deleteUser( superUserName, superPassword, userName ); printf("deleteUser() returned %s \n", &passReturnCodeStrings[result][0] ); break; } case 'n': { printf("\n newPasswordFile - enter full pathname : "); scanf("%s", passwordFileName ); printf("\n newPasswordFile - enter machine name :"); scanf("%s", machineName ); printf("\n newPasswordFile - enter supervisor name :"); scanf("%s", userName ); printf("\n newPasswordFile - enter supervisor number:"); scanf("%s", userNumber ); printf("\n newPasswordFile - enter supervisor password :"); scanf("%s", password ); result = newPasswordFile( passwordFileName, machineName, userName, userNumber, password ); printf("newPasswordFile() returned %s \n", &passReturnCodeStrings[result][0] ); break; } case 'u': { showUserDetails( userDetails ); printf("showUserDetails() :\n%s", userDetails ); /* Check current user details as recorded internally */ result = currentUserDetails( userName, userNumber, accessString ); if( result == PASS_OK ) { printf("currentUserDetails() returned a valid user:\n\ userName: %s\n\ userNumber: %s\n\ accessString: %s\n", userName, userNumber, accessString ); } else { printf("currentUserDetails() returned NO valid user:\n"); } break; } case 'h': { printf("\n\n%s\n\n", passwordHelp() ); break; } case 's': { displayPasswordStruct(); break; } case 'q': { printf("\n quitting ... \n"); break; } default: { printf("\n unrecognised option (%x)", (int)option ); break; } } /* switch */ } while( option != 'q' ); return( 0 ); } /* main() */ Figure 1: efa00b25cc4b3fb5aa29d507f9d2ad38 1 MachineName Trevor 0123456789 s 0c47cdd73a4e8f70c67671f968eae636 Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * # Unused Nobody * #