/*
* cache.c: Offers ability to cache /etc/group, /etc/passwd, /etc/shadow,
- * and /var/log/radutmp
*
* All users in the passwd/shadow files are stored in a hash table.
* the hash lookup is VERY fast, generally 1.0673 comparisons per
#endif
#include "radiusd.h"
-#include "radutmp.h"
#include "cache.h"
#include "config.h"
fclose(shadow);
#endif
- /* Finally, let's look at radutmp and make a record of everyone
- * that's logged in currently */
- /*unix_hashradutmp();*/
-
/* log how many entries we stored from the passwd file */
radlog(L_INFO, "HASH: Stored %d entries from %s", numread, passwd_file);
return 0;
}
-/* This function changes the loggedin variable for a user
- * when they login or out. This lets us keep track of
- * what radutmp is doing without having to read it
- */
-static void chgLoggedin(char *user, int diff) {
- struct mypasswd *cur;
-
- cur = findHashUser(user);
- if(cur) {
- cur->loggedin += diff;
- /* Can't have less than 0 logins */
- if(cur->loggedin<0) {
- cur->loggedin = 0;
- }
- DEBUG2(" HASH: Changed user %s to %d logins", user, cur->loggedin);
- }
-}
-
/*
* Looks up user in hashtable. If user can't be found, returns 0.
* Otherwise returns a pointer to the structure for the user
return (hash % HASHTABLESIZE);
}
-/* Reads radutmp file, and increments the loggedin variable
- * for every login a user has...assuming we can find the user
- * in the hashtable
- */
-int unix_hashradutmp(void) {
-
- int fd;
- struct radutmp u;
- struct mypasswd *cur;
-
- if ((fd = open(RADUTMP, O_CREAT|O_RDONLY, 0644)) < 0)
- return 0;
-
- while(read(fd, &u, sizeof(u)) == sizeof(u)) {
- if ((u.login) && (u.type == P_LOGIN)) {
- cur = findHashUser(u.login);
- if(cur) {
- cur->loggedin++;
- }
- }
- }
- close(fd);
-
- return 1;
-}
-
/*
* Emulate the cistron unix_pass function, but do it using
* our hashtable (iow, make it blaze).