7 /* match a host or domain name against a pattern list
9 /* #include <domain_list.h>
11 /* DOMAIN_LIST *domain_list_init(flags, pattern_list)
13 /* const char *pattern_list;
15 /* int domain_list_match(list, name)
19 /* void domain_list_free(list)
22 /* This is a convenience wrapper around the match_list module.
24 /* This module implements tests for list membership of a host or
27 /* Patterns are separated by whitespace and/or commas. A pattern
28 /* is either a string, a file name (in which case the contents
29 /* of the file are substituted for the file name) or a type:name
30 /* lookup table specification.
32 /* A host name matches a domain list when its name appears in the
33 /* list of domain patterns, or when any of its parent domains appears
34 /* in the list of domain patterns. The matching process is case
35 /* insensitive. In order to reverse the result, precede a
36 /* pattern with an exclamation point (!).
38 /* domain_list_init() performs initializations. The first argument
39 /* is the bit-wise OR of zero or more of the following:
41 /* .IP MATCH_FLAG_PARENT
42 /* The hostname pattern foo.com matches itself and any name below
43 /* the domain foo.com. If this flag is cleared, foo.com matches itself
44 /* only, and .foo.com matches any name below the domain foo.com.
46 /* Specify MATCH_FLAG_NONE to request none of the above.
47 /* The second argument is a list of domain patterns, or the name of
48 /* a file containing domain patterns.
50 /* domain_list_match() matches the specified host or domain name
51 /* against the specified pattern list.
53 /* domain_list_free() releases storage allocated by domain_list_init().
55 /* Fatal error: unable to open or read a domain_list file; invalid
56 /* domain_list pattern.
58 /* match_list(3) generic list matching
59 /* match_ops(3) match hosts by name or by address
63 /* The Secure Mailer license must be distributed with this software.
66 /* IBM T.J. Watson Research
68 /* Yorktown Heights, NY 10598, USA
75 /* Utility library. */
77 #include <match_list.h>
81 #include "domain_list.h"
89 #include <msg_vstream.h>
91 static void usage(char *progname
)
93 msg_fatal("usage: %s [-v] patterns hostname", progname
);
96 int main(int argc
, char **argv
)
102 msg_vstream_init(argv
[0], VSTREAM_ERR
);
104 while ((ch
= GETOPT(argc
, argv
, "v")) > 0) {
113 if (argc
!= optind
+ 2)
115 list
= domain_list_init(MATCH_FLAG_PARENT
, argv
[optind
]);
116 host
= argv
[optind
+ 1];
117 vstream_printf("%s: %s\n", host
, domain_list_match(list
, host
) ?
119 vstream_fflush(VSTREAM_OUT
);
120 domain_list_free(list
);