home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / shadow-3.1.4 / sppack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  2.1 KB  |  101 lines

  1. /*
  2.  * Copyright 1990, 1991, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #ifdef    BSD
  14. #include <strings.h>
  15. #else
  16. #include <string.h>
  17. #endif
  18.  
  19. #include "shadow.h"
  20.  
  21. #ifndef    lint
  22. static    char    sccsid[] = "@(#)sppack.c    3.2    08:46:24    9/12/91";
  23. #endif
  24.  
  25. int    spw_pack (spwd, buf)
  26. struct    spwd    *spwd;
  27. char    *buf;
  28. {
  29.     char    *cp;
  30.  
  31.     cp = buf;
  32.     strcpy (cp, spwd->sp_namp);
  33.     cp += strlen (cp) + 1;
  34.  
  35.     strcpy (cp, spwd->sp_pwdp);
  36.     cp += strlen (cp) + 1;
  37.  
  38.     memcpy (cp, &spwd->sp_min, sizeof spwd->sp_min);
  39.     cp += sizeof spwd->sp_min;
  40.  
  41.     memcpy (cp, &spwd->sp_max, sizeof spwd->sp_max);
  42.     cp += sizeof spwd->sp_max;
  43.  
  44.     memcpy (cp, &spwd->sp_lstchg, sizeof spwd->sp_lstchg);
  45.     cp += sizeof spwd->sp_lstchg;
  46.  
  47.     memcpy (cp, &spwd->sp_warn, sizeof spwd->sp_warn);
  48.     cp += sizeof spwd->sp_warn;
  49.  
  50.     memcpy (cp, &spwd->sp_inact, sizeof spwd->sp_inact);
  51.     cp += sizeof spwd->sp_inact;
  52.  
  53.     memcpy (cp, &spwd->sp_expire, sizeof spwd->sp_expire);
  54.     cp += sizeof spwd->sp_expire;
  55.  
  56.     memcpy (cp, &spwd->sp_flag, sizeof spwd->sp_flag);
  57.     cp += sizeof spwd->sp_flag;
  58.  
  59.     return cp - buf;
  60. }
  61.  
  62. int    spw_unpack (buf, len, spwd)
  63. char    *buf;
  64. int    len;
  65. struct    spwd    *spwd;
  66. {
  67.     char    *org = buf;
  68.  
  69.     spwd->sp_namp = buf;
  70.     buf += strlen (buf) + 1;
  71.  
  72.     spwd->sp_pwdp = buf;
  73.     buf += strlen (buf) + 1;
  74.  
  75.     memcpy (&spwd->sp_min, buf, sizeof spwd->sp_min);
  76.     buf += sizeof spwd->sp_min;
  77.  
  78.     memcpy (&spwd->sp_max, buf, sizeof spwd->sp_max);
  79.     buf += sizeof spwd->sp_max;
  80.  
  81.     memcpy (&spwd->sp_lstchg, buf, sizeof spwd->sp_lstchg);
  82.     buf += sizeof spwd->sp_lstchg;
  83.  
  84.     memcpy (&spwd->sp_warn, buf, sizeof spwd->sp_warn);
  85.     buf += sizeof spwd->sp_warn;
  86.  
  87.     memcpy (&spwd->sp_inact, buf, sizeof spwd->sp_inact);
  88.     buf += sizeof spwd->sp_inact;
  89.  
  90.     memcpy (&spwd->sp_expire, buf, sizeof spwd->sp_expire);
  91.     buf += sizeof spwd->sp_expire;
  92.  
  93.     memcpy (&spwd->sp_flag, buf, sizeof spwd->sp_flag);
  94.     buf += sizeof spwd->sp_flag;
  95.  
  96.     if (buf - org > len)
  97.         return -1;
  98.  
  99.     return 0;
  100. }
  101.