0
|
1 /* Distributed Checksum Clearinghouse |
|
2 * |
|
3 * test dccifd via dccif() |
|
4 * |
|
5 * Copyright (c) 2008 by Rhyolite Software, LLC |
|
6 * |
|
7 * This agreement is not applicable to any entity which sells anti-spam |
|
8 * solutions to others or provides an anti-spam solution as part of a |
|
9 * security solution sold to other entities, or to a private network |
|
10 * which employs the DCC or uses data provided by operation of the DCC |
|
11 * but does not provide corresponding data to other users. |
|
12 * |
|
13 * Permission to use, copy, modify, and distribute this software without |
|
14 * changes for any purpose with or without fee is hereby granted, provided |
|
15 * that the above copyright notice and this permission notice appear in all |
|
16 * copies and any distributed versions or copies are either unchanged |
|
17 * or not called anything similar to "DCC" or "Distributed Checksum |
|
18 * Clearinghouse". |
|
19 * |
|
20 * Parties not eligible to receive a license under this agreement can |
|
21 * obtain a commercial license to use DCC by contacting Rhyolite Software |
|
22 * at sales@rhyolite.com. |
|
23 * |
|
24 * A commercial license would be for Distributed Checksum and Reputation |
|
25 * Clearinghouse software. That software includes additional features. This |
|
26 * free license for Distributed ChecksumClearinghouse Software does not in any |
|
27 * way grant permision to use Distributed Checksum and Reputation Clearinghouse |
|
28 * software |
|
29 * |
|
30 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL |
|
31 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES |
|
32 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC |
|
33 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES |
|
34 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
|
35 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
|
36 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
|
37 * SOFTWARE. |
|
38 * |
|
39 * Rhyolite Software DCC 1.3.103-1.23 $Revision$ |
|
40 */ |
|
41 |
|
42 #include "dccif.h" |
|
43 #include "dcc_clnt.h" |
|
44 #include "dcc_paths.h" |
|
45 #include <arpa/inet.h> |
|
46 |
|
47 static void NRATTRIB |
|
48 usage(void) |
|
49 { |
|
50 dcc_logbad(EX_USAGE, |
|
51 "usage: [-VP] [-h FIFO | homedir | hostname,port] [-o opts]" |
|
52 " [-c clnt-IP-addr]\n" |
|
53 " [-l heLo] [-f env_from] [-I ifile] [-O ofile]" |
|
54 " [-r rcpt1[,user1]] [...]\n"); |
|
55 } |
|
56 |
|
57 |
|
58 |
|
59 int NRATTRIB |
|
60 main(int argc, char **argv) |
|
61 { |
|
62 DCC_EMSG emsg; |
|
63 const char *srvr_addr; |
|
64 const char *opts; |
|
65 DCC_SOCKU su, *sup; |
|
66 const char *clnt_nm; |
|
67 const char *helo; |
|
68 const char *env_from; |
|
69 DCCIF_RCPT *rcpts, *rcpt; |
|
70 int in_body_fd, out_body_fd; |
|
71 u_char dccproc; |
|
72 u_char result; |
|
73 char *p; |
|
74 int i, error; |
|
75 |
|
76 srvr_addr = 0; |
|
77 opts = 0; |
|
78 sup = 0; |
|
79 clnt_nm = 0; |
|
80 dccproc = 0; |
|
81 helo = 0; |
|
82 env_from = 0; |
|
83 in_body_fd = STDIN_FILENO; |
|
84 out_body_fd = dup(STDOUT_FILENO); |
|
85 rcpts = 0; |
|
86 |
|
87 dcc_syslog_init(0, argv[0], 0); |
|
88 |
|
89 while (EOF != (i = getopt(argc, argv, "VPh:o:c:l:f:I:O:r:"))) { |
|
90 switch (i) { |
|
91 case 'V': |
|
92 fprintf(stderr, DCC_VERSION"\n"); |
|
93 break; |
|
94 |
|
95 case 'P': |
|
96 dccproc = 1; |
|
97 dcc_no_syslog = 1; |
|
98 break; |
|
99 |
|
100 case 'h': |
|
101 srvr_addr = optarg; |
|
102 break; |
|
103 |
|
104 case 'o': |
|
105 /* convert commas that users like to type to blanks */ |
|
106 while ((p = strchr(optarg, ',')) != 0) |
|
107 *p = ' '; |
|
108 opts = optarg; |
|
109 break; |
|
110 |
|
111 case 'c': |
|
112 clnt_nm = optarg; |
|
113 dcc_host_lock(); |
|
114 if (!dcc_get_host(clnt_nm, 2, &error)) { |
|
115 dcc_logbad(EX_USAGE, "%s: %s\n", clnt_nm, |
|
116 DCC_HSTRERROR(error)); |
|
117 } |
|
118 dcc_ipv4sutoipv6(&su, &dcc_hostaddrs[0]); |
|
119 sup = &su; |
|
120 dcc_host_unlock(); |
|
121 break; |
|
122 |
|
123 case 'l': |
|
124 helo = optarg; |
|
125 break; |
|
126 |
|
127 case 'f': |
|
128 env_from = optarg; |
|
129 break; |
|
130 |
|
131 case 'I': |
|
132 close(in_body_fd); |
|
133 in_body_fd = open(optarg, O_RDONLY, 0); |
|
134 if (in_body_fd < 0) |
|
135 dcc_logbad(EX_IOERR, "open(%s): %s\n", |
|
136 optarg, strerror(errno)); |
|
137 break; |
|
138 |
|
139 case 'O': |
|
140 close(out_body_fd); |
|
141 out_body_fd = open(optarg, O_WRONLY | O_CREAT, 0666); |
|
142 if (out_body_fd < 0) { |
|
143 fprintf(stderr, "open(%s): %s\n", |
|
144 optarg, strerror(errno)); |
|
145 exit(1); |
|
146 } |
|
147 break; |
|
148 |
|
149 case 'r': |
|
150 rcpt = malloc(sizeof(*rcpt)); |
|
151 memset(rcpt, 0, sizeof(*rcpt)); |
|
152 rcpt->next = rcpts; |
|
153 rcpt->addr = optarg; |
|
154 p = strchr(optarg, ','); |
|
155 if (!p) { |
|
156 rcpt->user = ""; |
|
157 } else { |
|
158 *p++ = '\0'; |
|
159 rcpt->user = p; |
|
160 } |
|
161 rcpt->ok = '?'; |
|
162 rcpts = rcpt; |
|
163 break; |
|
164 |
|
165 default: |
|
166 usage(); |
|
167 break; |
|
168 } |
|
169 } |
|
170 argc -= optind; |
|
171 argv += optind; |
|
172 if (argc != 0) |
|
173 usage(); |
|
174 |
|
175 result = dccif(emsg, |
|
176 out_body_fd, 0, |
|
177 opts, sup, clnt_nm, helo, env_from, |
|
178 rcpts, in_body_fd, 0, srvr_addr); |
|
179 |
|
180 if (!dccproc) { |
|
181 if (!result) { |
|
182 printf("result 0: %s\n", emsg); |
|
183 exit(0); |
|
184 } |
|
185 printf("overall result = '%c'\n", result); |
|
186 for (rcpt = rcpts; rcpt; rcpt = rcpt->next) { |
|
187 printf(" %s%s%s: '%c'\n", |
|
188 rcpt->addr, |
|
189 (rcpt->user[0] != '\0') ? "," : "", |
|
190 rcpt->user, |
|
191 rcpt->ok); |
|
192 } |
|
193 putchar('\n'); |
|
194 } |
|
195 exit(0); |
|
196 } |