Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / namadr_list.c
blobdb6a288b327419e8b4e0ee254b16c5cf591d760a
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* namadr_list 3
6 /* SUMMARY
7 /* name/address list membership
8 /* SYNOPSIS
9 /* #include <namadr_list.h>
11 /* NAMADR_LIST *namadr_list_init(flags, pattern_list)
12 /* int flags;
13 /* const char *pattern_list;
15 /* int namadr_list_match(list, name, addr)
16 /* NAMADR_LIST *list;
17 /* const char *name;
18 /* const char *addr;
20 /* void namadr_list_free(list)
21 /* NAMADR_LIST *list;
22 /* DESCRIPTION
23 /* This is a convenience wrapper around the match_list module.
25 /* This module implements tests for list membership of a
26 /* hostname or network address.
28 /* A list pattern specifies a host name, a domain name,
29 /* an internet address, or a network/mask pattern, where the
30 /* mask specifies the number of bits in the network part.
31 /* When a pattern specifies a file name, its contents are
32 /* substituted for the file name; when a pattern is a
33 /* type:name table specification, table lookup is used
34 /* instead.
35 /* Patterns are separated by whitespace and/or commas. In
36 /* order to reverse the result, precede a pattern with an
37 /* exclamation point (!).
39 /* A host matches a list when its name or address matches
40 /* a pattern, or when any of its parent domains matches a
41 /* pattern. The matching process is case insensitive.
43 /* namadr_list_init() performs initializations. The first
44 /* argument is the bit-wise OR of zero or more of the
45 /* following:
46 /* .RS
47 /* .IP MATCH_FLAG_PARENT
48 /* The hostname pattern foo.com matches itself and any name below
49 /* the domain foo.com. If this flag is cleared, foo.com matches itself
50 /* only, and .foo.com matches any name below the domain foo.com.
51 /* .RE
52 /* Specify MATCH_FLAG_NONE to request none of the above.
53 /* The second argument is a list of patterns, or the absolute
54 /* pathname of a file with patterns.
56 /* namadr_list_match() matches the specified host name and
57 /* address against the specified list of patterns.
59 /* namadr_list_free() releases storage allocated by namadr_list_init().
60 /* DIAGNOSTICS
61 /* Fatal errors: unable to open or read a pattern file; invalid
62 /* pattern. Panic: interface violations.
63 /* SEE ALSO
64 /* match_list(3) generic list matching
65 /* match_ops(3) match host by name or by address
66 /* LICENSE
67 /* .ad
68 /* .fi
69 /* The Secure Mailer license must be distributed with this software.
70 /* AUTHOR(S)
71 /* Wietse Venema
72 /* IBM T.J. Watson Research
73 /* P.O. Box 704
74 /* Yorktown Heights, NY 10598, USA
75 /*--*/
77 /* System library. */
79 #include <sys_defs.h>
81 /* Utility library. */
83 #include <match_list.h>
85 /* Global library. */
87 #include "namadr_list.h"
89 #ifdef TEST
91 #include <msg.h>
92 #include <stdlib.h>
93 #include <unistd.h>
94 #include <vstream.h>
95 #include <msg_vstream.h>
97 static void usage(char *progname)
99 msg_fatal("usage: %s [-v] pattern_list hostname address", progname);
102 int main(int argc, char **argv)
104 NAMADR_LIST *list;
105 char *host;
106 char *addr;
107 int ch;
109 msg_vstream_init(argv[0], VSTREAM_ERR);
111 while ((ch = GETOPT(argc, argv, "v")) > 0) {
112 switch (ch) {
113 case 'v':
114 msg_verbose++;
115 break;
116 default:
117 usage(argv[0]);
120 if (argc != optind + 3)
121 usage(argv[0]);
122 list = namadr_list_init(MATCH_FLAG_PARENT, argv[optind]);
123 host = argv[optind + 1];
124 addr = argv[optind + 2];
125 vstream_printf("%s/%s: %s\n", host, addr,
126 namadr_list_match(list, host, addr) ?
127 "YES" : "NO");
128 vstream_fflush(VSTREAM_OUT);
129 namadr_list_free(list);
130 return (0);
133 #endif