int
lastlog_get_entry(struct logininfo *li)
{
	struct lastlog last;
	int fd, ret;

	if (!lastlog_openseek(li, &fd, O_RDONLY))
		return (0);

	ret = atomicio(read, fd, &last, sizeof(last));
	close(fd);

	switch (ret) {
	case 0:
		memset(&last, '\0', sizeof(last));
		/* FALLTHRU */
	case sizeof(last):
		lastlog_populate_entry(li, &last);
		return (1);
	case -1:
		error("%s: Error reading from %s: %s", __func__,
		    LASTLOG_FILE, strerror(errno));
		return (0);
	default:
		error("%s: Error reading from %s: Expecting %" LPRI_d_SIZE_T 
		      ", got %d", __func__, LASTLOG_FILE, sizeof(last), ret);
		return (0);
	}

	/* NOTREACHED */
	return (0);
}
示例#2
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 */

#ifdef HAVE_GETLASTLOGXBYNAME
int
lastlog_get_entry(struct logininfo *li)
{
	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)
{
	struct lastlog last;
	int fd, ret;

	if (!lastlog_openseek(li, &fd, O_RDONLY))
		return (0);

	ret = atomicio(read, fd, &last, sizeof(last));
	close(fd);

	switch (ret) {
	case 0:
		memset(&last, '\0', sizeof(last));
		/* FALLTHRU */
	case sizeof(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__,
		    LASTLOG_FILE, strerror(errno));
		return (0);
	default:
		error("%s: Error reading from %s: Expecting %d, got %d",
		    __func__, LASTLOG_FILE, (int)sizeof(last), ret);
		return (0);
	}

	/* NOTREACHED */
	return (0);
}
示例#3
0
		/* find this uid's offset in the lastlog file */
		offset = (off_t) ((long)li->uid * sizeof(struct lastlog));

		if (lseek(*fd, offset, SEEK_SET) != offset) {
			logit("%s: %s->lseek(): %s", __func__,
			    lastlog_file, strerror(errno));
			return (0);
		}
	}

	return (1);
}
#endif /* !LASTLOG_WRITE_PUTUTXLINE || !HAVE_GETLASTLOGXBYNAME */

#ifdef LASTLOG_WRITE_PUTUTXLINE
int
lastlog_write_entry(struct logininfo *li)
{
	switch(li->type) {
	case LTYPE_LOGIN:
		return 1; /* lastlog written by pututxline */
	default:
		logit("lastlog_write_entry: Invalid type field");
		return 0;
	}
}
#else /* LASTLOG_WRITE_PUTUTXLINE */
int
lastlog_write_entry(struct logininfo *li)
{
	struct lastlog last;
	int fd;

	switch(li->type) {
	case LTYPE_LOGIN:
		/* 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);
	}
}
static int
lastlog_perform_login(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("lastlog_write_filemode: Error writing to %s: %s",
		    LASTLOG_FILE, strerror(errno));
		return 0;
	}

	close(fd);
	return 1;
}