[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

don't use getlogin(), it's unreliable



getlogin() sometimes gives you totally wrong answers.  It's better to
use USER; if the caller is root, we may as well trust him.

*** 1.3	1993/06/02 02:15:19
--- sendmail.c	1993/06/02 02:23:42
***************
*** 279,285 ****
  		 * If still running as root, run as the trusted user.  If from
  		 * was specified, we're okay.  If from wasn't specified
  		 * but the real uid is nonzero, use that name.  Else if
! 		 * getlogin() returns something, use that.  Else use root.
  		 */
  		uid = getuid();
  		truid = runastrusteduser();
--- 279,285 ----
  		 * If still running as root, run as the trusted user.  If from
  		 * was specified, we're okay.  If from wasn't specified
  		 * but the real uid is nonzero, use that name.  Else if
! 		 * USER is set, use that. Else use root.
  		 */
  		uid = getuid();
  		truid = runastrusteduser();
***************
*** 317,323 ****
  			if (from == NULL) {
  				if (uid != 0 && (pwd = getpwuid(uid)) != NULL)
  					from = pwd->pw_name;
! 				else if ((cp = getlogin()) != NULL)
  					from = cp;
  				else /* could find with getpwnam */
  					from = "root";
--- 317,324 ----
  			if (from == NULL) {
  				if (uid != 0 && (pwd = getpwuid(uid)) != NULL)
  					from = pwd->pw_name;
! 				else if ((cp = getenv("USER")) != NULL
! 				     && getpwnam(cp) != NULL)
  					from = cp;
  				else /* could find with getpwnam */
  					from = "root";