acl.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /*****************************************************************************
  13. * acl.h
  14. *
  15. * Header file for ACL processing
  16. *
  17. *****************************************************************************/
  18. #ifndef _ACL_H_
  19. #define _ACL_H_
  20. /* Required to get portable printf/scanf format macros */
  21. #ifdef HAVE_INTTYPES_H
  22. #include <inttypes.h>
  23. /* NSPR uses the print macros a bit differently than ANSI C. We
  24. * need to use ll for a 64-bit integer, even when a long is 64-bit.
  25. */
  26. #undef PRIu64
  27. #define PRIu64 "llu"
  28. #undef PRI64
  29. #define PRI64 "ll"
  30. #else
  31. #error Need to define portable format macros such as PRIu64
  32. #endif /* HAVE_INTTYPES_H */
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <sys/types.h>
  36. #include <limits.h>
  37. #include <sys/socket.h>
  38. #include <netinet/in.h>
  39. #include <arpa/inet.h>
  40. #include <netdb.h>
  41. #include <ldap.h>
  42. #include <las.h>
  43. #include <aclproto.h>
  44. #include <aclerror.h>
  45. #include "prcvar.h"
  46. #include "slapi-plugin.h"
  47. #include "slap.h"
  48. #include "slapi-private.h"
  49. #include "portable.h"
  50. #include "avl.h"
  51. #include "cert.h"
  52. #include <plhash.h>
  53. #ifdef SOLARIS
  54. #include <tnf/probe.h>
  55. #else
  56. #define TNF_PROBE_0_DEBUG(a,b,c)
  57. #define TNF_PROBE_1_DEBUG(a,b,c,d,e,f)
  58. #endif
  59. #define ACL_PLUGIN_NAME "NSACLPlugin"
  60. extern char *plugin_name;
  61. /*
  62. * Define the OID for version 2 of the proxied authorization control if
  63. * it is not already defined (it is in recent copies of ldap.h).
  64. */
  65. #ifndef LDAP_CONTROL_PROXIEDAUTH
  66. #define LDAP_CONTROL_PROXIEDAUTH "2.16.840.1.113730.3.4.18"
  67. #endif
  68. #define ACLUCHP unsigned char *
  69. static char* const aci_attr_type = "aci";
  70. static char* const filter_string = "aci=*";
  71. static char* const aci_targetdn = "target";
  72. static char* const aci_targetattr = "targetattr";
  73. static char* const aci_targetattrfilters = "targattrfilters";
  74. static char* const aci_targetfilter = "targetfilter";
  75. static char* const aci_target_to = "target_to";
  76. static char* const aci_target_from = "target_from";
  77. static char* const LDAP_URL_prefix_core = "ldap://";
  78. static char* const LDAPS_URL_prefix_core = "ldaps://";
  79. static char* const LDAP_URL_prefix = "ldap:///";
  80. static char* const LDAPS_URL_prefix = "ldaps:///";
  81. static char* const access_str_compare = "compare";
  82. static char* const access_str_search = "search";
  83. static char* const access_str_read = "read";
  84. static char* const access_str_write = "write";
  85. static char* const access_str_delete = "delete";
  86. static char* const access_str_add = "add";
  87. static char* const access_str_selfwrite = "selfwrite";
  88. static char* const access_str_proxy = "proxy";
  89. static char* const access_str_moddn = "moddn";
  90. #define ACL_INIT_ATTR_ARRAY 5
  91. /* define the method */
  92. #define DS_METHOD "ds_method"
  93. #define ACL_ESCAPE_STRING_WITH_PUNCTUATION(x,y) (slapi_is_loglevel_set(SLAPI_LOG_ACL) ? escape_string_with_punctuation(x,y) : "")
  94. /* Lases */
  95. #define DS_LAS_USER "user"
  96. #define DS_LAS_GROUP "group"
  97. #define DS_LAS_USERDN "userdn"
  98. #define DS_LAS_GROUPDN "groupdn"
  99. #define DS_LAS_SELFDNATTR "selfdnattr"
  100. #define DS_LAS_USERDNATTR "userdnattr"
  101. #define DS_LAS_AUTHMETHOD "authmethod"
  102. #define DS_LAS_GROUPDNATTR "groupdnattr"
  103. #define DS_LAS_USERATTR "userattr"
  104. #define DS_LAS_ROLEDN "roledn"
  105. #define DS_LAS_ROLEDNATTR "rolednattr"
  106. #define DS_LAS_SSF "ssf"
  107. /* These define the things that aclutil_evaluate_macro() supports */
  108. typedef enum
  109. {
  110. ACL_EVAL_USER,
  111. ACL_EVAL_GROUP,
  112. ACL_EVAL_ROLE,
  113. ACL_EVAL_GROUPDNATTR,
  114. ACL_EVAL_TARGET_FILTER
  115. }acl_eval_types;
  116. typedef enum
  117. {
  118. ACL_RULE_MACRO_DN_TYPE,
  119. ACL_RULE_MACRO_DN_LEVELS_TYPE
  120. }acl_rule_macro_types;
  121. #define ACL_TARGET_MACRO_DN_KEY "($dn)"
  122. #define ACL_RULE_MACRO_DN_KEY "($dn)"
  123. #define ACL_RULE_MACRO_DN_LEVELS_KEY "[$dn]"
  124. #define ACL_RULE_MACRO_ATTR_KEY "($attr."
  125. #define ACL_EVAL_USER 0
  126. #define ACL_EVAL_GROUP 1
  127. #define ACL_EVAL_ROLE 2
  128. /* The LASes are implemented in the libaccess library */
  129. #define DS_LAS_TIMEOFDAY "timeofday"
  130. #define DS_LAS_DAYOFWEEK "dayofweek"
  131. /* ACL function return codes */
  132. #define ACL_TRUE 1 /* evaluation results to TRUE */
  133. #define ACL_OK ACL_TRUE
  134. #define ACL_FALSE 0 /* evaluation results to FALSE */
  135. #define ACL_ERR -1 /* generic error */
  136. #define ACL_TARGET_FILTER_ERR -2 /* Target filter not set properly */
  137. #define ACL_TARGETATTR_FILTER_ERR -3 /* TargetAttr filter not set properly */
  138. #define ACL_TARGETFILTER_ERR -4 /* Target filter not set properly */
  139. #define ACL_SYNTAX_ERR -5 /* Syntax error */
  140. #define ACL_ONEACL_TEXT_ERR -6 /* ONE ACL text error */
  141. #define ACL_ERR_CONCAT_HANDLES -7 /* unable to concat the handles */
  142. #define ACL_INVALID_TARGET -8 /* invalid target */
  143. #define ACL_INVALID_AUTHMETHOD -9 /* multiple client auth */
  144. #define ACL_INVALID_AUTHORIZATION -10 /* no authorization */
  145. #define ACL_INCORRECT_ACI_VERSION -11 /* incorrect version # */
  146. #define ACL_DONT_KNOW -12 /* the world is an uncertain place */
  147. /* supported by the DS */
  148. #define DS_PROP_CONNECTION "connection"
  149. #define DS_ATTR_USERDN "userdn"
  150. #define DS_ATTR_ENTRY "entry"
  151. #define DS_PROP_ACLPB "aclblock"
  152. #define DS_ATTR_AUTHTYPE "authtype"
  153. #define DS_ATTR_CERT "clientcert"
  154. #define DS_ATTR_SSF "ssf"
  155. #define DS_ATTR_LDAPI "ldapi"
  156. #define ACL_ANOM_MAX_ACL 40
  157. struct scoped_entry_anominfo {
  158. short anom_e_targetInfo[ACL_ANOM_MAX_ACL];
  159. short anom_e_nummatched;
  160. short anom_e_isrootds;
  161. };
  162. typedef struct targetattr {
  163. int attr_type;
  164. #define ACL_ATTR_FILTER 0x01
  165. #define ACL_ATTR_STRING 0x02
  166. #define ACL_ATTR_STAR 0x04 /* attr is * only */
  167. union {
  168. char *attr_str;
  169. struct slapi_filter *attr_filter;
  170. }u;
  171. }Targetattr;
  172. typedef struct targetattrfilter {
  173. char *attr_str;
  174. char *filterStr;
  175. struct slapi_filter *filter; /* value filter */
  176. }Targetattrfilter;
  177. typedef struct Aci_Macro {
  178. char *match_this;
  179. char *macro_ptr; /* ptr into match_this */
  180. }aciMacro;
  181. typedef PLHashTable acl_ht_t;
  182. /* Access Control Item (aci): Stores information about a particular ACL */
  183. typedef struct aci {
  184. int aci_type; /* Type of resurce */
  185. /* THE FIRST BYTE WAS USED TO KEEP THE RIGHTS. ITS BEEN MOVED TO
  186. ** aci_access and is now free.
  187. **
  188. **
  189. **
  190. */
  191. #define ACI_TARGET_MACRO_DN (int)0x0000001
  192. #define ACI_TARGET_FILTER_MACRO_DN (int)0x0000002
  193. #define ACI_TARGET_DN (int)0x0000100 /* target has DN */
  194. #define ACI_TARGET_ATTR (int)0x0000200 /* target is an attr */
  195. #define ACI_TARGET_PATTERN (int)0x0000400 /* target has some patt */
  196. #define ACI_TARGET_FILTER (int)0x0000800 /* target has a filter */
  197. #define ACI_ACLTXT (int)0x0001000 /* ACI has text only */
  198. #define ACI_TARGET_NOT (int)0x0002000 /* it's a != */
  199. #define ACI_TARGET_ATTR_NOT (int)0x0004000 /* It's a != manager */
  200. #define ACI_TARGET_FILTER_NOT (int)0x0008000 /* It's a != filter */
  201. #define ACI_UNUSED2 (int)0x0010000 /* Unused */
  202. #define ACI_HAS_ALLOW_RULE (int)0x0020000 /* allow (...) */
  203. #define ACI_HAS_DENY_RULE (int)0x0040000 /* deny (...) */
  204. #define ACI_CONTAIN_NOT_USERDN (int)0x0080000 /* userdn != blah */
  205. #define ACI_TARGET_ATTR_ADD_FILTERS (int)0x0100000
  206. #define ACI_TARGET_ATTR_DEL_FILTERS (int)0x0200000
  207. #define ACI_CONTAIN_NOT_GROUPDN (int)0x0400000 /* groupdn != blah */
  208. #define ACI_CONTAIN_NOT_ROLEDN (int)0x0800000
  209. #define ACI_TARGET_MODDN (int)0x1000000
  210. #define ACI_TARGET_MODDN_FROM_PATTERN (int)0x2000000
  211. #define ACI_TARGET_MODDN_TO_PATTERN (int)0x4000000
  212. int aci_access;
  213. /*
  214. * See also aclpb_access which is used to store rights too.
  215. */
  216. short aci_ruleType; /* kinds of rules in the ACL */
  217. #define ACI_USERDN_RULE (short) 0x0001
  218. #define ACI_USERDNATTR_RULE (short) 0x0002
  219. #define ACI_GROUPDN_RULE (short) 0x0004
  220. #define ACI_GROUPDNATTR_RULE (short) 0x0008
  221. #define ACI_AUTHMETHOD_RULE (short) 0x0010
  222. #define ACI_IP_RULE (short) 0x0020
  223. #define ACI_DNS_RULE (short) 0x0040
  224. #define ACI_TIMEOFDAY_RULE (short) 0x0080
  225. #define ACI_DAYOFWEEK_RULE (short) 0x0010
  226. #define ACI_USERATTR_RULE (short) 0x0200
  227. /*
  228. * These are extension of USERDN/GROUPDN rule. However since the
  229. * semantics are quite different, we classify them as different rules.
  230. * ex: groupdn = "ldap:///cn=helpdesk, ou=$attr.dept, o=$dn.o, o=isp"
  231. */
  232. #define ACI_PARAM_DNRULE (short) 0x0400
  233. #define ACI_PARAM_ATTRRULE (short) 0x0800
  234. #define ACI_USERDN_SELFRULE (short) 0x1000
  235. #define ACI_ROLEDN_RULE (short) 0x2000
  236. #define ACI_SSF_RULE (short) 0x4000
  237. #define ACI_ATTR_RULES ( ACI_USERDNATTR_RULE | ACI_GROUPDNATTR_RULE | ACI_USERATTR_RULE | ACI_PARAM_DNRULE | ACI_PARAM_ATTRRULE | ACI_USERDN_SELFRULE)
  238. #define ACI_CACHE_RESULT_PER_ENTRY ACI_ATTR_RULES
  239. short aci_elevel; /* Based on the aci type some idea about the
  240. ** execution flow
  241. */
  242. int aci_index; /* index # */
  243. Slapi_DN *aci_sdn; /* location */
  244. Slapi_Filter *target; /* Target is a DN */
  245. Targetattr **targetAttr;
  246. char *targetFilterStr;
  247. struct slapi_filter *targetFilter; /* Target has a filter */
  248. Targetattrfilter **targetAttrAddFilters;
  249. Targetattrfilter **targetAttrDelFilters;
  250. Slapi_Filter *target_to; /* Target is the destination DN of moddn */
  251. Slapi_Filter *target_from; /* Target is the source DN of moddn */
  252. char *aclName; /* ACL name */
  253. struct ACLListHandle *aci_handle; /*handle of the ACL */
  254. aciMacro *aci_macro;
  255. struct aci *aci_next; /* next one */
  256. }aci_t;
  257. /* Aci excution level
  258. ** The idea is that for each handle types, we can prioritize which one to evaluate first.
  259. ** Evaluating the user before the group is better.
  260. */
  261. #define ACI_ELEVEL_USERDN_ANYONE 0
  262. #define ACI_ELEVEL_USERDN_ALL 1
  263. #define ACI_ELEVEL_USERDN 2
  264. #define ACI_ELEVEL_USERDNATTR 3
  265. #define ACI_ELEVEL_GROUPDNATTR_URL 4
  266. #define ACI_ELEVEL_GROUPDNATTR 5
  267. #define ACI_ELEVEL_GROUPDN 6
  268. #define ACI_MAX_ELEVEL ACI_ELEVEL_GROUPDN +1
  269. #define ACI_DEFAULT_ELEVEL ACI_MAX_ELEVEL
  270. #define ACL_PLUGIN_CONFIG_ENTRY_DN "cn=ACL Plugin,cn=plugins,cn=config"
  271. /*
  272. * In plugin config entry, set this attribute to change the value
  273. * of aclpb_max_selected_acls and aclpb_max_cache_results.
  274. * If not set, DEFAULT_ACLPB_MAX_SELECTED_ACLS will be used.
  275. */
  276. #define ATTR_ACLPB_MAX_SELECTED_ACLS "nsslapd-aclpb-max-selected-acls"
  277. #define DEFAULT_ACLPB_MAX_SELECTED_ACLS 200
  278. int aclpb_max_selected_acls; /* initialized from plugin config entry */
  279. int aclpb_max_cache_results; /* initialized from plugin config entry */
  280. typedef struct result_cache {
  281. int aci_index;
  282. short aci_ruleType;
  283. short result;
  284. #define ACLPB_CACHE_READ_RES_ALLOW (short)0x0001 /* used for ALLOW handles only */
  285. #define ACLPB_CACHE_READ_RES_DENY (short)0x0002 /* used for DENY handles only */
  286. #define ACLPB_CACHE_SEARCH_RES_ALLOW (short)0x0004 /* used for ALLOW handles only */
  287. #define ACLPB_CACHE_SEARCH_RES_DENY (short)0x0008 /* used for DENY handles only */
  288. #define ACLPB_CACHE_SEARCH_RES_SKIP (short)0x0010 /* used for both types */
  289. #define ACLPB_CACHE_READ_RES_SKIP (short)0x0020 /* used for both types */
  290. #define ACLPB_CACHE_ERROR_REPORTED (short)0x8000 /* error is reported */
  291. }r_cache_t;
  292. /*
  293. * This is use to keep the result of the evaluation of the attr.
  294. * We are only intrested in read/searc only.
  295. */
  296. struct acl_attrEval {
  297. char *attrEval_name; /* Attribute Name */
  298. short attrEval_r_status; /* status of read evaluation */
  299. short attrEval_s_status; /* status of search evaluation */
  300. int attrEval_r_aciIndex; /* Index of the ACL which grants access*/
  301. int attrEval_s_aciIndex; /* Index of the ACL which grants access*/
  302. #define ACL_ATTREVAL_SUCCESS 0x1
  303. #define ACL_ATTREVAL_FAIL 0x2
  304. #define ACL_ATTREVAL_RECOMPUTE 0x4
  305. #define ACL_ATTREVAL_DETERMINISTIC 7
  306. #define ACL_ATTREVAL_INVALID 0x8
  307. };
  308. typedef struct acl_attrEval AclAttrEval;
  309. /*
  310. * Struct to keep the evaluation context information. This struct is
  311. * used in multiple places ( different instance ) to keep the context for
  312. * current entry evaluation, previous entry evaluation or previous operation
  313. * evaluation status.
  314. */
  315. #define ACLPB_MAX_ATTR_LEN 100
  316. #define ACLPB_MAX_ATTRS 100
  317. struct acleval_context {
  318. /* Information about the attrs */
  319. AclAttrEval acle_attrEval[ACLPB_MAX_ATTRS];
  320. short acle_numof_attrs;
  321. /* Handles information */
  322. short acle_numof_tmatched_handles;
  323. int *acle_handles_matched_target;
  324. };
  325. typedef struct acleval_context aclEvalContext;
  326. struct acl_usergroup {
  327. short aclug_signature;
  328. /*
  329. * To modify refcnt you need either the write lock on the whole cache or
  330. * the reader lock on the whole cache plus this refcnt mutex
  331. */
  332. short aclug_refcnt;
  333. PRLock *aclug_refcnt_mutex;
  334. char *aclug_ndn; /* Client's normalized DN */
  335. char **aclug_member_groups;
  336. short aclug_member_group_size;
  337. short aclug_numof_member_group;
  338. char **aclug_notmember_groups;
  339. short aclug_notmember_group_size;
  340. short aclug_numof_notmember_group;
  341. struct acl_usergroup *aclug_next;
  342. struct acl_usergroup *aclug_prev;
  343. };
  344. typedef struct acl_usergroup aclUserGroup;
  345. #define ACLUG_INCR_GROUPS_LIST 20
  346. struct aci_container {
  347. Slapi_DN *acic_sdn; /* node DN */
  348. aci_t *acic_list; /* List of the ACLs for that node */
  349. int acic_index; /* index to the container array */
  350. };
  351. typedef struct aci_container AciContainer;
  352. struct acl_pblock {
  353. int aclpb_state;
  354. #define ACLPB_ACCESS_ALLOWED_ON_A_ATTR 0x000001
  355. #define ACLPB_ACCESS_DENIED_ON_ALL_ATTRS 0x000002
  356. #define ACLPB_ACCESS_ALLOWED_ON_ENTRY 0x000004
  357. #define ACLPB_ATTR_STAR_MATCHED 0x000008
  358. #define ACLPB_FOUND_ATTR_RULE 0x000010
  359. #define ACLPB_SEARCH_BASED_ON_LIST 0x000020
  360. #define ACLPB_EXECUTING_DENY_HANDLES 0x000040
  361. #define ACLPB_EXECUTING_ALLOW_HANDLES 0x000080
  362. #define ACLPB_ACCESS_ALLOWED_USERATTR 0x000100
  363. #ifdef DETERMINE_ACCESS_BASED_ON_REQUESTED_ATTRIBUTES
  364. #define ACLPB_USER_SPECIFIED_ATTARS 0x000200
  365. #define ACLPB_USER_WANTS_ALL_ATTRS 0x000400
  366. #endif
  367. #define ACLPB_EVALUATING_FIRST_ATTR 0x000800
  368. #define ACLPB_FOUND_A_ENTRY_TEST_RULE 0x001000
  369. #define ACLPB_SEARCH_BASED_ON_ENTRY_LIST 0x002000
  370. #define ACLPB_DONOT_USE_CONTEXT_ACLS 0x004000
  371. #define ACLPB_HAS_ACLCB_EVALCONTEXT 0x008000
  372. #define ACLPB_COPY_EVALCONTEXT 0x010000
  373. #define ACLPB_MATCHES_ALL_ACLS 0x020000
  374. #define ACLPB_INITIALIZED 0x040000
  375. #define ACLPB_INCR_ACLCB_CACHE 0x080000
  376. #define ACLPB_UPD_ACLCB_CACHE 0x100000
  377. #define ACLPB_ATTR_RULE_EVALUATED 0x200000
  378. #define ACLPB_DONOT_EVALUATE_PROXY 0x400000
  379. #define ACLPB_CACHE_RESULT_PER_ENTRY_SKIP 0x800000
  380. #define ACLPB_RESET_MASK ( ACLPB_ACCESS_ALLOWED_ON_A_ATTR | ACLPB_ACCESS_DENIED_ON_ALL_ATTRS | \
  381. ACLPB_ACCESS_ALLOWED_ON_ENTRY | ACLPB_ATTR_STAR_MATCHED | \
  382. ACLPB_FOUND_ATTR_RULE | ACLPB_EVALUATING_FIRST_ATTR | \
  383. ACLPB_FOUND_A_ENTRY_TEST_RULE )
  384. #define ACLPB_STATE_ALL 0xffffff
  385. int aclpb_res_type;
  386. #define ACLPB_NEW_ENTRY 0x100
  387. #define ACLPB_EFFECTIVE_RIGHTS 0x200
  388. #define ACLPB_RESTYPE_ALL 0x7ff
  389. /*
  390. * The bottom bye used to be for rights. It's free now as they have
  391. * been moved to aclpb_access.
  392. */
  393. int aclpb_access;
  394. #define ACLPB_SLAPI_ACL_WRITE_ADD 0x200
  395. #define ACLPB_SLAPI_ACL_WRITE_DEL 0x400
  396. /* stores the requested access during an operation */
  397. short aclpb_signature;
  398. short aclpb_type;
  399. #define ACLPB_TYPE_MAIN 1
  400. #define ACLPB_TYPE_MAIN_STR "Main Block"
  401. #define ACLPB_TYPE_PROXY 2
  402. #define ACLPB_TYPE_PROXY_STR "Proxy Block"
  403. Slapi_Entry *aclpb_client_entry; /* A copy of client's entry */
  404. Slapi_PBlock *aclpb_pblock; /* back to LDAP PBlock */
  405. int aclpb_optype; /* current optype from pb */
  406. /* Current entry/dn/attr evaluation info */
  407. Slapi_Entry *aclpb_curr_entry; /* current Entry being processed */
  408. int aclpb_num_entries;
  409. Slapi_DN *aclpb_curr_entry_sdn; /* Entry's SDN */
  410. Slapi_DN *aclpb_authorization_sdn; /* dn used for authorization */
  411. AclAttrEval *aclpb_curr_attrEval; /* Current attr being evaluated */
  412. struct berval *aclpb_curr_attrVal; /* Value of Current attr */
  413. Slapi_Entry *aclpb_filter_test_entry; /* Scratch entry */
  414. aci_t *aclpb_curr_aci;
  415. char *aclpb_Evalattr; /* The last attr evaluated */
  416. /* Source entry (MODDN) */
  417. Slapi_DN *aclpb_moddn_source_sdn; /* This is a pointer into the pb, do not free it */
  418. /* Plist and eval info */
  419. ACLEvalHandle_t *aclpb_acleval; /* acleval handle for evaluation */
  420. struct PListStruct_s *aclpb_proplist;/* All the needed property */
  421. /* DENY ACI HANDLES */
  422. aci_t **aclpb_deny_handles;
  423. int aclpb_deny_handles_size;
  424. int aclpb_num_deny_handles;
  425. /* ALLOW ACI HANDLES */
  426. aci_t **aclpb_allow_handles;
  427. int aclpb_allow_handles_size;
  428. int aclpb_num_allow_handles;
  429. /* This is used in the groupdnattr="URL" rule
  430. ** Keep a list of base where searched has been done
  431. */
  432. char **aclpb_grpsearchbase;
  433. int aclpb_grpsearchbase_size;
  434. int aclpb_numof_bases;
  435. aclUserGroup *aclpb_groupinfo;
  436. /* Keep the Group nesting level */
  437. int aclpb_max_nesting_level;
  438. int aclpb_max_member_sizelimit;
  439. /* To keep the results in the cache */
  440. int aclpb_last_cache_result;
  441. struct result_cache *aclpb_cache_result;
  442. /* Index numbers of ACLs selected based on a locality search*/
  443. char *aclpb_search_base;
  444. int *aclpb_base_handles_index;
  445. int *aclpb_handles_index;
  446. /* Evaluation context info
  447. ** 1) Context cached from aclcb ( from connection struct )
  448. ** 2) Context cached from previous entry evaluation
  449. ** 3) current entry evaluation info
  450. */
  451. aclEvalContext aclpb_curr_entryEval_context;
  452. aclEvalContext aclpb_prev_entryEval_context;
  453. aclEvalContext aclpb_prev_opEval_context;
  454. /* Currentry anom profile sumamry */
  455. struct scoped_entry_anominfo aclpb_scoped_entry_anominfo;
  456. /* Some Statistics gathering */
  457. PRUint16 aclpb_stat_acllist_scanned;
  458. PRUint16 aclpb_stat_aclres_matched;
  459. PRUint16 aclpb_stat_total_entries;
  460. PRUint16 aclpb_stat_anom_list_scanned;
  461. PRUint16 aclpb_stat_num_copycontext;
  462. PRUint16 aclpb_stat_num_copy_attrs;
  463. PRUint16 aclpb_stat_num_tmatched_acls;
  464. PRUint16 aclpb_stat_unused;
  465. CERTCertificate *aclpb_clientcert;
  466. AciContainer *aclpb_aclContainer;
  467. struct acl_pblock *aclpb_proxy; /* Child proxy block */
  468. acl_ht_t *aclpb_macro_ht; /* ht for partial macro strs */
  469. struct acl_pblock *aclpb_prev; /* Previpous in the chain */
  470. struct acl_pblock *aclpb_next; /* Next in the chain */
  471. };
  472. typedef struct acl_pblock Acl_PBlock;
  473. /* PBLCOK TYPES */
  474. typedef enum
  475. {
  476. ACLPB_BINDDN_PBLOCK,
  477. ACLPB_PROXYDN_PBLOCK,
  478. ACLPB_ALL_PBLOCK
  479. }aclpb_types;
  480. #define ACLPB_EVALCONTEXT_CURR 1
  481. #define ACLPB_EVALCONTEXT_PREV 2
  482. #define ACLPB_EVALCONTEXT_ACLCB 3
  483. /* Cleaning/ deallocating/ ... acl_freeBlock() */
  484. #define ACL_CLEAN_ACLPB 1
  485. #define ACL_COPY_ACLCB 2
  486. #define ACL_CLEAN_ACLCB 3
  487. /* used to differentiate acl plugins sharing the same lib */
  488. #define ACL_PLUGIN_IDENTITY 1
  489. #define ACL_PREOP_PLUGIN_IDENTITY 2
  490. /* start with 50 and then add 50 more as required
  491. * The first ACI_MAX_ELEVEL slots are predefined.
  492. */
  493. #define ACLPB_INCR_LIST_HANDLES ACI_MAX_ELEVEL + 43
  494. #define ACLPB_INCR_BASES 5
  495. /*
  496. * acl private block which hangs from connection structure.
  497. * This is allocated the first time an operation is done and freed when the
  498. * connection are cleaned.
  499. *
  500. */
  501. struct acl_cblock {
  502. short aclcb_aclsignature;
  503. short aclcb_state;
  504. #define ACLCB_HAS_CACHED_EVALCONTEXT 0x1
  505. Slapi_DN *aclcb_sdn; /* Contains bind SDN */
  506. aclEvalContext aclcb_eval_context;
  507. PRLock *aclcb_lock; /* shared lock */
  508. };
  509. struct acl_groupcache {
  510. short aclg_state; /* status information */
  511. short aclg_signature;
  512. int aclg_num_userGroups;
  513. aclUserGroup *aclg_first;
  514. aclUserGroup *aclg_last;
  515. Slapi_RWLock *aclg_rwlock; /* lock to monitor the group cache */
  516. };
  517. typedef struct acl_groupcache aclGroupCache;
  518. /* Type of extensions that can be registered */
  519. typedef enum
  520. {
  521. ACL_EXT_OPERATION, /* extension for Operation object */
  522. ACL_EXT_CONNECTION, /* extension for Connection object */
  523. ACL_EXT_ALL
  524. }ext_type;
  525. /* Used to pass data around in acllas.c */
  526. typedef struct {
  527. char *clientDn;
  528. char *authType;
  529. int anomUser;
  530. Acl_PBlock *aclpb;
  531. Slapi_Entry *resourceEntry;
  532. int ssf;
  533. char *ldapi;
  534. }lasInfo;
  535. /* reasons why the subject allowed/denied access--good for logs */
  536. typedef enum{
  537. ACL_REASON_NO_ALLOWS,
  538. ACL_REASON_RESULT_CACHED_DENY,
  539. ACL_REASON_EVALUATED_DENY, /* evaluated deny */
  540. ACL_REASON_RESULT_CACHED_ALLOW, /* cached allow */
  541. ACL_REASON_EVALUATED_ALLOW, /* evalauted allow */
  542. ACL_REASON_NO_MATCHED_RESOURCE_ALLOWS, /* were allows/denies, but none matched */
  543. ACL_REASON_NONE, /* no reason available */
  544. ACL_REASON_ANON_ALLOWED,
  545. ACL_REASON_ANON_DENIED,
  546. ACL_REASON_NO_MATCHED_SUBJECT_ALLOWS,
  547. ACL_REASON_EVALCONTEXT_CACHED_ALLOW,
  548. ACL_REASON_EVALCONTEXT_CACHED_NOT_ALLOWED,
  549. ACL_REASON_EVALCONTEXT_CACHED_ATTR_STAR_ALLOW
  550. }aclReasonCode_t;
  551. typedef struct{
  552. aci_t *deciding_aci;
  553. aclReasonCode_t reason;
  554. }aclResultReason_t;
  555. #define ACL_NO_DECIDING_ACI_INDEX -10
  556. /* Extern declaration for backend state change fnc: acllist.c and aclinit.c */
  557. void acl_be_state_change_fnc ( void *handle, char *be_name, int old_state,
  558. int new_state);
  559. /* Extern declaration for ATTRs */
  560. extern int
  561. DS_LASIpGetter(NSErr_t *errp, PList_t subject, PList_t resource, PList_t
  562. auth_info, PList_t global_auth, void *arg);
  563. extern int
  564. DS_LASDnsGetter(NSErr_t *errp, PList_t subject, PList_t resource, PList_t
  565. auth_info, PList_t global_auth, void *arg);
  566. extern int
  567. DS_LASUserDnGetter(NSErr_t *errp, PList_t subject, PList_t resource, PList_t
  568. auth_info, PList_t global_auth, void *arg);
  569. extern int
  570. DS_LASGroupDnGetter(NSErr_t *errp, PList_t subject, PList_t resource, PList_t
  571. auth_info, PList_t global_auth, void *arg);
  572. extern int
  573. DS_LASEntryGetter(NSErr_t *errp, PList_t subject, PList_t resource,
  574. PList_t auth_info, PList_t global_auth, void *arg);
  575. extern int
  576. DS_LASCertGetter(NSErr_t *errp, PList_t subject, PList_t resource,
  577. PList_t auth_info, PList_t global_auth, void *arg);
  578. /* function declartion for LAses supported by DS */
  579. extern int DS_LASUserEval(NSErr_t *errp, char *attribute, CmpOp_t comparator,
  580. char *pattern, int *cachable, void **las_cookie,
  581. PList_t subject, PList_t resource, PList_t auth_info,
  582. PList_t global_auth);
  583. extern int DS_LASGroupEval(NSErr_t *errp, char *attribute, CmpOp_t comparator,
  584. char *pattern, int *cachable, void **las_cookie,
  585. PList_t subject, PList_t resource, PList_t auth_info,
  586. PList_t global_auth);
  587. extern int DS_LASUserDnEval(NSErr_t *errp, char *attribute, CmpOp_t comparator,
  588. char *pattern, int *cachable, void **las_cookie,
  589. PList_t subject, PList_t resource, PList_t auth_info,
  590. PList_t global_auth);
  591. extern int DS_LASGroupDnEval(NSErr_t *errp, char *attribute, CmpOp_t comparator,
  592. char *pattern, int *cachable, void **las_cookie,
  593. PList_t subject, PList_t resource, PList_t auth_info,
  594. PList_t global_auth);
  595. extern int DS_LASRoleDnEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  596. char *attr_pattern, int *cachable, void **LAS_cookie,
  597. PList_t subject, PList_t resource, PList_t auth_info,
  598. PList_t global_auth);
  599. extern int DS_LASUserDnAttrEval(NSErr_t *errp, char *attribute,
  600. CmpOp_t comparator,
  601. char *pattern, int *cachable, void **las_cookie,
  602. PList_t subject, PList_t resource, PList_t auth_info,
  603. PList_t global_auth);
  604. extern int DS_LASAuthMethodEval(NSErr_t *errp, char *attribute,
  605. CmpOp_t comparator,
  606. char *pattern, int *cachable, void **las_cookie,
  607. PList_t subject, PList_t resource, PList_t auth_info,
  608. PList_t global_auth);
  609. extern int DS_LASGroupDnAttrEval(NSErr_t *errp, char *attribute,
  610. CmpOp_t comparator,
  611. char *pattern, int *cachable, void **las_cookie,
  612. PList_t subject, PList_t resource, PList_t auth_info,
  613. PList_t global_auth);
  614. extern int DS_LASRoleDnAttrEval(NSErr_t *errp, char *attribute,
  615. CmpOp_t comparator,
  616. char *pattern, int *cachable, void **las_cookie,
  617. PList_t subject, PList_t resource, PList_t auth_info,
  618. PList_t global_auth);
  619. extern int DS_LASUserAttrEval(NSErr_t *errp, char *attribute,
  620. CmpOp_t comparator,
  621. char *pattern, int *cachable, void **las_cookie,
  622. PList_t subject, PList_t resource, PList_t auth_info,
  623. PList_t global_auth);
  624. extern int DS_LASSSFEval(NSErr_t *errp, char *attribute,
  625. CmpOp_t comparator,
  626. char *pattern, int *cachable, void **las_cookie,
  627. PList_t subject, PList_t resource, PList_t auth_info,
  628. PList_t global_auth);
  629. /* other function declaration */
  630. int aclinit_main();
  631. int acl_match_substring (struct slapi_filter *f, char *str, int match);
  632. void acl_print_acllib_err(NSErr_t *errp, char * str);
  633. void acl_initBlock ( Slapi_PBlock *pb );
  634. void acl_freeBlock ( Slapi_PBlock *pb, int state );
  635. int acl_read_access_allowed_on_entry ( Slapi_PBlock *pb, Slapi_Entry *e,
  636. char **attrs, int access);
  637. int acl_access_allowed_modrdn ( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
  638. struct berval *val, int access);
  639. int acl_read_access_allowed_on_attr ( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
  640. struct berval *val, int access);
  641. void acl_set_acllist (Slapi_PBlock *pb, int scope, char *base);
  642. void acl_gen_err_msg(int access, char *edn, char *attr, char **errbuf);
  643. void acl_modified (Slapi_PBlock *pb, int optype, Slapi_DN *e_sdn, void *change);
  644. int acl_access_allowed_disjoint_resource( Slapi_PBlock *pb, Slapi_Entry *e,
  645. char *attr, struct berval *val, int access );
  646. int acl_access_allowed_main ( Slapi_PBlock *pb, Slapi_Entry *e, char **attrs,
  647. struct berval *val, int access , int flags, char **errbuf);
  648. int acl_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
  649. struct berval *val, int access );
  650. aclUserGroup * acl_get_usersGroup ( struct acl_pblock *aclpb , char *n_dn);
  651. void acl_print_acllib_err (NSErr_t *errp , char * str);
  652. int acl_check_mods( Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char **errbuf );
  653. char * acl__access2str(int access);
  654. void acl_strcpy_special (char *d, char *s);
  655. int acl_parse(Slapi_PBlock *pb, char * str, aci_t *aci_item, char **errbuf);
  656. int acl_verify_aci_syntax (Slapi_PBlock *pb, Slapi_Entry *e, char **errbuf);
  657. int acl_verify_syntax(Slapi_PBlock *pb, const Slapi_DN *e_sdn,
  658. const struct berval *bval, char **errbuf);
  659. int acllist_insert_aci_needsLock_ext( Slapi_PBlock *pb, const Slapi_DN *e_sdn,
  660. const struct berval* aci_attr);
  661. char * acl_access2str ( int access );
  662. int acl_init_ext ();
  663. void acl_remove_ext ();
  664. void * acl_get_ext (ext_type type, void *object);
  665. void acl_set_ext (ext_type type, void *object, void *data);
  666. void acl_reset_ext_status (ext_type type, void *object);
  667. void acl_init_op_ext ( Slapi_PBlock *pb , int type, char *dn, int copy);
  668. void * acl_operation_ext_constructor (void *object, void *parent );
  669. void acl_operation_ext_destructor ( void *ext, void *object, void *parent );
  670. void * acl_conn_ext_constructor (void *object, void *parent );
  671. void acl_conn_ext_destructor ( void *ext, void *object, void *parent );
  672. void acl_clean_aclEval_context ( aclEvalContext *clean_me, int scrub_only );
  673. void acl_copyEval_context ( struct acl_pblock *aclpb, aclEvalContext *src,
  674. aclEvalContext *dest , int copy_attr_only );
  675. struct acl_pblock * acl_get_aclpb ( Slapi_PBlock *pb, int type );
  676. int acl_client_anonymous ( Slapi_PBlock *pb );
  677. short acl_get_aclsignature();
  678. void acl_set_aclsignature( short value);
  679. void acl_regen_aclsignature();
  680. struct acl_pblock * acl_new_proxy_aclpb( Slapi_PBlock *pb );
  681. void acl_set_authorization_dn( Slapi_PBlock *pb, char *dn, int type );
  682. void acl_init_aclpb ( Slapi_PBlock *pb , Acl_PBlock *aclpb,
  683. const char *dn, int copy_from_aclcb);
  684. int acl_create_aclpb_pool ();
  685. void acl_destroy_aclpb_pool ();
  686. int acl_skip_access_check ( Slapi_PBlock *pb, Slapi_Entry *e );
  687. int aclext_alloc_lockarray ();
  688. void aclext_free_lockarray();
  689. int aclutil_str_append(char **str1, const char *str2);
  690. void aclutil_print_err (int rv , const Slapi_DN *sdn,
  691. const struct berval* val, char **errbuf);
  692. void aclutil_print_aci (aci_t *aci_item, char *type);
  693. short aclutil_gen_signature ( short c_signature );
  694. void aclutil_print_resource( struct acl_pblock *aclpb, const char *right , char *attr, char *clientdn );
  695. char * aclutil_expand_paramString ( char *str, Slapi_Entry *e );
  696. void acllist_init_scan (Slapi_PBlock *pb, int scope, const char *base);
  697. aci_t * acllist_get_first_aci (Acl_PBlock *aclpb, PRUint32 *cookie );
  698. aci_t * acllist_get_next_aci ( Acl_PBlock *aclpb, aci_t *curraci, PRUint32 *cookie );
  699. aci_t * acllist_get_aci_new ();
  700. void acllist_free_aci (aci_t *item);
  701. void acllist_acicache_READ_UNLOCK(void);
  702. void acllist_acicache_READ_LOCK(void);
  703. void acllist_acicache_WRITE_UNLOCK(void);
  704. void acllist_acicache_WRITE_LOCK(void);
  705. void acllist_aciscan_update_scan ( Acl_PBlock *aclpb, char *edn );
  706. int acllist_remove_aci_needsLock( const Slapi_DN *sdn, const struct berval *attr );
  707. void free_acl_avl_list();
  708. int acllist_insert_aci_needsLock( const Slapi_DN *e_sdn, const struct berval* aci_attr);
  709. int acllist_init ();
  710. void acllist_free();
  711. int acllist_moddn_aci_needsLock ( Slapi_DN *oldsdn, char *newdn );
  712. void acllist_print_tree ( Avlnode *root, int *depth, char *start, char *side);
  713. AciContainer *acllist_get_aciContainer_new ( );
  714. void acllist_free_aciContainer ( AciContainer **container);
  715. void acllist_done_aciContainer ( AciContainer *);
  716. void free_targetattrfilters( Targetattrfilter ***attrFilterArray);
  717. aclUserGroup* aclg_find_userGroup (const char *n_dn);
  718. void aclg_regen_ugroup_signature( aclUserGroup *ugroup);
  719. void aclg_markUgroupForRemoval ( aclUserGroup *u_group );
  720. void aclg_reader_incr_ugroup_refcnt(aclUserGroup* u_group);
  721. int aclg_numof_usergroups(void);
  722. int aclgroup_init ();
  723. void aclgroup_free();
  724. void aclg_regen_group_signature ();
  725. void aclg_reset_userGroup ( struct acl_pblock *aclpb );
  726. void aclg_init_userGroup ( struct acl_pblock *aclpb, const char *dn , int got_lock);
  727. aclUserGroup * aclg_get_usersGroup ( struct acl_pblock *aclpb , char *n_dn);
  728. void aclg_lock_groupCache (int type );
  729. void aclg_unlock_groupCache (int type );
  730. int aclanom_init();
  731. int aclanom_match_profile (Slapi_PBlock *pb, struct acl_pblock *aclpb,
  732. Slapi_Entry *e, char *attr, int access);
  733. void aclanom_get_suffix_info(Slapi_Entry *e, struct acl_pblock *aclpb );
  734. void aclanom_invalidateProfile();
  735. void aclanom__del_profile (int closing);
  736. typedef enum{
  737. DONT_TAKE_ACLCACHE_READLOCK,
  738. DO_TAKE_ACLCACHE_READLOCK,
  739. DONT_TAKE_ACLCACHE_WRITELOCK,
  740. DO_TAKE_ACLCACHE_WRITELOCK
  741. }acl_lock_flag_t;
  742. void aclanom_gen_anomProfile (acl_lock_flag_t lock_flag);
  743. int aclanom_is_client_anonymous ( Slapi_PBlock *pb );
  744. int aclinit_main ();
  745. typedef struct aclinit_handler_callback_data {
  746. #define ACL_ADD_ACIS 1
  747. #define ACL_REMOVE_ACIS 0
  748. int op;
  749. int retCode;
  750. acl_lock_flag_t lock_flag;
  751. }aclinit_handler_callback_data_t;
  752. int
  753. aclinit_search_and_update_aci ( int thisbeonly, const Slapi_DN *base,
  754. char *be_name, int scope, int op,
  755. acl_lock_flag_t lock_flag);
  756. void *aclplugin_get_identity(int plug);
  757. int
  758. acl_dn_component_match( const char *ndn, char *match_this, int component_number);
  759. char *
  760. acl_match_macro_in_target( const char *ndn, char *match_this,
  761. char *macro_ptr);
  762. char* get_next_component(char *dn, int *index);
  763. int acl_match_prefix( char *macro_prefix, const char *ndn,
  764. int *exact_match);
  765. char *
  766. get_this_component(char *dn, int *index);
  767. int
  768. acl_find_comp_end( char * s);
  769. char *
  770. acl_replace_str(char * s, char *substr, char* replace_with);
  771. int acl_strstr(char * s, char *substr);
  772. int aclutil_evaluate_macro( char * rule, lasInfo *lasinfo,
  773. acl_eval_types evalType );
  774. int aclutil_str_append_ext(char **dest, size_t *dlen, const char *src, size_t slen);
  775. /* acl hash table functions */
  776. void acl_ht_add_and_freeOld(acl_ht_t * acl_ht, PLHashNumber key,char *value);
  777. void acl_ht_remove_and_free(acl_ht_t * acl_ht, PLHashNumber key);
  778. acl_ht_t *acl_ht_new(void);
  779. void acl_ht_free_all_entries_and_values( acl_ht_t *acl_ht);
  780. void acl_ht_remove( acl_ht_t *acl_ht, PLHashNumber key);
  781. void *acl_ht_lookup( acl_ht_t *acl_ht, PLHashNumber key);
  782. void acl_ht_display_ht( acl_ht_t *acl_ht);
  783. /* acl get effective rights */
  784. int
  785. acl_get_effective_rights ( Slapi_PBlock *pb, Slapi_Entry *e,
  786. char **attrs, struct berval *val, int access, char **errbuf );
  787. char* aclutil__access_str (int type , char str[]);
  788. int aclplugin_preop_common( Slapi_PBlock *pb );
  789. #endif /* _ACL_H_ */