How many i am fingered? - Linux

This is a discussion on How many i am fingered? - Linux ; Hi All, I am learning linux system programming. I have been given an assignment which requires me to findout how many times i have been fingered. (I need to use IPC somewhere). One approach could be. 1. Whenever a finger ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: How many i am fingered?

  1. How many i am fingered?

    Hi All,

    I am learning linux system programming. I have been given an assignment
    which requires me to findout how many times i have been fingered. (I
    need to use IPC somewhere).

    One approach could be.
    1. Whenever a finger command is ran on perticular user, .plan file from
    the user's HOME drectory is read and is displayed on the screen. Now, I
    can check the access time of the file and increment the counter (my be
    stored in the shared memory). But, I am unaware of how to findout the
    access time of the file. I need to write down user level C programm to
    do this assignment.

    Please provide some guidlines..

    Is there any better approach to do this assignment?

    Thanks in advance.........

    Thanks and regards,
    Prasad.


  2. Re: How many i am fingered?

    "Prasad" writes:

    > Hi All,
    >
    > I am learning linux system programming. I have been given an assignment
    > which requires me to findout how many times i have been fingered. (I
    > need to use IPC somewhere).
    >
    > One approach could be.
    > 1. Whenever a finger command is ran on perticular user, .plan file from
    > the user's HOME drectory is read and is displayed on the screen. Now, I
    > can check the access time of the file and increment the counter (my be
    > stored in the shared memory). But, I am unaware of how to findout the
    > access time of the file. I need to write down user level C programm to
    > do this assignment.


    This is not safe: the file system may be mounted with the noatime flag
    to increase performances.

    > Please provide some guidlines..
    >
    > Is there any better approach to do this assignment?


    finger uses the fingerd server for remote users. For local users, I
    don't know. Perhaps it accesses directly the user's file, perhaps it
    goes thru fingerd. You'll have to find out.


    One way would be to write a fingered-counter daemon that would accept
    messages containing the name of the local user that has been fingered,
    and to modify fingerd or both fingerd and finger to send a message to
    this fingered-counter-d everytime a local user is fingered. This
    daemon could accept another kind of messages, asking the counter value
    for a given user (and you can add other command, such as reset the
    counter of a user, or get the list of users with their counters, and
    reset everything, save the data in a file, etc). Write an additional
    user interface tool to send these messages and display the answers.


    --
    __Pascal Bourguignon__ http://www.informatimago.com/

    NOTE: The most fundamental particles in this product are held
    together by a "gluing" force about which little is currently known
    and whose adhesive power can therefore not be permanently
    guaranteed.

  3. Re: How many i am fingered?

    Hi Bill,

    That was a gr8 solution.

    I tried writing program for it but, it is failing.
    [Prasad@prasadjoshi finger_count]$ cat finger_count.c
    #include
    #include
    #include

    #include
    #include
    #include


    int main ()
    {
    char *file_name ;
    char *home_path ;
    char data[] = "No Plani re." ;
    int counter = 0 ;
    int fd ;

    if ( ! ( home_path = getenv("HOME") ) )
    {
    printf ( "$HOME Not Defined.\n" ) ;
    return 1 ;
    }

    file_name = malloc ( strlen(home_path) + strlen("/.plan") ) ;
    if ( ! file_name )
    {
    printf ( "Unable To Assign Memory." ) ;
    }
    strcpy ( file_name, home_path ) ;
    strcat ( file_name, "/.plan" ) ;

    printf ( "%s\n", file_name ) ;
    while ( 1 )
    {
    printf ( "Opening PIPE\n" ) ;
    if ( (fd = open (file_name, O_WRONLY) ) < 0 )
    {
    perror ( "open : " ) ;
    }
    write ( fd, data, strlen(data) ) ;

    close (fd) ;
    counter ++ ;
    printf ( "Counter : %d\n", counter ) ;
    }
    return 0 ;
    }

    [Prasad@prasadjoshi finger_count]$ ./a.out
    /home/Prasad/.plan
    Opening PIPE


    [Prasad@prasadjoshi finger_count]$ finger Prasad
    Login: Prasad Name: Prasad Joshi
    Directory: /home/Prasad Shell: /bin/bash
    On since Wed Dec 20 15:15 (IST) on :0 (messages off)
    On since Mon Jan 8 18:44 (IST) on pts/1 from :0.0
    2 minutes 57 seconds idle
    On since Mon Jan 8 18:29 (IST) on pts/2 from :0.0
    On since Mon Jan 8 15:44 (IST) on pts/3 from :0.0
    6 seconds idle
    On since Mon Jan 8 18:29 (IST) on pts/4 from :0.0
    4 minutes 19 seconds idle
    On since Mon Jan 8 18:30 (IST) on pts/5 from :0.0
    23 minutes 55 seconds idle
    On since Mon Jan 8 19:11 (IST) on pts/7 from :0.0
    9 minutes 28 seconds idle
    No mail.
    No Plan.
    <<<<
    it is printing NO Plan. which means .plan file is missing.
    >>>>

    [Prasad@prasadjoshi ~]$ ls -la | grep -i .plan
    prw-rw-r-- 1 Prasad Prasad 0 Jan 8 19:29 .plan


    Please help........

    Thanks and regards,
    Prasad.

    Bill Marcum wrote:
    > On 8 Jan 2007 03:01:13 -0800, Prasad
    > wrote:
    > >
    > >
    > > Hi All,
    > >
    > > I am learning linux system programming. I have been given an assignment
    > > which requires me to findout how many times i have been fingered. (I
    > > need to use IPC somewhere).
    > >
    > > One approach could be.
    > > 1. Whenever a finger command is ran on perticular user, .plan file from
    > > the user's HOME drectory is read and is displayed on the screen. Now, I
    > > can check the access time of the file and increment the counter (my be
    > > stored in the shared memory). But, I am unaware of how to findout the
    > > access time of the file. I need to write down user level C programm to
    > > do this assignment.
    > >
    > > Please provide some guidlines..
    > >

    > man 2 stat
    >
    > > Is there any better approach to do this assignment?
    > >

    > The .plan file could be a named pipe. You write a program that writes
    > to the pipe. The write will block until someone fingers you, then you
    > get the time.
    >
    >
    > --
    > Practically perfect people never permit sentiment to muddle their thinking.
    > -- Mary Poppins



  4. Re: How many i am fingered?

    If I try cat on .plan it is working. But, finger on the user does not
    seem to be working.

    [Prasad@prasadjoshi ~]$ cat .plan
    No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    re.No Plani re.No Plani re.No Plani re.No Plani re.[Prasad@prasadjoshi
    ~]$

    Prasad wrote:
    > Hi Bill,
    >
    > That was a gr8 solution.
    >
    > I tried writing program for it but, it is failing.
    > [Prasad@prasadjoshi finger_count]$ cat finger_count.c
    > #include
    > #include
    > #include
    >
    > #include
    > #include
    > #include
    >
    >
    > int main ()
    > {
    > char *file_name ;
    > char *home_path ;
    > char data[] = "No Plani re." ;
    > int counter = 0 ;
    > int fd ;
    >
    > if ( ! ( home_path = getenv("HOME") ) )
    > {
    > printf ( "$HOME Not Defined.\n" ) ;
    > return 1 ;
    > }
    >
    > file_name = malloc ( strlen(home_path) + strlen("/.plan") ) ;
    > if ( ! file_name )
    > {
    > printf ( "Unable To Assign Memory." ) ;
    > }
    > strcpy ( file_name, home_path ) ;
    > strcat ( file_name, "/.plan" ) ;
    >
    > printf ( "%s\n", file_name ) ;
    > while ( 1 )
    > {
    > printf ( "Opening PIPE\n" ) ;
    > if ( (fd = open (file_name, O_WRONLY) ) < 0 )
    > {
    > perror ( "open : " ) ;
    > }
    > write ( fd, data, strlen(data) ) ;
    >
    > close (fd) ;
    > counter ++ ;
    > printf ( "Counter : %d\n", counter ) ;
    > }
    > return 0 ;
    > }
    >
    > [Prasad@prasadjoshi finger_count]$ ./a.out
    > /home/Prasad/.plan
    > Opening PIPE
    >
    >
    > [Prasad@prasadjoshi finger_count]$ finger Prasad
    > Login: Prasad Name: Prasad Joshi
    > Directory: /home/Prasad Shell: /bin/bash
    > On since Wed Dec 20 15:15 (IST) on :0 (messages off)
    > On since Mon Jan 8 18:44 (IST) on pts/1 from :0.0
    > 2 minutes 57 seconds idle
    > On since Mon Jan 8 18:29 (IST) on pts/2 from :0.0
    > On since Mon Jan 8 15:44 (IST) on pts/3 from :0.0
    > 6 seconds idle
    > On since Mon Jan 8 18:29 (IST) on pts/4 from :0.0
    > 4 minutes 19 seconds idle
    > On since Mon Jan 8 18:30 (IST) on pts/5 from :0.0
    > 23 minutes 55 seconds idle
    > On since Mon Jan 8 19:11 (IST) on pts/7 from :0.0
    > 9 minutes 28 seconds idle
    > No mail.
    > No Plan.
    > <<<<
    > it is printing NO Plan. which means .plan file is missing.
    > >>>>

    > [Prasad@prasadjoshi ~]$ ls -la | grep -i .plan
    > prw-rw-r-- 1 Prasad Prasad 0 Jan 8 19:29 .plan
    >
    >
    > Please help........
    >
    > Thanks and regards,
    > Prasad.
    >
    > Bill Marcum wrote:
    > > On 8 Jan 2007 03:01:13 -0800, Prasad
    > > wrote:
    > > >
    > > >
    > > > Hi All,
    > > >
    > > > I am learning linux system programming. I have been given an assignment
    > > > which requires me to findout how many times i have been fingered. (I
    > > > need to use IPC somewhere).
    > > >
    > > > One approach could be.
    > > > 1. Whenever a finger command is ran on perticular user, .plan file from
    > > > the user's HOME drectory is read and is displayed on the screen. Now, I
    > > > can check the access time of the file and increment the counter (my be
    > > > stored in the shared memory). But, I am unaware of how to findout the
    > > > access time of the file. I need to write down user level C programm to
    > > > do this assignment.
    > > >
    > > > Please provide some guidlines..
    > > >

    > > man 2 stat
    > >
    > > > Is there any better approach to do this assignment?
    > > >

    > > The .plan file could be a named pipe. You write a program that writes
    > > to the pipe. The write will block until someone fingers you, then you
    > > get the time.
    > >
    > >
    > > --
    > > Practically perfect people never permit sentiment to muddle their thinking.
    > > -- Mary Poppins



  5. Re: How many i am fingered?

    On 8 Jan 2007 06:22:51 -0800 Prasad wrote:

    | If I try cat on .plan it is working. But, finger on the user does not
    | seem to be working.
    |
    | [Prasad@prasadjoshi ~]$ cat .plan
    | No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    | re.No Plani re.No Plani re.No Plani re.No Plani re.[Prasad@prasadjoshi
    | ~]$

    Maybe finger is specifically checking for a regular file. Try running
    finger via strace to see what steps it is doing (you would expect to
    see it open ".plan" if it is going to do what you want to accomplish).

    $ strace -ftt -o /tmp/finger.strace finger Prasad

    --
    |---------------------------------------/----------------------------------|
    | Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
    | first name lower case at ipal.net / spamtrap-2007-01-08-1029@ipal.net |
    |------------------------------------/-------------------------------------|

  6. Re: How many i am fingered?

    On Mon, 08 Jan 2007 13:05:54 +0100 Pascal Bourguignon wrote:
    | "Prasad" writes:
    |
    |> Hi All,
    |>
    |> I am learning linux system programming. I have been given an assignment
    |> which requires me to findout how many times i have been fingered. (I
    |> need to use IPC somewhere).
    |>
    |> One approach could be.
    |> 1. Whenever a finger command is ran on perticular user, .plan file from
    |> the user's HOME drectory is read and is displayed on the screen. Now, I
    |> can check the access time of the file and increment the counter (my be
    |> stored in the shared memory). But, I am unaware of how to findout the
    |> access time of the file. I need to write down user level C programm to
    |> do this assignment.
    |
    | This is not safe: the file system may be mounted with the noatime flag
    | to increase performances.

    FYI, I do this on all filesystems I run except for /var/spool/mail.


    |> Please provide some guidlines..
    |>
    |> Is there any better approach to do this assignment?
    |
    | finger uses the fingerd server for remote users. For local users, I
    | don't know. Perhaps it accesses directly the user's file, perhaps it
    | goes thru fingerd. You'll have to find out.

    He can use strace.

    --
    |---------------------------------------/----------------------------------|
    | Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
    | first name lower case at ipal.net / spamtrap-2007-01-08-1031@ipal.net |
    |------------------------------------/-------------------------------------|

  7. Re: How many i am fingered?

    Hi All,

    Thanks a lot for all the help.
    With making .plan file as a named pipe it is possible to count the
    number of fingers. I checked this on SUN Solaris it is really working
    fine.

    But, on Fedora Core 5 it is not working. Besically, what is happening
    is
    finger as a last step of it's execution does lstat on .plan file. and
    check whether it is a regular file or not. If not it prints default
    message. So, open on the .plan file does not happen if it is a FIFO
    file.


    14452 16:26:48.765403 lstat64("/home/Prasad/.plan",
    {st_mode=S_IFIFO|0664, st_size=0, ...}) = 0
    14452 16:26:48.765551 write(1, "No Plan.\n", 9) = 9


    This was really a good learning assignment.

    Does any one have some more such kind of assignments? please
    communicate them.

    I am really thankfull to all.........

    Thanks and regards,
    Prasad.

    phil-news-nospam@ipal.net wrote:
    > On 8 Jan 2007 06:22:51 -0800 Prasad wrote:
    >
    > | If I try cat on .plan it is working. But, finger on the user does not
    > | seem to be working.
    > |
    > | [Prasad@prasadjoshi ~]$ cat .plan
    > | No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani re.No Plani
    > | re.No Plani re.No Plani re.No Plani re.No Plani re.[Prasad@prasadjoshi
    > | ~]$
    >
    > Maybe finger is specifically checking for a regular file. Try running
    > finger via strace to see what steps it is doing (you would expect to
    > see it open ".plan" if it is going to do what you want to accomplish).
    >
    > $ strace -ftt -o /tmp/finger.strace finger Prasad
    >
    > --
    > |---------------------------------------/----------------------------------|
    > | Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
    > | first name lower case at ipal.net / spamtrap-2007-01-08-1029@ipal.net |
    > |------------------------------------/-------------------------------------|



+ Reply to Thread