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.

Access restriction information read by spc_host_init( ) is required to be in a very<br />

specific format. Whitespace is mostly ignored, and lines beginning with a hash mark<br />

(#) or a semicolon (;) are considered comments and ignored. Any other line in the<br />

file must begin with either “allow:” or “deny:” to indicate the type of rule.<br />

Following the rule type is a whitespace-separated list of addresses that are to be<br />

either allowed or denied access. Addresses may be hostnames or IP addresses. IP<br />

addresses may be specified as an address and mask or simply as an address. In the<br />

former case, the address may contain up to four parts, where each part must be<br />

expressed in decimal (ranging from 0 to 255), and a period (.) must be used to separate<br />

them. A forward slash (/) separates the address from the mask, and the mask is<br />

expressed as the number of bits to set. Table 8-1 lists example representations that<br />

are accepted as valid.<br />

Table 8-1. Example address representations accepted by spc_host_init( )<br />

Representation Meaning<br />

www.oreilly.com The host to which the reverse-and-forward<br />

maps www.oreilly.com will be matched.<br />

12.109.142.4 Only the specific address 12.109.142.4 will be<br />

matched.<br />

10/24 Any address starting with 10 will be matched.<br />

192.168/16 Any address starting with 192.168 will be<br />

matched.<br />

If any errors are encountered when parsing the access restriction data file, a message<br />

containing the name of the file and the line number is printed. Parsing of the file then<br />

continues on the next line. Fatal errors (e.g., out of memory) are also noted in a similar<br />

fashion, but parsing terminates immediately and any data successfully parsed so<br />

far is thrown away.<br />

When spc_host_init( ) completes successfully (even if parse errors are encountered),<br />

it will return 1; otherwise, it will return 0.<br />

#define SPC_HOST_ALLOW 1<br />

#define SPC_HOST_DENY 0<br />

typedef struct {<br />

int action;<br />

char *name;<br />

in_addr_t addr;<br />

in_addr_t mask;<br />

} spc_hostrule_t;<br />

static int spc_host_rulecount;<br />

static spc_hostrule_t *spc_host_rules;<br />

static int add_rule(spc_hostrule_t *rule) {<br />

spc_hostrule_t *tmp;<br />

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