acltext.y 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  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. /*
  39. * This grammar is intended to parse the version 3.0
  40. * and version 2.0 ACL text files and output an ACLListHandle_t
  41. * structure.
  42. */
  43. %{
  44. #include <string.h>
  45. #include <netsite.h>
  46. #include <base/util.h>
  47. #include <base/plist.h>
  48. #include <libaccess/acl.h>
  49. #include "aclpriv.h"
  50. #include <libaccess/aclproto.h>
  51. #include <libaccess/nserror.h>
  52. #include "parse.h"
  53. #include "aclscan.h"
  54. #define MAX_LIST_SIZE 255
  55. static ACLListHandle_t *curr_acl_list; /* current acl list */
  56. static ACLHandle_t *curr_acl; /* current acl */
  57. static ACLExprHandle_t *curr_expr; /* current expression */
  58. static PFlags_t pflags; /* current authorization flags */
  59. static char *curr_args_list[MAX_LIST_SIZE]; /* current args */
  60. static char *curr_user_list[MAX_LIST_SIZE]; /* current users v2 */
  61. static char *curr_ip_dns_list[MAX_LIST_SIZE]; /* current ip/dns v2 */
  62. static PList_t curr_auth_info; /* current authorization method */
  63. static int use_generic_rights; /* use generic rights for conversion */
  64. int acl_PushListHandle(ACLListHandle_t *handle)
  65. {
  66. curr_acl_list = handle;
  67. return(0);
  68. }
  69. static void
  70. acl_string_lower(char *s)
  71. {
  72. int ii;
  73. int len;
  74. len = strlen(s);
  75. for (ii = 0; ii < len; ii++)
  76. s[ii] = tolower(s[ii]);
  77. return;
  78. }
  79. static void
  80. acl_clear_args(char **args_list)
  81. {
  82. args_list[0] = NULL;
  83. }
  84. static void
  85. acl_add_arg(char **args_list, char *arg)
  86. {
  87. static int args_index;
  88. if ( args_list[0] == NULL ) {
  89. args_index = 0;
  90. }
  91. args_list[args_index] = arg;
  92. args_index++;
  93. args_list[args_index] = NULL;
  94. }
  95. static void
  96. acl_free_args(char **args_list)
  97. {
  98. int ii;
  99. for (ii = 0; ii < MAX_LIST_SIZE; ii++) {
  100. if ( args_list[ii] )
  101. free(args_list[ii]);
  102. else
  103. break;
  104. }
  105. }
  106. static int
  107. acl_set_args(ACLExprHandle_t *expr, char **args_list)
  108. {
  109. int ii;
  110. if (expr == NULL)
  111. return(-1);
  112. for (ii = 0; ii < MAX_LIST_SIZE; ii++) {
  113. if ( args_list[ii] ) {
  114. if ( ACL_ExprAddArg(NULL, expr, args_list[ii]) < 0 ) {
  115. yyerror("ACL_ExprAddArg() failed");
  116. return(-1);
  117. }
  118. } else
  119. break;
  120. }
  121. return(0);
  122. }
  123. static int
  124. acl_set_users_or_groups(ACLExprHandle_t *expr, char **user_list)
  125. {
  126. int ii;
  127. int jj;
  128. if (expr == NULL)
  129. return(-1);
  130. for (ii = 0; ii < MAX_LIST_SIZE; ii++) {
  131. if ( user_list[ii] ) {
  132. if ( ACL_ExprTerm(NULL, expr, "user", CMP_OP_EQ,
  133. user_list[ii]) < 0 ) {
  134. yyerror("ACL_ExprTerm() failed");
  135. acl_free_args(user_list);
  136. return(-1);
  137. }
  138. if ( ACL_ExprTerm(NULL, expr, "group", CMP_OP_EQ,
  139. user_list[ii]) < 0 ) {
  140. yyerror("ACL_ExprTerm() failed");
  141. acl_free_args(user_list);
  142. return(-1);
  143. }
  144. } else
  145. break;
  146. }
  147. acl_free_args(user_list);
  148. for (jj = 0; jj < (ii * 2) - 1; jj++) {
  149. if ( ACL_ExprOr(NULL, expr) < 0 ) {
  150. yyerror("ACL_ExprOr() failed");
  151. return(-1);
  152. }
  153. }
  154. return(0);
  155. }
  156. static int
  157. acl_set_ip_dns(ACLExprHandle_t *expr, char **ip_dns)
  158. {
  159. int ii;
  160. int jj;
  161. int len;
  162. const char *attr;
  163. char *val;
  164. if (expr == NULL)
  165. return(-1);
  166. for (ii = 0; ii < MAX_LIST_SIZE; ii++) {
  167. if ( ip_dns[ii] ) {
  168. attr = "ip";
  169. val = ip_dns[ii];
  170. len = strlen(val);
  171. for (jj = 0; jj < len; jj++) {
  172. if ( strchr("0123456789.*", val[jj]) == 0 ) {
  173. attr = "dns";
  174. break;
  175. }
  176. }
  177. if ( ACL_ExprTerm(NULL, expr, attr, CMP_OP_EQ,
  178. val) < 0 ) {
  179. yyerror("ACL_ExprTerm() failed");
  180. acl_free_args(ip_dns);
  181. return(-1);
  182. }
  183. } else
  184. break;
  185. }
  186. acl_free_args(ip_dns);
  187. for (jj = 0; jj < ii - 1; jj++) {
  188. if ( ACL_ExprOr(NULL, expr) < 0 ) {
  189. yyerror("ACL_ExprOr() failed");
  190. return(-1);
  191. }
  192. }
  193. return(0);
  194. }
  195. %}
  196. %union {
  197. char *string;
  198. int ival;
  199. }
  200. %token ACL_ABSOLUTE_TOK
  201. %token ACL_ACL_TOK
  202. %token ACL_ALLOW_TOK
  203. %token ACL_ALWAYS_TOK
  204. %token ACL_AND_TOK
  205. %token ACL_AT_TOK
  206. %token ACL_AUTHENTICATE_TOK
  207. %token ACL_CONTENT_TOK
  208. %token ACL_DEFAULT_TOK
  209. %token ACL_DENY_TOK
  210. %token ACL_GROUP_TOK
  211. %token ACL_IN_TOK
  212. %token ACL_INHERIT_TOK
  213. %token ACL_NOT_TOK
  214. %token ACL_NULL_TOK
  215. %token ACL_OR_TOK
  216. %token <string> ACL_QSTRING_TOK
  217. %token ACL_READ_TOK
  218. %token ACL_TERMINAL_TOK
  219. %token <string> ACL_VARIABLE_TOK
  220. %token ACL_VERSION_TOK
  221. %token ACL_WRITE_TOK
  222. %token ACL_WITH_TOK
  223. %token <ival> ACL_EQ_TOK
  224. %token <ival> ACL_GE_TOK
  225. %token <ival> ACL_GT_TOK
  226. %token <ival> ACL_LE_TOK
  227. %token <ival> ACL_LT_TOK
  228. %token <ival> ACL_NE_TOK
  229. %%
  230. /*
  231. * If no version is specified then we have a version 2.0 ACL.
  232. */
  233. start: | start_acl_v2
  234. | ACL_VERSION_TOK ACL_VARIABLE_TOK
  235. {
  236. free($<string>2);
  237. }
  238. ';' start_acl_v3
  239. ;
  240. /*
  241. ************************************************************
  242. * Parse version 2.0 ACL
  243. ************************************************************
  244. */
  245. start_acl_v2: acl_list_v2
  246. ;
  247. acl_list_v2: acl_v2
  248. | acl_list_v2 acl_v2
  249. ;
  250. acl_v2: ACL_ACL_TOK acl_name_v2
  251. '(' arg_list_v2 ')' '{' directive_list_v2 '}'
  252. {
  253. acl_free_args(curr_args_list);
  254. }
  255. ;
  256. acl_name_v2: ACL_VARIABLE_TOK
  257. {
  258. curr_acl = ACL_AclNew(NULL, $<string>1);
  259. free($<string>1);
  260. if ( ACL_ListAppend(NULL, curr_acl_list, curr_acl, 0) < 0 ) {
  261. yyerror("Couldn't add ACL to list.");
  262. return(-1);
  263. }
  264. acl_clear_args(curr_args_list);
  265. use_generic_rights = 0;
  266. if (strstr(curr_acl->tag, "READ")) {
  267. use_generic_rights++;
  268. acl_add_arg(curr_args_list, PERM_STRDUP("read"));
  269. acl_add_arg(curr_args_list, PERM_STRDUP("execute"));
  270. acl_add_arg(curr_args_list, PERM_STRDUP("list"));
  271. acl_add_arg(curr_args_list, PERM_STRDUP("info"));
  272. } if (strstr(curr_acl->tag, "WRITE")) {
  273. use_generic_rights++;
  274. acl_add_arg(curr_args_list, PERM_STRDUP("write"));
  275. acl_add_arg(curr_args_list, PERM_STRDUP("delete"));
  276. }
  277. }
  278. | ACL_QSTRING_TOK
  279. {
  280. curr_acl = ACL_AclNew(NULL, $<string>1);
  281. free($<string>1);
  282. if ( ACL_ListAppend(NULL, curr_acl_list, curr_acl, 0) < 0 ) {
  283. yyerror("Couldn't add ACL to list.");
  284. return(-1);
  285. }
  286. acl_clear_args(curr_args_list);
  287. use_generic_rights = 0;
  288. if (strstr(curr_acl->tag, "READ")) {
  289. use_generic_rights++;
  290. acl_add_arg(curr_args_list, PERM_STRDUP("read"));
  291. acl_add_arg(curr_args_list, PERM_STRDUP("execute"));
  292. acl_add_arg(curr_args_list, PERM_STRDUP("list"));
  293. acl_add_arg(curr_args_list, PERM_STRDUP("info"));
  294. } if (strstr(curr_acl->tag, "WRITE")) {
  295. use_generic_rights++;
  296. acl_add_arg(curr_args_list, PERM_STRDUP("write"));
  297. acl_add_arg(curr_args_list, PERM_STRDUP("delete"));
  298. }
  299. }
  300. ;
  301. arg_list_v2: arg_v2
  302. | arg_v2 ',' arg_list_v2
  303. ;
  304. arg_v2: ACL_VARIABLE_TOK
  305. {
  306. char acl_tmp_arg[255];
  307. char *acl_new_arg;
  308. if (!use_generic_rights) {
  309. acl_string_lower($<string>1);
  310. snprintf(acl_tmp_arg, sizeof(acl_tmp_arg), "http_%s", $<string>1);
  311. acl_tmp_arg[sizeof(acl_tmp_arg)-1] = '\0';
  312. PERM_FREE($<string>1);
  313. acl_new_arg = PERM_STRDUP(acl_tmp_arg);
  314. acl_add_arg(curr_args_list, acl_new_arg);
  315. } else {
  316. PERM_FREE($<string>1);
  317. }
  318. }
  319. | ACL_QSTRING_TOK
  320. {
  321. if (!use_generic_rights) {
  322. acl_add_arg(curr_args_list, $<string>1);
  323. } else {
  324. PERM_FREE($<string>1);
  325. }
  326. }
  327. ;
  328. directive_list_v2: directive_v2 ';'
  329. | directive_v2 ';' directive_list_v2
  330. ;
  331. directive_v2: auth_method_v2
  332. | auth_statement_v2
  333. ;
  334. auth_statement_v2: ACL_ALWAYS_TOK auth_type_v2
  335. {
  336. if ( ACL_ExprSetPFlags(NULL, curr_expr,
  337. ACL_PFLAG_ABSOLUTE) < 0 ) {
  338. yyerror("Could not set authorization processing flags");
  339. return(-1);
  340. }
  341. }
  342. host_spec_list_action_v2
  343. | ACL_DEFAULT_TOK auth_type_v2 host_spec_list_action_v2
  344. ;
  345. auth_type_v2: ACL_ALLOW_TOK
  346. {
  347. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_ALLOW) ;
  348. if ( curr_expr == NULL ) {
  349. yyerror("ACL_ExprNew(allow) failed");
  350. return(-1);
  351. }
  352. acl_clear_args(curr_user_list);
  353. acl_clear_args(curr_ip_dns_list);
  354. }
  355. | ACL_DENY_TOK
  356. {
  357. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_DENY) ;
  358. if ( curr_expr == NULL ) {
  359. yyerror("ACL_ExprNew(allow) failed");
  360. return(-1);
  361. }
  362. acl_clear_args(curr_user_list);
  363. acl_clear_args(curr_ip_dns_list);
  364. }
  365. ;
  366. auth_method_v2:
  367. ACL_ALWAYS_TOK ACL_AUTHENTICATE_TOK ACL_IN_TOK
  368. {
  369. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_AUTH) ;
  370. if ( curr_expr == NULL ) {
  371. yyerror("ACL_ExprNew(auth) failed");
  372. return(-1);
  373. }
  374. if ( ACL_ExprSetPFlags(NULL, curr_expr,
  375. ACL_PFLAG_ABSOLUTE) < 0 ) {
  376. yyerror("Could not set authorization processing flags");
  377. return(-1);
  378. }
  379. curr_auth_info = PListCreate(NULL, ACL_ATTR_INDEX_MAX, 0, 0);
  380. if ( ACL_ExprAddAuthInfo(curr_expr, curr_auth_info) < 0 ) {
  381. yyerror("Could not set authorization info");
  382. return(-1);
  383. }
  384. }
  385. realm_definition_v2
  386. | ACL_DEFAULT_TOK ACL_AUTHENTICATE_TOK ACL_IN_TOK
  387. {
  388. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_AUTH) ;
  389. if ( curr_expr == NULL ) {
  390. yyerror("ACL_ExprNew(auth) failed");
  391. return(-1);
  392. }
  393. curr_auth_info = PListCreate(NULL, ACL_ATTR_INDEX_MAX, 0, 0);
  394. if ( ACL_ExprAddAuthInfo(curr_expr, curr_auth_info) < 0 ) {
  395. yyerror("Could not set authorization info");
  396. return(-1);
  397. }
  398. }
  399. realm_definition_v2
  400. ;
  401. host_spec_list_action_v2: user_expr_v2 ACL_AT_TOK host_spec_list_v2
  402. {
  403. if ( acl_set_users_or_groups(curr_expr, curr_user_list) < 0 ) {
  404. yyerror("acl_set_users_or_groups() failed");
  405. return(-1);
  406. }
  407. if ( acl_set_ip_dns(curr_expr, curr_ip_dns_list) < 0 ) {
  408. yyerror("acl_set_ip_dns() failed");
  409. return(-1);
  410. }
  411. if ( ACL_ExprAnd(NULL, curr_expr) < 0 ) {
  412. yyerror("ACL_ExprAnd() failed");
  413. return(-1);
  414. }
  415. if ( acl_set_args(curr_expr, curr_args_list) < 0 ) {
  416. yyerror("acl_set_args() failed");
  417. return(-1);
  418. }
  419. if ( ACL_ExprAppend(NULL, curr_acl, curr_expr) < 0 ) {
  420. yyerror("Could not add authorization");
  421. return(-1);
  422. }
  423. }
  424. | user_expr_v2
  425. {
  426. if ( acl_set_users_or_groups(curr_expr, curr_user_list) < 0 ) {
  427. yyerror("acl_set_users_or_groups() failed");
  428. return(-1);
  429. }
  430. if ( acl_set_args(curr_expr, curr_args_list) < 0 ) {
  431. yyerror("acl_set_args() failed");
  432. return(-1);
  433. }
  434. if ( ACL_ExprAppend(NULL, curr_acl, curr_expr) < 0 ) {
  435. yyerror("Could not add authorization");
  436. return(-1);
  437. }
  438. }
  439. ;
  440. user_expr_v2: user_v2
  441. | '(' user_list_v2 ')'
  442. ;
  443. user_list_v2: user_v2
  444. | user_v2 ',' user_list_v2
  445. ;
  446. user_v2: ACL_VARIABLE_TOK
  447. {
  448. acl_add_arg(curr_user_list, $<string>1);
  449. }
  450. | ACL_QSTRING_TOK
  451. {
  452. acl_add_arg(curr_user_list, $<string>1);
  453. }
  454. ;
  455. host_spec_list_v2: dns_spec_v2
  456. | ip_spec_v2
  457. | '(' dns_ip_spec_list_v2 ')'
  458. ;
  459. dns_spec_v2: ACL_VARIABLE_TOK
  460. {
  461. acl_add_arg(curr_ip_dns_list, $<string>1);
  462. }
  463. | ACL_QSTRING_TOK
  464. {
  465. acl_add_arg(curr_ip_dns_list, $<string>1);
  466. }
  467. ;
  468. ip_spec_v2: ACL_VARIABLE_TOK ACL_VARIABLE_TOK
  469. {
  470. char tmp_str[255];
  471. util_sprintf(tmp_str, "%s+%s", $<string>1, $<string>2);
  472. free($<string>1);
  473. free($<string>2);
  474. acl_add_arg(curr_ip_dns_list, PERM_STRDUP(tmp_str));
  475. }
  476. ;
  477. dns_ip_spec_list_v2: dns_spec_v2
  478. | ip_spec_v2
  479. | dns_spec_v2 ',' dns_ip_spec_list_v2
  480. | ip_spec_v2 ',' dns_ip_spec_list_v2
  481. ;
  482. realm_definition_v2: '{' methods_list_v2 '}'
  483. {
  484. if ( ACL_ExprAddArg(NULL, curr_expr, "user") < 0 ) {
  485. yyerror("ACL_ExprAddArg() failed");
  486. return(-1);
  487. }
  488. if ( ACL_ExprAddArg(NULL, curr_expr, "group") < 0 ) {
  489. yyerror("ACL_ExprAddArg() failed");
  490. return(-1);
  491. }
  492. if ( ACL_ExprAppend(NULL, curr_acl, curr_expr) < 0 ) {
  493. yyerror("Could not add authorization");
  494. return(-1);
  495. }
  496. }
  497. ;
  498. method_v2: ACL_VARIABLE_TOK ACL_VARIABLE_TOK ';'
  499. {
  500. acl_string_lower($<string>1);
  501. if (strcmp($<string>1, "database") == 0) {
  502. free($<string>1);
  503. free($<string>2);
  504. } else {
  505. if ( PListInitProp(curr_auth_info,
  506. ACL_Attr2Index($<string>1), $<string>1, $<string>2, NULL) < 0 ) {
  507. }
  508. free($<string>1);
  509. }
  510. }
  511. | ACL_VARIABLE_TOK ACL_QSTRING_TOK ';'
  512. {
  513. acl_string_lower($<string>1);
  514. if (strcmp($<string>1, "database") == 0) {
  515. free($<string>1);
  516. free($<string>2);
  517. } else {
  518. if ( PListInitProp(curr_auth_info,
  519. ACL_Attr2Index($<string>1), $<string>1, $<string>2, NULL) < 0 ) {
  520. }
  521. free($<string>1);
  522. }
  523. }
  524. ;
  525. methods_list_v2: method_v2
  526. | method_v2 methods_list_v2
  527. ;
  528. /*
  529. ************************************************************
  530. * Parse version 3.0 ACL
  531. ************************************************************
  532. */
  533. start_acl_v3: acl_list
  534. ;
  535. acl_list: acl
  536. | acl_list acl
  537. ;
  538. acl: named_acl ';' body_list
  539. | named_acl ';'
  540. ;
  541. named_acl: ACL_ACL_TOK ACL_VARIABLE_TOK
  542. {
  543. curr_acl = ACL_AclNew(NULL, $<string>2);
  544. free($<string>2);
  545. if ( ACL_ListAppend(NULL, curr_acl_list, curr_acl, 0) < 0 ) {
  546. yyerror("Couldn't add ACL to list.");
  547. return(-1);
  548. }
  549. }
  550. | ACL_ACL_TOK ACL_QSTRING_TOK
  551. {
  552. curr_acl = ACL_AclNew(NULL, $<string>2);
  553. free($<string>2);
  554. if ( ACL_ListAppend(NULL, curr_acl_list, curr_acl, 0) < 0 ) {
  555. yyerror("Couldn't add ACL to list.");
  556. return(-1);
  557. }
  558. }
  559. ;
  560. body_list: body
  561. | body body_list
  562. ;
  563. body: authenticate_statement ';'
  564. | authorization_statement ';'
  565. | deny_statement ';'
  566. ;
  567. deny_statement:
  568. ACL_ABSOLUTE_TOK ACL_DENY_TOK ACL_WITH_TOK
  569. {
  570. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_RESPONSE) ;
  571. if ( curr_expr == NULL ) {
  572. yyerror("ACL_ExprNew(deny) failed");
  573. return(-1);
  574. }
  575. if ( ACL_ExprAppend(NULL, curr_acl, curr_expr) < 0 ) {
  576. yyerror("Could not add authorization");
  577. return(-1);
  578. }
  579. if ( ACL_ExprSetPFlags(NULL, curr_expr,
  580. ACL_PFLAG_ABSOLUTE) < 0 ) {
  581. yyerror("Could not set deny processing flags");
  582. return(-1);
  583. }
  584. }
  585. deny_common
  586. | ACL_DENY_TOK ACL_WITH_TOK
  587. {
  588. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_RESPONSE) ;
  589. if ( curr_expr == NULL ) {
  590. yyerror("ACL_ExprNew(deny) failed");
  591. return(-1);
  592. }
  593. if ( ACL_ExprAppend(NULL, curr_acl, curr_expr) < 0 ) {
  594. yyerror("Could not add authorization");
  595. return(-1);
  596. }
  597. }
  598. deny_common
  599. ;
  600. deny_common: ACL_VARIABLE_TOK ACL_EQ_TOK ACL_QSTRING_TOK
  601. {
  602. acl_string_lower($<string>1);
  603. if ( ACL_ExprSetDenyWith(NULL, curr_expr,
  604. $<string>1, $<string>3) < 0 ) {
  605. yyerror("ACL_ExprSetDenyWith() failed");
  606. return(-1);
  607. }
  608. free($<string>1);
  609. free($<string>3);
  610. }
  611. ;
  612. authenticate_statement: ACL_AUTHENTICATE_TOK
  613. {
  614. pflags = 0;
  615. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_AUTH) ;
  616. if ( curr_expr == NULL ) {
  617. yyerror("ACL_ExprNew(allow) failed");
  618. return(-1);
  619. }
  620. curr_auth_info = PListCreate(NULL, ACL_ATTR_INDEX_MAX, 0, 0);
  621. if ( ACL_ExprAddAuthInfo(curr_expr, curr_auth_info) < 0 ) {
  622. yyerror("Could not set authorization info");
  623. return(-1);
  624. }
  625. }
  626. '(' attribute_list ')' '{' parameter_list '}'
  627. {
  628. if ( ACL_ExprAppend(NULL, curr_acl, curr_expr) < 0 ) {
  629. yyerror("Could not add authorization");
  630. return(-1);
  631. }
  632. }
  633. ;
  634. attribute_list: attribute
  635. | attribute_list ',' attribute
  636. attribute: ACL_VARIABLE_TOK
  637. {
  638. acl_string_lower($<string>1);
  639. if ( ACL_ExprAddArg(NULL, curr_expr, $<string>1) < 0 ) {
  640. yyerror("ACL_ExprAddArg() failed");
  641. return(-1);
  642. }
  643. free($<string>1);
  644. }
  645. ;
  646. parameter_list: parameter ';'
  647. | parameter ';' parameter_list
  648. ;
  649. parameter: ACL_VARIABLE_TOK ACL_EQ_TOK ACL_QSTRING_TOK
  650. {
  651. acl_string_lower($<string>1);
  652. if ( PListInitProp(curr_auth_info,
  653. ACL_Attr2Index($<string>1), $<string>1, $<string>3, NULL) < 0 ) {
  654. }
  655. free($<string>1);
  656. }
  657. | ACL_VARIABLE_TOK ACL_EQ_TOK ACL_VARIABLE_TOK
  658. {
  659. acl_string_lower($<string>1);
  660. if ( PListInitProp(curr_auth_info,
  661. ACL_Attr2Index($<string>1), $<string>1, $<string>3, NULL) < 0 ) {
  662. }
  663. free($<string>1);
  664. }
  665. ;
  666. authorization_statement: ACL_ALLOW_TOK
  667. {
  668. pflags = 0;
  669. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_ALLOW) ;
  670. if ( curr_expr == NULL ) {
  671. yyerror("ACL_ExprNew(allow) failed");
  672. return(-1);
  673. }
  674. }
  675. auth_common_action
  676. | ACL_DENY_TOK
  677. {
  678. pflags = 0;
  679. curr_expr = ACL_ExprNew(ACL_EXPR_TYPE_DENY) ;
  680. if ( curr_expr == NULL ) {
  681. yyerror("ACL_ExprNew(deny) failed");
  682. return(-1);
  683. }
  684. }
  685. auth_common_action
  686. ;
  687. auth_common_action:
  688. {
  689. if ( ACL_ExprAppend(NULL, curr_acl, curr_expr) < 0 ) {
  690. yyerror("Could not add authorization");
  691. return(-1);
  692. }
  693. }
  694. auth_common
  695. {
  696. if ( ACL_ExprSetPFlags (NULL, curr_expr, pflags) < 0 ) {
  697. yyerror("Could not set authorization processing flags");
  698. return(-1);
  699. }
  700. #ifdef DEBUG
  701. if ( ACL_ExprDisplay(curr_expr) < 0 ) {
  702. yyerror("ACL_ExprDisplay() failed");
  703. return(-1);
  704. }
  705. printf("Parsed authorization.\n");
  706. #endif
  707. }
  708. ;
  709. auth_common: flag_list '(' args_list ')' expression
  710. ;
  711. flag_list:
  712. | ACL_ABSOLUTE_TOK
  713. {
  714. pflags = ACL_PFLAG_ABSOLUTE;
  715. }
  716. | ACL_ABSOLUTE_TOK content_static
  717. {
  718. pflags = ACL_PFLAG_ABSOLUTE;
  719. }
  720. | ACL_CONTENT_TOK
  721. {
  722. pflags = ACL_PFLAG_CONTENT;
  723. }
  724. | ACL_CONTENT_TOK absolute_static
  725. {
  726. pflags = ACL_PFLAG_CONTENT;
  727. }
  728. | ACL_TERMINAL_TOK
  729. {
  730. pflags = ACL_PFLAG_TERMINAL;
  731. }
  732. | ACL_TERMINAL_TOK content_absolute
  733. {
  734. pflags = ACL_PFLAG_TERMINAL;
  735. }
  736. ;
  737. content_absolute: ACL_CONTENT_TOK
  738. {
  739. pflags |= ACL_PFLAG_CONTENT;
  740. }
  741. | ACL_ABSOLUTE_TOK
  742. {
  743. pflags |= ACL_PFLAG_ABSOLUTE;
  744. }
  745. | ACL_CONTENT_TOK ACL_ABSOLUTE_TOK
  746. {
  747. pflags |= ACL_PFLAG_ABSOLUTE | ACL_PFLAG_CONTENT;
  748. }
  749. | ACL_ABSOLUTE_TOK ACL_CONTENT_TOK
  750. {
  751. pflags |= ACL_PFLAG_ABSOLUTE | ACL_PFLAG_CONTENT;
  752. }
  753. ;
  754. content_static: ACL_CONTENT_TOK
  755. {
  756. pflags |= ACL_PFLAG_CONTENT;
  757. }
  758. | ACL_TERMINAL_TOK
  759. {
  760. pflags |= ACL_PFLAG_TERMINAL;
  761. }
  762. | ACL_CONTENT_TOK ACL_TERMINAL_TOK
  763. {
  764. pflags |= ACL_PFLAG_TERMINAL | ACL_PFLAG_CONTENT;
  765. }
  766. | ACL_TERMINAL_TOK ACL_CONTENT_TOK
  767. {
  768. pflags |= ACL_PFLAG_TERMINAL | ACL_PFLAG_CONTENT;
  769. }
  770. ;
  771. absolute_static: ACL_ABSOLUTE_TOK
  772. {
  773. pflags |= ACL_PFLAG_ABSOLUTE;
  774. }
  775. | ACL_TERMINAL_TOK
  776. {
  777. pflags |= ACL_PFLAG_TERMINAL;
  778. }
  779. | ACL_ABSOLUTE_TOK ACL_TERMINAL_TOK
  780. {
  781. pflags |= ACL_PFLAG_TERMINAL | ACL_PFLAG_ABSOLUTE;
  782. }
  783. | ACL_TERMINAL_TOK ACL_ABSOLUTE_TOK
  784. {
  785. pflags |= ACL_PFLAG_TERMINAL | ACL_PFLAG_ABSOLUTE;
  786. }
  787. ;
  788. args_list: arg
  789. | args_list ',' arg
  790. ;
  791. arg: ACL_VARIABLE_TOK
  792. {
  793. acl_string_lower($<string>1);
  794. if ( ACL_ExprAddArg(NULL, curr_expr, $<string>1) < 0 ) {
  795. yyerror("ACL_ExprAddArg() failed");
  796. return(-1);
  797. }
  798. free( $<string>1 );
  799. }
  800. ;
  801. expression: factor
  802. | factor ACL_AND_TOK expression
  803. {
  804. if ( ACL_ExprAnd(NULL, curr_expr) < 0 ) {
  805. yyerror("ACL_ExprAnd() failed");
  806. return(-1);
  807. }
  808. }
  809. | factor ACL_OR_TOK expression
  810. {
  811. if ( ACL_ExprOr(NULL, curr_expr) < 0 ) {
  812. yyerror("ACL_ExprOr() failed");
  813. return(-1);
  814. }
  815. }
  816. ;
  817. factor: base_expr
  818. | '(' expression ')'
  819. | ACL_NOT_TOK factor
  820. {
  821. if ( ACL_ExprNot(NULL, curr_expr) < 0 ) {
  822. yyerror("ACL_ExprNot() failed");
  823. return(-1);
  824. }
  825. }
  826. ;
  827. base_expr: ACL_VARIABLE_TOK relop ACL_QSTRING_TOK
  828. {
  829. acl_string_lower($<string>1);
  830. if ( ACL_ExprTerm(NULL, curr_expr,
  831. $<string>1, (CmpOp_t) $<ival>2, $<string>3) < 0 ) {
  832. yyerror("ACL_ExprTerm() failed");
  833. free($<string>1);
  834. free($<string>3);
  835. return(-1);
  836. }
  837. free($<string>1);
  838. free($<string>3);
  839. }
  840. | ACL_VARIABLE_TOK relop ACL_VARIABLE_TOK
  841. {
  842. acl_string_lower($<string>1);
  843. if ( ACL_ExprTerm(NULL, curr_expr,
  844. $<string>1, (CmpOp_t) $<ival>2, $<string>3) < 0 ) {
  845. yyerror("ACL_ExprTerm() failed");
  846. free($<string>1);
  847. free($<string>3);
  848. return(-1);
  849. }
  850. free($<string>1);
  851. free($<string>3);
  852. }
  853. ;
  854. relop: ACL_EQ_TOK
  855. | ACL_GE_TOK
  856. | ACL_GT_TOK
  857. | ACL_LT_TOK
  858. | ACL_LE_TOK
  859. | ACL_NE_TOK
  860. ;
  861. %%