Page MenuHomeFreeBSD

Attempt to fix the old "he capability is stupid" bug in getty(8)
ClosedPublic

Authored by danfe on Jan 19 2017, 11:21 AM.
Tags
None
Referenced Files
F105874724: D9244.id24380.diff
Sat, Dec 21, 10:58 PM
Unknown Object (File)
Fri, Dec 13, 1:09 AM
Unknown Object (File)
Sep 18 2024, 2:11 AM
Unknown Object (File)
Sep 8 2024, 2:52 PM
Unknown Object (File)
Sep 8 2024, 10:35 AM
Unknown Object (File)
Sep 7 2024, 10:49 AM
Unknown Object (File)
Aug 17 2024, 4:51 AM
Unknown Object (File)
Aug 17 2024, 4:51 AM
Subscribers

Details

Summary

There is one capability explicitly documented in gettytab(5) as stupid: he. And it is indeed. It was meant to facilitate system's hostname modification, but is hardly usable in practice because it allows very limited editing (e.g., it depends on particular hostname, that is, non-generic).

Using regex(3) instead gives more freedom, does not complicate the code very much, and makes a lot more sense, in turn making he less stupid and actually useful. To keep implementation simple, currently there is no explicit substitution involved (regex(3) API does not provide this functionality).

Proposal is to treat he as POSIX "extended" regular expression, which is matched against the hostname. If there are no parenthesized subexpressions in the pattern, entire matched string is used as final hostname. Otherwise, all matched subexpressions are concatenated together use the first matched subexpression. If pattern does not match, original hostname is not modified.

This allows, as an example, to mimic login prompt which is often seem under GNU/Linux, where short hostname (nodename) precedes actual login: text:

default:\
:he=[\^.]+:\
:cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%t)\r\n\r\n%h :sp#1200:\
:if=/etc/issue:

Or, to conceal nodename and display only the domain part:

default:\
:he=[\^.]*(\\..*):\
:cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (<hidden>%h %t)\r\n\r\n:sp#1200:\
:if=/etc/issue:

As for backwards compatibility (@ and # characters-based editing), I did not include it because, well, it is indeed utterly stupid and the change would not affect normal system behavior anyway. Full-featured s/pattern/replacement/ abstinence is more tough; it would be nice to have, but that comes with cost of parsing substitution string (see regsub() function in sed(1) code for example). Since getty(8)'s output is generally only seen by administrators nowadays, I was keen on keeping it simple.

Opinions?

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 6883

Event Timeline

danfe retitled this revision from to Attempt to fix the old "he capability is stupid" bug in getty(8).
danfe updated this object.
danfe edited the test plan for this revision. (Show Details)
danfe set the repository for this revision to rS FreeBSD src repository - subversion.
danfe edited edge metadata.
wblock added inline comments.
gettytab.5
308

s/were no/are no/

309
the ​entire matched string is used as the final hostname.
311
If the pattern does not match, the original hostname is not modified.

I'm somewhat surprised to see this change, since getty's output is generally only seen by administrators nowadays, so complicated code to improve its cosmetics is less useful.

Perhaps using the first parenthesized subexpression (like expr(1)'s colon operator) is more appropriate than the concatenation of all of them.

danfe removed rS FreeBSD src repository - subversion as the repository for this revision.
danfe marked an inline comment as done.

Warren, Jilles, thank you guys for the feedback. I've updated the diff accordingly.

While I work and login from the console a lot, I do agree that complicating this code is not something desired (and that's the reason why I decided to waive the usual s/foo/bar/ form). Actually going with the first subexpression only is fair enough, since that's what in fact needed in majority of cases, and both my examples still hold after making this change.

danfe marked 2 inline comments as done.EditedJan 24 2017, 10:27 AM

Mark inline comments as done (missed the two checkboxes before).

jilles added a reviewer: jilles.
This revision is now accepted and ready to land.Jan 25 2017, 9:09 PM

Thanks @jilles; does positive review mean it's good to land, or shall I wait for more reviewers or explicit approval?

This revision was automatically updated to reflect the committed changes.