diff options
Diffstat (limited to '')
| -rw-r--r-- | src/cerberus.c | 68 | ||||
| -rw-r--r-- | src/cerberus.h | 1 | 
2 files changed, 69 insertions, 0 deletions
| diff --git a/src/cerberus.c b/src/cerberus.c index e3f3f95..987a497 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -25,6 +25,11 @@  /** + * The environment variables + */ +extern char** environ; + +/**   * Mane method   *    * @param   argc  The number of command line arguments @@ -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 <http://www.gnu.org/licenses/>.   */  #include <stdio.h> +#include <stdlib.h>  #include <unistd.h>  #include <signal.h>  #include <pwd.h> | 
