home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / putpwent.c < prev    next >
C/C++ Source or Header  |  1993-05-16  |  3KB  |  89 lines

  1. /****************************************************************/
  2. /* Module name:   putpwent.c                                    */
  3. /* Library name:  mintlibs for Atari ST                         */
  4. /* Author:        Hildo Biersma (boender@dutiws.twi.tudelft.nl) */
  5. /* Date:          January 12, 1993                              */
  6. /* Revision:      2 (add password aging)                        */
  7. /*                1 (first attempt, no password aging)          */
  8. /****************************************************************/
  9.  
  10. /* FIXME: should errno be set when an error occurs, or do we    */
  11. /*        trust errno as set by fprintf() or fflush()?          */
  12.  
  13. /*
  14. NAME
  15.     putpwent - write password file entry
  16.  
  17. SYNOPSIS
  18.     #include <stdio.h>
  19.     #include <pwd.h>
  20.     
  21.     int putpwent(const struct password *p, FILE *f);
  22.  
  23. DESCRIPTION
  24.     putpwent is the inverse of getpwent. Given a pointer to a
  25.     password structure created by getpwent (or getpwuid or
  26.     getpwnam), putpwent writes a line on the stream f, which
  27.     matches the format of /etc/passwd.
  28.  
  29. SEE ALSO
  30.     getpwent
  31.  
  32. RETURN VALUES
  33.     zero on success
  34.     non-zero if an error was detected
  35.  
  36. NOTES
  37.     Password ageing is supported.
  38.     
  39.     You are strongly discouraged to use a different way of writing
  40.     password structures to file, as that will leave you vulnerable
  41.     to any possible changes to the password structure or the file
  42.     format.
  43.  
  44. AUTHOR
  45.     Hildo Biersma, with the help of a UN*X System V man page.
  46. */
  47.  
  48. #include <stdio.h>
  49. #include <pwd.h>
  50.  
  51. /* Write a line on the stream f, which matches the format of    */
  52. /* /etc/passwd. Return non-zero on error, zero if okay.         */
  53. int putpwent(p, f)
  54. const struct passwd *p;
  55. FILE *f;
  56. {
  57.   if ((p->pw_passwd[0] == 0x00) || (p->pw_age[0] == 0x00))
  58.   {
  59.     /* Do not include age field if password is empty or age field not set */
  60.     if (fprintf(f, "%s:%s:%d:%d:%s:%s:%s\n",
  61.                 p->pw_name,
  62.                 p->pw_passwd,
  63.                 p->pw_uid,
  64.                 p->pw_gid,
  65.                 p->pw_gecos,
  66.                 p->pw_dir,
  67.                 p->pw_shell) == EOF)
  68.       return(-1);
  69.     else    
  70.       return(fflush(f));
  71.   }
  72.   else
  73.   {
  74.     /* Do include age field, separated from the password by a comma */
  75.     if (fprintf(f, "%s:%s,%s:%d:%d:%s:%s:%s\n",
  76.                 p->pw_name,
  77.                 p->pw_passwd,
  78.                 p->pw_age,
  79.                 p->pw_uid,
  80.                 p->pw_gid,
  81.                 p->pw_gecos,
  82.                 p->pw_dir,
  83.                 p->pw_shell) == EOF)
  84.       return(-1);
  85.     else    
  86.       return(fflush(f));
  87.   }
  88. } /* End of putpwent() */
  89.