- (djm) Fixes to login code - not setting li->uid, cleanups
This commit is contained in:
parent
0800647391
commit
f8af08d7cb
|
@ -1,3 +1,6 @@
|
||||||
|
20000627
|
||||||
|
- (djm) Fixes to login code - not setting li->uid, cleanups
|
||||||
|
|
||||||
20000626
|
20000626
|
||||||
- (djm) Better fix to aclocal tests from Garrick James <garrick@james.net>
|
- (djm) Better fix to aclocal tests from Garrick James <garrick@james.net>
|
||||||
- (djm) Account expiry support from Andreas Steinmetz <ast@domdv.de>
|
- (djm) Account expiry support from Andreas Steinmetz <ast@domdv.de>
|
||||||
|
|
54
loginrec.c
54
loginrec.c
|
@ -170,7 +170,7 @@
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "loginrec.h"
|
#include "loginrec.h"
|
||||||
|
|
||||||
RCSID("$Id: loginrec.c,v 1.9 2000/06/20 03:49:11 djm Exp $");
|
RCSID("$Id: loginrec.c,v 1.10 2000/06/26 23:40:06 djm Exp $");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** prototypes for helper functions in this file
|
** prototypes for helper functions in this file
|
||||||
|
@ -198,16 +198,9 @@ int lastlog_get_entry(struct logininfo *li);
|
||||||
int wtmp_get_entry(struct logininfo *li);
|
int wtmp_get_entry(struct logininfo *li);
|
||||||
int wtmpx_get_entry(struct logininfo *li);
|
int wtmpx_get_entry(struct logininfo *li);
|
||||||
|
|
||||||
|
|
||||||
#ifdef MIN
|
|
||||||
# undef MIN
|
|
||||||
# define MIN(a,b) ( (a)<(b) ? (a) : (b) )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* pick the shortest string */
|
/* pick the shortest string */
|
||||||
#define MIN_SIZEOF(s1,s2) ( sizeof(s1) < sizeof(s2) ? sizeof(s1) : sizeof(s2) )
|
#define MIN_SIZEOF(s1,s2) ( sizeof(s1) < sizeof(s2) ? sizeof(s1) : sizeof(s2) )
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** platform-independent login functions
|
** platform-independent login functions
|
||||||
**/
|
**/
|
||||||
|
@ -303,7 +296,7 @@ login_get_lastlog(struct logininfo *li, const int uid)
|
||||||
pw = getpwuid(uid);
|
pw = getpwuid(uid);
|
||||||
/* No MIN_SIZEOF here - we absolutely *must not* truncate the
|
/* No MIN_SIZEOF here - we absolutely *must not* truncate the
|
||||||
* username */
|
* username */
|
||||||
strlcpy(li->username, pw->pw_name, li->username);
|
strlcpy(li->username, pw->pw_name, sizeof(li->username));
|
||||||
#endif
|
#endif
|
||||||
if (getlast_entry(li))
|
if (getlast_entry(li))
|
||||||
return li;
|
return li;
|
||||||
|
@ -353,18 +346,27 @@ int
|
||||||
login_init_entry(struct logininfo *li, int pid, const char *username,
|
login_init_entry(struct logininfo *li, int pid, const char *username,
|
||||||
const char *hostname, const char *line)
|
const char *hostname, const char *line)
|
||||||
{
|
{
|
||||||
|
struct passwd *pw;
|
||||||
|
|
||||||
/* zero the structure */
|
/* zero the structure */
|
||||||
memset(li, 0, sizeof(struct logininfo));
|
memset(li, 0, sizeof(struct logininfo));
|
||||||
|
|
||||||
li->pid = pid;
|
li->pid = pid;
|
||||||
|
|
||||||
/* set the line information */
|
/* set the line information */
|
||||||
if (line)
|
if (line)
|
||||||
line_fullname(li->line, line, sizeof(li->line));
|
line_fullname(li->line, line, sizeof(li->line));
|
||||||
|
|
||||||
if (username)
|
if (username) {
|
||||||
strlcpy(li->username, username, sizeof(li->username));
|
strlcpy(li->username, username, sizeof(li->username));
|
||||||
|
pw = getpwnam(li->username);
|
||||||
|
if (pw == NULL)
|
||||||
|
fatal("login_init_entry: Cannot find user \"%s\"", li->username);
|
||||||
|
li->uid = pw->pw_uid;
|
||||||
|
}
|
||||||
if (hostname)
|
if (hostname)
|
||||||
strlcpy(li->hostname, hostname, sizeof(li->hostname));
|
strlcpy(li->hostname, hostname, sizeof(li->hostname));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,16 +379,12 @@ login_init_entry(struct logininfo *li, int pid, const char *username,
|
||||||
void
|
void
|
||||||
login_set_current_time(struct logininfo *li)
|
login_set_current_time(struct logininfo *li)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SYS_TIME_H
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
li->tv_sec = tv.tv_sec ; li->tv_usec = tv.tv_usec;
|
|
||||||
#else
|
li->tv_sec = tv.tv_sec;
|
||||||
time_t tm = time(0);
|
li->tv_usec = tv.tv_usec;
|
||||||
|
|
||||||
li->tv_sec = tm; li->tv_usec = 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1394,17 +1392,17 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
|
||||||
|
|
||||||
type = lastlog_filetype(LASTLOG_FILE);
|
type = lastlog_filetype(LASTLOG_FILE);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LL_FILE:
|
case LL_FILE:
|
||||||
strlcpy(lastlog_file, LASTLOG_FILE, sizeof(lastlog_file));
|
strlcpy(lastlog_file, LASTLOG_FILE, sizeof(lastlog_file));
|
||||||
break;
|
break;
|
||||||
case LL_DIR:
|
case LL_DIR:
|
||||||
snprintf(lastlog_file, sizeof(lastlog_file), "%s/%s",
|
snprintf(lastlog_file, sizeof(lastlog_file), "%s/%s",
|
||||||
LASTLOG_FILE, li->username);
|
LASTLOG_FILE, li->username);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log("lastlog_openseek: %.100s is not a file or directory!",
|
log("lastlog_openseek: %.100s is not a file or directory!",
|
||||||
LASTLOG_FILE);
|
LASTLOG_FILE);
|
||||||
return 0;
|
return 0;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
|
|
||||||
*fd = open(lastlog_file, filemode);
|
*fd = open(lastlog_file, filemode);
|
||||||
|
|
Loading…
Reference in New Issue