I got a chance to take another look at this today (just don't tell my boss I was looking at code). My C isn't the sharpest, but I think I have a working solution.
There are two different finger source files which handle the two different formats: short output (finger invoked with no user, or finger -s) and long output (finger invoked with a user argument, or finger -l). These files are respectively src/finger/sprint.c and src/finger/lprint.c.
If you look at sprint.c, line 120 begins to show where the office phone is generated. (A goto statement is used above to take us to the "office:" tag.)
Code:
office:
if (w->host[0] != '\0') {
xprintf(" (%s)", w->host);
} else {
if (pn->office)
(void)xprintf(" %-10.10s", pn->office);
else if (pn->officephone)
(void)xprintf(" %-10.10s", " ");
if (pn->officephone)
(void)xprintf(" %-.14s",
prphone(pn->officephone));
}
Things seem to start to get hung up at the first 'else' (line 4 of the code shown). This reads: if we get a value for w->host (the "display" field in short format, under the "Office" heading), then just print that. Otherwise, if we don't get a value for the "Office" for this user, then and only then go on to print the office number. If there is no value for the office, go on to see if there is a value for the office phone.
So, with this, you get your choice of showing either the Display (:0.0), or your office (GECOS field 2) under the "Office" heading, unless you want to just cram them both in. (The DNS FQDN comes in there somewhere as well.) That makes enough sense. However, I don't see a reason for the office phone field to be tied to the presence of either of the former. There may be logic behind it that I do not grok, but removing that logic seems to make things work the way I want them to.
To show the office phone field (GECOS field 3), simply make the first 'else' wrap around pn->office, and remove the second 'else' statement entirely.
Here is an example, where I just commented out the 'else' stuff I was talking about. Sure, you can delete it, this is just for illustration:
Code:
office:
if (w->host[0] != '\0') {
xprintf(" (%s)", w->host);
} else // { // first else
if (pn->office)
(void)xprintf(" %-10.10s", pn->office);
/* else */ if (pn->officephone) // second else
(void)xprintf(" %-10.10s", " ");
if (pn->officephone)
(void)xprintf(" %-.14s",
prphone(pn->officephone));
// } // remember to comment out this close-brace, too
If anyone actually wants a patch file I'll diff the original and post it up. In that case, I would actually clean up the above code a little; the compound else got made into an 'else if' which can fit on one line, and the last two 'if' statements checking for the value of officephone could be scrunched into one. But this serves its purpose to show where the changes are for manual editing.
This will show an office phone when it is available, and not show one when it is not available. There are some aesthetic issues since "Office" fields of varying size will make the office phone field misaligned, but this will actually make it work. You can, of course, play with the amount of space between the Office and Office Phone by decreasing the "14" in "%-.14s" of the last xprintf function call.
helzerr, if the Red Hat folks have gotten back to you, did they come up with a similar solution?