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();
- printf("\n");
- } 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
return -1;
}
+ printf("pid = %i\n", pid);
+
// Spawn shell in a child process
if(pid == 0)
{
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';
}