From: John Hodge Date: Thu, 1 Oct 2009 00:36:54 +0000 (+0800) Subject: Fixed CLIShell's `dir` command, added a logout/exit command. Added a newline after... X-Git-Tag: rel0.06~401 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;ds=sidebyside;h=ab47641a5334988563520c66f5097dd6d687ea48;p=tpg%2Facess2.git Fixed CLIShell's `dir` command, added a logout/exit command. Added a newline after a failed login prompt --- diff --git a/Usermode/Applications/CLIShell_src/Makefile b/Usermode/Applications/CLIShell_src/Makefile index 2d0d8f3a..a79952e7 100644 --- a/Usermode/Applications/CLIShell_src/Makefile +++ b/Usermode/Applications/CLIShell_src/Makefile @@ -22,7 +22,7 @@ $(BIN): $(AOBJ) $(COBJ) @echo --- $(LD) -o $@ @$(LD) $(LDFLAGS) -o $@ $(AOBJ) $(COBJ) -Map Map.txt objdump -d $(BIN) > $(BIN).dsm - cp $(BIN) /mnt/AcessHDD/Acess2/ + cp $(BIN) /mnt/AcessHDD/Acess2/Bin/ clean: $(RM) $(AOBJ) $(COBJ) $(BIN) diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index dbe18c59..ec83ac96 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "header.h" #define _stdin 0 @@ -14,8 +15,9 @@ char *ReadCommandLine(int *Length); void Parse_Args(char *str, char **dest); void CallCommand(char **Args); -void Command_Colour(int argc, char **argv); +void Command_Logout(int argc, char **argv); void Command_Clear(int argc, char **argv); +void Command_Colour(int argc, char **argv); void Command_Cd(int argc, char **argv); void Command_Dir(int argc, char **argv); @@ -25,6 +27,7 @@ struct { char *name; void (*fcn)(int argc, char **argv); } cBUILTINS[] = { + {"exit", Command_Logout}, {"logout", Command_Logout}, {"colour", Command_Colour}, {"clear", Command_Clear}, {"cd", Command_Cd}, {"dir", Command_Dir} }; @@ -311,9 +314,28 @@ void CallCommand(char **Args) } } +/** + * \fn void Command_Logout(int argc, char **argv) + * \brief Exit the shell, logging the user out + */ +void Command_Logout(int argc, char **argv) +{ + exit(0); +} + +/** + * \fn void Command_Clear(int argc, char **argv) + * \brief Clear the screen + */ +void Command_Clear(int argc, char **argv) +{ + write(_stdout, 4, "\x1B[2J"); //Clear Screen +} + /** * \fn void Command_Colour(int argc, char **argv) - * \brief + * \brief Set the colour of the shell prompt + * \note Conflicts with coloured `dir` display */ void Command_Colour(int argc, char **argv) { @@ -374,15 +396,6 @@ usage: return; } -/** - * \fn void Command_Clear(int argc, char **argv) - * \brief Clear the screen - */ -void Command_Clear(int argc, char **argv) -{ - write(_stdout, 4, "\x1B[2J"); //Clear Screen -} - /** * \fn void Command_Cd(int argc, char **argv) * \brief Change directory @@ -423,6 +436,8 @@ void Command_Cd(int argc, char **argv) } /** + * \fn void Command_Dir(int argc, char **argv) + * \brief Print the contents of a directory */ void Command_Dir(int argc, char **argv) { @@ -499,21 +514,24 @@ void Command_Dir(int argc, char **argv) write(_stdout, 1, "-"); // Print Mode + // - Owner acl.group = 0; acl.id = info.uid; _SysGetACL(fp, &acl); if(acl.perms & 1) modeStr[0] = 'r'; else modeStr[0] = '-'; if(acl.perms & 2) modeStr[1] = 'w'; else modeStr[1] = '-'; if(acl.perms & 8) modeStr[2] = 'x'; else modeStr[2] = '-'; + // - Group acl.group = 1; acl.id = info.gid; _SysGetACL(fp, &acl); if(acl.perms & 1) modeStr[3] = 'r'; else modeStr[3] = '-'; - if(acl.perms & 1) modeStr[4] = 'w'; else modeStr[4] = '-'; - if(acl.perms & 1) modeStr[5] = 'x'; else modeStr[5] = '-'; + if(acl.perms & 2) modeStr[4] = 'w'; else modeStr[4] = '-'; + if(acl.perms & 8) modeStr[5] = 'x'; else modeStr[5] = '-'; + // - World acl.group = 1; acl.id = -1; _SysGetACL(fp, &acl); if(acl.perms & 1) modeStr[6] = 'r'; else modeStr[6] = '-'; - if(acl.perms & 1) modeStr[7] = 'w'; else modeStr[7] = '-'; - if(acl.perms & 1) modeStr[8] = 'x'; else modeStr[8] = '-'; + if(acl.perms & 2) modeStr[7] = 'w'; else modeStr[7] = '-'; + if(acl.perms & 8) modeStr[8] = 'x'; else modeStr[8] = '-'; write(_stdout, 10, modeStr); close(fp); diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index 54532837..2e4906d1 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -14,22 +14,21 @@ char *GetPassword(); int main(int argc, char *argv[]) { char *sUsername, *sPassword; - int pid, uid; + int pid, uid = 0; int status = 0; tUserInfo *uinfo; - putchar('\n'); for(;;) { + printf("\x1B[2J"); // Clear Screen // Validate User do { + if(uid == -1) printf("\n"); sUsername = GetUsername(); sPassword = GetPassword(); + printf("\n"); } while( (uid = ValidateUser(sUsername, sPassword)) == -1 ); - putchar('\n'); - - // Get user information - uinfo = GetUserInfo(uid); + printf("\n"); // Create child process pid = clone(CLONE_VM, 0); @@ -42,12 +41,18 @@ int main(int argc, char *argv[]) // Spawn shell in a child process if(pid == 0) { - char *argv[2] = {uinfo->Shell, 0}; - char **envp = NULL; + char *child_argv[2] = {NULL, 0}; + char **child_envp = NULL; + + // Get user information + uinfo = GetUserInfo(uid); + + child_argv[0] = uinfo->Shell; + // Set Environment setgid(uinfo->GID); setuid(uid); - execve(uinfo->Shell, argv, envp); + execve(uinfo->Shell, child_argv, child_envp); exit(-1); }