acl.h 33 KB

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