aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-10-29 14:02:34 +0100
committerMattias Andrée <maandree@operamail.com>2014-10-29 14:02:34 +0100
commitf44fc6927a795517e6627d390157f89f4a75f5f7 (patch)
tree238f25ae1fde21eda2d2e1608f81863b719df605
parentfix warning (diff)
downloadcerberus-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>
-rw-r--r--Makefile4
-rw-r--r--src/cerberus.c57
-rw-r--r--src/cerberus.h1
-rw-r--r--src/config.h7
4 files changed, 63 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index c90d533..c5c7c0d 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ BIN = /bin
SBIN = /sbin
INSTALL_BIN = $(SBIN)
DEV = /dev
+ETC = /etc
DATA = /share
LICENSES = $(DATA)/licenses
COMMAND = cerberus
@@ -36,6 +37,7 @@ VCS = $(DEV)/vcs
VCSA = $(DEV)/vcsa
PATH = $(_LB):$(_UB):$(_SB)
PATH_ROOT = $(_LS):$(_LB):$(_US):$(_UB):$(_SS):$(_SB)
+CERBERUSRC = $(ETC)/cerberusrc
auth_none = 0
auth_crypt = 1
@@ -45,7 +47,7 @@ H = \#
VCS_LEN = $(shell vcs="$(VCS)" ; echo "$${$(H)vcs}")
VCSA_LEN = $(shell vcsa="$(VCSA)" ; echo "$${$(H)vcsa}")
-STR_DEFS = TTY_GROUP DEFAULT_HOME DEFAULT_SH DEFAULT_SHELL DEFAULT_TERM PATH PATH_ROOT VCS VCSA
+STR_DEFS = TTY_GROUP DEFAULT_HOME DEFAULT_SH DEFAULT_SHELL DEFAULT_TERM PATH PATH_ROOT VCS VCSA CERBERUSRC
VRB_DEFS = VCS_LEN VCSA_LEN
STR_CPPFLAGS = $(foreach D, $(STR_DEFS), -D'$(D)="$($(D))"')
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