[Midnightbsd-cvs] src [11370] trunk/libexec/ulog-helper: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri Jul 6 09:51:58 EDT 2018


Revision: 11370
          http://svnweb.midnightbsd.org/src/?rev=11370
Author:   laffer1
Date:     2018-07-06 09:51:57 -0400 (Fri, 06 Jul 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/libexec/ulog-helper/Makefile
    trunk/libexec/ulog-helper/ulog-helper.c

Modified: trunk/libexec/ulog-helper/Makefile
===================================================================
--- trunk/libexec/ulog-helper/Makefile	2018-07-06 13:51:35 UTC (rev 11369)
+++ trunk/libexec/ulog-helper/Makefile	2018-07-06 13:51:57 UTC (rev 11370)
@@ -1,9 +1,10 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/libexec/ulog-helper/Makefile 276486 2014-12-31 23:25:37Z ngie $
 
 PROG=	ulog-helper
 BINOWN=	root
 BINMODE=4555
-NO_MAN=
+MAN=
 
 DPADD=	${LIBULOG}
 LDADD=	-lulog

Modified: trunk/libexec/ulog-helper/ulog-helper.c
===================================================================
--- trunk/libexec/ulog-helper/ulog-helper.c	2018-07-06 13:51:35 UTC (rev 11369)
+++ trunk/libexec/ulog-helper/ulog-helper.c	2018-07-06 13:51:57 UTC (rev 11370)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/libexec/ulog-helper/ulog-helper.c 234469 2012-04-19 21:12:08Z ed $");
 
 #include <pwd.h>
 #include <unistd.h>
@@ -46,6 +47,28 @@
  * username.  It does allow users to log arbitrary hostnames.
  */
 
+static const char *
+get_username(void)
+{
+	const struct passwd *pw;
+	const char *login;
+	uid_t uid;
+
+	/*
+	 * Attempt to determine the username corresponding to this login
+	 * session.  First, validate the results of getlogin() against
+	 * the password database.  If getlogin() returns invalid data,
+	 * return an arbitrary username corresponding to this uid.
+	 */
+	uid = getuid();
+	if ((login = getlogin()) != NULL && (pw = getpwnam(login)) != NULL &&
+	    pw->pw_uid == uid)
+		return (login);
+	if ((pw = getpwuid(uid)) != NULL)
+		return (pw->pw_name);
+	return (NULL);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -57,7 +80,7 @@
 
 	if ((argc == 2 || argc == 3) && strcmp(argv[1], "login") == 0) {
 		/* Username. */
-		user = user_from_uid(getuid(), 1);
+		user = get_username();
 		if (user == NULL)
 			return (EX_OSERR);
 



More information about the Midnightbsd-cvs mailing list