32 #include <sys/ioctl.h> 43 #define FORCE_LOGIN_USER "root" 44 #define FORCE_LOGIN_PASS "root" 48 int g_RunningPid = -1;
51 extern int pedigree_login(
int uid,
const char *password);
57 if (g_RunningPid != -1)
65 klog(LOG_NOTICE,
"SIGINT ignored");
69 int main(
int argc,
char **argv)
71 setlocale(LC_ALL,
"");
72 bindtextdomain(
"login",
"/system/locale");
73 bind_textdomain_codeset(
"login",
"UTF-8");
78 printf(
"Loading installer, please wait...\n");
80 static const char *app_argv[] = {
"root»/applications/python",
81 "root»/code/installer/install.py", 0};
82 static const char *app_env[] = {
"TERM=xterm",
"PATH=/applications",
85 "root»/applications/python", (
char *
const *) app_argv,
86 (
char *
const *) app_env);
88 printf(
"FATAL: Couldn't load Python!\n");
95 klog(LOG_INFO,
"-- Hello, Travis! --");
99 signal(SIGINT, sigint);
103 ioctl(1, TIOCSCTTY, 0);
106 tcsetpgrp(1, getpgrp());
109 const char *TERM = getenv(
"TERM");
113 setenv(
"TERM", TERM, 1);
116 const char *envLcAll = getenv(
"LC_ALL");
119 envLcAll =
"en_US.UTF-8";
120 setenv(
"LC_ALL", envLcAll, 1);
126 if (!(curt.c_oflag & OPOST))
127 curt.c_oflag |= OPOST;
128 tcsetattr(1, TCSANOW, &curt);
137 printf(gettext(
"Welcome to Pedigree\n"));
140 if (!strcmp(TERM,
"xterm"))
143 printf(gettext(
"Pedigree Login"));
153 int fd = open(
"/dev/tty", 0);
158 printf(gettext(
"Username: "));
160 #ifdef FORCE_LOGIN_USER 161 const char *username = FORCE_LOGIN_USER;
162 printf(
"%s\n", username);
167 char *username = fgets(buffer, 256, stdin);
174 username[strlen(username) - 1] =
'\0';
175 if (!strlen(username))
181 struct passwd *pw = getpwnam(username);
184 printf(gettext(
"\nUnknown user: '%s'\n"), username);
189 printf(gettext(
"Password: "));
190 #ifdef FORCE_LOGIN_PASS 191 const char *password = FORCE_LOGIN_PASS;
192 printf(gettext(
"(forced)\n"));
196 char password[256], c;
200 curt.c_lflag &= ~(ECHO | ICANON);
201 tcsetattr(0, TCSANOW, &curt);
202 while (i < 256 && (c = getchar()) !=
'\n')
212 password[--i] =
'\0';
216 else if (c !=
'\033')
219 if (!strcmp(TERM,
"xterm"))
226 curt.c_lflag |= (ECHO | ICANON);
227 tcsetattr(0, TCSANOW, &curt);
234 if (pedigree_login(pw->pw_uid, password) != 0)
236 printf(gettext(
"Password incorrect.\n"));
242 if (!strcmp(TERM,
"xterm"))
243 printf(
"\033]0;%s\007", pw->pw_shell);
251 if (p && (p->ut_type == LOGIN_PROCESS && p->ut_pid == getpid()))
258 memcpy(&ut, p,
sizeof(ut));
261 gettimeofday(&tv, NULL);
263 ut.ut_type = USER_PROCESS;
264 strncpy(ut.ut_user, pw->pw_name, UT_NAMESIZE);
273 pid = g_RunningPid = fork();
287 newenv[0] = (
char *) malloc(256);
288 newenv[1] = (
char *) malloc(256);
289 newenv[2] = (
char *) malloc(256);
292 sprintf(newenv[0],
"HOME=%s", pw->pw_dir);
293 sprintf(newenv[1],
"TERM=%s", TERM);
294 sprintf(newenv[2],
"LC_ALL=%s", envLcAll);
297 char *shell = (
char *) malloc(strlen(pw->pw_shell) + 1);
298 sprintf(shell,
"-%s", pw->pw_shell);
301 execle(pw->pw_shell, shell, 0, newenv);
311 waitpid(pid, &stat, 0);