usrcache.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. /* #define DBG_PRINT */
  39. #include <netsite.h>
  40. extern "C" {
  41. #include <secitem.h>
  42. }
  43. #include <base/crit.h>
  44. #include <ldaputil/errors.h>
  45. #include <libaccess/usrcache.h>
  46. #include <libaccess/las.h>
  47. #include <libaccess/authdb.h>
  48. #include "permhash.h"
  49. /* uid is unique within a database. The user cache tables are stored per
  50. * database. The following table maps a database name to the corresponding
  51. * user cache table. The user cache table is another hash table which stores
  52. * the UserCacheObj instances.
  53. */
  54. static PRHashTable *databaseUserCacheTable = 0;
  55. static time_t acl_usr_cache_lifetime = (time_t)120;
  56. static PRCList *usrobj_list = 0;
  57. static const int num_usrobj = 200;
  58. static CRITICAL usr_hash_crit = NULL; /* Controls user cache hash tables & */
  59. /* usrobj link list */
  60. static pool_handle_t *usrcache_pool = NULL;
  61. static PRHashTable *singleDbTable = 0;
  62. #define USEROBJ_PTR(l) \
  63. ((UserCacheObj*) ((char*) (l) - offsetof(UserCacheObj, list)))
  64. static void user_hash_crit_enter (void)
  65. {
  66. /* Caching may be disabled (usr_hash_crit will be NULL) */
  67. if (usr_hash_crit) crit_enter(usr_hash_crit);
  68. }
  69. static void user_hash_crit_exit (void)
  70. {
  71. /* Caching may be disabled (usr_hash_crit will be NULL) */
  72. if (usr_hash_crit) crit_exit(usr_hash_crit);
  73. }
  74. static void user_hash_crit_init (void)
  75. {
  76. usr_hash_crit = crit_init();
  77. }
  78. static PRHashNumber
  79. usr_cache_hash_cert(const void *key)
  80. {
  81. PRHashNumber h;
  82. const unsigned char *s;
  83. unsigned int i = 0;
  84. SECItem *derCert = (SECItem *)key;
  85. unsigned int len = derCert->len;
  86. h = 0;
  87. for (s = (const unsigned char *)derCert->data; i < len; s++, i++)
  88. h = (h >> 28) ^ (h << 4) ^ *s;
  89. return h;
  90. }
  91. static PRHashNumber
  92. usr_cache_hash_fn (const void *key)
  93. {
  94. UserCacheObj *usrObj = (UserCacheObj *)key;
  95. if (usrObj->derCert)
  96. return usr_cache_hash_cert(usrObj->derCert);
  97. else
  98. return PR_HashCaseString(usrObj->uid);
  99. }
  100. static int
  101. usr_cache_compare_certs(const void *v1, const void *v2)
  102. {
  103. const SECItem *c1 = (const SECItem *)v1;
  104. const SECItem *c2 = (const SECItem *)v2;
  105. return (c1->len == c2 ->len && !memcmp(c1->data, c2->data, c1->len));
  106. }
  107. static int
  108. usr_cache_compare_fn(const void *v1, const void *v2)
  109. {
  110. UserCacheObj *usrObj1 = (UserCacheObj *)v1;
  111. UserCacheObj *usrObj2 = (UserCacheObj *)v2;
  112. if (usrObj1->derCert && usrObj2->derCert)
  113. return usr_cache_compare_certs(usrObj1->derCert, usrObj2->derCert);
  114. else if (!usrObj1->derCert && !usrObj2->derCert)
  115. return PR_CompareCaseStrings(usrObj1->uid, usrObj1->uid);
  116. else
  117. return 0;
  118. }
  119. static PRHashTable *alloc_db2uid_table ()
  120. {
  121. return PR_NewHashTable(0,
  122. usr_cache_hash_fn,
  123. usr_cache_compare_fn,
  124. PR_CompareValues,
  125. &ACLPermAllocOps,
  126. usrcache_pool);
  127. }
  128. int acl_usr_cache_set_timeout (const int nsec)
  129. {
  130. acl_usr_cache_lifetime = (time_t)nsec;
  131. return 0;
  132. }
  133. int acl_usr_cache_enabled ()
  134. {
  135. return (acl_usr_cache_lifetime > 0);
  136. }
  137. int acl_usr_cache_init ()
  138. {
  139. UserCacheObj *usrobj;
  140. int i;
  141. if (acl_usr_cache_lifetime <= 0) {
  142. /* Caching is disabled */
  143. DBG_PRINT1("usrcache is disabled");
  144. return 0;
  145. }
  146. usrcache_pool = pool_create();
  147. user_hash_crit_init();
  148. if (acl_num_databases() == 0) {
  149. /* Something wrong -- No databases registered yet! */
  150. return -1;
  151. }
  152. else if (acl_num_databases() == 1) {
  153. /* Optimize for single database */
  154. DBG_PRINT1("Optimizing usrcache for single db");
  155. singleDbTable = alloc_db2uid_table();
  156. }
  157. else {
  158. singleDbTable = 0;
  159. databaseUserCacheTable = PR_NewHashTable(0,
  160. PR_HashCaseString,
  161. PR_CompareCaseStrings,
  162. PR_CompareValues,
  163. &ACLPermAllocOps,
  164. usrcache_pool);
  165. }
  166. /* Allocate first UserCacheObj and initialize the circular link list */
  167. usrobj = (UserCacheObj *)pool_malloc(usrcache_pool, sizeof(UserCacheObj));
  168. if (!usrobj) return -1;
  169. memset((void *)usrobj, 0, sizeof(UserCacheObj));
  170. usrobj_list = &usrobj->list;
  171. PR_INIT_CLIST(usrobj_list);
  172. /* Allocate rest of the UserCacheObj and put them in the link list */
  173. for(i = 0; i < num_usrobj; i++){
  174. usrobj = (UserCacheObj *)pool_malloc(usrcache_pool,
  175. sizeof(UserCacheObj));
  176. if (!usrobj) return -1;
  177. memset((void *)usrobj, 0, sizeof(UserCacheObj));
  178. PR_INSERT_AFTER(&usrobj->list, usrobj_list);
  179. }
  180. return (singleDbTable || databaseUserCacheTable) ? 0 : -1;
  181. }
  182. /* If the user hash table exists in the databaseUserCacheTable then return it.
  183. * Otherwise, create a new hash table, insert it in the databaseUserCacheTable
  184. * and then return it.
  185. */
  186. static int usr_cache_table_get (const char *dbname, PRHashTable **usrTable)
  187. {
  188. PRHashTable *table;
  189. if (singleDbTable) {
  190. *usrTable = singleDbTable;
  191. return LAS_EVAL_TRUE;
  192. }
  193. user_hash_crit_enter();
  194. table = (PRHashTable *)PR_HashTableLookup(databaseUserCacheTable,
  195. dbname);
  196. if (!table) {
  197. /* create a new table and insert it in the databaseUserCacheTable */
  198. table = alloc_db2uid_table();
  199. if (table) {
  200. PR_HashTableAdd(databaseUserCacheTable,
  201. pool_strdup(usrcache_pool, dbname),
  202. table);
  203. }
  204. }
  205. *usrTable = table;
  206. user_hash_crit_exit();
  207. return table ? LAS_EVAL_TRUE : LAS_EVAL_FAIL;
  208. }
  209. int acl_usr_cache_insert (const char *uid, const char *dbname,
  210. const char *userdn, const char *passwd,
  211. const char *group,
  212. const SECItem *derCert, const time_t time)
  213. {
  214. PRHashTable *usrTable;
  215. UserCacheObj *usrobj;
  216. UserCacheObj key;
  217. int rv;
  218. if (acl_usr_cache_lifetime <= 0) {
  219. /* Caching is disabled */
  220. return LAS_EVAL_TRUE;
  221. }
  222. rv = usr_cache_table_get (dbname, &usrTable);
  223. if (rv != LAS_EVAL_TRUE) return rv;
  224. user_hash_crit_enter();
  225. key.uid = (char *)uid;
  226. key.derCert = (SECItem *)derCert;
  227. usrobj = (UserCacheObj *)PR_HashTableLookup(usrTable, &key);
  228. if (usrobj) {
  229. time_t elapsed = time - usrobj->time;
  230. int expired = (elapsed >= acl_usr_cache_lifetime);
  231. /* Free & reset the old values in usrobj if -- there is an old value
  232. * and if the new value is given then it is different or the usrobj
  233. * has expired */
  234. /* Set the field if the new value is given and the field is not set */
  235. /* If the usrobj has not expired then we only want to update the field
  236. * whose new value is non-NULL and different */
  237. /* Work on the 'uid' field */
  238. if (usrobj->uid &&
  239. (uid ? strcmp(usrobj->uid, uid) : expired))
  240. {
  241. pool_free(usrcache_pool, usrobj->uid);
  242. usrobj->uid = 0;
  243. }
  244. if (uid && !usrobj->uid) {
  245. usrobj->uid = pool_strdup(usrcache_pool, uid);
  246. }
  247. /* Work on the 'userdn' field */
  248. if (usrobj->userdn &&
  249. (userdn ? strcmp(usrobj->userdn, userdn) : expired))
  250. {
  251. pool_free(usrcache_pool, usrobj->userdn);
  252. usrobj->userdn = 0;
  253. }
  254. if (userdn && !usrobj->userdn) {
  255. usrobj->userdn = pool_strdup(usrcache_pool, userdn);
  256. }
  257. /* Work on the 'passwd' field */
  258. if (usrobj->passwd &&
  259. (passwd ? strcmp(usrobj->passwd, passwd) : expired))
  260. {
  261. pool_free(usrcache_pool, usrobj->passwd);
  262. usrobj->passwd = 0;
  263. }
  264. if (passwd && !usrobj->passwd) {
  265. usrobj->passwd = pool_strdup(usrcache_pool, passwd);
  266. }
  267. /* Work on the 'group' field -- not replace a valid group */
  268. if (!expired && usrobj->group &&
  269. (group ? strcmp(usrobj->group, group) : expired))
  270. {
  271. pool_free(usrcache_pool, usrobj->group);
  272. usrobj->group = 0;
  273. }
  274. if (group && !usrobj->group) {
  275. usrobj->group = pool_strdup(usrcache_pool, group);
  276. }
  277. /* Work on the 'derCert' field */
  278. if (usrobj->derCert &&
  279. (derCert ? (derCert->len != usrobj->derCert->len ||
  280. memcmp(usrobj->derCert->data, derCert->data,
  281. derCert->len))
  282. : expired))
  283. {
  284. SECITEM_FreeItem(usrobj->derCert, PR_TRUE);
  285. usrobj->derCert = 0;
  286. }
  287. if (derCert && !usrobj->derCert) {
  288. usrobj->derCert = SECITEM_DupItem((SECItem *)derCert);
  289. }
  290. /* Reset the time only if the usrobj has expired */
  291. if (expired) {
  292. DBG_PRINT1("Replace ");
  293. usrobj->time = time;
  294. }
  295. else {
  296. DBG_PRINT1("Update ");
  297. }
  298. }
  299. else {
  300. /* Get the last usrobj from the link list, erase it and use it */
  301. /* Maybe the last usrobj is not invalid yet but we don't want to grow
  302. * the list of usrobjs. The last obj is the best candidate for being
  303. * not valid. We don't want to compare the time -- just use it.
  304. */
  305. PRCList *tail = PR_LIST_TAIL(usrobj_list);
  306. usrobj = USEROBJ_PTR(tail);
  307. /* If the removed usrobj is in the hashtable, remove it from there */
  308. if (usrobj->hashtable) {
  309. PR_HashTableRemove(usrobj->hashtable, usrobj);
  310. }
  311. /* Free the memory associated with the usrobj */
  312. if (usrobj->userdn) pool_free(usrcache_pool, usrobj->userdn);
  313. if (usrobj->passwd) pool_free(usrcache_pool, usrobj->passwd);
  314. if (usrobj->group) pool_free(usrcache_pool, usrobj->group);
  315. if (usrobj->derCert) SECITEM_FreeItem(usrobj->derCert, PR_TRUE);
  316. if (usrobj->uid) pool_free(usrcache_pool, usrobj->uid);
  317. /* Fill in the usrobj with the current data */
  318. usrobj->uid = pool_strdup(usrcache_pool, uid);
  319. usrobj->userdn = userdn ? pool_strdup(usrcache_pool, userdn) : 0;
  320. usrobj->passwd = passwd ? pool_strdup(usrcache_pool, passwd) : 0;
  321. usrobj->derCert = derCert ? SECITEM_DupItem((SECItem *)derCert) : 0;
  322. usrobj->group = group ? pool_strdup(usrcache_pool, group) : 0;
  323. usrobj->time = time;
  324. /* Add the usrobj to the user hash table */
  325. PR_HashTableAdd(usrTable, usrobj, usrobj);
  326. usrobj->hashtable = usrTable;
  327. DBG_PRINT1("Insert ");
  328. }
  329. /* Move the usrobj to the head of the list */
  330. PR_REMOVE_LINK(&usrobj->list);
  331. PR_INSERT_AFTER(&usrobj->list, usrobj_list);
  332. /* Set the time in the UserCacheObj */
  333. if (usrobj) {
  334. rv = LAS_EVAL_TRUE;
  335. }
  336. else {
  337. rv = LAS_EVAL_FAIL;
  338. }
  339. DBG_PRINT4("acl_usr_cache_insert: derCert = \"%s\" uid = \"%s\" at time = %ld\n",
  340. usrobj->derCert ? (char *)usrobj->derCert->data : "<NONE>",
  341. uid, time);
  342. user_hash_crit_exit();
  343. return rv;
  344. }
  345. static int acl_usr_cache_get_usrobj (const char *uid, const SECItem *derCert,
  346. const char *dbname, const time_t time,
  347. UserCacheObj **usrobj_out)
  348. {
  349. PRHashTable *usrtable;
  350. UserCacheObj *usrobj;
  351. UserCacheObj key;
  352. time_t elapsed;
  353. int rv;
  354. *usrobj_out = 0;
  355. if (acl_usr_cache_lifetime <= 0) {
  356. /* Caching is disabled */
  357. return LAS_EVAL_FALSE;
  358. }
  359. rv = usr_cache_table_get(dbname, &usrtable);
  360. if (!usrtable) return LAS_EVAL_FALSE;
  361. key.uid = (char *)uid;
  362. key.derCert = (SECItem *)derCert;
  363. usrobj = (UserCacheObj *)PR_HashTableLookup(usrtable, &key);
  364. if (!usrobj) return LAS_EVAL_FALSE;
  365. rv = LAS_EVAL_FALSE;
  366. elapsed = time - usrobj->time;
  367. /* If the cache is valid, return the usrobj */
  368. if (elapsed < acl_usr_cache_lifetime) {
  369. rv = LAS_EVAL_TRUE;
  370. *usrobj_out = usrobj;
  371. DBG_PRINT4("usr_cache found: derCert = \"%s\" uid = \"%s\" at time = %ld\n",
  372. usrobj->derCert ? (char *)usrobj->derCert->data : "<NONE>",
  373. usrobj->uid, time);
  374. }
  375. else {
  376. DBG_PRINT4("usr_cache expired: derCert = \"%s\" uid = \"%s\" at time = %ld\n",
  377. usrobj->derCert ? (char *)usrobj->derCert->data : "<NONE>",
  378. usrobj->uid, time);
  379. }
  380. return rv;
  381. }
  382. int acl_usr_cache_passwd_check (const char *uid, const char *dbname,
  383. const char *passwd,
  384. const time_t time, char **dn,
  385. pool_handle_t *pool)
  386. {
  387. UserCacheObj *usrobj;
  388. int rv;
  389. user_hash_crit_enter();
  390. rv = acl_usr_cache_get_usrobj(uid, 0, dbname, time, &usrobj);
  391. if (rv == LAS_EVAL_TRUE && usrobj->passwd && passwd &&
  392. !strcmp(usrobj->passwd, passwd))
  393. {
  394. /* extract dn from the usrobj */
  395. *dn = usrobj->userdn ? pool_strdup(pool, usrobj->userdn) : 0;
  396. rv = LAS_EVAL_TRUE;
  397. DBG_PRINT1("Success ");
  398. }
  399. else {
  400. rv = LAS_EVAL_FALSE;
  401. DBG_PRINT1("Failed ");
  402. }
  403. DBG_PRINT3("acl_usr_cache_passwd_check: uid = \"%s\" at time = %ld\n",
  404. uid, time);
  405. user_hash_crit_exit();
  406. return rv;
  407. }
  408. int acl_usr_cache_group_check (const char *uid, const char *dbname,
  409. const char *group, const time_t time)
  410. {
  411. UserCacheObj *usrobj;
  412. int rv;
  413. user_hash_crit_enter();
  414. rv = acl_usr_cache_get_usrobj(uid, 0, dbname, time, &usrobj);
  415. if (rv == LAS_EVAL_TRUE && usrobj->group && group &&
  416. !strcmp(usrobj->group, group))
  417. {
  418. DBG_PRINT1("Success ");
  419. }
  420. else {
  421. rv = LAS_EVAL_FALSE;
  422. DBG_PRINT1("Failed ");
  423. }
  424. DBG_PRINT3("acl_usr_cache_group_check: uid = \"%s\" group = \"%s\"\n",
  425. uid, group ? group : "<NONE>");
  426. user_hash_crit_exit();
  427. return rv;
  428. }
  429. int acl_usr_cache_group_len_check (const char *uid, const char *dbname,
  430. const char *group, const int len,
  431. const time_t time)
  432. {
  433. UserCacheObj *usrobj;
  434. int rv;
  435. user_hash_crit_enter();
  436. rv = acl_usr_cache_get_usrobj(uid, 0, dbname, time, &usrobj);
  437. if (rv == LAS_EVAL_TRUE && usrobj->group && group &&
  438. !strncmp(usrobj->group, group, len))
  439. {
  440. rv = LAS_EVAL_TRUE;
  441. DBG_PRINT1("Success ");
  442. }
  443. else {
  444. rv = LAS_EVAL_FALSE;
  445. DBG_PRINT1("Failed ");
  446. }
  447. DBG_PRINT3("acl_usr_cache_group_check: uid = \"%s\" group = \"%s\"\n",
  448. uid, group);
  449. user_hash_crit_exit();
  450. return rv;
  451. }
  452. int acl_usr_cache_get_userdn (const char *uid, const char *dbname,
  453. const time_t time, char **userdn,
  454. pool_handle_t *pool)
  455. {
  456. UserCacheObj *usrobj;
  457. int rv;
  458. *userdn = 0;
  459. user_hash_crit_enter();
  460. rv = acl_usr_cache_get_usrobj(uid, 0, dbname, time, &usrobj);
  461. if (rv == LAS_EVAL_TRUE) {
  462. *userdn = usrobj->userdn ? pool_strdup(pool, usrobj->userdn) : 0;
  463. DBG_PRINT1("Success ");
  464. }
  465. else {
  466. DBG_PRINT1("Failed ");
  467. }
  468. DBG_PRINT3("acl_usr_cache_get_userdn: uid = \"%s\" userdn = \"%s\"\n",
  469. uid, *userdn ? *userdn : "<NONE>");
  470. user_hash_crit_exit();
  471. return *userdn ? LAS_EVAL_TRUE : LAS_EVAL_FALSE;
  472. }
  473. int acl_usr_cache_userdn_check (const char *uid, const char *dbname,
  474. const char *userdn, const time_t time)
  475. {
  476. UserCacheObj *usrobj;
  477. int rv;
  478. user_hash_crit_enter();
  479. rv = acl_usr_cache_get_usrobj(uid, 0, dbname, time, &usrobj);
  480. if (rv == LAS_EVAL_TRUE && usrobj->userdn && userdn &&
  481. !strcmp(usrobj->userdn, userdn))
  482. {
  483. DBG_PRINT1("Success ");
  484. }
  485. else {
  486. rv = LAS_EVAL_FALSE;
  487. DBG_PRINT1("Failed ");
  488. }
  489. DBG_PRINT3("acl_usr_cache_userdn_check: uid = \"%s\" userdn = \"%s\"\n",
  490. uid, userdn ? userdn : "<NONE>");
  491. user_hash_crit_exit();
  492. return rv;
  493. }
  494. int acl_usr_cache_set_userdn (const char *uid, const char *dbname,
  495. const char *userdn, const time_t time)
  496. {
  497. int rv;
  498. /* acl_usr_cache_insert updates the existing un-expired entry or creates a
  499. * new one */
  500. rv = acl_usr_cache_insert(uid, dbname, userdn, 0, 0, 0, time);
  501. return rv;
  502. }
  503. int acl_usr_cache_get_group (const char *uid, const char *dbname,
  504. const time_t time, char **group,
  505. pool_handle_t *pool)
  506. {
  507. UserCacheObj *usrobj;
  508. int rv;
  509. *group = 0;
  510. user_hash_crit_enter();
  511. rv = acl_usr_cache_get_usrobj(uid, 0, dbname, time, &usrobj);
  512. if (rv == LAS_EVAL_TRUE) {
  513. *group = usrobj->group ? pool_strdup(pool, usrobj->group) : 0;
  514. DBG_PRINT1("Success ");
  515. }
  516. else {
  517. DBG_PRINT1("Failed ");
  518. }
  519. DBG_PRINT3("acl_usr_cache_get_group: uid = \"%s\" group = \"%s\"\n",
  520. uid, *group ? *group : "<NONE>");
  521. user_hash_crit_exit();
  522. return *group ? LAS_EVAL_TRUE : LAS_EVAL_FALSE;
  523. }
  524. int acl_usr_cache_set_group (const char *uid, const char *dbname,
  525. const char *group, const time_t time)
  526. {
  527. int rv;
  528. /* acl_usr_cache_insert updates the existing un-expired entry or creates a
  529. * new one */
  530. rv = acl_usr_cache_insert(uid, dbname, 0, 0, group, 0, time);
  531. return rv;
  532. }
  533. int acl_cert_cache_insert (void *cert_in, const char *dbname,
  534. const char *uid, const char *dn,
  535. const time_t time)
  536. {
  537. CERTCertificate *cert = (CERTCertificate *)cert_in;
  538. SECItem derCert = cert->derCert;
  539. int rv;
  540. rv = acl_usr_cache_insert(uid, dbname, dn, 0, 0, &derCert, time);
  541. return rv;
  542. }
  543. /* Returns LAS_EVAL_TRUE if the user's cache is valid and returns uid */
  544. int acl_cert_cache_get_uid (void *cert_in, const char *dbname,
  545. const time_t time, char **uid, char **dn,
  546. pool_handle_t *pool)
  547. {
  548. CERTCertificate *cert = (CERTCertificate *)cert_in;
  549. SECItem derCert = cert->derCert;
  550. UserCacheObj *usrobj = 0;
  551. int rv;
  552. rv = acl_usr_cache_get_usrobj(0, &derCert, dbname, time, &usrobj);
  553. if (rv == LAS_EVAL_TRUE && usrobj && usrobj->uid) {
  554. *uid = pool_strdup(pool, usrobj->uid);
  555. *dn = usrobj->userdn ? pool_strdup(pool, usrobj->userdn) : 0;
  556. }
  557. else {
  558. *uid = 0;
  559. *dn = 0;
  560. rv = LAS_EVAL_FALSE;
  561. }
  562. return rv;
  563. }