acl.h 29 KB

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