Usermode - More syscall renaming
[tpg/acess2.git] / Usermode / Applications / login_src / main.c
index 2e4906d..59b4a78 100644 (file)
@@ -17,47 +17,45 @@ int main(int argc, char *argv[])
         int    pid, uid = 0;
         int    status = 0;
        tUserInfo       *uinfo;
-       
+
+       printf("\x1B[?25h");    // Re-enable the cursor 
+//     printf("\x1B[2J");      // Clear Screen
+
        for(;;)
        {
-               printf("\x1B[2J");      // Clear Screen
                // Validate User
-               do {
-                       if(uid == -1)   printf("\n");
+               for(;;)
+               {
                        sUsername = GetUsername();
                        sPassword = GetPassword();
-                       printf("\n");
-               } while( (uid = ValidateUser(sUsername, sPassword)) == -1 );
+                       if( (uid = ValidateUser(sUsername, sPassword)) == -1 )
+                       {
+                               printf("\nInvalid username or password\n");
+                               free(sUsername);
+                               free(sPassword);
+                       }
+                       else
+                               break;
+               }
                printf("\n");
-               
-               // Create child process
-               pid = clone(CLONE_VM, 0);
+
+               uinfo = GetUserInfo(uid);
+               struct s_sys_spawninfo  spawninfo;
+               spawninfo.flags = 0;
+               spawninfo.gid = uinfo->GID;
+               spawninfo.uid = uinfo->UID;
+               const char      *child_argv[2] = {"-", 0};
+               const char      **child_envp = NULL;
+                int    fds[] = {0, 1, 2};
+               pid = _SysSpawn(uinfo->Shell, child_argv, child_envp, 3, fds, &spawninfo);
                // Error check
                if(pid == -1) {
                        fprintf(stderr, "Unable to fork the login process!\n");
                        return -1;
                }
                
-               // Spawn shell in a child process
-               if(pid == 0)
-               {
-                       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, child_argv, child_envp);
-                       exit(-1);
-               }
-               
                // Wait for child to terminate
-               waittid(pid, &status);
+               _SysWaitTID(pid, &status);
        }
        
        return 0;
@@ -68,7 +66,7 @@ int main(int argc, char *argv[])
  */
 char *GetUsername()
 {
-       char    ret[BUFLEN];
+       char    ret[BUFLEN] = {0};
         int    pos = 0;
        char    ch;
        
@@ -79,6 +77,7 @@ char *GetUsername()
        while( (ch = fgetc(stdin)) != -1 && ch != '\n' )
        {
                if(ch == '\b') {
+                       if( pos <= 0 )  continue;
                        pos --;
                        ret[pos] = '\0';
                }
@@ -114,6 +113,7 @@ char *GetPassword()
        while( (ch = fgetc(stdin)) != -1 && ch != '\n' )
        {
                if(ch == '\b') {
+                       if( pos <= 0 )  continue;
                        pos --;
                        ret[pos] = '\0';
                }

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