3 * - By John Hodge (thePowersGang)
6 #include <acess/devices/pty.h> // Enable/disable echo
16 int main(int argc, char *argv[])
18 char *sUsername, *sPassword;
23 printf("\x1B[?25h"); // Re-enable the cursor
24 // printf("\x1B[2J"); // Clear Screen
31 sUsername = GetUsername();
32 if(!sUsername) continue;
33 sPassword = GetPassword();
34 if(!sPassword) continue;
35 if( (uid = ValidateUser(sUsername, sPassword)) == -1 )
37 printf("\nInvalid username or password\n");
38 _SysDebug("Auth failure: '%s':'%s'", sUsername, sPassword);
47 uinfo = GetUserInfo(uid);
48 struct s_sys_spawninfo spawninfo;
50 spawninfo.gid = uinfo->GID;
51 spawninfo.uid = uinfo->UID;
52 const char *child_argv[2] = {"-", 0};
53 const char **child_envp = NULL;
54 int fds[] = {0, 1, 2};
55 pid = _SysSpawn(uinfo->Shell, child_argv, child_envp, 3, fds, &spawninfo);
58 fprintf(stderr, "Unable to fork the login process!\n");
62 // Wait for child to terminate
63 _SysWaitTID(pid, &status);
69 char *_GetString(int bEcho)
76 const int is_pty = (_SysIOCtl(0, DRV_IOCTL_TYPE, NULL) == DRV_TYPE_TERMINAL);
79 if( !bEcho && is_pty ) {
80 _SysIOCtl(0, PTY_IOCTL_GETMODE, &mode);
81 mode.InputMode &= ~PTYIMODE_ECHO;
82 _SysIOCtl(0, PTY_IOCTL_SETMODE, &mode);
86 while( (ch = fgetc(stdin)) != -1 && ch != '\n' )
90 if( pos <= 0 ) continue;
95 else if( ch == 'c'-'a'+1)
98 else if( ch == 'u'-'a'+1)
101 else if( ch == '\r' )
106 if(pos == BUFLEN-1) break;
112 if( !bEcho && is_pty ) {
113 mode.InputMode |= PTYIMODE_ECHO;
114 _SysIOCtl(0, PTY_IOCTL_SETMODE, &mode);
121 * \fn char *GetUsername()
125 char ret[BUFLEN] = {0};
130 printf("Username: ");
133 return _GetString(1);
137 * \fn char *GetPassword()
142 printf("Password: ");
145 return _GetString(0);