logincache.h
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:3k
源码类别:

WEB邮件程序

开发平台:

C/C++

  1. /*
  2. ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
  3. ** distribution information.
  4. */
  5. /*
  6. The login cache is used to try to eliminate a call to getpw for each and
  7. every http request, which can be quite expensive on systems with large number
  8. of users and heave web traffic.
  9. The interface is abstracted into these functions:
  10. init_login_cache(seconds)
  11. prepare_login_cache()
  12. save_login_cache(userid, login_time)
  13. cancel_login_cache()
  14. check_login_cache(userid, login_time)
  15. The prepare, save, and cancel functions are used to cache the login information.
  16. prepare_login_cache should be called before we attempt to log in, when we're
  17. running as root.  We're about to drop root privileges after a successful
  18. login, but we need to be root in order to update the cache directory, so
  19. prepare forks a child process, which will wait patiently in a background.
  20. save_login_cache will send the following information to the child process,
  21. over a secured pipe.  save_login_cache will be called after a successful
  22. login:
  23. * The current directory.
  24. * The current user and group id.
  25. cancel_login_cache shall be called if the login failed.  It will kill the
  26. child process.
  27. The check function is called to query the cache file.  If it succeeds, it
  28. restores the cached directory, the user and group id, and returns 0.  If it
  29. fails to find the info in the cache, it returns non-0.
  30. There is no need to manually remove an expired cache entry upon logout.
  31. It will be cleaned up by a separate cron job.
  32. init_login_cache should be called before any other function.  It's argument
  33. specifies that hard timeout interval - the fixed amount of time after which
  34. any login becomes invalid.  It is used to organize the login cache directory.
  35. The login cache functions receive the saved original login time.  The login
  36. cache information is saved in a directory that should be writable by root
  37. only.  The cache directory contains subdirectories whose name is derived by
  38. dividing the login time by the hard timeout interval.  For example, when
  39. logging on in the afternoon of November 27, 1999, the current time, in seconds,
  40. is 943725152.  With the login interval being the default of 2 hours, 7200
  41. seconds, the top level directory would be 943725152 / 7200 or 131072.
  42. What this allows us to do is to quickly remove expired login entries, simply
  43. by reading the top level cache directory, and recursively delete subdirectories
  44. whose name is too old to contain any logins that are still active.
  45. If the login name is 'john', the cached login will be saved in the file
  46. 131072/jo/john, creating the subdirectories if necessary.
  47. Because the login name can contain special characters, the special characters
  48. will be escaped.  See the code for more info.
  49. */
  50. #ifndef logincache_h
  51. #define logincache_h
  52. #include <time.h>
  53. static const char rfc2047_h_rcsid[]="$Id: logincache.h,v 1.2 1999/12/08 06:00:38 mrsam Exp $";
  54. extern void init_login_cache(time_t);
  55. extern void prepare_login_cache(void);
  56. extern void save_login_cache(const char *, time_t);
  57. extern void cancel_login_cache(void);
  58. extern int check_login_cache(const char *, time_t);
  59. #endif