HTGroup.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /* MODULE HTGroup.c
  2. * GROUP FILE ROUTINES
  3. *
  4. * Contains group file parser and routines to match IP
  5. * address templates and to find out group membership.
  6. *
  7. *
  8. * AUTHORS:
  9. * AL Ari Luotonen luotonen@dxcern.cern.ch
  10. *
  11. * HISTORY:
  12. *
  13. *
  14. * BUGS:
  15. *
  16. *
  17. *
  18. * GROUP DEFINITION GRAMMAR:
  19. *
  20. * string = "sequence of alphanumeric characters"
  21. * user_name ::= string
  22. * group_name ::= string
  23. * group_ref ::= group_name
  24. * user_def ::= user_name | group_ref
  25. * user_def_list ::= user_def { ',' user_def }
  26. * user_part = user_def | '(' user_def_list ')'
  27. *
  28. * templ = "sequence of alphanumeric characters and '*'s"
  29. * ip_number_mask ::= templ '.' templ '.' templ '.' templ
  30. * domain_name_mask ::= templ { '.' templ }
  31. * address ::= ip_number_mask | domain_name_mask
  32. * address_def ::= address
  33. * address_def_list ::= address_def { ',' address_def }
  34. * address_part = address_def | '(' address_def_list ')'
  35. *
  36. * item ::= [user_part] ['@' address_part]
  37. * item_list ::= item { ',' item }
  38. * group_def ::= item_list
  39. * group_decl ::= group_name ':' group_def
  40. *
  41. */
  42. #include <HTUtils.h>
  43. #include <HTAAUtil.h>
  44. #include <HTLex.h> /* Lexical analysor */
  45. #include <HTGroup.h> /* Implemented here */
  46. #include <LYUtils.h>
  47. #include <LYLeaks.h>
  48. /*
  49. * Group file parser
  50. */
  51. typedef HTList UserDefList;
  52. typedef HTList AddressDefList;
  53. typedef struct {
  54. UserDefList *user_def_list;
  55. AddressDefList *address_def_list;
  56. } Item;
  57. typedef struct {
  58. char *name;
  59. GroupDef *translation;
  60. } Ref;
  61. static void syntax_error(FILE *fp, const char *msg,
  62. LexItem lex_item)
  63. {
  64. char buffer[41];
  65. int cnt = 0;
  66. int ch;
  67. while ((ch = getc(fp)) != EOF && ch != '\n')
  68. if (cnt < 40)
  69. buffer[cnt++] = (char) ch;
  70. buffer[cnt] = (char) 0;
  71. CTRACE((tfp, "%s %d before: '%s'\nHTGroup.c: %s (got %s)\n",
  72. "HTGroup.c: Syntax error in rule file at line",
  73. HTlex_line, buffer, msg, lex_verbose(lex_item)));
  74. HTlex_line++;
  75. }
  76. static AddressDefList *parse_address_part(FILE *fp)
  77. {
  78. AddressDefList *address_def_list = NULL;
  79. LexItem lex_item;
  80. BOOL only_one = NO;
  81. lex_item = lex(fp);
  82. if (lex_item == LEX_ALPH_STR || lex_item == LEX_TMPL_STR)
  83. only_one = YES;
  84. else if (lex_item != LEX_OPEN_PAREN ||
  85. ((lex_item = lex(fp)) != LEX_ALPH_STR &&
  86. lex_item != LEX_TMPL_STR)) {
  87. syntax_error(fp, "Expecting a single address or '(' beginning list",
  88. lex_item);
  89. return NULL;
  90. }
  91. address_def_list = HTList_new();
  92. for (;;) {
  93. Ref *ref = typecalloc(Ref);
  94. if (ref == NULL)
  95. outofmem(__FILE__, "parse_address_part");
  96. ref->name = NULL;
  97. ref->translation = NULL;
  98. StrAllocCopy(ref->name, HTlex_buffer);
  99. HTList_addObject(address_def_list, (void *) ref);
  100. if (only_one || (lex_item = lex(fp)) != LEX_ITEM_SEP)
  101. break;
  102. /*
  103. * Here lex_item == LEX_ITEM_SEP; after item separator it
  104. * is ok to have one or more newlines (LEX_REC_SEP) and
  105. * they are ignored (continuation line).
  106. */
  107. do {
  108. lex_item = lex(fp);
  109. } while (lex_item == LEX_REC_SEP);
  110. if (lex_item != LEX_ALPH_STR && lex_item != LEX_TMPL_STR) {
  111. syntax_error(fp, "Expecting an address template", lex_item);
  112. HTList_delete(address_def_list);
  113. address_def_list = NULL;
  114. return NULL;
  115. }
  116. }
  117. if (!only_one && lex_item != LEX_CLOSE_PAREN) {
  118. HTList_delete(address_def_list);
  119. address_def_list = NULL;
  120. syntax_error(fp, "Expecting ')' closing address list", lex_item);
  121. return NULL;
  122. }
  123. return address_def_list;
  124. }
  125. static UserDefList *parse_user_part(FILE *fp)
  126. {
  127. UserDefList *user_def_list = NULL;
  128. LexItem lex_item;
  129. BOOL only_one = NO;
  130. lex_item = lex(fp);
  131. if (lex_item == LEX_ALPH_STR)
  132. only_one = YES;
  133. else if (lex_item != LEX_OPEN_PAREN ||
  134. (lex_item = lex(fp)) != LEX_ALPH_STR) {
  135. syntax_error(fp, "Expecting a single name or '(' beginning list",
  136. lex_item);
  137. return NULL;
  138. }
  139. user_def_list = HTList_new();
  140. for (;;) {
  141. Ref *ref = typecalloc(Ref);
  142. if (ref == NULL)
  143. outofmem(__FILE__, "parse_user_part");
  144. ref->name = NULL;
  145. ref->translation = NULL;
  146. StrAllocCopy(ref->name, HTlex_buffer);
  147. HTList_addObject(user_def_list, (void *) ref);
  148. if (only_one || (lex_item = lex(fp)) != LEX_ITEM_SEP)
  149. break;
  150. /*
  151. * Here lex_item == LEX_ITEM_SEP; after item separator it
  152. * is ok to have one or more newlines (LEX_REC_SEP) and
  153. * they are ignored (continuation line).
  154. */
  155. do {
  156. lex_item = lex(fp);
  157. } while (lex_item == LEX_REC_SEP);
  158. if (lex_item != LEX_ALPH_STR) {
  159. syntax_error(fp, "Expecting user or group name", lex_item);
  160. HTList_delete(user_def_list);
  161. user_def_list = NULL;
  162. return NULL;
  163. }
  164. }
  165. if (!only_one && lex_item != LEX_CLOSE_PAREN) {
  166. HTList_delete(user_def_list);
  167. user_def_list = NULL;
  168. syntax_error(fp, "Expecting ')' closing user/group list", lex_item);
  169. return NULL;
  170. }
  171. return user_def_list;
  172. }
  173. static Item *parse_item(FILE *fp)
  174. {
  175. Item *item = NULL;
  176. UserDefList *user_def_list = NULL;
  177. AddressDefList *address_def_list = NULL;
  178. LexItem lex_item;
  179. lex_item = lex(fp);
  180. if (lex_item == LEX_ALPH_STR || lex_item == LEX_OPEN_PAREN) {
  181. unlex(lex_item);
  182. user_def_list = parse_user_part(fp);
  183. lex_item = lex(fp);
  184. }
  185. if (lex_item == LEX_AT_SIGN) {
  186. lex_item = lex(fp);
  187. if (lex_item == LEX_ALPH_STR || lex_item == LEX_TMPL_STR ||
  188. lex_item == LEX_OPEN_PAREN) {
  189. unlex(lex_item);
  190. address_def_list = parse_address_part(fp);
  191. } else {
  192. if (user_def_list) {
  193. HTList_delete(user_def_list); /* @@@@ */
  194. user_def_list = NULL;
  195. }
  196. syntax_error(fp, "Expected address part (single address or list)",
  197. lex_item);
  198. return NULL;
  199. }
  200. } else
  201. unlex(lex_item);
  202. if (!user_def_list && !address_def_list) {
  203. syntax_error(fp, "Empty item not allowed", lex_item);
  204. return NULL;
  205. }
  206. item = typecalloc(Item);
  207. if (item == NULL)
  208. outofmem(__FILE__, "parse_item");
  209. item->user_def_list = user_def_list;
  210. item->address_def_list = address_def_list;
  211. return item;
  212. }
  213. static ItemList *parse_item_list(FILE *fp)
  214. {
  215. ItemList *item_list = HTList_new();
  216. Item *item;
  217. LexItem lex_item;
  218. for (;;) {
  219. if (!(item = parse_item(fp))) {
  220. HTList_delete(item_list); /* @@@@ */
  221. item_list = NULL;
  222. return NULL;
  223. }
  224. HTList_addObject(item_list, (void *) item);
  225. lex_item = lex(fp);
  226. if (lex_item != LEX_ITEM_SEP) {
  227. unlex(lex_item);
  228. return item_list;
  229. }
  230. /*
  231. * Here lex_item == LEX_ITEM_SEP; after item separator it
  232. * is ok to have one or more newlines (LEX_REC_SEP) and
  233. * they are ignored (continuation line).
  234. */
  235. do {
  236. lex_item = lex(fp);
  237. } while (lex_item == LEX_REC_SEP);
  238. unlex(lex_item);
  239. }
  240. }
  241. GroupDef *HTAA_parseGroupDef(FILE *fp)
  242. {
  243. ItemList *item_list = NULL;
  244. GroupDef *group_def = NULL;
  245. LexItem lex_item;
  246. if (!(item_list = parse_item_list(fp))) {
  247. return NULL;
  248. }
  249. group_def = typecalloc(GroupDef);
  250. if (group_def == NULL)
  251. outofmem(__FILE__, "HTAA_parseGroupDef");
  252. group_def->group_name = NULL;
  253. group_def->item_list = item_list;
  254. if ((lex_item = lex(fp)) != LEX_REC_SEP) {
  255. syntax_error(fp, "Garbage after group definition", lex_item);
  256. }
  257. return group_def;
  258. }
  259. #if 0
  260. static GroupDef *parse_group_decl(FILE *fp)
  261. {
  262. char *group_name = NULL;
  263. GroupDef *group_def = NULL;
  264. LexItem lex_item;
  265. do {
  266. lex_item = lex(fp);
  267. } while (lex_item == LEX_REC_SEP); /* Ignore empty lines */
  268. if (lex_item != LEX_ALPH_STR) {
  269. if (lex_item != LEX_EOF)
  270. syntax_error(fp, "Expecting group name", lex_item);
  271. return NULL;
  272. }
  273. StrAllocCopy(group_name, HTlex_buffer);
  274. if (LEX_FIELD_SEP != (lex_item = lex(fp))) {
  275. syntax_error(fp, "Expecting field separator", lex_item);
  276. FREE(group_name);
  277. return NULL;
  278. }
  279. if (!(group_def = HTAA_parseGroupDef(fp))) {
  280. FREE(group_name);
  281. return NULL;
  282. }
  283. group_def->group_name = group_name;
  284. return group_def;
  285. }
  286. /*
  287. * Group manipulation routines
  288. */
  289. static GroupDef *find_group_def(GroupDefList *group_list,
  290. const char *group_name)
  291. {
  292. if (group_list && group_name) {
  293. GroupDefList *cur = group_list;
  294. GroupDef *group_def;
  295. while (NULL != (group_def = (GroupDef *) HTList_nextObject(cur))) {
  296. if (!strcmp(group_name, group_def->group_name)) {
  297. return group_def;
  298. }
  299. }
  300. }
  301. return NULL;
  302. }
  303. void HTAA_resolveGroupReferences(GroupDef *group_def,
  304. GroupDefList *group_def_list)
  305. {
  306. if (group_def && group_def->item_list && group_def_list) {
  307. ItemList *cur1 = group_def->item_list;
  308. Item *item;
  309. while (NULL != (item = (Item *) HTList_nextObject(cur1))) {
  310. UserDefList *cur2 = item->user_def_list;
  311. Ref *ref;
  312. while (NULL != (ref = (Ref *) HTList_nextObject(cur2)))
  313. ref->translation = find_group_def(group_def_list, ref->name);
  314. /* Does NOT translate address_def_list */
  315. }
  316. }
  317. }
  318. static void add_group_def(GroupDefList *group_def_list,
  319. GroupDef *group_def)
  320. {
  321. HTAA_resolveGroupReferences(group_def, group_def_list);
  322. HTList_addObject(group_def_list, (void *) group_def);
  323. }
  324. static GroupDefList *parse_group_file(FILE *fp)
  325. {
  326. GroupDefList *group_def_list = HTList_new();
  327. GroupDef *group_def;
  328. while (NULL != (group_def = parse_group_decl(fp)))
  329. add_group_def(group_def_list, group_def);
  330. return group_def_list;
  331. }
  332. #endif
  333. /*
  334. * Trace functions
  335. */
  336. static void print_item(Item *item)
  337. {
  338. if (!item)
  339. fprintf(tfp, "\tNULL-ITEM\n");
  340. else {
  341. UserDefList *cur1 = item->user_def_list;
  342. AddressDefList *cur2 = item->address_def_list;
  343. Ref *user_ref = (Ref *) HTList_nextObject(cur1);
  344. Ref *addr_ref = (Ref *) HTList_nextObject(cur2);
  345. if (user_ref) {
  346. fprintf(tfp, "\t[%s%s", user_ref->name,
  347. (user_ref->translation ? "*REF*" : ""));
  348. while (NULL != (user_ref = (Ref *) HTList_nextObject(cur1)))
  349. fprintf(tfp, "; %s%s", user_ref->name,
  350. (user_ref->translation ? "*REF*" : ""));
  351. fprintf(tfp, "] ");
  352. } else
  353. fprintf(tfp, "\tANYBODY ");
  354. if (addr_ref) {
  355. fprintf(tfp, "@ [%s", addr_ref->name);
  356. while (NULL != (addr_ref = (Ref *) HTList_nextObject(cur2)))
  357. fprintf(tfp, "; %s", addr_ref->name);
  358. fprintf(tfp, "]\n");
  359. } else
  360. fprintf(tfp, "@ ANYADDRESS\n");
  361. }
  362. }
  363. static void print_item_list(ItemList *item_list)
  364. {
  365. ItemList *cur = item_list;
  366. Item *item;
  367. if (!item_list)
  368. fprintf(tfp, "EMPTY");
  369. else
  370. while (NULL != (item = (Item *) HTList_nextObject(cur)))
  371. print_item(item);
  372. }
  373. void HTAA_printGroupDef(GroupDef *group_def)
  374. {
  375. if (!group_def) {
  376. fprintf(tfp, "\nNULL RECORD\n");
  377. return;
  378. }
  379. fprintf(tfp, "\nGroup %s:\n",
  380. (group_def->group_name ? group_def->group_name : "NULL"));
  381. print_item_list(group_def->item_list);
  382. fprintf(tfp, "\n");
  383. }
  384. #if 0
  385. static void print_group_def_list(GroupDefList *group_list)
  386. {
  387. GroupDefList *cur = group_list;
  388. GroupDef *group_def;
  389. while (NULL != (group_def = (GroupDef *) HTList_nextObject(cur)))
  390. HTAA_printGroupDef(group_def);
  391. }
  392. /*
  393. * IP address template matching
  394. */
  395. /* static part_match()
  396. * MATCH ONE PART OF INET ADDRESS AGAIST
  397. * A PART OF MASK (inet address has 4 parts)
  398. * ON ENTRY:
  399. * tcur pointer to the beginning of template part.
  400. * icur pointer to the beginning of actual inet
  401. * number part.
  402. *
  403. * ON EXIT:
  404. * returns YES, if match.
  405. */
  406. static BOOL part_match(const char *tcur,
  407. const char *icur)
  408. {
  409. char required[4];
  410. char actual[4];
  411. const char *cur;
  412. int cnt;
  413. BOOL status;
  414. if (!tcur || !icur)
  415. return NO;
  416. cur = tcur;
  417. cnt = 0;
  418. while (cnt < 3 && *cur && *cur != '.')
  419. required[cnt++] = *(cur++);
  420. required[cnt] = (char) 0;
  421. cur = icur;
  422. cnt = 0;
  423. while (cnt < 3 && *cur && *cur != '.')
  424. actual[cnt++] = *(cur++);
  425. actual[cnt] = (char) 0;
  426. status = HTAA_templateMatch(required, actual);
  427. CTRACE((tfp, "part_match: req: '%s' act: '%s' match: %s\n",
  428. required, actual, (status ? "yes" : "no")));
  429. return status;
  430. }
  431. /* static ip_number_match()
  432. * MATCH INET NUMBER AGAINST AN INET NUMBER MASK
  433. * ON ENTRY:
  434. * template mask to match agaist, e.g., 128.141.*.*
  435. * the_inet_addr actual inet address, e.g., 128.141.201.74
  436. *
  437. * ON EXIT:
  438. * returns YES, if match; NO, if not.
  439. */
  440. static BOOL ip_number_match(const char *ctemplate,
  441. const char *the_inet_addr)
  442. {
  443. const char *tcur = ctemplate;
  444. const char *icur = the_inet_addr;
  445. int cnt;
  446. for (cnt = 0; cnt < 4; cnt++) {
  447. if (!tcur || !icur || !part_match(tcur, icur))
  448. return NO;
  449. if (NULL != (tcur = strchr(tcur, '.')))
  450. tcur++;
  451. if (NULL != (icur = strchr(icur, '.')))
  452. icur++;
  453. }
  454. return YES;
  455. }
  456. /* static is_domain_mask()
  457. * DETERMINE IF A GIVEN MASK IS A
  458. * DOMAIN NAME MASK OR AN INET NUMBER MASK
  459. * ON ENTRY:
  460. * mask either a domain name mask,
  461. * e.g.
  462. * *.cern.ch
  463. *
  464. * or an inet number mask,
  465. * e.g.
  466. * 128.141.*.*
  467. *
  468. * ON EXIT:
  469. * returns YES, if mask is a domain name mask.
  470. * NO, if it is an inet number mask.
  471. */
  472. static BOOL is_domain_mask(const char *mask)
  473. {
  474. const char *cur = mask;
  475. if (!mask)
  476. return NO;
  477. while (*cur) {
  478. if (*cur != '.' && *cur != '*' && (*cur < '0' || *cur > '9'))
  479. return YES; /* Even one non-digit makes it a domain name mask */
  480. cur++;
  481. }
  482. return NO; /* All digits and dots, so it is an inet number mask */
  483. }
  484. /* static ip_mask_match()
  485. * MATCH AN IP NUMBER MASK OR IP NAME MASK
  486. * AGAINST ACTUAL IP NUMBER OR IP NAME
  487. *
  488. * ON ENTRY:
  489. * mask mask. Mask may be either an inet number
  490. * mask or a domain name mask,
  491. * e.g.
  492. * 128.141.*.*
  493. * or
  494. * *.cern.ch
  495. *
  496. * ip_number IP number of connecting host.
  497. * ip_name IP name of the connecting host.
  498. *
  499. * ON EXIT:
  500. * returns YES, if hostname/internet number
  501. * matches the mask.
  502. * NO, if no match (no fire).
  503. */
  504. static BOOL ip_mask_match(const char *mask,
  505. const char *ip_number,
  506. const char *ip_name)
  507. {
  508. if (mask && (ip_number || ip_name)) {
  509. if (is_domain_mask(mask)) {
  510. if (HTAA_templateMatch(mask, ip_name))
  511. return YES;
  512. } else {
  513. if (ip_number_match(mask, ip_number))
  514. return YES;
  515. }
  516. }
  517. return NO;
  518. }
  519. static BOOL ip_in_def_list(AddressDefList *address_def_list,
  520. char *ip_number,
  521. char *ip_name)
  522. {
  523. if (address_def_list && (ip_number || ip_name)) {
  524. AddressDefList *cur = address_def_list;
  525. Ref *ref;
  526. while (NULL != (ref = (Ref *) HTList_nextObject(cur))) {
  527. /* Value of ref->translation is ignored, i.e., */
  528. /* no recursion for ip address tamplates. */
  529. if (ip_mask_match(ref->name, ip_number, ip_name))
  530. return YES;
  531. }
  532. }
  533. return NO;
  534. }
  535. /*
  536. * Group file cached reading
  537. */
  538. typedef struct {
  539. char *group_filename;
  540. GroupDefList *group_list;
  541. } GroupCache;
  542. typedef HTList GroupCacheList;
  543. static GroupCacheList *group_cache_list = NULL;
  544. GroupDefList *HTAA_readGroupFile(const char *filename)
  545. {
  546. FILE *fp;
  547. GroupCache *group_cache;
  548. if (isEmpty(filename))
  549. return NULL;
  550. if (!group_cache_list)
  551. group_cache_list = HTList_new();
  552. else {
  553. GroupCacheList *cur = group_cache_list;
  554. while (NULL != (group_cache = (GroupCache *) HTList_nextObject(cur))) {
  555. if (!strcmp(filename, group_cache->group_filename)) {
  556. CTRACE((tfp, "%s '%s' %s\n",
  557. "HTAA_readGroupFile: group file",
  558. filename, "already found in cache"));
  559. return group_cache->group_list;
  560. } /* if cache match */
  561. } /* while cached files remain */
  562. } /* cache exists */
  563. CTRACE((tfp, "HTAA_readGroupFile: reading group file `%s'\n",
  564. filename));
  565. if (!(fp = fopen(filename, TXT_R))) {
  566. CTRACE((tfp, "%s '%s'\n",
  567. "HTAA_readGroupFile: unable to open group file",
  568. filename));
  569. return NULL;
  570. }
  571. if ((group_cache = typecalloc(GroupCache)) == 0)
  572. outofmem(__FILE__, "HTAA_readGroupFile");
  573. group_cache->group_filename = NULL;
  574. StrAllocCopy(group_cache->group_filename, filename);
  575. group_cache->group_list = parse_group_file(fp);
  576. HTList_addObject(group_cache_list, (void *) group_cache);
  577. fclose(fp);
  578. CTRACE((tfp, "Read group file '%s', results follow:\n", filename));
  579. if (TRACE)
  580. print_group_def_list(group_cache->group_list);
  581. return group_cache->group_list;
  582. }
  583. /* PUBLIC HTAA_userAndInetInGroup()
  584. * CHECK IF USER BELONGS TO TO A GIVEN GROUP
  585. * AND THAT THE CONNECTION COMES FROM AN
  586. * ADDRESS THAT IS ALLOWED BY THAT GROUP
  587. * ON ENTRY:
  588. * group the group definition structure.
  589. * username connecting user.
  590. * ip_number browser host IP number, optional.
  591. * ip_name browser host IP name, optional.
  592. * However, one of ip_number or ip_name
  593. * must be given.
  594. * ON EXIT:
  595. * returns HTAA_IP_MASK, if IP address mask was
  596. * reason for failing.
  597. * HTAA_NOT_MEMBER, if user does not belong
  598. * to the group.
  599. * HTAA_OK if both IP address and user are ok.
  600. */
  601. HTAAFailReasonType HTAA_userAndInetInGroup(GroupDef *group,
  602. char *username,
  603. char *ip_number,
  604. char *ip_name)
  605. {
  606. HTAAFailReasonType reason = HTAA_NOT_MEMBER;
  607. if (group && username) {
  608. ItemList *cur1 = group->item_list;
  609. Item *item;
  610. while (NULL != (item = (Item *) HTList_nextObject(cur1))) {
  611. if (!item->address_def_list || /* Any address allowed */
  612. ip_in_def_list(item->address_def_list, ip_number, ip_name)) {
  613. if (!item->user_def_list) /* Any user allowed */
  614. return HTAA_OK;
  615. else {
  616. UserDefList *cur2 = item->user_def_list;
  617. Ref *ref;
  618. while (NULL != (ref = (Ref *) HTList_nextObject(cur2))) {
  619. if (ref->translation) { /* Group, check recursively */
  620. reason = HTAA_userAndInetInGroup(ref->translation,
  621. username,
  622. ip_number, ip_name);
  623. if (reason == HTAA_OK)
  624. return HTAA_OK;
  625. } else { /* Username, check directly */
  626. if (username && *username &&
  627. 0 == strcmp(ref->name, username))
  628. return HTAA_OK;
  629. }
  630. /* Every user/group name in this group */
  631. }
  632. /* search for username */
  633. }
  634. /* IP address ok */
  635. } else {
  636. reason = HTAA_IP_MASK;
  637. }
  638. } /* while items in group */
  639. }
  640. /* valid parameters */
  641. return reason; /* No match, or invalid parameters */
  642. }
  643. void GroupDef_delete(GroupDef *group_def)
  644. {
  645. if (group_def) {
  646. FREE(group_def->group_name);
  647. if (group_def->item_list) {
  648. HTList_delete(group_def->item_list); /* @@@@ */
  649. group_def->item_list = NULL;
  650. }
  651. FREE(group_def);
  652. }
  653. }
  654. #endif