OrionUserland
Barry Importing existing Orion Userland 19aefaa (3 years, 3 months ago)
diff --git a/login/main.c b/login/main.c
new file mode 100644
index 0000000..d1bfd55
--- /dev/null
+++ b/login/main.c
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <pwd.h>
+
+#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;
+}