usrcache.cpp 18 KB

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