Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / domain_list.c
blob211e5e97e0048f7ba27e5e9084099095e3f3a30e
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* domain_list 3
6 /* SUMMARY
7 /* match a host or domain name against a pattern list
8 /* SYNOPSIS
9 /* #include <domain_list.h>
11 /* DOMAIN_LIST *domain_list_init(flags, pattern_list)
12 /* int flags;
13 /* const char *pattern_list;
15 /* int domain_list_match(list, name)
16 /* DOMAIN_LIST *list;
17 /* const char *name;
19 /* void domain_list_free(list)
20 /* DOMAIN_LIST *list;
21 /* DESCRIPTION
22 /* This is a convenience wrapper around the match_list module.
24 /* This module implements tests for list membership of a host or
25 /* domain name.
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:
40 /* .RS
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.
45 /* .RE
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().
54 /* DIAGNOSTICS
55 /* Fatal error: unable to open or read a domain_list file; invalid
56 /* domain_list pattern.
57 /* SEE ALSO
58 /* match_list(3) generic list matching
59 /* match_ops(3) match hosts by name or by address
60 /* LICENSE
61 /* .ad
62 /* .fi
63 /* The Secure Mailer license must be distributed with this software.
64 /* AUTHOR(S)
65 /* Wietse Venema
66 /* IBM T.J. Watson Research
67 /* P.O. Box 704
68 /* Yorktown Heights, NY 10598, USA
69 /*--*/
71 /* System library. */
73 #include <sys_defs.h>
75 /* Utility library. */
77 #include <match_list.h>
79 /* Global library. */
81 #include "domain_list.h"
83 #ifdef TEST
85 #include <msg.h>
86 #include <stdlib.h>
87 #include <unistd.h>
88 #include <vstream.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)
98 DOMAIN_LIST *list;
99 char *host;
100 int ch;
102 msg_vstream_init(argv[0], VSTREAM_ERR);
104 while ((ch = GETOPT(argc, argv, "v")) > 0) {
105 switch (ch) {
106 case 'v':
107 msg_verbose++;
108 break;
109 default:
110 usage(argv[0]);
113 if (argc != optind + 2)
114 usage(argv[0]);
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) ?
118 "YES" : "NO");
119 vstream_fflush(VSTREAM_OUT);
120 domain_list_free(list);
121 return (0);
124 #endif