LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-09-2009, 06:39 PM   #1
gratuitous_arp
LQ Newbie
 
Registered: Jul 2009
Posts: 28

Rep: Reputation: 17
Finger command not showing office phone from /etc/passwd


Just curious why it is that the "office phone" column of finger does not seem to report anything even when data is entered in the GECOS field of /etc/passwd. I am using Ubuntu 8.10, kernel 2.6.27-11, finger version 'bsd-finger-0.17' compiled from source (available at http://us.archive.ubuntu.com/ubuntu/.../b/bsd-finger/). To the best of my knowledge, this is also the version of finger that ships with Ubuntu 8.10.

User jpublic's entry from /etc/passwd:

Code:
jpublic:x:1000:1000:John,101,9999,555-1234:/home/jpublic:/bin/bash
Result of "finger" with no arguments:

Code:
jpublic> finger
Login     Name       Tty      Idle  Login Time   Office     Office Phone
jpublic   John      *pts/0          Oct  9 18:02 (localhost)
Result of "finger jpublic":

Code:
jpublic> finger jpublic
Login: jpublic        			Name: John
Directory: /home/jpublic            	Shell: /bin/bash
Office: 101, x9999			Home Phone: 555-1234
On since Fri Oct  9 18:02 (EDT) on pts/0 from localhost (messages off)
No mail.
No Plan.
Comparing the output of 'finger' with 'finger jpublic', there are a couple differences which interest me:

1. The Office Phone shows in 'finger public', and not in 'finger' with no arguments.

2. The Office column in the 'finger' command shows where the user is logged in from (in this example, I had used telnet to connect to localhost). The Office entry in the 'finger jpublic' command displays sections 2 and 3 of the GECOS field in /etc/passwd.

I have attempted to follow through the source code of bsd-finger-0.17, but have made a poor job of it as I am not very c-savvy. There was a commented warning about how some gecos information may not display properly from distribution to distribution, but another part of code seems to clearly extract four sections out of the gecos field (function starting on line 83 of util.c). Even so, I'm not sure if this is intended to be used in the output of the command when it has no parameters ('finger') or rather when it has a username passed as a parameter (e.g., 'finger jpublic').

Here is the comment from finger.c:

Code:
 * Finger prints out information about users.  It is not portable since
 * certain fields (e.g. the full user name, office, and phone numbers) are
 * extracted from the gecos field of the passwd file which other UNIXes
 * may not have or may use for other things. (This is not really true any
 * more, btw.)
Could this comment be applicable? Being a BSD version of finger, would there be some Ubuntu/Debian specific change necessary to have the office phone show up properly?

Am I just doing something wrong?

Thanks for the help.

Last edited by gratuitous_arp; 10-09-2009 at 06:40 PM.
 
Old 10-11-2009, 03:24 AM   #2
DinoFly
Member
 
Registered: Nov 2007
Distribution: Fedora, CentOS,
Posts: 72

Rep: Reputation: Disabled
By default finger command doesnt display home phone info if given without the username.

But you can change this behavior with chfn. In your cause you need to add -h or --home-phone.

look at man pages how to use chfn command
man 1 chfn
 
Old 10-11-2009, 03:16 PM   #3
gratuitous_arp
LQ Newbie
 
Registered: Jul 2009
Posts: 28

Original Poster
Rep: Reputation: 17
Hi DinoFly,

First, let me thank you for your reply.

Finger doesn't appear to have a column for the home phone information if given without a user name. Did you mean the office phone? I used chfn to originally set this information, yet this is the result I receive after using chfn -h (as per your suggestion) and chfn -w (to set the office phone, the field I am concerned with):

Code:
jpublic> chfn -h 555-2222
Password: 

jpublic> chfn -w 1234
Password: 

jpublic> finger
Login     Name       Tty      Idle  Login Time   Office     Office Phone
jpublic   John      *pts/2          Oct 11 15:45 (localhost)
The office phone field is unset. If you get a different result, could you please post any version information you have about your finger package, or what distribution yours was included in?

However, the gecos field is changed accordingly in /etc/passwd, and the changes are applied correctly in the output of 'finger jpublic':

Code:
jpublic> grep jpublic /etc/passwd
jpublic:x:1003:1003:John,101,1234,555-2222:/home/jpublic:/bin/bash

jpublic> finger jpublic
Login: jpublic        			Name: John
Directory: /home/jpublic            	Shell: /bin/bash
Office: 101, x1234			Home Phone: 555-2222
On since Sun Oct 11 15:45 (EDT) on pts/2 from localhost (messages off)
No mail.
No Plan.
The changes seem to be "taking" properly, they are simply not displayed when a username is not given as a parameter to 'finger'. The finger command doesn't seem to be looking in /etc/passwd for this information unless it is passed a username as a parameter. It seems very strange for the code to label different information with the same field (depending on if 'finger' is passed a username parameter).

Thanks again, any other ideas?

Last edited by gratuitous_arp; 10-11-2009 at 09:04 PM.
 
Old 10-26-2009, 10:24 AM   #4
helzerr
LQ Newbie
 
Registered: Nov 2003
Location: Orlando, FL
Distribution: CentOS, Gentoo, RHEL
Posts: 4

Rep: Reputation: 0
The `finger` command appears to replace the GECOS information with the remote system name for pseudo-terminal connections (I.E. originating from SSH.)

Hence, when I log in via SSH this is what I see from `finger`

Code:
[rhelzer@cozvgh01 ~]# finger -s rhelzer
Login     Name         Tty      Idle  Login Time   Office     Office Phone
rhelzer   Ron Helzer   pts/1          Oct 26 11:15 (host.domain.tld)
However, when I'm logged in to the console I get the expected output:

Code:
[rhelzer@cozvgh01 ~]# finger -s rhelzer
Login     Name         Tty      Idle  Login Time   Office     Office Phone
rhelzer   Ron Helzer   tty1           Oct 26 11:15 HGV ITG    (XXX) XXX-XXX
I am converting some scripts from HP-UX to Linux and need the finger output to function correctly regardless how the user logs in...

Last edited by helzerr; 10-26-2009 at 10:27 AM.
 
Old 10-27-2009, 11:26 AM   #5
gratuitous_arp
LQ Newbie
 
Registered: Jul 2009
Posts: 28

Original Poster
Rep: Reputation: 17
helzerr,

Very interesting! I get the same result. Thank you for your reply, and for pointing out this subtlety.
 
Old 10-27-2009, 01:17 PM   #6
helzerr
LQ Newbie
 
Registered: Nov 2003
Location: Orlando, FL
Distribution: CentOS, Gentoo, RHEL
Posts: 4

Rep: Reputation: 0
I have opened a support ticket with Red Hat for this issue.
 
Old 11-16-2009, 04:17 PM   #7
gratuitous_arp
LQ Newbie
 
Registered: Jul 2009
Posts: 28

Original Poster
Rep: Reputation: 17
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?

Last edited by gratuitous_arp; 11-16-2009 at 05:13 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getent passwd not showing some users dmusil Linux - Software 0 05-14-2008 12:20 PM
kbluepin not showing up when trying to pair phone to pc johngreenwood Linux - General 3 02-17-2007 05:18 PM
Showing Users from passwd kemplej Programming 1 12-30-2004 10:10 AM
finger and cut command Craig Bowes Linux - Newbie 3 10-09-2004 12:49 PM
finger - command rob99 Linux - Networking 2 02-02-2003 11:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration