X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FApplications%2Flogin_src%2Fmain.c;h=5ece35754a8f286c042882ce0fa6627a68644ebd;hb=8b0bac226378940df6cb56e5112b447570c3a39d;hp=248e13b9c8a7c1461af839f7c193b43e35ab702b;hpb=d1f16adf5f2e94e836ea6658186a6ff6d94f54d8;p=tpg%2Facess2.git diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index 248e13b9..5ece3575 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -17,16 +17,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 - do { - if(uid == -1) printf("\n"); + for(;;) + { sUsername = GetUsername(); sPassword = GetPassword(); - } 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 @@ -37,6 +47,8 @@ int main(int argc, char *argv[]) return -1; } + printf("pid = %i\n", pid); + // Spawn shell in a child process if(pid == 0) { @@ -49,7 +61,8 @@ int main(int argc, char *argv[]) child_argv[0] = uinfo->Shell; // Set Environment setgid(uinfo->GID); - setuid(uid); + //setuid(uid); + setuid(uinfo->UID); execve(uinfo->Shell, child_argv, child_envp); exit(-1); @@ -67,7 +80,7 @@ int main(int argc, char *argv[]) */ char *GetUsername() { - char ret[BUFLEN]; + char ret[BUFLEN] = {0}; int pos = 0; char ch; @@ -78,6 +91,7 @@ char *GetUsername() while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) { if(ch == '\b') { + if( pos <= 0 ) continue; pos --; ret[pos] = '\0'; } @@ -113,6 +127,7 @@ char *GetPassword() while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) { if(ch == '\b') { + if( pos <= 0 ) continue; pos --; ret[pos] = '\0'; }