Ejemplo n.º 1
0
void
update_db(int quietlog, int rootlogin, int fflag)
{
	struct sockaddr_storage ass;
	char assbuf[1024];
	socklen_t alen;
	const char *hname;
	int remote;

	hname = (hostname == NULL) ? "?" : hostname;
	if (getpeername(STDIN_FILENO, (struct sockaddr *)&ass, &alen) != -1) {
		(void)sockaddr_snprintf(assbuf,
		    sizeof(assbuf), "%A (%a)", (void *)&ass);
		if (have_ss) {
			char ssbuf[1024];
			(void)sockaddr_snprintf(ssbuf,
			    sizeof(ssbuf), "%A(%a)", (void *)&ss);
			 if (memcmp(&ass, &ss, alen) != 0)
				syslog(LOG_NOTICE,
				    "login %s on tty %s address mismatch "
				    "passed %s != actual %s", username, tty,
				    ssbuf, assbuf);
		} else
			ss = ass;
		remote = 1;
	} else if (have_ss) {
		(void)sockaddr_snprintf(assbuf,
		    sizeof(assbuf), "%A(%a)", (void *)&ss);
		remote = 1;
	} else if (hostname) {
		(void)snprintf(assbuf, sizeof(assbuf), "? ?");
		remote = 1;
	} else
		remote = 0;

	/* If fflag is on, assume caller/authenticator has logged root login. */
	if (rootlogin && fflag == 0) {
		if (remote)
			syslog(LOG_NOTICE, "ROOT LOGIN (%s) on tty %s from %s /"
			    " %s", username, tty, hname, assbuf);
		else
			syslog(LOG_NOTICE, "ROOT LOGIN (%s) on tty %s",
			    username, tty);
	} else if (nested != NULL) {
		if (remote)
			syslog(LOG_NOTICE, "%s to %s on tty %s from %s / "
			    "%s", nested, pwd->pw_name, tty, hname, assbuf);
		else
			syslog(LOG_NOTICE, "%s to %s on tty %s", nested,
			    pwd->pw_name, tty);
	} else {
		if (remote)
			syslog(LOG_NOTICE, "%s on tty %s from %s / %s",
			    pwd->pw_name, tty, hname, assbuf);
		else
			syslog(LOG_NOTICE, "%s on tty %s", 
			    pwd->pw_name, tty);
	}
	(void)gettimeofday(&now, NULL);
#ifdef SUPPORT_UTMPX
	doutmpx();
	dolastlogx(quietlog);
	quietlog = 1;
#endif	
#ifdef SUPPORT_UTMP
	doutmp();
	dolastlog(quietlog);
#endif
}
Ejemplo n.º 2
0
int
main(int argc, char *argv[])
{
	const char *logfile =
#if defined(SUPPORT_UTMPX)
	    _PATH_LASTLOGX;
#elif defined(SUPPORT_UTMP)
	    _PATH_LASTLOG;
#else
	#error "either SUPPORT_UTMP or SUPPORT_UTMPX must be defined"
#endif
	int	ch;
	size_t	len;

	while ((ch = getopt(argc, argv, "f:H:L:nN:rt")) != -1) {
		switch (ch) {
		case 'H':
			hostlen = atoi(optarg);
			break;
		case 'f':
			logfile = optarg;
			break;
		case 'L':
			linelen = atoi(optarg);
			break;
		case 'n':
			numeric++;
			break;
		case 'N':
			namelen = atoi(optarg);
			break;
		case 'r':
			sortlog |= SORT_REVERSE;
			break;
		case 't':
			sortlog |= SORT_TIME;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	len = strlen(logfile);

	setpassent(1);	/* Keep passwd file pointers open */

#if defined(SUPPORT_UTMPX)
	if (len > 0 && logfile[len - 1] == 'x')
		dolastlogx(logfile, argc, argv);
	else
#endif
#if defined(SUPPORT_UTMP)
		dolastlog(logfile, argc, argv);
#endif

	setpassent(0);	/* Close passwd file pointers */

	if (outstack && DOSORT(sortlog))
		sortoutput(outstack);

	return 0;
}