home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3348 / sppack.c < prev   
Encoding:
C/C++ Source or Header  |  1991-05-17  |  2.1 KB  |  103 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 <stdio.h>
  14. #ifdef    BSD
  15. #include <strings.h>
  16. #else
  17. #include <string.h>
  18. #endif
  19.  
  20. #include "shadow.h"
  21.  
  22. #ifndef    lint
  23. static    char    sccsid[] = "@(#)sppack.c    3.1    08:16:27    11/21/90";
  24. #endif
  25.  
  26. int    spw_pack (spwd, buf)
  27. struct    spwd    *spwd;
  28. char    *buf;
  29. {
  30.     char    *cp;
  31.  
  32.     cp = buf;
  33.     strcpy (cp, spwd->sp_namp);
  34.     cp += strlen (cp) + 1;
  35.  
  36.     strcpy (cp, spwd->sp_pwdp);
  37.     cp += strlen (cp) + 1;
  38.  
  39.     memcpy (cp, &spwd->sp_min, sizeof spwd->sp_min);
  40.     cp += sizeof spwd->sp_min;
  41.  
  42.     memcpy (cp, &spwd->sp_max, sizeof spwd->sp_max);
  43.     cp += sizeof spwd->sp_max;
  44.  
  45.     memcpy (cp, &spwd->sp_lstchg, sizeof spwd->sp_lstchg);
  46.     cp += sizeof spwd->sp_lstchg;
  47.  
  48.     memcpy (cp, &spwd->sp_warn, sizeof spwd->sp_warn);
  49.     cp += sizeof spwd->sp_warn;
  50.  
  51.     memcpy (cp, &spwd->sp_inact, sizeof spwd->sp_inact);
  52.     cp += sizeof spwd->sp_inact;
  53.  
  54.     memcpy (cp, &spwd->sp_expire, sizeof spwd->sp_expire);
  55.     cp += sizeof spwd->sp_expire;
  56.  
  57.     memcpy (cp, &spwd->sp_flag, sizeof spwd->sp_flag);
  58.     cp += sizeof spwd->sp_flag;
  59.  
  60.     return cp - buf;
  61. }
  62.  
  63. int    spw_unpack (buf, len, spwd)
  64. char    *buf;
  65. int    len;
  66. struct    spwd    *spwd;
  67. {
  68.     char    *org = buf;
  69.     char    *cp;
  70.  
  71.     spwd->sp_namp = buf;
  72.     buf += strlen (buf) + 1;
  73.  
  74.     spwd->sp_pwdp = buf;
  75.     buf += strlen (buf) + 1;
  76.  
  77.     memcpy (&spwd->sp_min, buf, sizeof spwd->sp_min);
  78.     buf += sizeof spwd->sp_min;
  79.  
  80.     memcpy (&spwd->sp_max, buf, sizeof spwd->sp_max);
  81.     buf += sizeof spwd->sp_max;
  82.  
  83.     memcpy (&spwd->sp_lstchg, buf, sizeof spwd->sp_lstchg);
  84.     buf += sizeof spwd->sp_lstchg;
  85.  
  86.     memcpy (&spwd->sp_warn, buf, sizeof spwd->sp_warn);
  87.     buf += sizeof spwd->sp_warn;
  88.  
  89.     memcpy (&spwd->sp_inact, buf, sizeof spwd->sp_inact);
  90.     buf += sizeof spwd->sp_inact;
  91.  
  92.     memcpy (&spwd->sp_expire, buf, sizeof spwd->sp_expire);
  93.     buf += sizeof spwd->sp_expire;
  94.  
  95.     memcpy (&spwd->sp_flag, buf, sizeof spwd->sp_flag);
  96.     buf += sizeof spwd->sp_flag;
  97.  
  98.     if (buf - org > len)
  99.         return -1;
  100.  
  101.     return 0;
  102. }
  103.