acltest.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #include <stdio.h>
  42. #include <netsite.h>
  43. #include <base/systhr.h>
  44. #include <libaccess/nserror.h>
  45. #include <libaccess/acl.h>
  46. #include "../aclpriv.h"
  47. #include <libaccess/aclproto.h>
  48. #include "../aclcache.h"
  49. #include <libaccess/las.h>
  50. extern ACLListHandle_t *ACL_ParseFile(NSErr_t *errp, char *filename);
  51. int
  52. TestEvalFunc(NSErr_t *errp, char *attr, CmpOp_t comparator,
  53. char *attr_pattern, ACLCachable_t *cachable,
  54. void **las_cookie, PList_t subject, PList_t resource,
  55. PList_t auth_info, PList_t global_auth)
  56. {
  57. return 0;
  58. }
  59. void
  60. TestFlushFunc(void **cookie)
  61. {
  62. return;
  63. }
  64. static int parse_dburl (NSErr_t *errp, ACLDbType_t dbtype,
  65. const char *dbname, const char *url,
  66. PList_t plist, void **db)
  67. {
  68. *db = strdup(url);
  69. return 0;
  70. }
  71. int main(int argc, char **argv)
  72. {
  73. ACLListHandle_t *acl_list;
  74. int result;
  75. ACLCachable_t cachable = 0;
  76. void *las_cookie=NULL;
  77. ACLEvalHandle_t eval;
  78. char *rights[3];
  79. char filename[20];
  80. char newfilename[25];
  81. int i;
  82. char *map_generic[7];
  83. LASEvalFunc_t Eval_funcp;
  84. LASFlushFunc_t Flush_funcp;
  85. char *bong;
  86. char *bong_type;
  87. char *acl_tag;
  88. int expr_num;
  89. int ii;
  90. char **name_list;
  91. ACLMethod_t method=NULL;
  92. ACLDbType_t dbtype=NULL;
  93. int rv;
  94. ACLAttrGetterList_t aglist;
  95. ACLAttrGetter_t *agptr;
  96. char **names;
  97. int cnt;
  98. systhread_init("acl_utest");
  99. char *acl_file_list[3] = {"aclfile6", "aclfile7", NULL};
  100. char *new_filename = "merge6_7";
  101. char *acl_name_list[3] = {"aclfile6", "aclfile7", NULL};
  102. char *new_aclname = "merge6_7";
  103. char *bad_acl_file_list[3] = {"bad_aclfile6", "bad_aclfile7", NULL};
  104. if ( ACL_FileMergeFile(NULL, new_filename, bad_acl_file_list, 0) < 0 ) {
  105. printf("Failed ACL_FileMergeFile() test.\n");
  106. }
  107. if ( ACL_FileMergeFile(NULL, new_filename, acl_file_list, 0) < 0 ) {
  108. printf("Failed ACL_FileMergeFile() test.\n");
  109. }
  110. if ( ACL_FileMergeAcl(NULL, new_filename, acl_name_list, new_aclname, 0) < 0 ) {
  111. printf("Failed ACL_FileMergeAcl() test.\n");
  112. }
  113. /* LAS Registration Unit Tests */
  114. ACL_Init();
  115. rv = ACL_MethodRegister(NULL, "one", &method);
  116. printf("Method one is #%d, rv=%d\n", (int)method, rv);
  117. rv = ACL_MethodRegister(NULL, "two", &method);
  118. printf("Method two is #%d, rv=%d\n", (int)method, rv);
  119. rv = ACL_MethodRegister(NULL, "one", &method);
  120. printf("Method one repeated is #%d, rv=%d\n", (int)method, rv);
  121. rv = ACL_MethodRegister(NULL, "three", &method);
  122. printf("Method three is #%d, rv=%d\n", (int)method, rv);
  123. rv = ACL_MethodNamesGet(NULL, &names, &cnt);
  124. for(i = 0; i < cnt; i++) {
  125. printf("\tMethod[%d] = \"%s\"\n", i, names[i]);
  126. }
  127. ACL_MethodNamesFree(NULL, names, cnt);
  128. if (!ACL_MethodIsEqual(NULL, method, method)) {
  129. printf("Error comparing methods");
  130. }
  131. if (!ACL_MethodNameIsEqual(NULL, method, "three")) {
  132. printf("Error comparing method by name");
  133. }
  134. /* Since LDAP is already registered by ACL_Init, the first number
  135. * we'll get is actually 2.
  136. */
  137. rv = ACL_DbTypeRegister(NULL, "two", parse_dburl, &dbtype);
  138. printf("DbType two is #%d, rv=%d\n", (int)dbtype, rv);
  139. rv = ACL_DbTypeRegister(NULL, "three", parse_dburl, &dbtype);
  140. printf("DbType three is #%d, rv=%d\n", (int)dbtype, rv);
  141. rv = ACL_DbTypeRegister(NULL, "two", parse_dburl, &dbtype);
  142. printf("DbType two repeated is #%d, rv=%d\n", (int)dbtype, rv);
  143. rv = ACL_DbTypeRegister(NULL, "four", parse_dburl, &dbtype);
  144. printf("DbType four is #%d, rv=%d\n", (int)dbtype, rv);
  145. if (!ACL_DbTypeIsEqual(NULL, dbtype, dbtype)) {
  146. printf("Error comparing dbtypes\n");
  147. }
  148. if (!ACL_DbTypeNameIsEqual(NULL, dbtype, "four")) {
  149. printf("Error comparing dbtype by name\n");
  150. }
  151. rv = ACL_DatabaseRegister(NULL, dbtype, "db1", "url for db1", NULL);
  152. if (rv < 0) {
  153. printf("ACL_DatabaseRegister failed for db1\n");
  154. }
  155. rv = ACL_DatabaseRegister(NULL, dbtype, "db2", "url for db2", NULL);
  156. if (rv < 0) {
  157. printf("ACL_DatabaseRegister failed for db2\n");
  158. }
  159. rv = ACL_DatabaseRegister(NULL, dbtype, "db3", "url for db3", NULL);
  160. if (rv < 0) {
  161. printf("ACL_DatabaseRegister failed for db3\n");
  162. }
  163. rv = ACL_DatabaseNamesGet(NULL, &names, &cnt);
  164. for(i = 0; i < cnt; i++) {
  165. printf("\tDatabase[%d] = \"%s\"\n", i, names[i]);
  166. }
  167. if (ACL_AttrGetterRegister(NULL, "attr", (ACLAttrGetterFn_t)2, (ACLMethod_t)10, (ACLDbType_t)20, ACL_AT_FRONT, NULL)) {
  168. printf("Error registering attr getter\n");
  169. }
  170. if (ACL_AttrGetterRegister(NULL, "attr", (ACLAttrGetterFn_t)3, (ACLMethod_t)10, (ACLDbType_t)20, ACL_AT_END, NULL)) {
  171. printf("Error registering attr getter\n");
  172. }
  173. if (ACL_AttrGetterRegister(NULL, "attr", (ACLAttrGetterFn_t)1, (ACLMethod_t)10, (ACLDbType_t)20, ACL_AT_FRONT, NULL)) {
  174. printf("Error registering attr getter\n");
  175. }
  176. if (ACL_AttrGetterRegister(NULL, "attr", (ACLAttrGetterFn_t)4, (ACLMethod_t)10, (ACLDbType_t)20, ACL_AT_END, NULL)) {
  177. printf("Error registering attr getter\n");
  178. }
  179. if (ACL_AttrGetterFind(NULL, "attr", &aglist)) {
  180. printf("Error finding attr getter\n");
  181. }
  182. for (i = 0, agptr = ACL_AttrGetterFirst(&aglist);
  183. i < 4;
  184. i++, agptr = ACL_AttrGetterNext(&aglist, agptr)) {
  185. if (agptr) {
  186. printf("position %d\n", (int)(agptr->fn));
  187. }
  188. else {
  189. printf("***Error: missing getter ***\n");
  190. }
  191. }
  192. #ifndef XP_WIN32
  193. if (ACL_LasRegister(NULL, "test_attr", TestEvalFunc, TestFlushFunc)) {
  194. printf("Error registering Test LAS functions\n");
  195. }
  196. ACL_LasFindEval(NULL, "test_attr", &Eval_funcp);
  197. if (Eval_funcp != TestEvalFunc) {
  198. printf("Error finding Eval function - expecting %x, got %x\n",
  199. TestEvalFunc, Eval_funcp);
  200. }
  201. ACL_LasFindFlush(NULL, "test_attr", &Flush_funcp);
  202. if (Flush_funcp != TestFlushFunc) {
  203. printf("Error finding Flush function - expecting %x, got %x\n",
  204. TestFlushFunc, Flush_funcp);
  205. }
  206. ACL_LasFindEval(NULL, "wrong_attr", &Eval_funcp);
  207. if (Eval_funcp != NULL) {
  208. printf("Error finding Eval function - expecting NULL, got %x\n",
  209. Eval_funcp);
  210. }
  211. ACL_LasFindFlush(NULL, "wrong_attr", &Flush_funcp);
  212. if (Flush_funcp != NULL) {
  213. printf("Error finding Flush function - expecting NULL, got %x\n",
  214. Flush_funcp);
  215. }
  216. #endif /* !XP_WIN32 */
  217. /* ACL Eval Unit Tests
  218. */
  219. rights[0] = "http_get";
  220. rights[1] = "http_post";
  221. rights[2] = NULL;
  222. eval.subject = NULL;
  223. eval.resource = NULL;
  224. eval.default_result = ACL_RES_DENY;
  225. for (i=0; i<10; i++) {
  226. sprintf(filename, "aclfile%d", i);
  227. eval.acllist = ACL_ParseFile((NSErr_t *)NULL, filename);
  228. if ( eval.acllist == NULL ) {
  229. printf("Couldn't parse.\n");
  230. continue;
  231. }
  232. sprintf(newfilename, "%s.v30", filename);
  233. if ( ACL_WriteFile(NULL, newfilename, eval.acllist) < 0) {
  234. printf("Couldn't write %s.\n", newfilename);
  235. }
  236. result = ACL_EvalTestRights(NULL, &eval, &rights[0],
  237. http_generic, &bong, &bong_type, &acl_tag, &expr_num);
  238. ACL_ListDestroy(NULL, eval.acllist);
  239. printf("%s = %d\n\n", filename, result);
  240. }
  241. /********************************************************************
  242. TEST #1
  243. TEST ACL_ParseString()
  244. TEST ACL_WriteFile()
  245. TEST ACL_ParseFile()
  246. TEST ACL_ListFind()
  247. *********************************************************************/
  248. acl_list = ACL_ParseString((NSErr_t *)NULL,
  249. "version 3.0; acl > franco;");
  250. if ( acl_list != NULL ) {
  251. ACL_ListDestroy(NULL, acl_list);
  252. printf("Test #1a fails parsed invalid ACL\n");
  253. goto skip_test;
  254. }
  255. acl_list = ACL_ParseString((NSErr_t *)NULL,
  256. "version 3.0; acl franco; \nallow (read) user=franco;");
  257. if ( acl_list == NULL ) {
  258. printf("Test #1b fails couldn't parse valid ACL\n");
  259. goto skip_test;
  260. } else {
  261. if ( ACL_WriteFile(NULL, "buffer", acl_list) < 0) {
  262. printf("Test #1b, couldn't write %s.\n", "buffer");
  263. }
  264. ACL_ListDestroy(NULL, acl_list);
  265. }
  266. acl_list = ACL_ParseString((NSErr_t *)NULL,
  267. "version 3.0; acl franco; \njunk (read) user=franco;");
  268. if ( acl_list != NULL ) {
  269. printf("Test #1c failed missed syntax error\n");
  270. ACL_ListDestroy(NULL, acl_list);
  271. goto skip_test;
  272. }
  273. acl_list = ACL_ParseString((NSErr_t *)NULL,
  274. "version 3.0; acl franco; \nallow (read) user=franco;");
  275. if ( acl_list == NULL ) {
  276. printf("Test #1d couldn't parse valid ACL\n");
  277. } else {
  278. ACL_ListDestroy(NULL, acl_list);
  279. goto skip_test;
  280. }
  281. acl_list= ACL_ParseFile((NSErr_t *)NULL, "buffer");
  282. if ( acl_list == NULL ) {
  283. printf("Test #1e, couldn't perform ACL_ParseFile(buffer)\n");
  284. goto skip_test;
  285. } else {
  286. if ( ACL_ListFind(NULL, acl_list, "franco", ACL_CASE_INSENSITIVE) == NULL ) {
  287. printf("Test #1e, couldn't find %s in %s.\n", "franco", "buffer");
  288. }
  289. ACL_ListDestroy(NULL, acl_list);
  290. }
  291. /********************************************************************
  292. TEST #2
  293. TEST ACL_FileDeleteAcl()
  294. TEST ACL_ParseFile()
  295. TEST ACL_ListFind()
  296. *********************************************************************/
  297. if ( ACL_FileDeleteAcl(NULL, "buffer", "franco", ACL_CASE_INSENSITIVE) < 0) {
  298. printf("Test #2, couldn't write %s.\n", "buffer");
  299. }
  300. acl_list= ACL_ParseFile((NSErr_t *)NULL, "buffer");
  301. if ( acl_list == NULL ) {
  302. printf("Test #2, couldn't perform ACL_ParseFile(buffer)\n");
  303. goto skip_test;
  304. } else {
  305. if ( ACL_ListFind(NULL, acl_list, "franco", ACL_CASE_INSENSITIVE) ) {
  306. printf("Couldn't delete %s from %s.\n", "franco", "buffer");
  307. }
  308. ACL_ListDestroy(NULL, acl_list);
  309. }
  310. /********************************************************************
  311. TEST #3
  312. TEST ACL_FileSetAcl()
  313. TEST ACL_ParseFile()
  314. TEST ACL_ListFind()
  315. *********************************************************************/
  316. if ( ACL_FileSetAcl(NULL, "buffer",
  317. "version 3.0; acl FileSetAcl; \nallow (read) user=franco;",
  318. ACL_CASE_INSENSITIVE)< 0) {
  319. printf("Test #3, couldn't ACL_FileSetACL(%s).\n", "FileSetAcl");
  320. }
  321. if ( ACL_FileSetAcl(NULL, "buffer",
  322. "version 3.0; acl franco; \nallow (read) user=franco;",
  323. ACL_CASE_INSENSITIVE)< 0) {
  324. printf("Test #3, couldn't ACL_FileSetACL(%s).\n", "franco");
  325. }
  326. acl_list= ACL_ParseFile((NSErr_t *)NULL, "buffer");
  327. if ( acl_list == NULL ) {
  328. printf("Test #3, couldn't perform ACL_ParseFile(buffer)\n");
  329. goto skip_test;
  330. } else {
  331. if ( ACL_ListFind(NULL, acl_list, "franco", ACL_CASE_INSENSITIVE) == NULL) {
  332. printf("Test #3, couldn't set %s in %s.\n", "franco", "buffer");
  333. }
  334. if ( ACL_ListFind(NULL, acl_list, "filesetacl", ACL_CASE_INSENSITIVE) == NULL) {
  335. printf("Test #3, couldn't set %s in %s.\n", "filesetacl", "buffer");
  336. }
  337. ACL_ListDestroy(NULL, acl_list);
  338. }
  339. /********************************************************************
  340. TEST #4
  341. TEST ACL_FileRenameAcl()
  342. TEST ACL_ParseFile()
  343. TEST ACL_ListFind()
  344. *********************************************************************/
  345. if ( ACL_FileRenameAcl(NULL, "buffer", "FileSetAcl", "loser", ACL_CASE_INSENSITIVE)< 0) {
  346. printf("Test #4, fail ACL_FileRenameACL(filesetacl, loser).\n");
  347. }
  348. if ( ACL_FileRenameAcl(NULL, "buffer", "franco", "bigdogs",
  349. ACL_CASE_INSENSITIVE)< 0) {
  350. printf("Test #4, fail ACL_FileRenameACL(franco, bigdogs).\n");
  351. }
  352. acl_list= ACL_ParseFile((NSErr_t *)NULL, "buffer");
  353. if ( acl_list == NULL ) {
  354. printf("Test #3, couldn't perform ACL_ParseFile(buffer)\n");
  355. goto skip_test;
  356. } else {
  357. if ( ACL_ListFind(NULL, acl_list, "loser", ACL_CASE_INSENSITIVE) == NULL) {
  358. printf("Test #4, fail rename %s in %s.\n", "loser", "buffer");
  359. }
  360. if ( ACL_ListFind(NULL, acl_list, "bigdogs", ACL_CASE_INSENSITIVE) == NULL) {
  361. printf("Test #4, fail rename %s in %s.\n", "bigdogs", "buffer");
  362. }
  363. if ( ACL_ListGetNameList(NULL, acl_list, &name_list) < 0 ) {
  364. printf("Test #4, yikes, the GetNameList failed.\n");
  365. } else {
  366. for (ii = 0; name_list[ii]; ii++)
  367. printf("ACL %s\n", name_list[ii]);
  368. ACL_NameListDestroy(NULL, name_list);
  369. }
  370. ACL_ListDestroy(NULL, acl_list);
  371. }
  372. skip_test:
  373. /********************************************************************
  374. END
  375. *********************************************************************/
  376. rights[0] = "html_read";
  377. rights[1] = "html_write";
  378. map_generic[0] = "html_read";
  379. map_generic[1] = "html_write";
  380. map_generic[2] = "N/A";
  381. map_generic[3] = "html_create";
  382. map_generic[4] = "html_delete";
  383. map_generic[5] = "N/A";
  384. map_generic[6] = NULL;
  385. for (i=10; i<20; i++) {
  386. sprintf(filename, "aclfile%d", i);
  387. eval.acllist = ACL_ParseFile((NSErr_t *)NULL, filename);
  388. if ( eval.acllist == NULL ) {
  389. printf("Parse failed.\n");
  390. continue;
  391. }
  392. result = ACL_EvalTestRights(NULL, &eval, &rights[0], map_generic, &bong, &bong_type, &acl_tag, &expr_num);
  393. ACL_ListDestroy(NULL, eval.acllist);
  394. printf("%s = %d\n\n", filename, result);
  395. }
  396. /*
  397. * DNS LAS Unit Tests
  398. */
  399. result = LASDnsEval(NULL, "dnsalias", CMP_OP_EQ, "*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  400. printf("dnsalias = *? %d\n\n", result);
  401. LASDnsFlush(&las_cookie);
  402. result = LASDnsEval(NULL, "dnsalias", CMP_OP_EQ, "aruba.mcom.com brain251.mcom.com", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  403. printf("dnsalias = aruba.mcom.com brain251.mcom.com? %d\n\n", result);
  404. LASDnsFlush(&las_cookie);
  405. result = LASDnsEval(NULL, "dns", CMP_OP_EQ, "*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  406. printf("dns = *? %d\n\n", result);
  407. result = LASDnsEval(NULL, "dns", CMP_OP_NE, "*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  408. printf("dns != *? %d\n\n", result);
  409. LASDnsFlush(&las_cookie);
  410. result = LASDnsEval(NULL, "dns", CMP_OP_EQ, "aruba.mcom.com", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  411. printf("dns = aruba.mcom.com? %d\n\n", result);
  412. LASDnsFlush(&las_cookie);
  413. result = LASDnsEval(NULL, "dns", CMP_OP_EQ, "ai.mit.edu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  414. printf("dns = ai.mit.edu? %d\n\n", result);
  415. LASDnsFlush(&las_cookie);
  416. result = LASDnsEval(NULL, "dns", CMP_OP_EQ, "*.ai.mit.edu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  417. printf("dns = *.ai.mit.edu? %d\n\n", result);
  418. LASDnsFlush(&las_cookie);
  419. result = LASDnsEval(NULL, "dns", CMP_OP_EQ, "*.mit.edu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  420. printf("dns = *.mit.edu? %d\n\n", result);
  421. LASDnsFlush(&las_cookie);
  422. result = LASDnsEval(NULL, "dns", CMP_OP_EQ, "*.edu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  423. printf("dns = *.edu? %d\n\n", result);
  424. LASDnsFlush(&las_cookie);
  425. result = LASDnsEval(NULL, "dns", CMP_OP_NE, "*.edu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  426. printf("dns != *.edu? %d\n\n", result);
  427. LASDnsFlush(&las_cookie);
  428. result = LASDnsEval(NULL, "mistake", CMP_OP_NE, "*.edu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  429. printf("mistake != *.edu? %d\n\n", result);
  430. LASDnsFlush(&las_cookie);
  431. result = LASDnsEval(NULL, "dns", CMP_OP_GT, "*.edu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  432. printf("dns > *.edu? %d\n\n", result);
  433. LASDnsFlush(&las_cookie);
  434. /*
  435. * IP LAS Unit Tests
  436. */
  437. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  438. printf ("ip = *? %d\n\n", result);
  439. LASIpFlush(&las_cookie);
  440. result = LASIpEval(NULL, "ip", CMP_OP_NE, "*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  441. printf ("ip != *? %d\n\n", result);
  442. LASIpFlush(&las_cookie);
  443. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "*.*.*.*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  444. printf ("ip = *.*.*.*? %d\n\n", result);
  445. LASIpFlush(&las_cookie);
  446. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  447. printf ("ip = 17.*? %d\n\n", result);
  448. LASIpFlush(&las_cookie);
  449. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.*.*.*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  450. printf ("ip = 17.*.*.*? %d\n\n", result);
  451. LASIpFlush(&las_cookie);
  452. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  453. printf ("ip = 17.34.*? %d\n\n", result);
  454. LASIpFlush(&las_cookie);
  455. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.*.*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  456. printf ("ip = 17.34.*.*? %d\n\n", result);
  457. LASIpFlush(&las_cookie);
  458. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.*", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  459. printf ("ip = 17.34.51.*? %d\n\n", result);
  460. LASIpFlush(&las_cookie);
  461. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.*+255.255.255.255", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  462. printf ("ip = 17.34.51.*+255.255.255.255? %d\n\n", result);
  463. LASIpFlush(&las_cookie);
  464. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.69+255.255.255.254, 123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  465. printf ("ip = 17.34.51.69+255.255.255.254, 123.45.67.89? %d\n\n", result);
  466. LASIpFlush(&las_cookie);
  467. result = LASIpEval(NULL, "ip", CMP_OP_NE, "17.34.51.69+255.255.255.254, 123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  468. printf ("ip != 17.34.51.69+255.255.255.254, 123.45.67.89? %d\n\n", result);
  469. LASIpFlush(&las_cookie);
  470. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.68, 17.34.51.69", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  471. printf ("ip = 17.34.51.68, 17.34.51.69? %d\n\n", result);
  472. LASIpFlush(&las_cookie);
  473. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.68, 17.34.51.69, 123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  474. printf ("ip = 17.34.51.68, 17.34.51.69, 123.45.67.89? %d\n\n", result);
  475. LASIpFlush(&las_cookie);
  476. result = LASIpEval(NULL, "ip", CMP_OP_NE, "17.34.51.68, 17.34.51.69, 123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  477. printf ("ip != 17.34.51.68, 17.34.51.69, 123.45.67.89? %d\n\n", result);
  478. LASIpFlush(&las_cookie);
  479. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.68", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  480. printf ("ip = 17.34.51.68? %d\n\n", result);
  481. LASIpFlush(&las_cookie);
  482. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.69", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  483. printf ("ip = 17.34.51.69? %d\n\n", result);
  484. LASIpFlush(&las_cookie);
  485. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.51.69+255.255.255.254", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  486. printf ("ip = 17.34.51.69+255.255.255.254? %d\n\n", result);
  487. LASIpFlush(&las_cookie);
  488. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.34.50.69+255.255.254.0", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  489. printf ("ip = 17.34.50.69+255.255.254.0? %d\n\n", result);
  490. LASIpFlush(&las_cookie);
  491. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "17.35.50.69+255.254.0.0", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  492. printf ("ip = 17.35.50.69+255.254.0.0? %d\n\n", result);
  493. LASIpFlush(&las_cookie);
  494. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "16.35.50.69+254.0.0.0", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  495. printf ("ip = 16.35.50.69+254.0.0.0? %d\n\n", result);
  496. LASIpFlush(&las_cookie);
  497. result = LASIpEval(NULL, "ip", CMP_OP_EQ, "123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  498. printf ("ip = 123.45.67.89? %d\n\n", result);
  499. result = LASIpEval(NULL, "ip", CMP_OP_NE, "123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  500. printf ("ip != 123.45.67.89? %d\n\n", result);
  501. result = LASIpEval(NULL, "ip", CMP_OP_GT, "123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  502. printf ("ip > 123.45.67.89? %d\n\n", result);
  503. result = LASIpEval(NULL, "ip", CMP_OP_LT, "123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  504. printf ("ip < 123.45.67.89? %d\n\n", result);
  505. result = LASIpEval(NULL, "ip", CMP_OP_GE, "123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  506. printf ("ip >= 123.45.67.89? %d\n\n", result);
  507. result = LASIpEval(NULL, "ip", CMP_OP_LE, "123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  508. printf ("ip <= 123.45.67.89? %d\n\n", result);
  509. LASIpFlush(&las_cookie);
  510. result = LASIpEval(NULL, "mistake", CMP_OP_LE, "123.45.67.89", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  511. printf ("mistake <= 123.45.67.89? %d\n\n", result);
  512. LASIpFlush(&las_cookie);
  513. /*
  514. * Time of Day unit tests.
  515. */
  516. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_EQ, "2120", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  517. printf("time = 2120? %d\n\n", result);
  518. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_NE, "2120", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  519. printf("time != 2120? %d\n\n", result);
  520. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_EQ, "0700", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  521. printf("time = 0700? %d\n\n", result);
  522. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_NE, "0700", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  523. printf("time != 0700? %d\n\n", result);
  524. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_EQ, "2400", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  525. printf("time = 2400? %d\n\n", result);
  526. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_NE, "2400", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  527. printf("time != 2400? %d\n\n", result);
  528. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_GT, "2120", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  529. printf("time > 2120? %d\n\n", result);
  530. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_LT, "2120", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  531. printf("time < 2120? %d\n\n", result);
  532. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_GT, "0700", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  533. printf("time > 0700? %d\n\n", result);
  534. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_LT, "0700", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  535. printf("time < 0700? %d\n\n", result);
  536. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_GT, "2400", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  537. printf("time > 2400? %d\n\n", result);
  538. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_LT, "2400", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  539. printf("time < 2400? %d\n\n", result);
  540. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_GE, "2120", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  541. printf("time >= 2120? %d\n\n", result);
  542. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_LE, "2120", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  543. printf("time <= 2120? %d\n\n", result);
  544. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_GE, "0700", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  545. printf("time >= 0700? %d\n\n", result);
  546. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_LE, "0700", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  547. printf("time <= 0700? %d\n\n", result);
  548. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_GE, "2400", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  549. printf("time >= 2400? %d\n\n", result);
  550. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_LE, "2400", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  551. printf("time <= 2400? %d\n\n", result);
  552. result = LASTimeOfDayEval(NULL, "mistake", CMP_OP_LE, "2400", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  553. printf("mistake <= 2400? %d\n\n", result);
  554. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_EQ, "0800-2200", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  555. printf("time = 0800-2200? %d\n\n", result);
  556. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_NE, "0800-2200", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  557. printf("time != 0800-2200? %d\n\n", result);
  558. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_EQ, "2200-0800", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  559. printf("time = 2200-0800? %d\n\n", result);
  560. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_NE, "2200-0800", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  561. printf("time != 2200-0800? %d\n\n", result);
  562. result = LASTimeOfDayEval(NULL, "timeofday", CMP_OP_LE, "2200-0800", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  563. printf("time <= 2200-0800? %d\n\n", result);
  564. /*
  565. * Day Of Week Unit Tests
  566. */
  567. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "Mon", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  568. printf("= mon? %d\n\n", result);
  569. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "tUe", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  570. printf("= tUe? %d\n\n", result);
  571. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "weD", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  572. printf("= weD? %d\n\n", result);
  573. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "THu", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  574. printf("= THu? %d\n\n", result);
  575. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "FrI", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  576. printf("= FrI? %d\n\n", result);
  577. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "sAT", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  578. printf("= tUe? %d\n\n", result);
  579. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "Sun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  580. printf("= Sun? %d\n\n", result);
  581. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_EQ, "mon,tuewed,thu,frisatsun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  582. printf("= mon,tuewed,thu,frisatsun? %d\n\n", result);
  583. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_NE, "mon,tuewed,thu,frisatsun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  584. printf("!= mon,tuewed,thu,frisatsun? %d\n\n", result);
  585. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_GT, "Sun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  586. printf("> Sun? %d\n\n", result);
  587. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_LT, "Sun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  588. printf("< Sun? %d\n\n", result);
  589. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_GE, "Sun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  590. printf(">= Sun? %d\n\n", result);
  591. result = LASDayOfWeekEval(NULL, "dayofweek", CMP_OP_LE, "Sun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  592. printf("<= Sun? %d\n\n", result);
  593. result = LASDayOfWeekEval(NULL, "mistake", CMP_OP_LE, "Sun", &cachable, &las_cookie, NULL, NULL, NULL, NULL);
  594. printf("mistake <= Sun? %d\n\n", result);
  595. ACL_Destroy();
  596. exit(0);
  597. }