X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Flogin_src%2Fmain.c;h=23d932948629b82bafb72d13a7cab90da18ea973;hb=341d51ca40a4a26ed89914feaacc940c64b22197;hp=bc9013d42823c2d21040493d6ef623677fd0b96f;hpb=536d7d5d3374c4d13afe7d5d099fd15a526d63fd;p=tpg%2Facess2.git diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index bc9013d4..23d93294 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -1,14 +1,16 @@ /* * Acess 2 Login + * - By John Hodge (thePowersGang) */ #include "header.h" +#include // Enable/disable echo // === CONSTANTS === #define BUFLEN 1024 // === PROTOTYPES === -char *GetUsername(); -char *GetPassword(); +char *GetUsername(void); +char *GetPassword(void); // === CODE === int main(int argc, char *argv[]) @@ -27,9 +29,12 @@ int main(int argc, char *argv[]) for(;;) { sUsername = GetUsername(); - if(!sUsername) continue; + if(!sUsername || !sUsername[0]) continue; sPassword = GetPassword(); - if(!sPassword) continue; + if(!sPassword) { + free(sUsername); + continue; + } if( (uid = ValidateUser(sUsername, sPassword)) == -1 ) { printf("\nInvalid username or password\n"); @@ -59,6 +64,11 @@ int main(int argc, char *argv[]) // Wait for child to terminate _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; @@ -70,6 +80,16 @@ char *_GetString(int bEcho) int pos = 0; char ch; + 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' ) { @@ -91,18 +111,17 @@ char *_GetString(int bEcho) else ret[pos++] = ch; - // Don't echo out to the screen - if( bEcho ) { - fputc(ch, stdout); - fflush(stdout); - } - if(pos == BUFLEN-1) break; } 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); } @@ -111,10 +130,6 @@ char *_GetString(int bEcho) */ char *GetUsername() { - char ret[BUFLEN] = {0}; - int pos = 0; - char ch; - // Prompt the user printf("Username: "); fflush(stdout);