home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1641 / pwpack.c < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.8 KB  |  94 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. #ifndef    lint
  16. static    char    sccsid[] = "@(#)pwpack.c    2.1    14:30:43    7/22/90";
  17. #endif
  18.  
  19. int    pw_pack (passwd, buf)
  20. struct    passwd    *passwd;
  21. char    *buf;
  22. {
  23.     char    *cp;
  24.  
  25.     cp = buf;
  26.     strcpy (cp, passwd->pw_name);
  27.     cp += strlen (cp) + 1;
  28.  
  29.     strcpy (cp, passwd->pw_passwd);
  30.     cp += strlen (cp) + 1;
  31.  
  32.     memcpy (cp, (void *) &passwd->pw_uid, sizeof passwd->pw_uid);
  33.     cp += sizeof passwd->pw_uid;
  34.  
  35.     memcpy (cp, (void *) &passwd->pw_gid, sizeof passwd->pw_gid);
  36.     cp += sizeof passwd->pw_gid;
  37.  
  38.     strcpy (cp, passwd->pw_gecos);
  39.     cp += strlen (cp) + 1;
  40.  
  41.     strcpy (cp, passwd->pw_dir);
  42.     cp += strlen (cp) + 1;
  43.  
  44.     strcpy (cp, passwd->pw_shell);
  45.         cp += strlen (cp) + 1;
  46.  
  47.     return cp - buf;
  48. }
  49.  
  50. int    pw_unpack (buf, len, passwd)
  51. char    *buf;
  52. int    len;
  53. struct    passwd    *passwd;
  54. {
  55.     char    *org = buf;
  56.  
  57.     passwd->pw_name = buf;
  58.     buf += strlen (buf) + 1;
  59.     if (buf - org > len)
  60.         return -1;
  61.  
  62.     passwd->pw_passwd = buf;
  63.     buf += strlen (buf) + 1;
  64.     if (buf - org > len)
  65.         return -1;
  66.  
  67.     memcpy ((void *) &passwd->pw_uid, (void *) buf, sizeof passwd->pw_uid);
  68.     buf += sizeof passwd->pw_uid;
  69.     if (buf - org > len)
  70.         return -1;
  71.  
  72.     memcpy ((void *) &passwd->pw_gid, (void *) buf, sizeof passwd->pw_gid);
  73.     buf += sizeof passwd->pw_gid;
  74.     if (buf - org > len)
  75.         return -1;
  76.  
  77.     passwd->pw_gecos = buf;
  78.     buf += strlen (buf) + 1;
  79.     if (buf - org > len)
  80.         return -1;
  81.  
  82.     passwd->pw_dir = buf;
  83.     buf += strlen (buf) + 1;
  84.     if (buf - org > len)
  85.         return -1;
  86.  
  87.     passwd->pw_shell = buf;
  88.     buf += strlen (buf) + 1;
  89.     if (buf - org > len)
  90.         return -1;
  91.  
  92.     return 0;
  93. }
  94.