40#include <pedigree/log.h>
49extern int pedigree_login(
int uid);
54 if (g_RunningPid != -1) {
59 pedigree_log(LOG_NOTICE,
"SIGINT ignored");
63static int password_matches(
const char* password,
const char* stored) {
64 if (!stored || stored[0] ==
'!' || stored[0] ==
'*')
68 if (stored[0] ==
'$') {
69 const char* encrypted = crypt(password, stored);
70 return encrypted && !strcmp(encrypted, stored);
74 return !strcmp(password, stored);
77int main(
int argc,
char** argv) {
78 setlocale(LC_ALL,
"");
79 bindtextdomain(
"login",
"/usr/share/locale");
80 bind_textdomain_codeset(
"login",
"UTF-8");
85 printf(
"Loading installer, please wait...\n");
87 static const char* app_argv[] = {
"/usr/bin/python",
"/code/installer/install.py", 0};
88 static const char* app_env[] = {
"TERM=xterm",
"PATH=/usr/bin:/usr/sbin",
"PYTHONHOME=/", 0};
89 execve(
"/usr/bin/python", (
char*
const*)app_argv, (
char*
const*)app_env);
91 printf(
"FATAL: Couldn't load Python!\n");
97 signal(SIGINT, sigint);
101 ioctl(1, TIOCSCTTY, 0);
104 tcsetpgrp(1, getpgrp());
107 const char* TERM = getenv(
"TERM");
110 setenv(
"TERM", TERM, 1);
113 const char* envLcAll = getenv(
"LC_ALL");
115 envLcAll =
"en_US.UTF-8";
116 setenv(
"LC_ALL", envLcAll, 1);
122 if (!(curt.c_oflag & OPOST))
123 curt.c_oflag |= OPOST;
124 tcsetattr(1, TCSANOW, &curt);
132 printf(gettext(
"Welcome to Pedigree\n"));
135 if (!strcmp(TERM,
"xterm")) {
137 printf(gettext(
"Pedigree Login"));
146 int fd = open(
"/dev/tty", O_RDONLY);
148 pedigree_log(LOG_ERR,
"Opening /dev/tty failed: %s", strerror(errno));
151 if (fd != STDIN_FILENO) {
152 if (dup2(fd, STDIN_FILENO) < 0) {
153 pedigree_log(LOG_ERR,
"Replacing stdin failed: %s", strerror(errno));
161 printf(gettext(
"Username: "));
164 char* username = NULL;
168 username = fgets(buffer, 256, stdin);
174 username[strlen(username) - 1] =
'\0';
175 if (!strlen(username)) {
179 struct passwd* pw = getpwnam(username);
180 struct spwd* sp = getspnam(username);
182 printf(gettext(
"\nUnknown user: '%s'\n"), username);
187 printf(gettext(
"Password: "));
189 char* password = NULL;
197 curt.c_lflag &= ~(ECHO | ICANON);
198 tcsetattr(0, TCSANOW, &curt);
199 while ((c = getchar()) !=
'\n' && c != EOF) {
202 }
else if (c ==
'\b') {
207 }
else if (c !=
'\033' && i < (
sizeof(buffer) - 1)) {
209 if (!strcmp(TERM,
"xterm")) {
217 curt.c_lflag |= (ECHO | ICANON);
218 tcsetattr(0, TCSANOW, &curt);
227 int passwordValid = password_matches(password, sp->sp_pwdp);
229 if (!passwordValid || pedigree_login(pw->pw_uid) != 0) {
230 printf(gettext(
"Password incorrect.\n"));
234 if (!strcmp(TERM,
"xterm"))
235 printf(
"\033]0;%s\007", pw->pw_shell);
242 if (p && (p->ut_type == LOGIN_PROCESS && p->ut_pid == getpid()))
248 memcpy(&ut, p,
sizeof(ut));
251 gettimeofday(&tv, NULL);
253 ut.ut_type = USER_PROCESS;
254 strncpy(ut.ut_user, pw->pw_name, UT_NAMESIZE);
263 pid = g_RunningPid = fork();
268 }
else if (pid == 0) {
274 size_t homeSize = strlen(pw->pw_dir) +
sizeof(
"HOME=");
275 size_t termSize = strlen(TERM) +
sizeof(
"TERM=");
276 size_t localeSize = strlen(envLcAll) +
sizeof(
"LC_ALL=");
278 newenv[0] = (
char*)malloc(homeSize);
279 newenv[1] = (
char*)malloc(termSize);
280 newenv[2] = (
char*)malloc(localeSize);
284 size_t shellSize = strlen(pw->pw_shell) + 2;
285 char* shell = (
char*)malloc(shellSize);
287 if (!newenv[0] || !newenv[1] || !newenv[2] || !shell) {
292 snprintf(newenv[0], homeSize,
"HOME=%s", pw->pw_dir);
293 snprintf(newenv[1], termSize,
"TERM=%s", TERM);
294 snprintf(newenv[2], localeSize,
"LC_ALL=%s", envLcAll);
295 snprintf(shell, shellSize,
"-%s", pw->pw_shell);
298 execle(pw->pw_shell, shell, 0, newenv);
306 waitpid(pid, &stat, 0);