X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Flogin_src%2Fmain.c;h=59b4a784d5bab9d047f3864a267d2ad20efc7aa6;hb=6a99a6d70179161964d47de9a825fd61e8445b86;hp=54532837d5bbd17a4bb0b081c14357b0dd68c324;hpb=c13663104076a7780d1bbbaf77273416733cbb58;p=tpg%2Facess2.git diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index 54532837..59b4a784 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -14,45 +14,48 @@ 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'); + + printf("\x1B[?25h"); // Re-enable the cursor +// printf("\x1B[2J"); // Clear Screen + for(;;) { // Validate User - do { + for(;;) + { sUsername = GetUsername(); sPassword = GetPassword(); - } while( (uid = ValidateUser(sUsername, sPassword)) == -1 ); - putchar('\n'); - - // Get user information + if( (uid = ValidateUser(sUsername, sPassword)) == -1 ) + { + printf("\nInvalid username or password\n"); + free(sUsername); + free(sPassword); + } + else + break; + } + printf("\n"); + uinfo = GetUserInfo(uid); - - // Create child process - pid = clone(CLONE_VM, 0); + 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 *argv[2] = {uinfo->Shell, 0}; - char **envp = NULL; - setgid(uinfo->GID); - setuid(uid); - - execve(uinfo->Shell, argv, envp); - exit(-1); - } - // Wait for child to terminate - waittid(pid, &status); + _SysWaitTID(pid, &status); } return 0; @@ -63,7 +66,7 @@ int main(int argc, char *argv[]) */ char *GetUsername() { - char ret[BUFLEN]; + char ret[BUFLEN] = {0}; int pos = 0; char ch; @@ -74,6 +77,7 @@ char *GetUsername() while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) { if(ch == '\b') { + if( pos <= 0 ) continue; pos --; ret[pos] = '\0'; } @@ -109,6 +113,7 @@ char *GetPassword() while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) { if(ch == '\b') { + if( pos <= 0 ) continue; pos --; ret[pos] = '\0'; }