diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-10-29 14:02:34 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-10-29 14:02:34 +0100 |
| commit | f44fc6927a795517e6627d390157f89f4a75f5f7 (patch) | |
| tree | 238f25ae1fde21eda2d2e1608f81863b719df605 /src | |
| parent | fix warning (diff) | |
| download | cerberus-f44fc6927a795517e6627d390157f89f4a75f5f7.tar.gz cerberus-f44fc6927a795517e6627d390157f89f4a75f5f7.tar.bz2 cerberus-f44fc6927a795517e6627d390157f89f4a75f5f7.tar.xz | |
add login- and logout-hook support instead of implementing logging in this project
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cerberus.c | 57 | ||||
| -rw-r--r-- | src/cerberus.h | 1 | ||||
| -rw-r--r-- | src/config.h | 7 |
3 files changed, 60 insertions, 5 deletions
diff --git a/src/cerberus.c b/src/cerberus.c index c70fb70..14eb31d 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -19,8 +19,12 @@ #include "cerberus.h" #include <string.h> +#include <unistd.h> + + +#define HOOK_LOGIN 0 +#define HOOK_LOGOUT 1 -/* TODO use log */ #ifdef USE_TTY_GROUP @@ -65,6 +69,13 @@ int main(int argc, char** argv) signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); + /* Run login hook */ + if (fork() == 0) + { + exec_hook(HOOK_LOGIN, argc, argv); + return 0; + } + /* Wait for the login shell and all grandchildren to exit */ while ((wait(NULL) == -1) && (errno == EINTR)) ; @@ -73,10 +84,9 @@ int main(int argc, char** argv) if (tty_device) { int fd = open(tty_device, O_RDWR | O_NONBLOCK); - if (fd) - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); + if (fd != 0) dup2(fd, 0); + if (fd != 1) dup2(fd, 1); + if (fd != 2) dup2(fd, 2); } /* Reset terminal ownership and mode */ @@ -85,11 +95,48 @@ int main(int argc, char** argv) /* Close login session */ close_login_session(); + /* Run logout hook */ + exec_hook(HOOK_LOGOUT, argc, argv); return 0; } /** + * Exec /etc/cerberusrc + * + * @param hook The ID of the hook to run + * @param argc The number of command line arguments + * @param argv The command line arguments + */ +void exec_hook(int hook, int argc, char** argv) +{ + static char cerberusrc[] = CERBERUSRC; + static char hooks[][7] = + { + [HOOK_LOGIN] = "login", + [HOOK_LOGOUT] = "logout", + }; + + char** args = malloc((size_t)(argc + 2) * sizeof(char*)); + int i; + + if (args == NULL) + { + perror("malloc"); + return; + } + + args[0] = cerberusrc; + args[1] = hooks[hook]; + for (i = 1; i < argc; i++) + args[i + 1] = argv[i]; + args[argc + 1] = NULL; + + execv(CERBERUSRC, args); +} + + +/** * Do everything before the fork and do everything the exec fork * * @param argc The number of command line arguments diff --git a/src/cerberus.h b/src/cerberus.h index 4737a97..93cbc6d 100644 --- a/src/cerberus.h +++ b/src/cerberus.h @@ -51,6 +51,7 @@ #endif +void exec_hook(int hook, int argc, char** argv); void do_login(int argc, char** argv); #if AUTH > 0 diff --git a/src/config.h b/src/config.h index b6e3f50..6e5c60c 100644 --- a/src/config.h +++ b/src/config.h @@ -21,6 +21,13 @@ /** + * Pathname for the program that implemements login and logout hooks + */ +#ifndef CERBERUSRC +#define CERBERUSRC "/etc/cerberusrc" +#endif + +/** * Mode for TTY devices */ #ifndef TTY_PERM |
