home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1610 / pwpack.c < prev   
C/C++ Source or Header  |  1990-12-28  |  2KB  |  90 lines

  1. /*
  2.  * Copyright 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  *
  8.  * Duplication is permitted for non-commercial [ profit making ]
  9.  * purposes provided this and other copyright notices remain
  10.  * intact.
  11.  */
  12.  
  13. #include <pwd.h>
  14.  
  15. int    pw_pack (passwd, buf)
  16. struct    passwd    *passwd;
  17. char    *buf;
  18. {
  19.     char    *cp;
  20.  
  21.     cp = buf;
  22.     strcpy (cp, passwd->pw_name);
  23.     cp += strlen (cp) + 1;
  24.  
  25.     strcpy (cp, passwd->pw_passwd);
  26.     cp += strlen (cp) + 1;
  27.  
  28.     memcpy (cp, (void *) &passwd->pw_uid, sizeof passwd->pw_uid);
  29.     cp += sizeof passwd->pw_uid;
  30.  
  31.     memcpy (cp, (void *) &passwd->pw_gid, sizeof passwd->pw_gid);
  32.     cp += sizeof passwd->pw_gid;
  33.  
  34.     strcpy (cp, passwd->pw_gecos);
  35.     cp += strlen (cp) + 1;
  36.  
  37.     strcpy (cp, passwd->pw_dir);
  38.     cp += strlen (cp) + 1;
  39.  
  40.     strcpy (cp, passwd->pw_shell);
  41.         cp += strlen (cp) + 1;
  42.  
  43.     return cp - buf;
  44. }
  45.  
  46. int    pw_unpack (buf, len, passwd)
  47. char    *buf;
  48. int    len;
  49. struct    passwd    *passwd;
  50. {
  51.     char    *org = buf;
  52.  
  53.     passwd->pw_name = buf;
  54.     buf += strlen (buf) + 1;
  55.     if (buf - org > len)
  56.         return -1;
  57.  
  58.     passwd->pw_passwd = buf;
  59.     buf += strlen (buf) + 1;
  60.     if (buf - org > len)
  61.         return -1;
  62.  
  63.     memcpy ((void *) &passwd->pw_uid, (void *) buf, sizeof passwd->pw_uid);
  64.     buf += sizeof passwd->pw_uid;
  65.     if (buf - org > len)
  66.         return -1;
  67.  
  68.     memcpy ((void *) &passwd->pw_gid, (void *) buf, sizeof passwd->pw_gid);
  69.     buf += sizeof passwd->pw_gid;
  70.     if (buf - org > len)
  71.         return -1;
  72.  
  73.     passwd->pw_gecos = buf;
  74.     buf += strlen (buf) + 1;
  75.     if (buf - org > len)
  76.         return -1;
  77.  
  78.     passwd->pw_dir = buf;
  79.     buf += strlen (buf) + 1;
  80.     if (buf - org > len)
  81.         return -1;
  82.  
  83.     passwd->pw_shell = buf;
  84.     buf += strlen (buf) + 1;
  85.     if (buf - org > len)
  86.         return -1;
  87.  
  88.     return 0;
  89. }
  90.