keithw/mosh — pull request #219 by saurik (2012-04-18 12:16:05+00:00)
Title: Replace libutempter with... Unix login. (setuid -> fail)

So, the goal of this commit is to solve a bunch of the random little bugs that have been accumulated on various platforms and various corner cases by going into the good ol' drawer o' Unix and pulling out our old friend /bin/login to wield as a massive hammer to smash all of them at once.

Keeping score, this fixes the following issues (or, in the couple cases, obsoletes the fix that was added for them, allowing that code to be deleted). (It additionally fixes an issue I haven't even reported yet, which is that the current mechanism ends up in a level-two shell with double-.bashrc.)

Fix #47: hostname is set in utmpx by login
Fix #61: login handles utmpx on Mac OS X
Obsolete #190: motd is now handled by login
Fix #193: login correctly sets cwd to home
Obsolete #199: shell lookup is done by login
Fix #201: login understands username maps
Fix #216: .hushlogin is handled by login

As hostnames can no longer be set dynamically, the hostname is now statically set to the PID of mosh-server without a hostname (which happens to fix the truncated PIDs reported on FreeBSD by zi).

That all said, though: I seriously doubt that this commit will ever be merged to upstream, however, as it requires mosh-server to be setuid root (given previous discussion that seems to indicate a strong preference against making mosh-server itself even have temporary privileges, no matter how many bugs it fixes or how cleaner it makes the code; I am not certain I agree with that stance, but I will happily admit that it is justifiable, and maybe even "more correct" given the security concerns of this particular component).

Regardless, I have opened a pull request related to it, as I think it is an interesting discussion to have, given that the alternative seems to be to slowly reimplement login (and even then, probably fail to fully support OS X; even with this patch I'm still having an issue with the security session system: I seem to be getting disconnected from my bootstrap context... I added a sleep(2) which mostly mitigates the problem, but that is obviously not a reasonable solution).

(BTW: I'm sorry that all related bugs ended up with a double "related commits" attached to it... I wonder if GitHub will ever realize those other commits got replaced and clean them up... I didn't realize they had such horribly painfully stale caching all over the place, or I would not have bothered to change the commit message to add the notes that I did; *sigh*.)