#include #include #include #include #include #include #include #include #include #define MANUAL_LOGIN /* Main function */ int main(int argc, char *argv[]) { int fd, sz; char *buf, *line, *input = malloc(1024); Passwd *pwd; Termios tcold, tcnew; while (1) { printf("\nUsername: "); memset(input, 0, 1024); #ifdef MANUAL_LOGIN sz = read(STDIN_FILENO, input, 1024); #else printf("root\n"); sz = 5; memcpy(input, "root", 5); #endif input[--sz] = '\0'; if (sz < 1) continue; pwd = getpwname(input); if (!pwd) continue; printf("Password: "); memset(input, 0, 1024); ioctl(STDIN_FILENO, TCGETS, &tcold); memcpy(&tcnew, &tcold, sizeof(Termios)); tcnew.lflag &= ~ECHO; ioctl(STDIN_FILENO, TCSETS, &tcnew); #ifdef MANUAL_LOGIN sz = read(STDIN_FILENO, input, 1024); #else printf("password\n"); sz = 9; memcpy(input, "password", 9); #endif input[--sz] = '\0'; if (sz < 1) continue; ioctl(STDIN_FILENO, TCSETS, &tcold); if (!strcmp(input, pwd->password)) break; printf("Login incorrect\n"); } printf("\n"); dbgprintf("Authenticating \"%s\" (%d:%d) -> \"%s\" @ \"%s\"", pwd->username, pwd->uid, pwd->gid, pwd->shell, pwd->homedir); chdir(pwd->homedir); setuid(pwd->uid); setgid(pwd->gid); char *v[] = { "sh", NULL }; execve(pwd->shell, v, NULL); return 0; }