logincache.h
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:3k
- /*
- ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
- ** distribution information.
- */
- /*
- The login cache is used to try to eliminate a call to getpw for each and
- every http request, which can be quite expensive on systems with large number
- of users and heave web traffic.
- The interface is abstracted into these functions:
- init_login_cache(seconds)
- prepare_login_cache()
- save_login_cache(userid, login_time)
- cancel_login_cache()
- check_login_cache(userid, login_time)
- The prepare, save, and cancel functions are used to cache the login information.
- prepare_login_cache should be called before we attempt to log in, when we're
- running as root. We're about to drop root privileges after a successful
- login, but we need to be root in order to update the cache directory, so
- prepare forks a child process, which will wait patiently in a background.
- save_login_cache will send the following information to the child process,
- over a secured pipe. save_login_cache will be called after a successful
- login:
- * The current directory.
- * The current user and group id.
- cancel_login_cache shall be called if the login failed. It will kill the
- child process.
- The check function is called to query the cache file. If it succeeds, it
- restores the cached directory, the user and group id, and returns 0. If it
- fails to find the info in the cache, it returns non-0.
- There is no need to manually remove an expired cache entry upon logout.
- It will be cleaned up by a separate cron job.
- init_login_cache should be called before any other function. It's argument
- specifies that hard timeout interval - the fixed amount of time after which
- any login becomes invalid. It is used to organize the login cache directory.
- The login cache functions receive the saved original login time. The login
- cache information is saved in a directory that should be writable by root
- only. The cache directory contains subdirectories whose name is derived by
- dividing the login time by the hard timeout interval. For example, when
- logging on in the afternoon of November 27, 1999, the current time, in seconds,
- is 943725152. With the login interval being the default of 2 hours, 7200
- seconds, the top level directory would be 943725152 / 7200 or 131072.
- What this allows us to do is to quickly remove expired login entries, simply
- by reading the top level cache directory, and recursively delete subdirectories
- whose name is too old to contain any logins that are still active.
- If the login name is 'john', the cached login will be saved in the file
- 131072/jo/john, creating the subdirectories if necessary.
- Because the login name can contain special characters, the special characters
- will be escaped. See the code for more info.
- */
- #ifndef logincache_h
- #define logincache_h
- #include <time.h>
- static const char rfc2047_h_rcsid[]="$Id: logincache.h,v 1.2 1999/12/08 06:00:38 mrsam Exp $";
- extern void init_login_cache(time_t);
- extern void prepare_login_cache(void);
- extern void save_login_cache(const char *, time_t);
- extern void cancel_login_cache(void);
- extern int check_login_cache(const char *, time_t);
- #endif