diff options
author | Tomas Mraz <tm@t8m.info> | 2005-09-21 10:00:58 +0000 |
---|---|---|
committer | Tomas Mraz <tm@t8m.info> | 2005-09-21 10:00:58 +0000 |
commit | be09d6354efcb2571731bdffc47da86f22621ac8 (patch) | |
tree | 82117bfbaadb46495a545ba4f567dc9bddd97c33 /modules/pammodutil/modutil_getlogin.c | |
parent | 627a0401899af257f0fb711ad54194e14a75c530 (diff) | |
download | pam-be09d6354efcb2571731bdffc47da86f22621ac8.tar.gz pam-be09d6354efcb2571731bdffc47da86f22621ac8.tar.bz2 pam-be09d6354efcb2571731bdffc47da86f22621ac8.zip |
Relevant BUGIDs:
Purpose of commit: new feature
Commit summary:
---------------
Moved functions from pammodutil to libpam.
Diffstat (limited to 'modules/pammodutil/modutil_getlogin.c')
-rw-r--r-- | modules/pammodutil/modutil_getlogin.c | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/modules/pammodutil/modutil_getlogin.c b/modules/pammodutil/modutil_getlogin.c deleted file mode 100644 index fa67402d..00000000 --- a/modules/pammodutil/modutil_getlogin.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * $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 "pammodutil.h" - -#include <stdlib.h> -#include <unistd.h> -#include <utmp.h> - -#define _PAMMODUTIL_GETLOGIN "_pammodutil_getlogin" - -const char *_pammodutil_getlogin(pam_handle_t *pamh) -{ - int status; - const void *logname; - const void *void_curr_tty; - const char *curr_tty; - char *curr_user; - struct utmp *ut, line; - - status = pam_get_data(pamh, _PAMMODUTIL_GETLOGIN, &logname); - if (status == PAM_SUCCESS) { - return logname; - } - - status = pam_get_item(pamh, PAM_TTY, &void_curr_tty); - if ((status != PAM_SUCCESS) || (void_curr_tty == NULL)) - curr_tty = ttyname(0); - else - curr_tty = (const char*)void_curr_tty; - - 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)); - /* calloc already zeroed the memory */ - - status = pam_set_data(pamh, _PAMMODUTIL_GETLOGIN, curr_user, - _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; -} |