X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Flogin_src%2Fmain.c;h=e151ff944b9ab053099f74de32031835e42f92b3;hb=c62d9852a19f6a93ac2c5eaffa823d44b2ef256a;hp=59b4a784d5bab9d047f3864a267d2ad20efc7aa6;hpb=04a050f42807686dc119838c82372409246d55bb;p=tpg%2Facess2.git diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index 59b4a784..e151ff94 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 @@ -27,10 +29,13 @@ int main(int argc, char *argv[]) for(;;) { sUsername = GetUsername(); + if(!sUsername) continue; sPassword = GetPassword(); + if(!sPassword) continue; if( (uid = ValidateUser(sUsername, sPassword)) == -1 ) { printf("\nInvalid username or password\n"); + _SysDebug("Auth failure: '%s':'%s'", sUsername, sPassword); free(sUsername); free(sPassword); } @@ -61,73 +66,81 @@ int main(int argc, char *argv[]) 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'; + + // Re-set echo + if( !bEcho && is_pty ) { + mode.InputMode |= PTYIMODE_ECHO; + _SysIOCtl(0, PTY_IOCTL_SETMODE, &mode); + } - printf("\n"); 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); }