summaryrefslogtreecommitdiff
path: root/modules/pammodutil
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2003-01-14 05:43:07 +0000
committerAndrew G. Morgan <morgan@kernel.org>2003-01-14 05:43:07 +0000
commit7050b307e9e712471d987e0c5f8dd1cb2260511c (patch)
tree5bf06d87cc804cb3255e12d0cb1b47064a2d1755 /modules/pammodutil
parent2b71955aec63541e4b071c12eae9fba76e7085fa (diff)
Relevant BUGIDs: 667584 664290
Purpose of commit: bugfix Commit summary: --------------- Two bug fixes in one: don't trust getlogin() and sanely lower the time the password databases are locked in pam_unix.
Diffstat (limited to 'modules/pammodutil')
-rw-r--r--modules/pammodutil/Makefile3
-rw-r--r--modules/pammodutil/include/security/_pam_modutil.h4
-rw-r--r--modules/pammodutil/modutil_getlogin.c71
3 files changed, 76 insertions, 2 deletions
diff --git a/modules/pammodutil/Makefile b/modules/pammodutil/Makefile
index a97388ef..b4868528 100644
--- a/modules/pammodutil/Makefile
+++ b/modules/pammodutil/Makefile
@@ -18,7 +18,8 @@ CFLAGS += $(PIC) $(STATIC) $(MOREFLAGS) \
-DLIBPAM_VERSION_MINOR=$(MINOR_REL)
# all the object files we care about
-LIBOBJECTS = modutil_cleanup.o modutil_getpwnam.o modutil_getpwuid.o
+LIBOBJECTS = modutil_cleanup.o modutil_getpwnam.o modutil_getpwuid.o \
+ modutil_getlogin.o
# static library name
LIBSTATIC = $(LIBNAME).a
diff --git a/modules/pammodutil/include/security/_pam_modutil.h b/modules/pammodutil/include/security/_pam_modutil.h
index af8a7ae1..5e063651 100644
--- a/modules/pammodutil/include/security/_pam_modutil.h
+++ b/modules/pammodutil/include/security/_pam_modutil.h
@@ -15,7 +15,7 @@
* On systems that simply can't support thread safe programming, these
* functions don't support it either - sorry.
*
- * Copyright (c) 2001 Andrew Morgan <morgan@kernel.org>
+ * Copyright (c) 2001-2002 Andrew Morgan <morgan@kernel.org>
*/
#include <pwd.h>
@@ -30,4 +30,6 @@ extern struct passwd *_pammodutil_getpwuid(pam_handle_t *pamh,
extern void _pammodutil_cleanup(pam_handle_t *pamh, void *data,
int error_status);
+extern const char *_pammodutil_getlogin(pam_handle_t *pamh);
+
#endif /* _PAM_MODUTIL_H */
diff --git a/modules/pammodutil/modutil_getlogin.c b/modules/pammodutil/modutil_getlogin.c
new file mode 100644
index 00000000..b624def1
--- /dev/null
+++ b/modules/pammodutil/modutil_getlogin.c
@@ -0,0 +1,71 @@
+/*
+ * $Id$
+ *
+ * A central point for invoking getlogin(). Hopefully, this is a
+ * little harder to spoof than all the other versions that are out
+ * there.
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <utmp.h>
+
+#include "pammodutil.h"
+
+#define _PAMMODUTIL_GETLOGIN "_pammodutil_getlogin"
+
+const char *_pammodutil_getlogin(pam_handle_t *pamh)
+{
+ int status;
+ const char *logname, *curr_tty;
+ char *curr_user;
+ struct utmp *ut, line;
+
+ status = pam_get_data(pamh, _PAMMODUTIL_GETLOGIN,
+ (const void **) &logname);
+ if (status == PAM_SUCCESS) {
+ return logname;
+ }
+
+ status = pam_get_item(pamh, PAM_TTY, (const void **) &curr_tty);
+ if ((status != PAM_SUCCESS) || (curr_tty == NULL)) {
+ curr_tty = ttyname(0);
+ }
+
+ if ((curr_tty == NULL) || memcmp(curr_tty, "/dev/", 5)) {
+ return NULL;
+ }
+
+ curr_tty += 5; /* strlen("/dev/") */
+ logname = NULL;
+
+ setutent();
+ strncpy(line.ut_line, curr_tty, sizeof(line.ut_line));
+
+ if ((ut = getutline(&line)) == NULL) {
+ goto clean_up_and_go_home;
+ }
+
+ curr_user = calloc(sizeof(line.ut_user)+1, 1);
+ if (curr_user == NULL) {
+ goto clean_up_and_go_home;
+ }
+
+ strncpy(curr_user, ut->ut_user, sizeof(ut->ut_user));
+ curr_user[sizeof(line.ut_user)] = '\0';
+
+ status = pam_set_data(pamh, _PAMMODUTIL_GETLOGIN, logname,
+ _pammodutil_cleanup);
+ if (status != PAM_SUCCESS) {
+ free(curr_user);
+ goto clean_up_and_go_home;
+ }
+
+ logname = curr_user;
+
+clean_up_and_go_home:
+
+ endutent();
+
+ return logname;
+}