home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3349 / spdbm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  933 b   |  64 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.  
  9. #ifndef    lint
  10. static    char    sccsid[] = "@(#)spdbm.c    3.1    08:16:16    11/21/90";
  11. #endif
  12.  
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include "config.h"
  16. #include "shadow.h"
  17.  
  18. #ifdef    NDBM
  19. #include <ndbm.h>
  20. DBM    *sp_dbm;
  21.  
  22. /*
  23.  * sp_dbm_update
  24.  *
  25.  * Updates the DBM password files, if they exist.
  26.  */
  27.  
  28. int
  29. sp_dbm_update (sp)
  30. struct    spwd    *sp;
  31. {
  32.     datum    key;
  33.     datum    content;
  34.     char    data[BUFSIZ];
  35.     char    spwdkey[60];
  36.     char    *cp;
  37.     int    len;
  38.     int    i;
  39.     int    cnt;
  40.     static    int    once;
  41.  
  42.     if (! once) {
  43.         if (! sp_dbm)
  44.             setspent ();
  45.  
  46.         once++;
  47.     }
  48.     if (! sp_dbm)
  49.         return 0;
  50.  
  51.     len = spw_pack (sp, data);
  52.  
  53.     content.dsize = len;
  54.     content.dptr = data;
  55.  
  56.     key.dsize = strlen (sp->sp_namp);
  57.     key.dptr = sp->sp_namp;
  58.     if (dbm_store (sp_dbm, key, content, DBM_REPLACE))
  59.         return 0;
  60.  
  61.     return 1;
  62. }
  63. #endif
  64.