Fixed CLIShell's `dir` command, added a logout/exit command. Added a newline after...
authorJohn Hodge <[email protected]>
Thu, 1 Oct 2009 00:36:54 +0000 (08:36 +0800)
committerJohn Hodge <[email protected]>
Thu, 1 Oct 2009 00:36:54 +0000 (08:36 +0800)
Usermode/Applications/CLIShell_src/Makefile
Usermode/Applications/CLIShell_src/main.c
Usermode/Applications/login_src/main.c

index 2d0d8f3..a79952e 100644 (file)
@@ -22,7 +22,7 @@ $(BIN): $(AOBJ) $(COBJ)
        @echo --- $(LD) -o $@\r
        @$(LD) $(LDFLAGS) -o $@ $(AOBJ) $(COBJ) -Map Map.txt\r
        objdump -d $(BIN) > $(BIN).dsm\r
-       cp $(BIN) /mnt/AcessHDD/Acess2/\r
+       cp $(BIN) /mnt/AcessHDD/Acess2/Bin/\r
 \r
 clean:\r
        $(RM) $(AOBJ) $(COBJ) $(BIN)\r
index dbe18c5..ec83ac9 100644 (file)
@@ -4,6 +4,7 @@
 #include <acess/sys.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
+#include <string.h>\r
 #include "header.h"\r
 \r
 #define _stdin 0\r
@@ -14,8 +15,9 @@
 char   *ReadCommandLine(int *Length);\r
 void   Parse_Args(char *str, char **dest);\r
 void   CallCommand(char **Args);\r
-void   Command_Colour(int argc, char **argv);\r
+void   Command_Logout(int argc, char **argv);\r
 void   Command_Clear(int argc, char **argv);\r
+void   Command_Colour(int argc, char **argv);\r
 void   Command_Cd(int argc, char **argv);\r
 void   Command_Dir(int argc, char **argv);\r
 \r
@@ -25,6 +27,7 @@ struct        {
        char    *name;\r
        void    (*fcn)(int argc, char **argv);\r
 }      cBUILTINS[] = {\r
+       {"exit", Command_Logout},       {"logout", Command_Logout},\r
        {"colour", Command_Colour}, {"clear", Command_Clear},\r
        {"cd", Command_Cd}, {"dir", Command_Dir}\r
 };\r
@@ -311,9 +314,28 @@ void CallCommand(char **Args)
        }\r
 }\r
 \r
+/**\r
+ * \fn void Command_Logout(int argc, char **argv)\r
+ * \brief Exit the shell, logging the user out\r
+ */\r
+void Command_Logout(int argc, char **argv)\r
+{\r
+       exit(0);\r
+}\r
+\r
+/**\r
+ * \fn void Command_Clear(int argc, char **argv)\r
+ * \brief Clear the screen\r
+ */\r
+void Command_Clear(int argc, char **argv)\r
+{\r
+       write(_stdout, 4, "\x1B[2J");   //Clear Screen\r
+}\r
+\r
 /**\r
  * \fn void Command_Colour(int argc, char **argv)\r
- * \brief \r
+ * \brief Set the colour of the shell prompt\r
+ * \note Conflicts with coloured `dir` display\r
  */\r
 void Command_Colour(int argc, char **argv)\r
 {\r
@@ -374,15 +396,6 @@ usage:
        return;\r
 }\r
 \r
-/**\r
- * \fn void Command_Clear(int argc, char **argv)\r
- * \brief Clear the screen\r
- */\r
-void Command_Clear(int argc, char **argv)\r
-{\r
-       write(_stdout, 4, "\x1B[2J");   //Clear Screen\r
-}\r
-\r
 /**\r
  * \fn void Command_Cd(int argc, char **argv)\r
  * \brief Change directory\r
@@ -423,6 +436,8 @@ void Command_Cd(int argc, char **argv)
 }\r
 \r
 /**\r
+ * \fn void Command_Dir(int argc, char **argv)\r
+ * \brief Print the contents of a directory\r
  */\r
 void Command_Dir(int argc, char **argv)\r
 {\r
@@ -499,21 +514,24 @@ void Command_Dir(int argc, char **argv)
                        write(_stdout, 1, "-");\r
                \r
                // Print Mode\r
+               // - Owner\r
                acl.group = 0;  acl.id = info.uid;\r
                _SysGetACL(fp, &acl);\r
                if(acl.perms & 1)       modeStr[0] = 'r';       else    modeStr[0] = '-';\r
                if(acl.perms & 2)       modeStr[1] = 'w';       else    modeStr[1] = '-';\r
                if(acl.perms & 8)       modeStr[2] = 'x';       else    modeStr[2] = '-';\r
+               // - Group\r
                acl.group = 1;  acl.id = info.gid;\r
                _SysGetACL(fp, &acl);\r
                if(acl.perms & 1)       modeStr[3] = 'r';       else    modeStr[3] = '-';\r
-               if(acl.perms & 1)       modeStr[4] = 'w';       else    modeStr[4] = '-';\r
-               if(acl.perms & 1)       modeStr[5] = 'x';       else    modeStr[5] = '-';\r
+               if(acl.perms & 2)       modeStr[4] = 'w';       else    modeStr[4] = '-';\r
+               if(acl.perms & 8)       modeStr[5] = 'x';       else    modeStr[5] = '-';\r
+               // - World\r
                acl.group = 1;  acl.id = -1;\r
                _SysGetACL(fp, &acl);\r
                if(acl.perms & 1)       modeStr[6] = 'r';       else    modeStr[6] = '-';\r
-               if(acl.perms & 1)       modeStr[7] = 'w';       else    modeStr[7] = '-';\r
-               if(acl.perms & 1)       modeStr[8] = 'x';       else    modeStr[8] = '-';\r
+               if(acl.perms & 2)       modeStr[7] = 'w';       else    modeStr[7] = '-';\r
+               if(acl.perms & 8)       modeStr[8] = 'x';       else    modeStr[8] = '-';\r
                write(_stdout, 10, modeStr);\r
                close(fp);\r
                \r
index 5453283..2e4906d 100644 (file)
@@ -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);
                }
                

UCC git Repository :: git.ucc.asn.au