ggeettppwweenntt() -- General Function (libc)

Get password file information
#iinncclluuddee <ppwwdd.hh>
ssttrruucctt ppaasssswwdd *ggeettppwweenntt()

The COHERENT  system has  five routines  that search the  file /eettcc/ppaasssswwdd,
which contains  information about every  user of the  system.  The returned
structure ppaasssswwdd is defined in the  header file ppwwdd.hh. For a description of
this structure, see ppwwdd.hh.

ggeettppwweenntt() returns the next entry from /eettcc/ppaasssswwdd.

_E_x_a_m_p_l_e
The  following  example  demonstrates ggeettppwweenntt(),  ggeettppwwnnaamm(),  ggeettppwwuuiidd(),
sseettppwweenntt(), and eennddppwweenntt().

#include    <pwd.h>
#include    <stdio.h>
#include    <unistd.h>

main()
{
     int euid,           /* Effective user id */
         ruid;           /* Real user id */
     struct passwd *pstp;
     int i;

     /* Print out all users and home directories */
     i = 0;
     setpwent();         /* Rewind file /etc/passwd */
     while ((pstp = getpwent()) != NULL)
          printf("%d: user name is %s, home directory is %s.\n",
                  ++i, pstp->pw_name, pstp->pw_dir);

     /* Find real user name.
      * NOTE: functions getpwuid and getpwnam rewind /etc/passwd
      * by calling setpwent().
      */
     ruid = getuid();
     if ((pstp = getpwuid(ruid)) == NULL) {
          /* If this message appears, something's wrong */
          fprintf(stderr, "Cannot find user with id number %d\n", pstp);
          exit (EXIT_FAILURE);
     } else
          printf("User's real name is %s\n", pstp->pw_name);

     /* Find the user id for superuser root */
     ((pstp = getpwnam("root")) == NULL) ?
          fprintf(stderr, "Do you have user root on your system?\n") :
          printf("root id is  %d\n", pstp->pw_uid);

     /* Check if the effective process id is the superuser id.
      *
      * NOTE: if you wish to see how to enable the root
      * privileges, you can run this command:
      * cc pwfun.c
      * su root chown root pwfun
      * su root chmod 4511 pwfun
      */

     euid = geteuid();   /* Get effective user id. */
     printf("Process ");
     (euid == pstp->pw_uid) ? printf("has ") : printf("doesn't have ");
     printf("the root privileges\n");
     exit(EXIT_SUCCESS);
}

_F_i_l_e_s
/eettcc/ppaasssswwdd
ppwwdd.hh

_S_e_e _A_l_s_o
eennddppwweenntt(), ggeettppwwnnaamm(), ggeettppwwuuiidd(), lliibbcc, ppwwdd.hh, sseettppwweenntt()

_D_i_a_g_n_o_s_t_i_c_s
ggeettppwweenntt() returns NULL for any error or on end of file.

_N_o_t_e_s
All structures  and information  returned are  in static areas  internal to
ggeettppwweenntt(). Therefore,  information from a previous  call is overwritten by
each subsequent call.
