I’ve probably seen Charlie & several hundred times in an /etc/passwd, and I’ve likely seen mails from Charlie Root even more often, but the penny never dropped that the "&" was being replaced by "Root" until I read about the full name of the root account in BSD yesterday.

While interesting, that post didn’t fully answer my questions. For example, why does getent(1) not show Charlie’s surname?

$ grep '^root' /etc/passwd
root:*:0:0:Charlie &:/root:/usr/local/bin/bash
$ getent passwd root
root:$6$xMB.X....h.hXL/:0:0:Charlie &:/root:/usr/local/bin/bash

But why does an email from root show the surname?

# echo hello | mail root
# grep From: /var/mail/root
From: Charlie Root <root@fb12.ww.mens.de>

The secret must be hidden in mail(1), thought I, but boy was I wrong. It took me a bit to find it, but the secret is in sendmail(8) (where I should have suspected it to start with).

Sendmail translates the ampersand (&) in a user’s gecos field to the capitalized username in sm_pwfullname():

if (*p == '&')
{
	/* interpolate full name */
	(void) sm_strlcpy(bp, user, buflen - (bp - buf));
	*bp = toupper(*bp);
	bp += strlen(bp);
}

Is that really so? Yes. :-)

# pw useradd jolie -c 'Jane & & & &'
# finger jolie
Login: jolie                Name: Jane Jolie Jolie Jolie Jolie
Directory: /home/jolie      Shell: /bin/sh
No Mail.
No Plan.

Another bit of history learned with thanks to Sevan for enticing me to search for the answer.

unix, root, history, and bsd :: 28 Feb 2020 :: e-mail