home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / LINUX_PC.TAR / pcnfsd_linux2 / pcnfsd_cache.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  2.7 KB  |  103 lines

  1. /* RE_SID: @(%)/tmp_mnt/vol/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_cache.c 1.3 93/02/08 10:18:12 SMI */
  2. /*
  3. **=====================================================================
  4. ** Copyright (c) 1986-1993 by Sun Microsystems, Inc.
  5. **    @(#)pcnfsd_cache.c    1.3    2/8/93
  6. **=====================================================================
  7. */
  8. #include "common.h"
  9. /*
  10. **=====================================================================
  11. **             I N C L U D E   F I L E   S E C T I O N                *
  12. **                                                                    *
  13. ** If your port requires different include files, add a suitable      *
  14. ** #define in the customization section, and make the inclusion or    *
  15. ** exclusion of the files conditional on this.                        *
  16. **=====================================================================
  17. */
  18. #include "pcnfsd.h"
  19.  
  20. #include <stdio.h>
  21. #include <pwd.h>
  22. #include <errno.h>
  23. #include <string.h>
  24.  
  25. extern char    *crypt();
  26.  
  27.  
  28. /*
  29. **---------------------------------------------------------------------
  30. **                       Misc. variable definitions
  31. **---------------------------------------------------------------------
  32. */
  33.  
  34. extern int      errno;
  35.  
  36. #ifdef USER_CACHE
  37. #define CACHE_SIZE 16        /* keep it small, as linear searches are
  38.                  * done */
  39. struct cache 
  40.        {
  41.        int   cuid;
  42.        int   cgid;
  43.        char  cpw[32];
  44.        char  cuname[10];    /* keep this even for machines
  45.                  * with alignment problems */
  46.        }User_cache[CACHE_SIZE];
  47.  
  48.  
  49.  
  50. /*
  51. **---------------------------------------------------------------------
  52. **                 User cache support procedures 
  53. **---------------------------------------------------------------------
  54. */
  55.  
  56.  
  57. int
  58. check_cache(name, pw, p_uid, p_gid)
  59.     char           *name;
  60.    char           *pw;
  61.    int            *p_uid;
  62.    int            *p_gid;
  63. {
  64.     int             i;
  65.    int             c1, c2;
  66.  
  67.     for (i = 0; i < CACHE_SIZE; i++) {
  68.         if (!strcmp(User_cache[i].cuname, name)) {
  69.                    c1 = strlen(pw);
  70.                    c2 = strlen(User_cache[i].cpw);
  71.                 if ((!c1 && !c2) ||
  72.                          !(strcmp(User_cache[i].cpw,
  73.                               crypt(pw, User_cache[i].cpw)))) {
  74.                     *p_uid = User_cache[i].cuid;
  75.                     *p_gid = User_cache[i].cgid;
  76.                     return (1);
  77.                 }
  78.                 User_cache[i].cuname[0] = '\0'; /* nuke entry */
  79.                    return (0);
  80.                }
  81.     }
  82.     return (0);
  83. }
  84.  
  85. void
  86. add_cache_entry(p)
  87.     struct passwd  *p;
  88. {
  89.     int             i;
  90.  
  91.     for (i = CACHE_SIZE - 1; i > 0; i--)
  92.         User_cache[i] = User_cache[i - 1];
  93.     User_cache[0].cuid = p->pw_uid;
  94.     User_cache[0].cgid = p->pw_gid;
  95.     (void)strcpy(User_cache[0].cpw, p->pw_passwd);
  96.     (void)strcpy(User_cache[0].cuname, p->pw_name);
  97. }
  98.  
  99.  
  100. #endif                /* USER_CACHE */
  101.  
  102.  
  103.