X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Flogin_src%2Fmain.c;h=86b188420a5d27d82129b4a8d0d699c0b5696da5;hb=1afa04ad5e32695ead32ec2b666899783b273609;hp=456974fcafe83d72ed414daee6428566b63b9cf8;hpb=a98b0e6ff33593616a21337492bb2fd48e9e5845;p=tpg%2Facess2.git diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index 456974fc..86b18842 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -1,7 +1,9 @@ /* * Acess 2 Login + * - By John Hodge (thePowersGang) */ #include "header.h" +#include // Enable/disable echo // === CONSTANTS === #define BUFLEN 1024 @@ -17,18 +19,26 @@ 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 for(;;) { sUsername = GetUsername(); + if(!sUsername || !sUsername[0]) continue; sPassword = GetPassword(); + if(!sPassword) { + free(sUsername); + continue; + } if( (uid = ValidateUser(sUsername, sPassword)) == -1 ) { - printf("\nInvalid username or password for '%s'\n", sUsername); + printf("\nInvalid username or password\n"); + _SysDebug("Auth failure: '%s':'%s'", sUsername, sPassword); free(sUsername); free(sPassword); } @@ -36,108 +46,109 @@ int main(int argc, char *argv[]) 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); - setuid(uinfo->UID); - - execve(uinfo->Shell, child_argv, child_envp); - exit(-1); - } - // Wait for child to terminate - waittid(pid, &status); + _SysWaitTID(pid, &status); + + // Clear graphics mode + struct ptymode mode = {.InputMode = PTYIMODE_ECHO|PTYIMODE_CANON,.OutputMode=0}; + _SysIOCtl(0, PTY_IOCTL_SETMODE, &mode); + fprintf(stderr, "\x1b[R"); } return 0; } -/** - * \fn char *GetUsername() - */ -char *GetUsername() +char *_GetString(int bEcho) { - char ret[BUFLEN] = {0}; + char ret[BUFLEN]; int pos = 0; char ch; - // Prompt the user - printf("Username: "); + struct ptymode mode; + const int is_pty = (_SysIOCtl(0, DRV_IOCTL_TYPE, NULL) == DRV_TYPE_TERMINAL); + + // Clear PTY echo + if( !bEcho && is_pty ) { + _SysIOCtl(0, PTY_IOCTL_GETMODE, &mode); + mode.InputMode &= ~PTYIMODE_ECHO; + _SysIOCtl(0, PTY_IOCTL_SETMODE, &mode); + } // Read in text while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) { + // Handle backspace if(ch == '\b') { if( pos <= 0 ) continue; pos --; ret[pos] = '\0'; } + // Ctrl-C : Cancel + else if( ch == 'c'-'a'+1) + pos = 0; + // Ctrl-U : Clear + else if( ch == 'u'-'a'+1) + pos = 0; + // Ignore \r + else if( ch == '\r' ) + continue; else ret[pos++] = ch; - // Echo out to the screen - fputc(ch, stdout); - if(pos == BUFLEN-1) break; } - // Finish String ret[pos] = '\0'; - - printf("\n"); + + // Re-set echo + if( !bEcho && is_pty ) { + mode.InputMode |= PTYIMODE_ECHO; + _SysIOCtl(0, PTY_IOCTL_SETMODE, &mode); + } + return strdup(ret); } /** - * \fn char *GetPassword() + * \fn char *GetUsername() */ -char *GetPassword() +char *GetUsername() { - char ret[BUFLEN]; + char ret[BUFLEN] = {0}; int pos = 0; char ch; // Prompt the user - printf("Password: "); - - // Read in text - while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) - { - if(ch == '\b') { - if( pos <= 0 ) continue; - pos --; - ret[pos] = '\0'; - } - else - ret[pos++] = ch; - - // Don't echo out to the screen - //fputc(stdout, ch); - - if(pos == BUFLEN-1) break; - } + printf("Username: "); + fflush(stdout); - ret[pos] = '\0'; + return _GetString(1); +} + +/** + * \fn char *GetPassword() + */ +char *GetPassword() +{ + // Prompt the user + printf("Password: "); + fflush(stdout); - printf("\n"); - return strdup(ret); + return _GetString(0); }