#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
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
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
}\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
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
}\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
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
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);
// 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);
}