From owner-freebsd-arch@freebsd.org Thu Oct 1 20:34:40 2015 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B667EA0EF65 for ; Thu, 1 Oct 2015 20:34:40 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mailhost.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 81FD81085; Thu, 1 Oct 2015 20:34:40 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 43F273592E4; Thu, 1 Oct 2015 22:34:37 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 0121728494; Thu, 1 Oct 2015 22:34:36 +0200 (CEST) Date: Thu, 1 Oct 2015 22:34:36 +0200 From: Jilles Tjoelker To: Bryan Drewery Cc: freebsd-arch@FreeBSD.org Subject: Re: login -f changing session getlogin(2) Message-ID: <20151001203436.GA22737@stack.nl> References: <560D826D.7000302@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <560D826D.7000302@FreeBSD.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Oct 2015 20:34:40 -0000 On Thu, Oct 01, 2015 at 11:58:53AM -0700, Bryan Drewery wrote: > This issue has bothered me forever. > As root running 'login -f someuser' and then exit, logname(1) and > getlogin(2) will forever return that user's name, rather than root. > The issue is that login(1) uses setlogin(2) without ever restoring the > login from the parent when it exits. > This is easily fixed by something like: > [snip] > I'm not sure this is the right way though. > My initial instinct was to use setsid(2) in the child but that clobbers > the terminal. > It makes me wonder if there's bigger architectural issues here that need > addressing with session and login. Perhaps login -f is just a special > case though. I don't think login -f should be used like that. For that use case, su -l looks more appropriate. In either case, the two login sessions are strangely intertwined. Using ssh to localhost provides two normal login sessions. Resetting the login name also affects processes started by the logged in user that still run (as long as they have not created a new session). This may confuse applications and hinders traceability. This breakage would also affect normal login sessions on terminals. I think the supposed use case for login -f is a remote login daemon that handles authentication by itself but wants to delegate account and session functionality. Indeed, sshd has UseLogin, but it is rarely used and discouraged. -- Jilles Tjoelker