21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

if (!(f = fopen(filename, "r"))) return 0;<br />

if (!(buf = (char *)malloc(256))) {<br />

fclose(f);<br />

return 0;<br />

}<br />

while (fgets(buf + len, bufsz - len, f) != 0) {<br />

len += strlen(buf + len);<br />

if (buf[len - 1] != '\n') {<br />

if (!(buf = (char *)realloc((tmp = buf), bufsz += 256))) {<br />

fprintf(stderr, "%s line %d: out of memory\n", filename, ++lineno);<br />

free(tmp);<br />

fclose(f);<br />

free_rules( );<br />

return 0;<br />

}<br />

continue;<br />

}<br />

buf[--len] = 0;<br />

lineno++;<br />

for (tmp = buf; *tmp && isspace(*tmp); tmp++) len--;<br />

while (len && isspace(tmp[len - 1])) len--;<br />

tmp[len] = 0;<br />

len = 0;<br />

if (!tmp[0] || tmp[0] = = '#' || tmp[0] = = ';') continue;<br />

memset(&rule, 0, sizeof(rule));<br />

if (strncasecmp(tmp, "allow:", 6) && strncasecmp(tmp, "deny:", 5)) {<br />

fprintf(stderr, "%s line %d: parse error; continuing anyway.\n",<br />

filename, lineno);<br />

continue;<br />

}<br />

if (!strncasecmp(tmp, "deny:", 5)) {<br />

rule.action = SPC_HOST_DENY;<br />

tmp += 5;<br />

} else {<br />

rule.action = SPC_HOST_ALLOW;<br />

tmp += 6;<br />

}<br />

while (*tmp && isspace(*tmp)) tmp++;<br />

if (!*tmp) {<br />

fprintf(stderr, "%s line %d: parse error; continuing anyway.\n",<br />

filename, lineno);<br />

continue;<br />

}<br />

for (p = tmp; *p; tmp = p) {<br />

while (*p && !isspace(*p)) p++;<br />

if (*p) *p++ = 0;<br />

if ((slash = strchr(tmp, '/')) != 0) {<br />

*slash++ = 0;<br />

rule.name = 0;<br />

rule.addr = parse_addr(tmp);<br />

rule.mask = make_mask(atoi(slash));<br />

384 | Chapter 8: Authentication and Key Exchange<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!