aboutsummaryrefslogtreecommitdiffstats
path: root/src/cerberus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cerberus.c')
-rw-r--r--src/cerberus.c68
1 files changed, 3 insertions, 65 deletions
diff --git a/src/cerberus.c b/src/cerberus.c
index 49e9857..807db40 100644
--- a/src/cerberus.c
+++ b/src/cerberus.c
@@ -25,11 +25,6 @@
/**
- * The environment variables
- */
-extern char** environ;
-
-/**
* Mane method
*
* @param argc The number of command line arguments
@@ -188,66 +183,9 @@ int main(int argc, char** argv)
/* TODO login */
-
- /* Change directory */
- if (chdir(entry->pw_dir))
- {
- perror("chdir");
- if (chdir(DEFAULT_HOME))
- {
- perror("chdir");
- sleep(ERROR_SLEEP);
- return 1;
- }
- entry->pw_dir = DEFAULT_HOME;
- }
-
- /* Make sure the shell to use is definied */
- if ((entry->pw_shell && *(entry->pw_shell)) == 0)
- entry->pw_shell = DEFAULT_SHELL;
-
- /* 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 ?: DEFAULT_TERM, 1);
- setenv("PATH", entry->pw_uid ? PATH : PATH_ROOT, 1);
-
- if (term)
- free(term);
- }
+ chdir_home(entry);
+ ensure_shell(entry);
+ set_environ(entry, preserve_env);
/* Reset terminal ownership and mode */