/**
** TODO:
- ** homegrown ttyslot()q
+ ** homegrown ttyslot()
** test, test, test
**
** Platform status:
** ----------------
**
** Known good:
- ** Linux (Redhat 6.2, need more variants)
+ ** Linux (Redhat 6.2, Debian)
+ ** Solaris
** HP-UX 10.20 (gcc only)
** IRIX
+ ** NeXT - M68k/HPPA/Sparc (4.2/3.3)
**
** Testing required: Please send reports!
- ** Solaris
** NetBSD
** HP-UX 11
** AIX
**
** Platforms with known problems:
- ** NeXT
+ ** Some variants of Slackware Linux
**
**/
#include "ssh.h"
#include "xmalloc.h"
#include "loginrec.h"
+#include "log.h"
+#include "atomicio.h"
RCSID("$Id$");
+#ifdef HAVE_UTIL_H
+# include <util.h>
+#endif
+
+#ifdef HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+
/**
** prototypes for helper functions in this file
**/
int
login_write (struct logininfo *li)
{
+#ifndef HAVE_CYGWIN
if ((int)geteuid() != 0) {
log("Attempt to write login records by non-root user (aborting)");
return 1;
}
+#endif
/* set the timestamp */
login_set_current_time(li);
line_fullname(char *dst, const char *src, int dstsize)
{
memset(dst, '\0', dstsize);
- if ((strncmp(src, "/dev/", 5) == 0) || (dstsize < (strlen(src) + 5)))
+ if ((strncmp(src, "/dev/", 5) == 0) || (dstsize < (strlen(src) + 5))) {
strlcpy(dst, src, dstsize);
- else {
+ } else {
strlcpy(dst, "/dev/", dstsize);
strlcat(dst, src, dstsize);
}
{
memset(dst, '\0', dstsize);
if (strncmp(src, "/dev/", 5) == 0)
- strlcpy(dst, &src[5], dstsize);
+ strlcpy(dst, src + 5, dstsize);
else
strlcpy(dst, src, dstsize);
return dst;
memset(dst, '\0', dstsize);
/* Always skip prefix if present */
+#ifdef sgi
+ if (strncmp(src, "/dev/tty", 8) == 0)
+ src += 8;
+#else
if (strncmp(src, "/dev/", 5) == 0)
src += 5;
+#endif
len = strlen(src);
strncpy(utx->ut_host, li->hostname, MIN_SIZEOF(utx->ut_host, li->hostname));
# endif
# ifdef HAVE_ADDR_IN_UTMPX
- /* FIXME: (ATL) not supported yet */
+ /* this is just a 32-bit IP address */
+ if (li->hostaddr.sa.sa_family == AF_INET)
+ utx->ut_addr = li->hostaddr.sa_in.sin_addr.s_addr;
# endif
# ifdef HAVE_SYSLEN_IN_UTMPX
/* ut_syslen is the length of the utx_host string */
/* FIXME: (ATL) ttyslot() needs local implementation */
-#if defined(SUNOS4) && defined(HAVE_GETTTYENT)
+#if defined(HAVE_GETTTYENT)
register struct ttyent *ty;
tty=0;
tty = ttyslot(); /* seems only to work for /dev/ttyp? style names */
-#endif /* SUNOS4 && HAVE_GETTTYENT */
+#endif /* HAVE_GETTTYENT */
if (tty > 0 && (fd = open(UTMP_FILE, O_RDWR|O_CREAT, 0644)) >= 0) {
(void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
/* create our struct lastlog */
lastlog_construct(li, &last);
+ if (!lastlog_openseek(li, &fd, O_RDWR|O_CREAT))
+ return(0);
+
/* write the entry */
- if (lastlog_openseek(li, &fd, O_RDWR|O_CREAT)) {
- if (atomicio(write, fd, &last, sizeof(last)) != sizeof(last)) {
- log("lastlog_write_filemode: Error writing to %s: %s",
- LASTLOG_FILE, strerror(errno));
- return 0;
- }
- return 1;
- } else {
+ if (atomicio(write, fd, &last, sizeof(last)) != sizeof(last)) {
+ close(fd);
+ log("lastlog_write_filemode: Error writing to %s: %s",
+ LASTLOG_FILE, strerror(errno));
return 0;
}
+
+ close(fd);
+ return 1;
}
int