From 846947081c91d212187fbbcd6dd8c93debe1dc0d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 18 Nov 2013 19:12:05 +0100 Subject: some login actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/cerberus.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cerberus.h | 1 + 2 files changed, 69 insertions(+) diff --git a/src/cerberus.c b/src/cerberus.c index e3f3f95..987a497 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -24,6 +24,11 @@ #endif +/** + * The environment variables + */ +extern char** environ; + /** * Mane method * @@ -153,6 +158,7 @@ int main(int argc, char** argv) sleep(ERROR_SLEEP); return 1; } + username = entry->pw_name; /* Get the passphrase, if -f has not been used */ @@ -165,6 +171,8 @@ int main(int argc, char** argv) /* Passphrase entered, turn off timeout */ alarm(0); + /* TODO verify passphrase */ + /* Wipe and free the passphrase from the memory */ if (skip_auth == 0) { @@ -181,6 +189,66 @@ int main(int argc, char** argv) /* TODO login */ + /* Change directory */ + if (chdir(entry->pw_dir)) + { + perror("chdir"); + if (chdir("/")) + { + perror("chdir"); + sleep(ERROR_SLEEP); + return 1; + } + entry->pw_dir = "/"; + } + + /* Make sure the shell to use is definied */ + if ((entry->pw_shell && *(entry->pw_shell)) == 0) + entry->pw_shell = "/bin/sh"; + + /* Set environment variables */ + { + char* _term = getenv("TERM"); + char* term = NULL; + if (_term) + { + int n = 0, i; + while (*(_term + n++)) + ; + term = malloc(n * sizeof(char)); + if (term == NULL) + { + perror("malloc"); + sleep(ERROR_SLEEP); + return 1; + } + for (i = 0; i < n; i++) + *(term + i) = *(_term + i); + } + + if (preserve_env == 0) + { + environ = malloc(sizeof(char*)); + if (environ == NULL) + { + perror("malloc"); + sleep(ERROR_SLEEP); + return 1; + } + *environ = NULL; + } + + setenv("HOME", entry->pw_dir, 1); + setenv("USER", entry->pw_name, 1); + setenv("LOGUSER", entry->pw_name, 1); + setenv("SHELL", entry->pw_shell, 1); + setenv("TERM", term ?: "dumb", 1); + if (term) + free(term); + + /* TODO set PATH */ + } + /* Reset terminal ownership and mode */ chown_tty(0, tty_group, 0); diff --git a/src/cerberus.h b/src/cerberus.h index 4f7b7b9..acafddf 100644 --- a/src/cerberus.h +++ b/src/cerberus.h @@ -17,6 +17,7 @@ * along with this program. If not, see . */ #include +#include #include #include #include -- cgit v1.2.3-70-g09d2