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.

This function has the following arguments:<br />

sockfd<br />

Socket descriptor for the remote connection. This argument is used solely to<br />

obtain the IP address of the remote connection.<br />

strict<br />

Boolean value indicating whether strict DNS spoofing checks are to be done. If<br />

this argument is specified as 0, IP addresses that do not have a reverse mapping<br />

will be allowed; otherwise, SPC_ERROR_NOREVERSE will be returned for such connections.<br />

action<br />

Default action to take if the remote IP address does not match any of the defined<br />

access restriction rules. It may be specified as either SPC_HOST_ALLOW or SPC_HOST_<br />

DENY. Any other value will be treated as equivalent to SPC_HOST_DENY.<br />

You may use spc_host_check( ) without using spc_host_init( ), in which case it will<br />

essentially only perform DNS spoofing checks. If you do not use spc_host_init( ),<br />

spc_host_check( ) will have an empty rule set, and it will always use the default<br />

action if the remote connection passes the DNS spoofing checks.<br />

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

int i, rc;<br />

char *hostname;<br />

struct sockaddr_in addr;<br />

if ((rc = check_spoofdns(sockfd, &addr, &hostname)) = = -1) return -1;<br />

if (rc && (rc != SPC_ERROR_NOREVERSE || strict)) return rc;<br />

for (i = 0; i < spc_host_rulecount; i++) {<br />

if (spc_host_rules[i].name) {<br />

if (hostname && !strcasecmp(hostname, spc_host_rules[i].name)) {<br />

free(hostname);<br />

return (spc_host_rules[i].action = = SPC_HOST_ALLOW);<br />

}<br />

} else {<br />

if ((addr.sin_addr.s_addr & spc_host_rules[i].mask) = =<br />

spc_host_rules[i].addr) {<br />

free(hostname);<br />

return (spc_host_rules[i].action = = SPC_HOST_ALLOW);<br />

}<br />

}<br />

}<br />

if (hostname) free(hostname);<br />

return (action = = SPC_HOST_ALLOW);<br />

}<br />

386 | 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!