#include <stdio.h>
#include <string.h>
#include <sys/types.h>
-#define __USE_BSD
#include <syslog.h>
#include <unistd.h>
#include <security/pam_modules.h>
#include <security/_pam_macros.h>
+#include <security/_pam_modutil.h>
/* some syslogging */
D(("begin to converse"));
retval = pam_get_item( pamh, PAM_CONV, (const void **) &conv ) ;
- if ( retval == PAM_SUCCESS ) {
+ if ( retval == PAM_SUCCESS && conv) {
retval = conv->conv(nargs, ( const struct pam_message ** ) message
, response, conv->appdata_ptr);
} else {
_log_err(LOG_ERR, "couldn't obtain coversation function [%s]"
, pam_strerror(pamh, retval));
+ if (retval == PAM_SUCCESS)
+ retval = PAM_BAD_ITEM; /* conv was NULL */
}
D(("ready to return from module conversation"));
sleep(LASTLOG_IGNORE_LOCK_TIME);
}
- win = ( read(last_fd, &last_login, sizeof(last_login))
- == sizeof(last_login) );
+ win = (_pammodutil_read (last_fd, (char *) &last_login,
+ sizeof(last_login)) == sizeof(last_login));
last_lock.l_type = F_UNLCK;
(void) fcntl(last_fd, F_SETLK, &last_lock); /* unlock */
if (!(announce & LASTLOG_QUIET)) {
if (last_login.ll_time) {
+ time_t ll_time;
char *the_time;
char *remark;
- the_time = ctime(&last_login.ll_time);
+ ll_time = last_login.ll_time;
+ the_time = ctime(&ll_time);
the_time[-1+strlen(the_time)] = '\0'; /* delete '\n' */
remark = malloc(LASTLOG_MAXSIZE);
/* write latest value */
{
+ time_t ll_time;
const char *remote_host=NULL
, *terminal_line=DEFAULT_TERM;
/* set this login date */
D(("set the most recent login time"));
- (void) time(&last_login.ll_time); /* set the time */
+ (void) time(&ll_time); /* set the time */
+ last_login.ll_time = ll_time;
/* set the remote host */
(void) pam_get_item(pamh, PAM_RHOST, (const void **)&remote_host);
}
/* copy to last_login */
- strncpy(last_login.ll_host, remote_host
- , sizeof(last_login.ll_host));
+ strncpy(last_login.ll_host, remote_host,
+ sizeof(last_login.ll_host));
+ last_login.ll_host[sizeof(last_login.ll_host) - 1] = '\0';
remote_host = NULL;
/* set the terminal line */
D(("terminal = %s", terminal_line));
/* copy to last_login */
- strncpy(last_login.ll_line, terminal_line
- , sizeof(last_login.ll_line));
+ strncpy(last_login.ll_line, terminal_line,
+ sizeof(last_login.ll_line));
+ last_login.ll_host[sizeof(last_login.ll_host) - 1] = '\0';
terminal_line = NULL;
D(("locking last_log file"));
}
D(("writing to the last_log file"));
- (void) write(last_fd, &last_login, sizeof(last_login));
+ _pammodutil_write (last_fd, (char *) &last_login,
+ sizeof (last_login));
last_lock.l_type = F_UNLCK;
(void) fcntl(last_fd, F_SETLK, &last_lock); /* unlock */
/* what uid? */
- pwd = getpwnam(user);
+ pwd = _pammodutil_getpwnam (pamh, user);
if (pwd == NULL) {
D(("couldn't identify user %s", user));
return PAM_CRED_INSUFFICIENT;