summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/loginrec.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2009-05-22 18:46:28 +0000
committerdes <des@FreeBSD.org>2009-05-22 18:46:28 +0000
commit8bf56a9772e08d79d1a808bb69be82ca688afc76 (patch)
treed3b23c04145e95d8d26c4e6efa1cd05fa34fd795 /crypto/openssh/loginrec.c
parent56fa0af6738b5c4466957197aaa372d30e74440b (diff)
parentf4c3a2131f559534b5693fd15df8d89049db7cbb (diff)
downloadFreeBSD-src-8bf56a9772e08d79d1a808bb69be82ca688afc76.zip
FreeBSD-src-8bf56a9772e08d79d1a808bb69be82ca688afc76.tar.gz
Upgrade to OpenSSH 5.2p1.
MFC after: 3 months
Diffstat (limited to 'crypto/openssh/loginrec.c')
-rw-r--r--crypto/openssh/loginrec.c139
1 files changed, 66 insertions, 73 deletions
diff --git a/crypto/openssh/loginrec.c b/crypto/openssh/loginrec.c
index b411141..f4af067 100644
--- a/crypto/openssh/loginrec.c
+++ b/crypto/openssh/loginrec.c
@@ -1456,25 +1456,14 @@ syslogin_write_entry(struct logininfo *li)
**/
#ifdef USE_LASTLOG
-#define LL_FILE 1
-#define LL_DIR 2
-#define LL_OTHER 3
-
-static void
-lastlog_construct(struct logininfo *li, struct lastlog *last)
-{
- /* clear the structure */
- memset(last, '\0', sizeof(*last));
-
- line_stripname(last->ll_line, li->line, sizeof(last->ll_line));
- strlcpy(last->ll_host, li->hostname,
- MIN_SIZEOF(last->ll_host, li->hostname));
- last->ll_time = li->tv_sec;
-}
+#if !defined(LASTLOG_WRITE_PUTUTXLINE) || !defined(HAVE_GETLASTLOGXBYNAME)
+/* open the file (using filemode) and seek to the login entry */
static int
-lastlog_filetype(char *filename)
+lastlog_openseek(struct logininfo *li, int *fd, int filemode)
{
+ off_t offset;
+ char lastlog_file[1024];
struct stat st;
if (stat(LASTLOG_FILE, &st) != 0) {
@@ -1482,34 +1471,12 @@ lastlog_filetype(char *filename)
LASTLOG_FILE, strerror(errno));
return (0);
}
- if (S_ISDIR(st.st_mode))
- return (LL_DIR);
- else if (S_ISREG(st.st_mode))
- return (LL_FILE);
- else
- return (LL_OTHER);
-}
-
-
-/* open the file (using filemode) and seek to the login entry */
-static int
-lastlog_openseek(struct logininfo *li, int *fd, int filemode)
-{
- off_t offset;
- int type;
- char lastlog_file[1024];
-
- type = lastlog_filetype(LASTLOG_FILE);
- switch (type) {
- case LL_FILE:
- strlcpy(lastlog_file, LASTLOG_FILE,
- sizeof(lastlog_file));
- break;
- case LL_DIR:
+ if (S_ISDIR(st.st_mode)) {
snprintf(lastlog_file, sizeof(lastlog_file), "%s/%s",
LASTLOG_FILE, li->username);
- break;
- default:
+ } else if (S_ISREG(st.st_mode)) {
+ strlcpy(lastlog_file, LASTLOG_FILE, sizeof(lastlog_file));
+ } else {
logit("%s: %.100s is not a file or directory!", __func__,
LASTLOG_FILE);
return (0);
@@ -1522,7 +1489,7 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
return (0);
}
- if (type == LL_FILE) {
+ if (S_ISREG(st.st_mode)) {
/* find this uid's offset in the lastlog file */
offset = (off_t) ((long)li->uid * sizeof(struct lastlog));
@@ -1535,52 +1502,74 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
return (1);
}
+#endif /* !LASTLOG_WRITE_PUTUTXLINE || !HAVE_GETLASTLOGXBYNAME */
-static int
-lastlog_perform_login(struct logininfo *li)
+#ifdef LASTLOG_WRITE_PUTUTXLINE
+int
+lastlog_write_entry(struct logininfo *li)
{
- struct lastlog last;
- int fd;
-
- /* create our struct lastlog */
- lastlog_construct(li, &last);
-
- if (!lastlog_openseek(li, &fd, O_RDWR|O_CREAT))
- return (0);
-
- /* write the entry */
- if (atomicio(vwrite, fd, &last, sizeof(last)) != sizeof(last)) {
- close(fd);
- logit("%s: Error writing to %s: %s", __func__,
- LASTLOG_FILE, strerror(errno));
- return (0);
+ switch(li->type) {
+ case LTYPE_LOGIN:
+ return 1; /* lastlog written by pututxline */
+ default:
+ logit("lastlog_write_entry: Invalid type field");
+ return 0;
}
-
- close(fd);
- return (1);
}
-
+#else /* LASTLOG_WRITE_PUTUTXLINE */
int
lastlog_write_entry(struct logininfo *li)
{
+ struct lastlog last;
+ int fd;
+
switch(li->type) {
case LTYPE_LOGIN:
- return (lastlog_perform_login(li));
+ /* create our struct lastlog */
+ memset(&last, '\0', sizeof(last));
+ line_stripname(last.ll_line, li->line, sizeof(last.ll_line));
+ strlcpy(last.ll_host, li->hostname,
+ MIN_SIZEOF(last.ll_host, li->hostname));
+ last.ll_time = li->tv_sec;
+
+ if (!lastlog_openseek(li, &fd, O_RDWR|O_CREAT))
+ return (0);
+
+ /* write the entry */
+ if (atomicio(vwrite, fd, &last, sizeof(last)) != sizeof(last)) {
+ close(fd);
+ logit("%s: Error writing to %s: %s", __func__,
+ LASTLOG_FILE, strerror(errno));
+ return (0);
+ }
+
+ close(fd);
+ return (1);
default:
logit("%s: Invalid type field", __func__);
return (0);
}
}
+#endif /* LASTLOG_WRITE_PUTUTXLINE */
-static void
-lastlog_populate_entry(struct logininfo *li, struct lastlog *last)
+#ifdef HAVE_GETLASTLOGXBYNAME
+int
+lastlog_get_entry(struct logininfo *li)
{
- line_fullname(li->line, last->ll_line, sizeof(li->line));
- strlcpy(li->hostname, last->ll_host,
- MIN_SIZEOF(li->hostname, last->ll_host));
- li->tv_sec = last->ll_time;
-}
+ struct lastlogx l, *ll;
+ if ((ll = getlastlogxbyname(li->username, &l)) == NULL) {
+ memset(&l, '\0', sizeof(l));
+ ll = &l;
+ }
+ line_fullname(li->line, ll->ll_line, sizeof(li->line));
+ strlcpy(li->hostname, ll->ll_host,
+ MIN_SIZEOF(li->hostname, ll->ll_host));
+ li->tv_sec = ll->ll_tv.tv_sec;
+ li->tv_usec = ll->ll_tv.tv_usec;
+ return (1);
+}
+#else /* HAVE_GETLASTLOGXBYNAME */
int
lastlog_get_entry(struct logininfo *li)
{
@@ -1598,7 +1587,10 @@ lastlog_get_entry(struct logininfo *li)
memset(&last, '\0', sizeof(last));
/* FALLTHRU */
case sizeof(last):
- lastlog_populate_entry(li, &last);
+ line_fullname(li->line, last.ll_line, sizeof(li->line));
+ strlcpy(li->hostname, last.ll_host,
+ MIN_SIZEOF(li->hostname, last.ll_host));
+ li->tv_sec = last.ll_time;
return (1);
case -1:
error("%s: Error reading from %s: %s", __func__,
@@ -1613,6 +1605,7 @@ lastlog_get_entry(struct logininfo *li)
/* NOTREACHED */
return (0);
}
+#endif /* HAVE_GETLASTLOGXBYNAME */
#endif /* USE_LASTLOG */
#ifdef USE_BTMP
OpenPOWER on IntegriCloud