21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

} else {<br />

if (inet_addr(tmp) = = INADDR_NONE) rule.name = strdup(tmp);<br />

else {<br />

rule.name = 0;<br />

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

rule.mask = 0xFFFFFFFF;<br />

}<br />

}<br />

if (!add_rule(&rule)) {<br />

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

free(buf);<br />

fclose(f);<br />

free_rules( );<br />

return 0;<br />

}<br />

}<br />

}<br />

free(buf);<br />

fclose(f);<br />

return 1;<br />

}<br />

Finally, the function spc_host_check( ) performs access restriction checks. If the<br />

remote connection should be allowed, the return will be 0. If some kind of error unrelated<br />

to access restriction occurs (e.g., out of memory, bad socket descriptor, etc.), the<br />

return will be –1. Otherwise, one of the following error constants may be returned:<br />

SPC_ERROR_NOREVERSE<br />

Indicates that the IP address of the remote connection has no reverse mapping. If<br />

strict checking is not being done, this error code will not be returned.<br />

SPC_ERROR_NOHOSTNAME<br />

Indicates that the IP address of the remote connection reverse-maps to a hostname<br />

that does not map to any IP address. This condition does not necessarily<br />

indicate that a DNS spoofing attack is taking place; however, we do recommend<br />

that you treat it as such.<br />

SPC_ERROR_BADHOSTNAME<br />

Indicates that the likelihood of a DNS spoofing attack is high. The IP address of<br />

the remote connection does not match any of the IP addresses that its hostname<br />

maps to.<br />

SPC_ERROR_HOSTDENIED<br />

Indicates that no DNS spoofing attack is believed to be taking place, but the<br />

access restriction rules have matched the remote address with a deny rule.<br />

The function spc_host_check( ) has the following signature:<br />

int spc_host_check(int sockfd, int strict, int action);<br />

Restricting Access Based on Hostname or IP Address | 385<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!