aclparse.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  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. #include "acl.h"
  7. /****************************************************************************/
  8. /* prototypes */
  9. /****************************************************************************/
  10. static int __aclp__parse_aci(char *str, aci_t *aci_item);
  11. static int __aclp__sanity_check_acltxt(aci_t *aci_item, char *str);
  12. static char * __aclp__normalize_acltxt (aci_t *aci_item, char *str);
  13. static char * __aclp__getNextLASRule(aci_t *aci_item, char *str,
  14. char **endOfCurrRule);
  15. static char * __aclp__dn_normalize( char *dn , char *end);
  16. static int __aclp__get_aci_right ( char *str);
  17. static int __aclp__init_targetattr (aci_t *aci, char *attr_val);
  18. static int __acl__init_targetattrfilters( aci_t *aci_item, char *str);
  19. static int process_filter_list( Targetattrfilter ***attrfilterarray,
  20. char * str);
  21. static int __acl_init_targetattrfilter( Targetattrfilter *attrfilter, char *str );
  22. static void __aclp_chk_paramRules ( aci_t *aci_item, char *start,
  23. char *end);
  24. static void __acl_strip_trailing_space( char *str);
  25. static void __acl_strip_leading_space( char **str);
  26. static char * __acl_trim_filterstr( char * str );
  27. static int acl_verify_exactly_one_attribute( char *attr_name, Slapi_Filter *f);
  28. static int type_compare( Slapi_Filter *f, void *arg);
  29. static int acl_check_for_target_macro( aci_t *aci_item, char *value);
  30. static int get_acl_rights_as_int( char * strValue);
  31. /***************************************************************************
  32. *
  33. * acl_parse
  34. *
  35. * Parses the input string and copies the information into the
  36. * correct place in the aci.
  37. *
  38. *
  39. * Input:
  40. * char *str - Input string which has the ACL
  41. * This is a duped copy, so here we have
  42. * the right to stich '\0' characters into str for
  43. * processing purposes. If you want to keep
  44. * a piece of str, you'll need to dup it
  45. * as it gets freed outside the scope of acl_parse.
  46. * aci_t *item - the aci item where the ACL info will be
  47. * - stored.
  48. *
  49. * Returns:
  50. * 0 -- Parsed okay
  51. * < 0 -- error codes
  52. *
  53. * Error Handling:
  54. * None.
  55. *
  56. **************************************************************************/
  57. int
  58. acl_parse(char * str, aci_t *aci_item)
  59. {
  60. int rv=0;
  61. char *next;
  62. char *save;
  63. while(*str) {
  64. __acl_strip_leading_space( &str );
  65. if (*str == '\0') break;
  66. if (*str == '(') {
  67. if ((next = slapi_find_matching_paren(str)) == NULL) {
  68. return(ACL_SYNTAX_ERR);
  69. }
  70. } else {
  71. /* then we have done all the processing */
  72. return 0;
  73. }
  74. LDAP_UTF8INC(str); /* skip the "(" */
  75. save = next;
  76. LDAP_UTF8INC(next);
  77. *save = '\0';
  78. /* Now we have a "str)" */
  79. if ( 0 != (rv = __aclp__parse_aci(str, aci_item))) {
  80. return(rv);
  81. }
  82. /* Move to the next */
  83. str = next;
  84. }
  85. /* check if have a ACLTXT or not */
  86. if (!(aci_item->aci_type & ACI_ACLTXT))
  87. return ACL_SYNTAX_ERR;
  88. if (aci_item->target) {
  89. Slapi_Filter *f;
  90. /* Make sure that the target is a valid target.
  91. ** Example: ACL is located in
  92. ** "ou=engineering, o=ace industry, c=us
  93. ** but if the target is "o=ace industry, c=us",
  94. ** then it's an ERROR.
  95. */
  96. f = aci_item->target;
  97. if (aci_item->aci_type & ACI_TARGET_DN) {
  98. char *avaType;
  99. struct berval *avaValue;
  100. const char *dn;
  101. dn = slapi_sdn_get_ndn ( aci_item->aci_sdn );
  102. slapi_filter_get_ava ( f, &avaType, &avaValue );
  103. if (!slapi_dn_issuffix( avaValue->bv_val, dn))
  104. return ACL_INVALID_TARGET;
  105. }
  106. }
  107. /*
  108. ** We need to keep the taregetFilterStr for anyone ACL only.
  109. ** same for targetValueFilterStr.
  110. ** We need to keep it for macros too as it needs to be expnaded at eval time.
  111. **
  112. */
  113. if ( (aci_item->aci_elevel != ACI_ELEVEL_USERDN_ANYONE) &&
  114. !(aci_item->aci_type & ACI_TARGET_MACRO_DN) ) {
  115. slapi_ch_free ( (void **) & aci_item->targetFilterStr );
  116. }
  117. /*
  118. * If we parsed the aci and there was a ($dn) on the user side
  119. * but none in hte taget then that's an error as the user side
  120. * value is derived from the target side value.
  121. */
  122. if (!(aci_item->aci_type & ACI_TARGET_MACRO_DN) &&
  123. (aci_item->aci_ruleType & ACI_PARAM_DNRULE)) {
  124. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  125. "acl_parse: A macro in a subject ($dn) must have a macro in the target.\n");
  126. return(ACL_INVALID_TARGET);
  127. }
  128. return 0;
  129. }
  130. /***************************************************************************
  131. *
  132. * __aclp__parse_aci
  133. *
  134. * Parses Each individual subset of information/
  135. *
  136. * Input:
  137. * char *str - Input string which has the ACL like "str)"
  138. * aci_t *item - the aci item where the ACL info will be
  139. * - stored.
  140. *
  141. * Returns:
  142. * 0 -- Parsed okay
  143. * < 0 -- error codes
  144. *
  145. * Error Handling:
  146. * None.
  147. *
  148. **************************************************************************/
  149. static int
  150. __aclp__parse_aci (char *str, aci_t *aci_item)
  151. {
  152. int len;
  153. int rv;
  154. int type;
  155. char *tmpstr;
  156. char *s = NULL;
  157. char *value = NULL;
  158. Slapi_Filter *f = NULL;
  159. int targetattrlen = strlen(aci_targetattr);
  160. int targetdnlen = strlen (aci_targetdn);
  161. int tfilterlen = strlen(aci_targetfilter);
  162. int targetattrfilterslen = strlen(aci_targetattrfilters);
  163. __acl_strip_leading_space( &str );
  164. if (*str == '\0') {
  165. return(ACL_SYNTAX_ERR);
  166. }
  167. /* The first letter should tell us something */
  168. switch(*str) {
  169. case 'v':
  170. type = ACI_ACLTXT;
  171. if ( 0 != (rv= __aclp__sanity_check_acltxt(aci_item, str ) ) ) {
  172. return rv;
  173. }
  174. break;
  175. case 't':
  176. if (strncmp(str, aci_targetattrfilters,targetattrfilterslen ) == 0) {
  177. type = ACI_TARGET_ATTR;
  178. /*
  179. * The targetattrfilters bit looks like this:
  180. * (targetattrfilters="add= attr1:F1 && attr2:F2 ... && attrn:Fn,
  181. * del= attr1:F1 && attr2:F2... && attrn:Fn")
  182. */
  183. if ( 0 != (rv= __acl__init_targetattrfilters(
  184. aci_item, str))) {
  185. return rv;
  186. }
  187. } else if (strncmp(str, aci_targetattr,targetattrlen ) == 0) {
  188. type = ACI_TARGET_ATTR;
  189. if ( (s = strstr( str, "!=" )) != NULL ) {
  190. type |= ACI_TARGET_ATTR_NOT;
  191. strncpy(s, " ", 1);
  192. }
  193. /* Get individual components of the targetattr.
  194. * (targetattr = "cn || u* || phone ||tel:add:(tel=1234)
  195. * || sn:del:(gn=5678)")
  196. * If it contains a value filter, the type will also be
  197. * ACI_TARGET_VALUE_ATTR.
  198. */
  199. if ( 0 != (rv= __aclp__init_targetattr(
  200. aci_item, str))) {
  201. return rv;
  202. }
  203. } else if (strncmp(str, aci_targetfilter,tfilterlen ) == 0) {
  204. if ( aci_item->targetFilter)
  205. return ACL_SYNTAX_ERR;
  206. type = ACI_TARGET_FILTER;
  207. /* we need to remove the targetfilter stuff*/
  208. if ( (s = strstr( str, "!=" )) != NULL ) {
  209. type |= ACI_TARGET_FILTER_NOT;
  210. }
  211. /*
  212. * If it's got a macro in the targetfilter then it must
  213. * have a target and it must have a macro.
  214. */
  215. if ((s = strstr (str, ACL_RULE_MACRO_DN_KEY)) != NULL ||
  216. ((s = strstr(str, ACL_RULE_MACRO_DN_LEVELS_KEY)) != NULL)) {
  217. /* Must have a targetmacro */
  218. if ( !(aci_item->aci_type & ACI_TARGET_MACRO_DN)) {
  219. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  220. "acl_parse: A macro in a targetfilter ($dn) must have a macro in the target.\n");
  221. return(ACL_SYNTAX_ERR);
  222. }
  223. type|= ACI_TARGET_FILTER_MACRO_DN;
  224. }
  225. tmpstr = strchr(str, '=');
  226. tmpstr++;
  227. __acl_strip_leading_space(&tmpstr);
  228. /*
  229. * Trim off enclosing quotes and enclosing
  230. * superfluous brackets.
  231. * The result has been duped so it can be kept.
  232. */
  233. tmpstr = __acl_trim_filterstr( tmpstr );
  234. f = slapi_str2filter(tmpstr);
  235. /* save the filter string */
  236. aci_item->targetFilterStr = tmpstr;
  237. } else if (strncmp(str, aci_targetdn, targetdnlen) == 0) {
  238. char *tstr = NULL;
  239. const size_t LDAP_URL_prefix_len = strlen (LDAP_URL_prefix);
  240. char *tt;
  241. type = ACI_TARGET_DN;
  242. /* Keep a copy of the target attr */
  243. if (aci_item->target) {
  244. return (ACL_SYNTAX_ERR);
  245. }
  246. if ( (s = strstr( str, "!=" )) != NULL ) {
  247. type |= ACI_TARGET_NOT;
  248. strncpy(s, " ", 1);
  249. }
  250. /* Convert it to lower as slapi_dn_normalize() does not */
  251. for (tt = str; *tt; tt++) *tt = TOLOWER ( *tt );
  252. if ( (s = strchr( str, '=' )) != NULL ) {
  253. value = s + 1;
  254. slapi_dn_normalize(value);
  255. len = strlen ( value );
  256. if (*value == '"' && value[len-1] == '"'){
  257. value[len-1] = '\0';
  258. value++;
  259. }
  260. __acl_strip_leading_space(&value);
  261. } else {
  262. return ( ACL_SYNTAX_ERR );
  263. }
  264. if ( strncasecmp ( value, LDAP_URL_prefix , LDAP_URL_prefix_len) )
  265. return ( ACL_SYNTAX_ERR );
  266. value += LDAP_URL_prefix_len;
  267. len = strlen ( value );
  268. tstr = (char *) slapi_ch_malloc ( targetdnlen + len + 4 );
  269. sprintf ( tstr, "(target=%s)", value);
  270. if ( (rv = acl_check_for_target_macro( aci_item, value)) == -1) {
  271. slapi_ch_free ( (void **) &tstr );
  272. return(ACL_SYNTAX_ERR);
  273. } else if ( rv > 0) {
  274. /* is present, so the type is now ACL_TARGET_MACRO_DN */
  275. type = ACI_TARGET_MACRO_DN;
  276. } else {
  277. /* it's a normal target with no macros inside */
  278. f = slapi_str2filter ( tstr );
  279. }
  280. slapi_ch_free ( (void **) &tstr );
  281. } else {
  282. /* did start with a 't' but was not a recognsied keyword */
  283. return(ACL_SYNTAX_ERR);
  284. }
  285. /*
  286. * Here, it was a recognised keyword that started with 't'.
  287. * Check that the filter associated with ACI_TARGET_DN and
  288. * ACI_TARGET_FILTER are OK.
  289. */
  290. if (f == NULL) {
  291. /* The following types require a filter to have been created */
  292. if (type & ACI_TARGET_DN)
  293. return ACL_TARGET_FILTER_ERR;
  294. else if (type & ACI_TARGET_FILTER)
  295. return ACL_TARGETFILTER_ERR;
  296. } else {
  297. int filterChoice;
  298. filterChoice = slapi_filter_get_choice ( f );
  299. if ( (type & ACI_TARGET_DN) &&
  300. ( filterChoice == LDAP_FILTER_PRESENT)) {
  301. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  302. "acl__parse_aci: Unsupported filter type:%d\n", filterChoice);
  303. return(ACL_SYNTAX_ERR);
  304. } else if (( filterChoice == LDAP_FILTER_SUBSTRINGS) &&
  305. (type & ACI_TARGET_DN)) {
  306. type &= ~ACI_TARGET_DN;
  307. type |= ACI_TARGET_PATTERN;
  308. }
  309. }
  310. if ((type & ACI_TARGET_DN) ||
  311. (type & ACI_TARGET_PATTERN)) {
  312. if (aci_item->target) {
  313. /* There is something already. ERROR */
  314. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  315. "Multiple targets in the ACL syntax\n",
  316. 0,0,0);
  317. slapi_filter_free(f, 1);
  318. return(ACL_SYNTAX_ERR);
  319. } else {
  320. aci_item->target = f;
  321. }
  322. } else if ( type & ACI_TARGET_FILTER) {
  323. if (aci_item->targetFilter) {
  324. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  325. "Multiple target Filters in the ACL Syntax\n",
  326. 0,0,0);
  327. slapi_filter_free(f, 1);
  328. return(ACL_SYNTAX_ERR);
  329. } else {
  330. aci_item->targetFilter = f;
  331. }
  332. }
  333. break; /* 't' */
  334. default:
  335. /* Here the keyword did not start with 'v' ot 't' so error */
  336. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  337. "Unknown keyword at \"%s\"\n Expecting"
  338. " \"target\", \"targetattr\", \"targetfilter\", \"targattrfilters\""
  339. " or \"version\"\n", str, 0, 0);
  340. return(ACL_SYNTAX_ERR);
  341. }/* switch() */
  342. /* Store the type info */
  343. aci_item->aci_type |= type;
  344. return 0;
  345. }
  346. /***************************************************************************
  347. * acl__sanity_check_acltxt
  348. *
  349. * Check the input ACL text. Reports any errors. Also forgivs if certain
  350. * things are missing.
  351. *
  352. * Input:
  353. * char *str - String containg the acl text
  354. * int *err - error status
  355. *
  356. * Returns:
  357. * 0 --- good status
  358. * <0 --- error
  359. *
  360. * Error Handling:
  361. * None.
  362. *
  363. *
  364. **************************************************************************/
  365. static int
  366. __aclp__sanity_check_acltxt (aci_t *aci_item, char *str)
  367. {
  368. NSErr_t errp;
  369. char *s;
  370. ACLListHandle_t *handle = NULL;
  371. char *newstr = NULL;
  372. char *word;
  373. char *next;
  374. memset (&errp, 0, sizeof(NSErr_t));
  375. newstr = str;
  376. while ((s = strstr(newstr, "authenticate")) != NULL) {
  377. char *next;
  378. next = s + 12;
  379. s--;
  380. while (s != str && ldap_utf8isspace(s)) LDAP_UTF8DEC(s);
  381. if (s && *s == ';') {
  382. /* We don't support authenticate stuff */
  383. return ACL_INVALID_AUTHORIZATION;
  384. } else {
  385. newstr = next;
  386. }
  387. }
  388. newstr = slapi_ch_strdup (str);
  389. word = ldap_utf8strtok_r(newstr, " ", &next);
  390. if (strcasecmp (word, "version") == 0) {
  391. word = ldap_utf8strtok_r(NULL, " ", &next);
  392. if (atoi(word) != 3) {
  393. slapi_ch_free ( (void **) &newstr );
  394. return ACL_INCORRECT_ACI_VERSION;
  395. }
  396. }
  397. slapi_ch_free ( (void **) &newstr );
  398. /* We need to normalize the DNs in the userdn and group dn
  399. ** so that, it's only done once.
  400. */
  401. if ((newstr = __aclp__normalize_acltxt (aci_item, str )) == NULL) {
  402. return ACL_SYNTAX_ERR;
  403. }
  404. slapi_log_error(SLAPI_LOG_ACL, plugin_name, "Normalized String:%s\n", newstr, 0,0);
  405. /* check for acl syntax error */
  406. if ((handle = (ACLListHandle_t *) ACL_ParseString(&errp,
  407. newstr)) == NULL) {
  408. acl_print_acllib_err(&errp, str);
  409. slapi_ch_free ( (void **) &newstr );
  410. return ACL_SYNTAX_ERR;
  411. } else {
  412. /* get the rights and the aci type */
  413. aci_item->aci_handle = handle;
  414. nserrDispose(&errp);
  415. slapi_ch_free ( (void **) &newstr );
  416. return 0;
  417. }
  418. }
  419. /******************************************************************************
  420. *
  421. * acl__normalize_acltxt
  422. *
  423. *
  424. * XXXrbyrne this routine should be re-written when someone eventually
  425. * gets sick enough of it. Same for getNextLAS() below.
  426. *
  427. * Normalize the acltxt i.e normalize all the DNs specified in the
  428. * Userdn and Groupdn rule so that we normalize once here and not
  429. * over and over again at the runtime in the LASes. We have to normalize
  430. * before we generate the handle otherwise it's of no use.
  431. * Also convert deny to deny absolute
  432. *
  433. * The string that comes in is something like:
  434. * version 3.0; acl "Dept domain administration"; allow (all)
  435. * groupdn = "ldap:///cn=Domain Administrators, o=$dn.o, o=ISP"; )
  436. *
  437. * Returns NULL on error.
  438. *
  439. ******************************************************************************/
  440. static char *
  441. __aclp__normalize_acltxt ( aci_t * aci_item, char * str )
  442. {
  443. char *s, *p;
  444. char *end;
  445. char *aclstr, *s_aclstr;
  446. char *ret_str = NULL;
  447. int len;
  448. char *ptr, *aclName;
  449. char *nextACE;
  450. char *tmp_str = NULL;
  451. char *acestr = NULL;
  452. char *s_acestr = NULL;
  453. int aci_rights_val = 0; /* bug 389975 */
  454. /* make a copy first */
  455. s_aclstr = aclstr = slapi_ch_strdup ( str );
  456. /* The rules are like this version 3.0; acl "xyz"; rule1; rule2; */
  457. s = strchr (aclstr, ';');
  458. if ( NULL == s) {
  459. slapi_ch_free ( (void **) &s_aclstr );
  460. return NULL;
  461. }
  462. aclstr = ++s;
  463. /* From DS 4.0, we support both aci (or aci) "name" -- we have to change to acl
  464. ** as libaccess will not like it
  465. */
  466. s = aclstr;
  467. while (s && ldap_utf8isspace(s)) LDAP_UTF8INC(s);
  468. *(s+2 ) = 'l';
  469. aclName = s+3;
  470. s = strchr (aclstr, ';');
  471. if ( NULL == s) {
  472. slapi_ch_free ( (void **) &s_aclstr );
  473. return NULL;
  474. }
  475. aclstr = s;
  476. LDAP_UTF8INC(aclstr);
  477. *s = '\0';
  478. /* Here aclName is the acl description string */
  479. aci_item->aclName = slapi_ch_strdup ( aclName );
  480. aclutil_str_appened (&ret_str, s_aclstr);
  481. aclutil_str_appened (&ret_str, ";");
  482. /* start with the string */
  483. acestr = aclstr;
  484. /*
  485. * Here acestr is something like:
  486. *
  487. * " allow (all) groupdn = "ldap:///cn=Domain Administrators, o=$dn.o, o=ISP";)"
  488. *
  489. *
  490. */
  491. normalize_nextACERule:
  492. /* now we are in the rule part */
  493. tmp_str = acestr;
  494. s = strchr (tmp_str, ';');
  495. if ( s == NULL) {
  496. if (ret_str) slapi_ch_free ( (void **) &ret_str );
  497. slapi_ch_free ( (void **) &s_aclstr );
  498. return NULL;
  499. }
  500. nextACE = s;
  501. LDAP_UTF8INC(nextACE);
  502. *s = '\0';
  503. /* acestr now will hold copy of the ACE. Also add
  504. ** some more space in case we need to add "absolute"
  505. ** for deny rule. We will never need more 2 times
  506. ** the len.
  507. */
  508. len = strlen (tmp_str);
  509. s_acestr = acestr = slapi_ch_calloc ( 1, 2 * len);
  510. __acl_strip_leading_space(&tmp_str);
  511. /*
  512. * Now it's something like:
  513. * allow (all) groupdn = "ldap:///cn=Domain Administrators, o=$dn.o, o=ISP";
  514. */
  515. if (strncasecmp(tmp_str, "allow", 5) == 0) {
  516. memcpy(acestr, tmp_str, len);
  517. tmp_str += 5;
  518. /* gather the rights */
  519. aci_rights_val = __aclp__get_aci_right (tmp_str);/* bug 389975 */
  520. aci_item->aci_type |= ACI_HAS_ALLOW_RULE;
  521. } else if (strncasecmp(tmp_str, "deny", 4) == 0) {
  522. char *d_rule ="deny absolute";
  523. /* Then we have to add "absolute" to the deny rule
  524. ** What we are doing here is to tackle this situation.
  525. **
  526. ** allow -- deny -- allow
  527. ** deny -- allow
  528. **
  529. ** by using deny absolute we force the precedence rule
  530. ** i.e deny has a precedence over allow. Since there doesn't
  531. ** seem to be an easy to detect the mix, forcing this
  532. ** to all the deny rules will do the job.
  533. */
  534. __acl_strip_leading_space(&tmp_str);
  535. tmp_str += 4;
  536. /* We might have an absolute there already */
  537. if ((s = strstr (tmp_str, "absolute")) != NULL) {
  538. tmp_str = s;
  539. tmp_str += 8;
  540. }
  541. /* gather the rights */
  542. aci_rights_val = __aclp__get_aci_right (tmp_str);/* bug 389975 */
  543. aci_item->aci_type |= ACI_HAS_DENY_RULE;
  544. len = strlen ( d_rule );
  545. memcpy (acestr, d_rule, len );
  546. memcpy (acestr+len, tmp_str, strlen (tmp_str) );
  547. } else {
  548. /* wrong syntax */
  549. aci_rights_val = -1 ;
  550. }
  551. if (aci_rights_val == -1 )
  552. {
  553. /* wrong syntax */
  554. slapi_ch_free ( (void **) &ret_str );
  555. slapi_ch_free ( (void **) &s_acestr );
  556. slapi_ch_free ( (void **) &s_aclstr );
  557. return NULL;
  558. } else
  559. aci_item->aci_access |= aci_rights_val;
  560. /* Normalize all the DNs in the userdn rule */
  561. /*
  562. *
  563. * Here acestr starts like this:
  564. * " allow (all) groupdn = "ldap:///cn=Domain Administrators, o=$dn.o, o=ISP"
  565. */
  566. s = __aclp__getNextLASRule(aci_item, acestr, &end);
  567. while ( s ) {
  568. if ( 0 == strncmp ( s, DS_LAS_USERDNATTR, 10) ||
  569. ( 0 == strncmp ( s, DS_LAS_USERATTR, 8))) {
  570. /*
  571. ** For userdnattr/userattr rule, the resources changes and hence
  572. ** we cannot cache the result. See above for more comments.
  573. */
  574. aci_item->aci_elevel = ACI_ELEVEL_USERDNATTR;
  575. } else if ( 0== strncmp ( s, DS_LAS_USERDN, 6)) {
  576. p = strstr ( s, "=");
  577. p--;
  578. if ( strncmp (p, "!=", 2) == 0)
  579. aci_item->aci_type |= ACI_CONTAIN_NOT_USERDN;
  580. /* XXXrbyrne
  581. * Here we need to scan for more ldap:/// within
  582. * this userdn rule type:
  583. * eg. userdn = "ldap:///cn=joe,o=sun.com || ldap:///self"
  584. * This is handled correctly in DS_LASUserDnEval
  585. * but the bug here is not setting ACI_USERDN_SELFRULE
  586. * which would ensure that acl info is not cached from
  587. * one resource entry to the next. (bug 558519)
  588. */
  589. p = strstr ( p, "ldap");
  590. if (p == NULL) {
  591. /* must start with ldap */
  592. if (s_acestr) slapi_ch_free ( (void **) &s_acestr );
  593. if (ret_str) slapi_ch_free ( (void **) &ret_str );
  594. slapi_ch_free ( (void **) &s_aclstr );
  595. return (NULL);
  596. }
  597. p += 8; /* for ldap:/// */
  598. if( __aclp__dn_normalize (p, end) == NULL) {
  599. if (s_acestr) slapi_ch_free ( (void **) &s_acestr );
  600. if (ret_str) slapi_ch_free ( (void **) &ret_str );
  601. slapi_ch_free ( (void **) &s_aclstr );
  602. return (NULL);
  603. }
  604. /* we have a rule like userdn = "ldap:///blah". s points to blah now.
  605. ** let's find if we have a SELF rule like userdn = "ldap:///self".
  606. ** Since the resource changes on entry basis, we can't cache the
  607. ** evalation of handle for all time. The cache result is valid
  608. ** within the evaluation of that resource.
  609. */
  610. if (strncasecmp(p, "self", 4) == 0) {
  611. aci_item->aci_ruleType |= ACI_USERDN_SELFRULE;
  612. } else if ( strncasecmp(p, "anyone", 6) == 0 ) {
  613. aci_item->aci_elevel = ACI_ELEVEL_USERDN_ANYONE;
  614. } else if ( strncasecmp(p, "all", 3) == 0 ) {
  615. if ( aci_item->aci_elevel > ACI_ELEVEL_USERDN_ALL )
  616. aci_item->aci_elevel = ACI_ELEVEL_USERDN_ALL;
  617. } else {
  618. if ( aci_item->aci_elevel > ACI_ELEVEL_USERDN )
  619. aci_item->aci_elevel = ACI_ELEVEL_USERDN;
  620. }
  621. /* See if we have a parameterized rule */
  622. __aclp_chk_paramRules ( aci_item, p, end );
  623. } else if ( 0 == strncmp ( s, DS_LAS_GROUPDNATTR, 11)) {
  624. /*
  625. ** For groupdnattr rule, the resources changes and hence
  626. ** we cannot cache the result. See above for more comments.
  627. */
  628. /* Find out if we have a URL type of rule */
  629. if ((p= strstr (s, "ldap")) != NULL) {
  630. if ( aci_item->aci_elevel > ACI_ELEVEL_GROUPDNATTR_URL )
  631. aci_item->aci_elevel = ACI_ELEVEL_GROUPDNATTR_URL;
  632. } else if ( aci_item->aci_elevel > ACI_ELEVEL_GROUPDNATTR ) {
  633. aci_item->aci_elevel = ACI_ELEVEL_GROUPDNATTR;
  634. }
  635. aci_item->aci_ruleType |= ACI_GROUPDNATTR_RULE;
  636. } else if ( 0 == strncmp ( s, DS_LAS_GROUPDN, 7)) {
  637. p = strstr ( s, "=");
  638. p--;
  639. if ( strncmp (p, "!=", 2) == 0)
  640. aci_item->aci_type |= ACI_CONTAIN_NOT_GROUPDN;
  641. p = strstr ( s, "ldap");
  642. if (p == NULL) {
  643. /* must start with ldap */
  644. if (s_acestr) slapi_ch_free ( (void **) &s_acestr );
  645. if (ret_str) slapi_ch_free ( (void **) &ret_str );
  646. slapi_ch_free ( (void **) &s_aclstr );
  647. return (NULL);
  648. }
  649. p += 8;
  650. if (__aclp__dn_normalize (p, end) == NULL) {
  651. if (s_acestr) slapi_ch_free ( (void **) &s_acestr );
  652. if (ret_str) slapi_ch_free ( (void **) &ret_str );
  653. slapi_ch_free ( (void **) &s_aclstr );
  654. return (NULL);
  655. }
  656. /* check for param rules */
  657. __aclp_chk_paramRules ( aci_item, p, end );
  658. if ( aci_item->aci_elevel > ACI_ELEVEL_GROUPDN )
  659. aci_item->aci_elevel = ACI_ELEVEL_GROUPDN;
  660. aci_item->aci_ruleType |= ACI_GROUPDN_RULE;
  661. } else if ( 0 == strncmp ( s, DS_LAS_ROLEDN, 6)) {
  662. p = strstr ( s, "=");
  663. p--;
  664. if ( strncmp (p, "!=", 2) == 0)
  665. aci_item->aci_type |= ACI_CONTAIN_NOT_ROLEDN;
  666. p = strstr ( s, "ldap");
  667. if (p == NULL) {
  668. /* must start with ldap */
  669. if (s_acestr) slapi_ch_free ( (void **) &s_acestr );
  670. if (ret_str) slapi_ch_free ( (void **) &ret_str );
  671. slapi_ch_free ( (void **) &s_aclstr );
  672. return (NULL);
  673. }
  674. p += 8;
  675. if (__aclp__dn_normalize (p, end) == NULL) {
  676. if (s_acestr) slapi_ch_free ( (void **) &s_acestr );
  677. if (ret_str) slapi_ch_free ( (void **) &ret_str );
  678. slapi_ch_free ( (void **) &s_aclstr );
  679. return (NULL);
  680. }
  681. /* check for param rules */
  682. __aclp_chk_paramRules ( aci_item, p, end );
  683. /* XXX need this for roledn ?
  684. if ( aci_item->aci_elevel > ACI_ELEVEL_GROUPDN )
  685. aci_item->aci_elevel = ACI_ELEVEL_GROUPDN;*/
  686. aci_item->aci_ruleType |= ACI_ROLEDN_RULE;
  687. }
  688. s = ++end;
  689. s = __aclp__getNextLASRule(aci_item, s, &end);
  690. }/* while */
  691. /* get the head of the string */
  692. acestr = s_acestr;
  693. len = strlen( acestr);
  694. ptr = acestr +len-1;
  695. while (*ptr && *ptr != '\"' && *ptr != ')' ) *ptr-- = ' ';
  696. ptr++;
  697. *ptr = ';';
  698. aclutil_str_appened (&ret_str, acestr);
  699. if (s_acestr) {
  700. slapi_ch_free ( (void **) &s_acestr );
  701. }
  702. s_acestr = NULL;
  703. if (nextACE) {
  704. s = strstr (nextACE, "allow");
  705. if (s == NULL) s = strstr (nextACE, "deny");
  706. if (s == NULL) {
  707. if (nextACE && *nextACE != '\0')
  708. aclutil_str_appened (&ret_str, nextACE);
  709. slapi_ch_free ( (void **) &s_aclstr );
  710. return (ret_str);
  711. }
  712. acestr = nextACE;
  713. goto normalize_nextACERule;
  714. }
  715. slapi_ch_free ( (void **) &s_aclstr );
  716. return (ret_str);
  717. }
  718. /*
  719. *
  720. * acl__getNextLASRule
  721. * Find the next rule.
  722. *
  723. * Returns:
  724. * endOfCurrRule - end of current rule
  725. * nextRule - start of next rule
  726. */
  727. static char *
  728. __aclp__getNextLASRule (aci_t *aci_item, char *original_str , char **endOfCurrRule)
  729. {
  730. char *newstr, *word, *next, *start, *end;
  731. char *ruleStart = NULL;
  732. int len, ruleLen;
  733. int in_dn_expr = 0;
  734. *endOfCurrRule = NULL;
  735. end = start = NULL;
  736. newstr = slapi_ch_strdup (original_str);
  737. if ( (strncasecmp(newstr, "allow", 5) == 0) ||
  738. (strncasecmp(newstr, "deny", 4) == 0) ) {
  739. word = ldap_utf8strtok_r(newstr, ")", &next);
  740. }
  741. else {
  742. word = ldap_utf8strtok_r(newstr, " ", &next);
  743. }
  744. /*
  745. * The first word is of no interest -- skip it
  746. * it's allow or deny followed by the rights (<rights>),
  747. * so skip over the rights as well or it's 'and', 'or',....
  748. */
  749. while ( (word = ldap_utf8strtok_r(NULL, " ", &next)) != NULL) {
  750. int got_rule = 0;
  751. int ruleType = 0;
  752. /*
  753. ** The next word must be one of these to be considered
  754. ** a valid rule.
  755. ** This is making me crazy. We might have a case like
  756. ** "((userdn=". strtok is returning me that word.
  757. */
  758. len = strlen ( word );
  759. word [len] = '\0';
  760. if ( (ruleStart= strstr(word, DS_LAS_USERDNATTR)) != NULL) {
  761. ruleType |= ACI_USERDNATTR_RULE;
  762. ruleLen = strlen ( DS_LAS_USERDNATTR) ;
  763. } else if ( (ruleStart = strstr(word, DS_LAS_USERDN)) != NULL) {
  764. ruleType = ACI_USERDN_RULE;
  765. ruleLen = strlen ( DS_LAS_USERDN);
  766. in_dn_expr = 1;
  767. } else if ( (ruleStart = strstr(word, DS_LAS_GROUPDNATTR)) != NULL) {
  768. ruleType = ACI_GROUPDNATTR_RULE;
  769. ruleLen = strlen ( DS_LAS_GROUPDNATTR) ;
  770. } else if ((ruleStart= strstr(word, DS_LAS_GROUPDN)) != NULL) {
  771. ruleType = ACI_GROUPDN_RULE;
  772. ruleLen = strlen ( DS_LAS_GROUPDN) ;
  773. in_dn_expr = 1;
  774. } else if ((ruleStart = strstr(word, DS_LAS_USERATTR)) != NULL) {
  775. ruleType = ACI_USERATTR_RULE;
  776. ruleLen = strlen ( DS_LAS_USERATTR) ;
  777. } else if ((ruleStart= strstr(word, DS_LAS_ROLEDN)) != NULL) {
  778. ruleType = ACI_ROLEDN_RULE;
  779. ruleLen = strlen ( DS_LAS_ROLEDN);
  780. in_dn_expr = 1;
  781. } else if ((ruleStart= strstr(word, DS_LAS_AUTHMETHOD)) != NULL) {
  782. ruleType = ACI_AUTHMETHOD_RULE;
  783. ruleLen = strlen ( DS_LAS_AUTHMETHOD);
  784. } else if ((ruleStart = strstr(word, ACL_ATTR_IP)) != NULL) {
  785. ruleType = ACI_IP_RULE;
  786. ruleLen = strlen ( ACL_ATTR_IP) ;
  787. } else if ((ruleStart = strstr(word, DS_LAS_TIMEOFDAY)) != NULL) {
  788. ruleType = ACI_TIMEOFDAY_RULE;
  789. ruleLen = strlen ( DS_LAS_TIMEOFDAY) ;
  790. } else if ((ruleStart = strstr(word, DS_LAS_DAYOFWEEK)) != NULL) {
  791. ruleType = ACI_DAYOFWEEK_RULE;
  792. ruleLen = strlen ( DS_LAS_DAYOFWEEK) ;
  793. } else if ((ruleStart = strstr(word, ACL_ATTR_DNS)) != NULL) {
  794. ruleType = ACI_DNS_RULE;
  795. ruleLen = strlen ( ACL_ATTR_DNS) ;
  796. }
  797. /* Here, we've found a space...if we were in in_dn_expr mode
  798. * and we'vve found a closure for that ie.a '"' or a ')'
  799. * eg. "'ldap:///all"' or 'ldap:///all")' then exit in_dn_expr mode.
  800. */
  801. if ( in_dn_expr && (word[len-1] == '"' ||
  802. len>1 && word[len-2] == '"' ||
  803. len>2 && word[len-3] == '"')) {
  804. in_dn_expr = 0;
  805. }
  806. /*
  807. * ruleStart may be NULL as word could be (all) for example.
  808. * this word will just be skipped--we're really waiting for
  809. * userdn or groupdn or...
  810. */
  811. if ( ruleStart && ruleType ) {
  812. /* Look in the current word for "=" or else look into
  813. ** the next word -- if none of them are true, then this
  814. ** is not the start of the rule
  815. */
  816. char *tmpStr = ruleStart + ruleLen;
  817. if ( strchr ( tmpStr, '=') ||
  818. ((word = ldap_utf8strtok_r(NULL, " ", &next) ) &&
  819. word && ((strncmp ( word, "=", 1) == 0 ) ||
  820. (strncmp ( word, "!=",2) ==0) ||
  821. (strncmp ( word, ">", 1) == 0 ) ||
  822. (strncmp ( word, "<", 1) == 0 ) ||
  823. (strncmp ( word, "<", 1) == 0 ) ||
  824. (strncmp ( word, "<=",2) ==0 ) ||
  825. (strncmp ( word, ">=",2) ==0) ||
  826. (strncmp ( word, "=>",2) ==0) ||
  827. (strncmp ( word, "=<",2) ==0))
  828. ) ){
  829. aci_item->aci_ruleType |= ruleType;
  830. got_rule = 1;
  831. }
  832. }
  833. if ( NULL == start && got_rule ) {
  834. /*
  835. * We've just found a rule start--keep going though because
  836. * we need to return the end of this rule too.
  837. */
  838. start= ruleStart;
  839. got_rule = 0;
  840. } else {
  841. /*
  842. * Here, we have a candidate for the end of the rule we've found
  843. * (the start of which is currently in start).
  844. * But we need to be sure it really is the end and not a
  845. * "fake end" due to a keyword bbeing embeded in a dn.
  846. */
  847. if (word && !in_dn_expr &&
  848. ((strcasecmp(word, "and") == 0) ||
  849. (strcasecmp(word, "or") == 0) ||
  850. (strcasecmp(word, "not") == 0) ||
  851. (strcasecmp(word, ";") == 0))) {
  852. /* If we have start, then it really is the end */
  853. word--;
  854. if (start) {
  855. end = word;
  856. break;
  857. } else {
  858. /* We found a fake end, but we've no start so keep going */
  859. }
  860. }
  861. }
  862. } /* while */
  863. if ( end ) {
  864. /* Found an end to the rule and it's not the last rule */
  865. len = end - newstr;
  866. end = original_str +len;
  867. while ( (end != original_str) && *end != '\"') end--;
  868. *endOfCurrRule = end;
  869. len = start - newstr;
  870. ruleStart = original_str + len;
  871. } else {
  872. /* Walked off the end of the string so it's the last rule */
  873. end = original_str + strlen(original_str)-1;
  874. while ( (end != original_str) && *end != '\"') end--;
  875. *endOfCurrRule = end;
  876. }
  877. if ( start ) {
  878. /* Got a rule, fixup the pointer */
  879. len = start - newstr;
  880. ruleStart = original_str + len;
  881. }
  882. slapi_ch_free ( (void **) &newstr );
  883. /*
  884. * Here, ruleStart points to the start of the next rule in original_str.
  885. * end points to the end of this rule.
  886. */
  887. return ( ruleStart );
  888. }
  889. /******************************************************************************
  890. *
  891. * __aclp__dn_normalize
  892. *
  893. * Normalize the DN INPLACE. This routine is similar to slapi_dn_normalize()
  894. * except various small stuff at the end.
  895. * Normalize until the "end" and not to the end of string.
  896. *
  897. ******************************************************************************/
  898. static char *
  899. __aclp__dn_normalize( char *dn , char *end)
  900. {
  901. char *d;
  902. if ((end - dn) < 0) {
  903. return(NULL);
  904. }
  905. d = slapi_dn_normalize_to_end ( dn, end );
  906. /* Do I have the quotes already */
  907. if (*d != '\"' ) {
  908. /*
  909. ** We are taking care of this situation
  910. ** " ") ". We need to remove the space
  911. ** infront and tack it after the quote like this.
  912. ** "" ) ".
  913. */
  914. *d = '\"';
  915. d++;
  916. while (*d && *d != '\"') *d++ = ' ';
  917. *d = ' ';
  918. }
  919. return( dn );
  920. }
  921. /***************************************************************************
  922. * acl__get_aci_right
  923. *
  924. * Go thru the one acl text str and figure our the rights declared.
  925. *
  926. *****************************************************************************/
  927. static int
  928. __aclp__get_aci_right (char *str)
  929. {
  930. char *sav_str = slapi_ch_strdup(str);
  931. char *t, *tt;
  932. int type = 0;
  933. char *delimiter = ",";
  934. char *val = NULL;
  935. int aclval = 0;
  936. t = sav_str;
  937. __acl_strip_leading_space( &t );
  938. if (*t == '(' ) {
  939. if ((tt = slapi_find_matching_paren(t)) == NULL) {
  940. slapi_ch_free ( (void **) &sav_str );
  941. return -1;
  942. } else {
  943. t++; /* skip the first character which is ( */
  944. *tt = '\0';
  945. }
  946. } else {
  947. slapi_ch_free ( (void **) &sav_str );
  948. return -1;
  949. }
  950. /* get the tokens separated by "," */
  951. val = ldap_utf8strtok_r(t,delimiter, &tt);
  952. if (val == NULL )
  953. {
  954. slapi_ch_free ( (void **) &sav_str );
  955. return -1;
  956. }
  957. while (val != NULL)
  958. {
  959. /* get the corresponding integer value */
  960. aclval = get_acl_rights_as_int(val);
  961. if (aclval == -1 )
  962. {
  963. type = -1;
  964. break;
  965. }
  966. type |= aclval;
  967. val = ldap_utf8strtok_r(NULL,delimiter, &tt); /* get the next token */
  968. }
  969. slapi_ch_free ( (void **) &sav_str );
  970. return type;
  971. }
  972. static int get_acl_rights_as_int( char * strValue)
  973. {
  974. if (strValue == NULL )
  975. return -1;
  976. /* First strip out the leading and trailing spaces */
  977. __acl_strip_leading_space( &strValue );
  978. __acl_strip_trailing_space( strValue );
  979. /* We have to do a strcasecmp (case insensitive cmp) becuase we should return
  980. only if it is exact match. */
  981. if (strcasecmp (strValue, "read") == 0 )
  982. return SLAPI_ACL_READ;
  983. else if (strcasecmp (strValue, "write") == 0 )
  984. return SLAPI_ACL_WRITE;
  985. else if (strcasecmp (strValue, "search") == 0 )
  986. return SLAPI_ACL_SEARCH;
  987. else if (strcasecmp (strValue, "compare") == 0 )
  988. return SLAPI_ACL_COMPARE;
  989. else if (strcasecmp (strValue, "add") == 0 )
  990. return SLAPI_ACL_ADD;
  991. else if (strcasecmp (strValue, "delete") == 0 )
  992. return SLAPI_ACL_DELETE;
  993. else if (strcasecmp (strValue, "proxy") == 0 )
  994. return SLAPI_ACL_PROXY;
  995. else if (strcasecmp (strValue, "selfwrite") == 0 )
  996. return (SLAPI_ACL_SELF | SLAPI_ACL_WRITE);
  997. else if (strcasecmp (strValue, "all") == 0 )
  998. return SLAPI_ACL_ALL;
  999. else
  1000. return -1; /* error */
  1001. }
  1002. /***************************************************************************
  1003. *
  1004. * acl_access2str
  1005. *
  1006. * Convert the access bits into character strings.
  1007. * Example: "read, self read"
  1008. *
  1009. * Input:
  1010. *
  1011. * int access - The access in bits
  1012. * char **rights - rights in chars
  1013. *
  1014. * Returns:
  1015. * NULL - No rights to start with
  1016. * right - rights converted.
  1017. *
  1018. * Error Handling:
  1019. * None.
  1020. *
  1021. **************************************************************************/
  1022. char *
  1023. acl_access2str(int access)
  1024. {
  1025. if ( access & SLAPI_ACL_COMPARE ) {
  1026. return access_str_compare;
  1027. } else if ( access & SLAPI_ACL_SEARCH ) {
  1028. return access_str_search;
  1029. } else if ( access & SLAPI_ACL_READ ) {
  1030. return access_str_read;
  1031. } else if ( access & SLAPI_ACL_DELETE) {
  1032. return access_str_delete;
  1033. } else if ( access & SLAPI_ACL_ADD) {
  1034. return access_str_add;
  1035. } else if ( (access & SLAPI_ACL_WRITE ) && (access & SLAPI_ACL_SELF)) {
  1036. return access_str_selfwrite;
  1037. } else if (access & SLAPI_ACL_WRITE ) {
  1038. return access_str_write;
  1039. } else if (access & SLAPI_ACL_PROXY ) {
  1040. return access_str_proxy;
  1041. }
  1042. return NULL;
  1043. }
  1044. /***************************************************************************
  1045. *
  1046. * __aclp__init_targetattr
  1047. *
  1048. * Parse the targetattr string and create a array of attrs. This will
  1049. * help us to do evaluation at run time little faster.
  1050. * entry.
  1051. * Here, also extract any target value filters.
  1052. *
  1053. * Input:
  1054. * aci_t *aci -- The aci item
  1055. * char *str -- the targetattr string
  1056. *
  1057. * Returns:
  1058. * ACL_OK - everything ok
  1059. * ACL_SYNTAX_ERROR - in case of error.
  1060. *
  1061. *
  1062. ***************************************************************************/
  1063. static int
  1064. __aclp__init_targetattr (aci_t *aci, char *attr_val)
  1065. {
  1066. int numattr=0;
  1067. Targetattr **attrArray;
  1068. char *s, *end_attr, *str;
  1069. int len;
  1070. Targetattr *attr = NULL;
  1071. s = strchr (attr_val, '=');
  1072. s++;
  1073. __acl_strip_leading_space(&s);
  1074. len = strlen(s);
  1075. if (*s == '"' && s[len-1] == '"') {
  1076. s[len-1] = '\0';
  1077. s++;
  1078. }
  1079. str = s;
  1080. attrArray = aci->targetAttr;
  1081. if (attrArray[0] != NULL) {
  1082. /*
  1083. ** That means we are visiting more than once.
  1084. ** Syntax error. We have a case like: (targetattr) (targetattr)
  1085. */
  1086. return ACL_SYNTAX_ERR;
  1087. }
  1088. while (str != 0 && *str != 0) {
  1089. __acl_strip_leading_space(&str);
  1090. if ((end_attr = strstr(str, "||")) != NULL) {
  1091. /* skip the two '|' chars */
  1092. auto char *t = end_attr;
  1093. LDAP_UTF8INC(end_attr);
  1094. LDAP_UTF8INC(end_attr);
  1095. *t = 0;
  1096. }
  1097. __acl_strip_trailing_space(str);
  1098. /*
  1099. * Here:
  1100. * end_attr points to the next attribute thing.
  1101. *
  1102. * str points to the current one to be processed and it looks like this:
  1103. * rbyrneXXX Watchout is it OK to use : as the speperator ?
  1104. * cn
  1105. * c*n*
  1106. * *
  1107. * The attribute goes in the attrTarget list.
  1108. *
  1109. */
  1110. attr = (Targetattr *) slapi_ch_malloc (sizeof (Targetattr));
  1111. memset (attr, 0, sizeof(Targetattr));
  1112. if (strchr(str, '*')) {
  1113. /* It contains a * so it's something like * or cn* */
  1114. if (strcmp(str, "*" ) != 0) {
  1115. char line[100];
  1116. char *lineptr = &line[0];
  1117. char *newline = NULL;
  1118. int lenstr = 0;
  1119. struct slapi_filter *f = NULL;
  1120. if ((lenstr = strlen(str)) > 91) { /* 100 - 8 for "(attr =%s)" */
  1121. newline = slapi_ch_malloc(lenstr + 9);
  1122. lineptr = newline;
  1123. }
  1124. attr->attr_type = ACL_ATTR_FILTER;
  1125. sprintf (lineptr, "(attr =%s)", str);
  1126. f = slapi_str2filter (lineptr);
  1127. if (f == NULL) {
  1128. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  1129. "__aclp__init_targetattr:Unable to generate filter (%s)\n", lineptr,0,0);
  1130. } else {
  1131. attr->u.attr_filter = f;
  1132. }
  1133. if (newline) slapi_ch_free((void **) &newline);
  1134. } else {
  1135. attr->attr_type = ACL_ATTR_STAR;
  1136. attr->u.attr_str = slapi_ch_strdup (str);
  1137. }
  1138. } else {
  1139. attr->u.attr_str = slapi_ch_strdup (str);
  1140. attr->attr_type = ACL_ATTR_STRING;
  1141. }
  1142. /*
  1143. * Add the attr to the targetAttr list
  1144. */
  1145. attrArray[numattr] = attr;
  1146. numattr++;
  1147. if (!(numattr % ACL_INIT_ATTR_ARRAY)) {
  1148. aci->targetAttr = (Targetattr **) slapi_ch_realloc (
  1149. (void *) aci->targetAttr,
  1150. (numattr+ACL_INIT_ATTR_ARRAY) *
  1151. sizeof(Targetattr *));
  1152. attrArray = aci->targetAttr;
  1153. }
  1154. /* Move on to the next attribute in the list */
  1155. str = end_attr;
  1156. } /* while */
  1157. /* NULL teminate the list */
  1158. attrArray[numattr] = NULL;
  1159. return 0;
  1160. }
  1161. void
  1162. acl_strcpy_special (char *d, char *s)
  1163. {
  1164. for (; *s; LDAP_UTF8INC(s)) {
  1165. switch (*s) {
  1166. case '.':
  1167. case '\\':
  1168. case '[':
  1169. case ']':
  1170. case '*':
  1171. case '+':
  1172. case '^':
  1173. case '$':
  1174. *d = '\\';
  1175. LDAP_UTF8INC(d);
  1176. /* FALL */
  1177. default:
  1178. d += LDAP_UTF8COPY(d, s);
  1179. }
  1180. }
  1181. *d = '\0';
  1182. }
  1183. /***************************************************************************
  1184. *
  1185. * acl_verify_aci_syntax
  1186. * verify if the aci's being added for the entry has a valid syntax or not.
  1187. *
  1188. * Input:
  1189. * Slapi_Entry *e - The Slapi_Entry itself
  1190. * char **errbuf; -- error message
  1191. *
  1192. * Returns:
  1193. * -1 (ACL_ERR) - Syntax error
  1194. * 0 - No error
  1195. *
  1196. * Error Handling:
  1197. * None.
  1198. *
  1199. **************************************************************************/
  1200. int
  1201. acl_verify_aci_syntax (Slapi_Entry *e, char **errbuf)
  1202. {
  1203. if (e != NULL) {
  1204. Slapi_DN *e_sdn;
  1205. int rv;
  1206. Slapi_Attr *attr = NULL;
  1207. Slapi_Value *sval=NULL;
  1208. const struct berval *attrVal;
  1209. int i;
  1210. e_sdn = slapi_entry_get_sdn ( e );
  1211. slapi_entry_attr_find (e, aci_attr_type, &attr);
  1212. if (! attr ) return 0;
  1213. i= slapi_attr_first_value ( attr,&sval );
  1214. while ( i != -1 ) {
  1215. attrVal = slapi_value_get_berval ( sval );
  1216. rv=acl_verify_syntax ( e_sdn, attrVal);
  1217. if ( 0 != rv ) {
  1218. aclutil_print_err(rv, e_sdn, attrVal, errbuf);
  1219. return ACL_ERR;
  1220. }
  1221. i = slapi_attr_next_value ( attr, i, &sval );
  1222. }
  1223. }
  1224. return(0);
  1225. }
  1226. /***************************************************************************
  1227. *
  1228. * acl__verify_syntax
  1229. * Called from slapi_acl_check_mods() to verify if the new aci being
  1230. * added/replaced has the right syntax or not.
  1231. *
  1232. * Input:
  1233. * Slapi_DN *e_sdn - sdn of the entry
  1234. * berval *bval - The berval containg the aci value
  1235. *
  1236. * Returns:
  1237. * return values from acl__parse_aci()
  1238. *
  1239. * Error Handling:
  1240. * None.
  1241. *
  1242. **************************************************************************/
  1243. int
  1244. acl_verify_syntax(const Slapi_DN *e_sdn, const struct berval *bval)
  1245. {
  1246. aci_t *aci_item;
  1247. int rv = 0;
  1248. char *str;
  1249. aci_item = acllist_get_aci_new ();
  1250. slapi_sdn_set_ndn_byval ( aci_item->aci_sdn, slapi_sdn_get_ndn ( e_sdn ) );
  1251. /* make a copy the the string */
  1252. str = slapi_ch_strdup(bval->bv_val);
  1253. rv = acl_parse(str, aci_item);
  1254. /* cleanup before you leave ... */
  1255. acllist_free_aci (aci_item);
  1256. slapi_ch_free ( (void **) &str );
  1257. return(rv);
  1258. }
  1259. static void
  1260. __aclp_chk_paramRules ( aci_t *aci_item, char *start, char *end)
  1261. {
  1262. size_t len;
  1263. char *str;
  1264. char *p, *s;
  1265. len = end - start;
  1266. s = str = (char *) slapi_ch_calloc(1, len + 1);
  1267. memcpy ( str, start, len);
  1268. while ( (p= strchr ( s, '$')) != NULL) {
  1269. p++; /* skip the $ */
  1270. if ( 0 == strncasecmp ( p, "dn", 2))
  1271. aci_item->aci_ruleType |= ACI_PARAM_DNRULE;
  1272. else if ( 0 == strncasecmp ( p, "attr", 4))
  1273. aci_item->aci_ruleType |= ACI_PARAM_ATTRRULE;
  1274. s = p;
  1275. }
  1276. slapi_ch_free ( (void **) &str );
  1277. }
  1278. /*
  1279. * Check for an ocurrence of a macro aci in the target.
  1280. * value is the normalized target string.
  1281. *
  1282. * this is something like:
  1283. * (target="ldap:///cn=*,ou=people,($dn),o=sun.com")
  1284. *
  1285. *
  1286. * returns 1 if there is a $dn present.
  1287. * returns 0 if not.
  1288. * returns -1 is syntax error.
  1289. * If succes then:
  1290. * ACI_TARGET_MACRO_DN is the type.
  1291. * type can also include, ACI_TARGET_PATTERN, ACI_TARGET_NOT.
  1292. * Also aci_item->aci_macro->match_this is set to be
  1293. * cn=*,ou=people,($dn),o=sun.com, to be used later.
  1294. *
  1295. * . we allow at most one ($dn) in a target.
  1296. * . if a "*" accurs with it, it must be the first component and at most
  1297. * once.
  1298. * . it's ok for ($dn) to occur on it's own in a target, but if it appears in
  1299. * a user rule, then it must be in the target.
  1300. *
  1301. *
  1302. *
  1303. */
  1304. static int
  1305. acl_check_for_target_macro( aci_t *aci_item, char *value)
  1306. {
  1307. char *str = NULL;
  1308. str = strstr( value, ACL_TARGET_MACRO_DN_KEY);
  1309. if (str != NULL) {
  1310. aci_item->aci_type &= ~ACI_TARGET_DN;
  1311. aci_item->aci_type |= ACI_TARGET_MACRO_DN;
  1312. aci_item->aci_macro = (aciMacro *)slapi_ch_malloc(sizeof(aciMacro));
  1313. aci_item->aci_macro->match_this = slapi_ch_strdup(value);
  1314. aci_item->aci_macro->macro_ptr = strstr( aci_item->aci_macro->match_this,
  1315. ACL_TARGET_MACRO_DN_KEY);
  1316. return(1);
  1317. }
  1318. return(0);
  1319. }
  1320. /* Strip trailing spaces from str by writing '\0' into them */
  1321. static void
  1322. __acl_strip_trailing_space( char *str) {
  1323. char *ptr = NULL;
  1324. int len = 0;
  1325. if (*str) {
  1326. /* ignore trailing whitespace */
  1327. len = strlen(str);
  1328. ptr = str+len-1;
  1329. while(ldap_utf8isspace(ptr)){ *ptr = '\0'; LDAP_UTF8DEC(ptr); }
  1330. }
  1331. }
  1332. /*
  1333. * Strip leading spaces by resetting str to point to the first
  1334. * non-space charater.
  1335. */
  1336. static void
  1337. __acl_strip_leading_space( char **str) {
  1338. char *tmp_ptr = NULL;
  1339. tmp_ptr = *str;
  1340. while ( *tmp_ptr && ldap_utf8isspace( tmp_ptr ) ) LDAP_UTF8INC(tmp_ptr);
  1341. *str = tmp_ptr;
  1342. }
  1343. /*
  1344. * str is a string containing an LDAP filter.
  1345. * Trim off enclosing quotes and enclosing
  1346. * superfluous brackets.
  1347. * The result is duped so it can be kept.
  1348. */
  1349. static char *
  1350. __acl_trim_filterstr( char * str ) {
  1351. char *tmpstr;
  1352. int len;
  1353. char *end;
  1354. tmpstr = str;
  1355. /* If the last char is a "," take it out */
  1356. len = strlen (tmpstr);
  1357. if (len>0 && (tmpstr[len-1] == ',')) {
  1358. tmpstr [len-1] = '\0';
  1359. }
  1360. /* Does it have quotes around it */
  1361. len = strlen (tmpstr);
  1362. if (*tmpstr == '"' && tmpstr[len-1] == '"') {
  1363. tmpstr [len-1] = '\0';
  1364. tmpstr++;
  1365. }
  1366. str = tmpstr;
  1367. /* If we have a filter like
  1368. ** (((&(...) (...)))), we need to get rid of the
  1369. ** multiple parens or slapi_str2filter will not
  1370. ** evaluate properly. Need to package like
  1371. ** (filter ). probably I should fix str2filter
  1372. ** code.
  1373. */
  1374. while (*tmpstr++ == '(' && *tmpstr == '(') {
  1375. if ((end = slapi_find_matching_paren( str )) != NULL) {
  1376. *end = '\0';
  1377. str++;
  1378. }
  1379. }
  1380. return( slapi_ch_strdup(str));
  1381. }
  1382. /*
  1383. * Here str points to a targetattrfilters thing which looks tlike this:
  1384. *
  1385. * targetattrfilters="add=attr1:F1 && attr2:F2 ... && attrn:Fn,
  1386. * del=attr1:F1 && attr2:F2... && attrn:Fn")
  1387. *
  1388. *
  1389. */
  1390. static int __acl__init_targetattrfilters( aci_t *aci, char *input_str) {
  1391. int numattr=0;
  1392. char *s, *str;
  1393. int len;
  1394. char *addlistptr = NULL;
  1395. char *dellistptr = NULL;
  1396. if (aci->targetAttrAddFilters != NULL ||
  1397. aci->targetAttrDelFilters != NULL) {
  1398. /*
  1399. ** That means we are visiting more than once.
  1400. ** Syntax error.
  1401. ** We have a case like: (targetattrfilters) (targetattrfilters)
  1402. */
  1403. return ACL_SYNTAX_ERR;
  1404. }
  1405. /* First, skip the "targetattrfilters" */
  1406. s = strchr (input_str, '=');
  1407. s++; /* skip the = */
  1408. __acl_strip_leading_space(&s); /* skip to next significant character */
  1409. len = strlen(s); /* Knock off the " and trailing ) */
  1410. if (*s == '"' && s[len-1] == '"') {
  1411. s[len-1] = '\0';
  1412. s++; /* skip the first " */
  1413. } else { /* No matching quotes */
  1414. return (ACL_SYNTAX_ERR);
  1415. }
  1416. str = s;
  1417. /*
  1418. * Here str looks like add=attr1:F1...attrn:Fn,
  1419. * del=attr1:F1...attrn:Fn
  1420. *
  1421. * extract the add and del filter lists and process each one
  1422. * in turn.
  1423. */
  1424. s = strchr (str, '=');
  1425. *s = '\0';
  1426. s++; /* skip the = */
  1427. __acl_strip_leading_space(&s); /* start of the first filter list */
  1428. /*
  1429. * Now str is add or del
  1430. * s points to the first filter list.
  1431. */
  1432. if (strcmp(str, "add") == 0) {
  1433. aci->aci_type |= ACI_TARGET_ATTR_ADD_FILTERS;
  1434. addlistptr = s;
  1435. /* Now isolate the first filter list. */
  1436. if ((str = strstr(s , "del=")) || ((str = strstr(s , "del ="))) ) {
  1437. str--;
  1438. *str = '\0';
  1439. *str++;
  1440. }
  1441. } else if (strcmp(str, "del") == 0) {
  1442. aci->aci_type |= ACI_TARGET_ATTR_DEL_FILTERS;
  1443. dellistptr = s;
  1444. /* Now isolate the first filter list. */
  1445. if ((str = strstr(s , "add=")) || ((str = strstr(s , "add ="))) ) {
  1446. str--;
  1447. *str = '\0';
  1448. *str++;
  1449. }
  1450. } else {
  1451. return(ACL_SYNTAX_ERR);
  1452. }
  1453. __acl_strip_trailing_space(s);
  1454. /*
  1455. * Here, we have isolated the first filter list.
  1456. * There may be a second one.
  1457. * Now, str points to the start of the
  1458. * string that contains the second filter list.
  1459. * If there is none then str is NULL.
  1460. */
  1461. if (str != NULL ){
  1462. __acl_strip_leading_space(&str);
  1463. s = strchr (str, '=');
  1464. *s = '\0';
  1465. s++;
  1466. __acl_strip_trailing_space(str);
  1467. __acl_strip_leading_space(&s);
  1468. /*
  1469. * s points to the start of the second filter list.
  1470. * str is add or del
  1471. */
  1472. if (aci->aci_type & ACI_TARGET_ATTR_ADD_FILTERS) {
  1473. if (strcmp(str, "del") == 0) {
  1474. aci->aci_type |= ACI_TARGET_ATTR_DEL_FILTERS;
  1475. dellistptr = s;
  1476. } else {
  1477. return(ACL_SYNTAX_ERR);
  1478. }
  1479. } else if ( aci->aci_type & ACI_TARGET_ATTR_DEL_FILTERS ) {
  1480. if (strcmp(str, "add") == 0) {
  1481. aci->aci_type |= ACI_TARGET_ATTR_ADD_FILTERS;
  1482. addlistptr = s;
  1483. } else {
  1484. return(ACL_SYNTAX_ERR);
  1485. }
  1486. }
  1487. }
  1488. /*
  1489. * addlistptr points to the add filter list.
  1490. * dellistptr points to the del filter list.
  1491. * In both cases the strings have been leading and trailing space
  1492. * stripped.
  1493. * Either may be NULL.
  1494. */
  1495. if (process_filter_list( &aci->targetAttrAddFilters, addlistptr)
  1496. == ACL_SYNTAX_ERR) {
  1497. return( ACL_SYNTAX_ERR);
  1498. }
  1499. if (process_filter_list( &aci->targetAttrDelFilters, dellistptr)
  1500. == ACL_SYNTAX_ERR) {
  1501. return( ACL_SYNTAX_ERR);
  1502. }
  1503. return(0);
  1504. }
  1505. /*
  1506. * We have a list of filters that looks like this:
  1507. * attr1:F1 &&....attrn:Fn
  1508. *
  1509. * We need to put each component into a targetattrfilter component of
  1510. * the array.
  1511. *
  1512. */
  1513. static int process_filter_list( Targetattrfilter ***input_attrFilterArray,
  1514. char * input_str) {
  1515. char *str, *end_attr, *tmp_attr;
  1516. Targetattrfilter *attrfilter = NULL;
  1517. int numattr=0;
  1518. Targetattrfilter **attrFilterArray = NULL;
  1519. str = input_str;
  1520. while (str != 0 && *str != 0) {
  1521. if ((end_attr = strstr(str, "&&")) != NULL) {
  1522. /* skip the two '|' chars */
  1523. auto char *t = end_attr;
  1524. LDAP_UTF8INC(end_attr);
  1525. LDAP_UTF8INC(end_attr);
  1526. *t = 0;
  1527. }
  1528. __acl_strip_trailing_space(str);
  1529. __acl_strip_leading_space(&str);
  1530. /*
  1531. * Here:
  1532. * end_attr points to the next attribute thing.
  1533. *
  1534. * str points to the current one to be processed and it looks like
  1535. * this:
  1536. *
  1537. * attr1:F1
  1538. *
  1539. */
  1540. attrfilter = (Targetattrfilter *) slapi_ch_malloc (sizeof (Targetattrfilter));
  1541. memset (attrfilter, 0, sizeof(Targetattrfilter));
  1542. if ((tmp_attr = strstr( str,":")) != NULL) {
  1543. if ( __acl_init_targetattrfilter( attrfilter, str ) != 0 ) {
  1544. slapi_ch_free((void**)&attrfilter);
  1545. return(ACL_SYNTAX_ERR);
  1546. }
  1547. } else {
  1548. slapi_ch_free((void**)&attrfilter);
  1549. return(ACL_SYNTAX_ERR);
  1550. }
  1551. /*
  1552. * Add the attrfilte to the targetAttrFilter list
  1553. */
  1554. attrFilterArray = (Targetattrfilter **) slapi_ch_realloc (
  1555. (void *) attrFilterArray,
  1556. ((numattr+1)*sizeof(Targetattrfilter *)) );
  1557. attrFilterArray[numattr] = attrfilter;
  1558. numattr++;
  1559. /* Move on to the next attribute in the list */
  1560. str = end_attr;
  1561. }/* while */
  1562. /* NULL terminate the list */
  1563. attrFilterArray = (Targetattrfilter **) slapi_ch_realloc (
  1564. (void *) attrFilterArray,
  1565. ((numattr+1)*sizeof(Targetattrfilter *)) );
  1566. attrFilterArray[numattr] = NULL;
  1567. *input_attrFilterArray = attrFilterArray;
  1568. return 0;
  1569. }
  1570. /*
  1571. * Take str and put it into the attrfilter component.
  1572. *
  1573. * str looks as follows: attr1:F1
  1574. *
  1575. * It has had leading and trailing space stripped.
  1576. */
  1577. static int __acl_init_targetattrfilter( Targetattrfilter *attrfilter,
  1578. char *str ) {
  1579. char *tmp_ptr, *s, *filter_ptr;
  1580. Slapi_Filter *f = NULL;
  1581. s = str;
  1582. /* First grab the attribute name */
  1583. if ( (tmp_ptr = strstr( str, ":")) == NULL ) {
  1584. /* No :, syntax error */
  1585. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  1586. "Bad targetattrfilter %s:%s\n",
  1587. str,"Expecting \":\"",0);
  1588. return(ACL_SYNTAX_ERR);
  1589. }
  1590. *tmp_ptr = '\0';
  1591. LDAP_UTF8INC(tmp_ptr);
  1592. __acl_strip_trailing_space(s);
  1593. /* s should be the attribute name-make sure it's non-empty. */
  1594. if ( *s == '\0' ) {
  1595. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  1596. "No attribute name in targattrfilters\n",
  1597. 0,0);
  1598. return(ACL_SYNTAX_ERR);
  1599. }
  1600. attrfilter->attr_str = slapi_ch_strdup (s);
  1601. /* Now grab the filter */
  1602. filter_ptr = tmp_ptr;
  1603. __acl_strip_leading_space(&filter_ptr);
  1604. __acl_strip_trailing_space(filter_ptr);
  1605. /* trim dups the string, so we need to free it later if it's not kept. */
  1606. tmp_ptr = __acl_trim_filterstr(filter_ptr);
  1607. if ((f = slapi_str2filter(tmp_ptr)) == NULL) {
  1608. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  1609. "Bad targetattr filter for attribute %s:%s\n",
  1610. attrfilter->attr_str,tmp_ptr,0);
  1611. slapi_ch_free( (void **) &attrfilter->attr_str);
  1612. slapi_ch_free( (void **) &tmp_ptr);
  1613. return(ACL_SYNTAX_ERR);
  1614. }
  1615. /*
  1616. * Here verify that the named attribute is the only one
  1617. * that appears in the filter.
  1618. */
  1619. if (acl_verify_exactly_one_attribute( attrfilter->attr_str, f) !=
  1620. SLAPI_FILTER_SCAN_NOMORE) {
  1621. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  1622. "Exactly one attribute type per filter allowed in targattrfilters (%s)\n",
  1623. attrfilter->attr_str, 0);
  1624. slapi_ch_free( (void **) &attrfilter->attr_str);
  1625. slapi_ch_free( (void **) &tmp_ptr);
  1626. slapi_filter_free( f, 1 );
  1627. return(ACL_SYNTAX_ERR);
  1628. }
  1629. /* free the tmp_ptr */
  1630. slapi_ch_free( (void **) &tmp_ptr);
  1631. attrfilter->filterStr = slapi_ch_strdup (filter_ptr);
  1632. attrfilter->filter = f;
  1633. return(LDAP_SUCCESS);
  1634. }
  1635. /*
  1636. * Returns 0 if attr_name is the only attribute name to
  1637. * appear in original_filter AND it appears at least once.
  1638. * Otherwise returns STOP_FILTER_SCAN.
  1639. */
  1640. static int acl_verify_exactly_one_attribute( char *attr_name,
  1641. Slapi_Filter *original_filter) {
  1642. int error_code;
  1643. return( slapi_filter_apply( original_filter, type_compare,
  1644. (void *)attr_name, &error_code));
  1645. }
  1646. static int type_compare( Slapi_Filter *f, void *arg) {
  1647. /* Compare only the base names: eg cn and cn;lang-eb will be the same. */
  1648. char *t = (char *)arg;
  1649. char *filter_type;
  1650. int rc = SLAPI_FILTER_SCAN_STOP;
  1651. if (slapi_filter_get_attribute_type( f, &filter_type) == 0) {
  1652. t = slapi_attr_syntax_normalize(t);
  1653. filter_type = slapi_attr_syntax_normalize(filter_type);
  1654. if (slapi_attr_type_cmp(filter_type, t, 1) == 0) {
  1655. rc = SLAPI_FILTER_SCAN_CONTINUE;
  1656. }
  1657. slapi_ch_free( (void **)&t );
  1658. slapi_ch_free( (void **)&filter_type );
  1659. }
  1660. return rc;
  1661. }