int status = 0;
tUserInfo *uinfo;
+ 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 for '%s'\n", sUsername);
+ free(sUsername);
+ free(sPassword);
+ }
+ else
+ break;
+ }
printf("\n");
// Create child process
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);
*/
char *GetUsername()
{
- char ret[BUFLEN];
+ char ret[BUFLEN] = {0};
int pos = 0;
char ch;
while( (ch = fgetc(stdin)) != -1 && ch != '\n' )
{
if(ch == '\b') {
+ if( pos <= 0 ) continue;
pos --;
ret[pos] = '\0';
}
while( (ch = fgetc(stdin)) != -1 && ch != '\n' )
{
if(ch == '\b') {
+ if( pos <= 0 ) continue;
pos --;
ret[pos] = '\0';
}