1 /*
2 * binkleyforce -- unix FTN mailer project
3 *
4 * Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * $Id: prot_yoohoo_api.c,v 1.1.1.1 2004/09/09 09:52:39 kstepanenkov Exp $
12 */
13
14 #include "includes.h"
15 #include "confread.h"
16 #include "version.h"
17 #include "logger.h"
18 #include "util.h"
19 #include "nodelist.h"
20 #include "session.h"
21 #include "prot_yoohoo.h"
22
23 void yoohoo_init(s_handshake_protocol *THIS);
24 void yoohoo_deinit(s_handshake_protocol *THIS);
25 int yoohoo_incoming(s_handshake_protocol *THIS);
26 int yoohoo_outgoing(s_handshake_protocol *THIS);
27 s_faddr *yoohoo_remote_address(s_handshake_protocol *THIS);
28 char *yoohoo_remote_password(s_handshake_protocol *THIS);
29 char *yoohoo_remote_sysop_name(s_handshake_protocol *THIS);
30 char *yoohoo_remote_system_name(s_handshake_protocol *THIS);
31 char *yoohoo_remote_location(s_handshake_protocol *THIS);
32 char *yoohoo_remote_phone(s_handshake_protocol *THIS);
33 char *yoohoo_remote_flags(s_handshake_protocol *THIS);
34 char *yoohoo_remote_mailer(s_handshake_protocol *THIS);
35 s_faddr *yoohoo_local_address(s_handshake_protocol *THIS);
36 char *yoohoo_local_password(s_handshake_protocol *THIS);
37
38 s_handshake_protocol handshake_protocol_yoohoo = {
39 /* Section 1 */
40 "YooHoo",
41 "",
42 "",
43 NULL,
44 NULL,
45 0,
46 yoohoo_init,
47 yoohoo_deinit,
48 yoohoo_incoming,
49 yoohoo_outgoing,
50 /* Section 2 */
51 yoohoo_remote_address,
52 yoohoo_remote_password,
53 yoohoo_remote_sysop_name,
54 yoohoo_remote_system_name,
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 /* Section 3 */
61 yoohoo_local_address,
62 yoohoo_local_password
63 };
64
yoohoo_init(s_handshake_protocol * THIS)65 void yoohoo_init(s_handshake_protocol *THIS)
66 {
67 ASSERT(THIS);
68 ASSERT(THIS->remote_data == NULL);
69 ASSERT(THIS->local_data == NULL);
70
71 THIS->remote_data = (char *)xmalloc(sizeof(s_yoohoo_sysinfo));
72 THIS->local_data = (char *)xmalloc(sizeof(s_yoohoo_sysinfo));
73
74 memset(THIS->remote_data, '\0', sizeof(s_yoohoo_sysinfo));
75 memset(THIS->local_data, '\0', sizeof(s_yoohoo_sysinfo));
76 }
77
yoohoo_deinit(s_handshake_protocol * THIS)78 void yoohoo_deinit(s_handshake_protocol *THIS)
79 {
80 ASSERT(THIS);
81 ASSERT(THIS->remote_data);
82 ASSERT(THIS->local_data);
83
84 if( THIS->remote_data )
85 {
86 memset(THIS->remote_data, '\0', sizeof(s_yoohoo_sysinfo));
87 free(THIS->remote_data);
88 }
89
90 if( THIS->local_data )
91 {
92 memset(THIS->local_data, '\0', sizeof(s_yoohoo_sysinfo));
93 free(THIS->local_data);
94 }
95 }
96
yoohoo_incoming(s_handshake_protocol * THIS)97 int yoohoo_incoming(s_handshake_protocol *THIS)
98 {
99 int rc = HRC_OK;
100 s_yoohoo_sysinfo *remote_data = NULL;
101 s_yoohoo_sysinfo *local_data = NULL;
102
103 ASSERT(THIS);
104 ASSERT(THIS->remote_data);
105 ASSERT(THIS->local_data);
106
107 remote_data = (s_yoohoo_sysinfo *)THIS->remote_data;
108 local_data = (s_yoohoo_sysinfo *)THIS->local_data;
109
110 if( yoohoo_recv_hello(remote_data) )
111 return HRC_OTHER_ERR;
112
113 /*
114 * Check password(s)
115 */
116 if( session_addrs_check(remote_data->addrs, remote_data->anum,
117 remote_data->passwd, NULL, 0) )
118 {
119 rc = HRC_BAD_PASSWD;
120 /* Don't return. Send HELLO with
121 * invalid password messages */
122 }
123 else
124 {
125 /* Lock (create BSY) remote addresses */
126 if( session_addrs_lock(remote_data->addrs,
127 remote_data->anum) )
128 {
129 bf_log("all remote addresses are busy");
130 rc = HRC_BUSY;
131 }
132 else
133 {
134 /*
135 * Fill state.node with a first valid
136 * address, try to lookup it in nodelist
137 */
138 session_remote_lookup(remote_data->addrs, remote_data->anum);
139
140 if( session_check_speed() )
141 rc = HRC_LOW_SPEED;
142 }
143 }
144
145 /*
146 * Put HELLO information to the log
147 */
148 (void)yoohoo_log_sysinfo(remote_data);
149
150 session_remote_log_status();
151
152 if( rc == HRC_OK )
153 {
154 const long options = conf_options(cf_options);
155
156 /*
157 * Set inbound directories, ignore errors,
158 * because we want send mail in any case.
159 */
160 (void)session_set_inbound();
161
162 /*
163 * Set protocol that we will use
164 */
165 if( (remote_data->capabilities & YOOHOO_HYDRA)
166 && !(options & OPTIONS_NO_HYDRA) )
167 THIS->protocol = PROT_HYDRA;
168 else if( (remote_data->capabilities & YOOHOO_ZEDZAP)
169 && !(options & OPTIONS_NO_ZEDZAP) )
170 THIS->protocol = PROT_ZEDZAP;
171 else if( (remote_data->capabilities & YOOHOO_ZMODEM)
172 && !(options & OPTIONS_NO_ZMODEM) )
173 THIS->protocol = PROT_ZMODEM;
174 else /* NCP */
175 {
176 THIS->protocol = PROT_NOPROT;
177 rc = HRC_NO_PROTOS;
178 }
179
180 /*
181 * Create mail/files queue
182 */
183 session_create_files_queue(remote_data->addrs, remote_data->anum);
184
185 /*
186 * Set FREQ processor status
187 */
188 if( rc == HRC_OK && THIS->protocol != PROT_NOPROT )
189 session_set_freqs_status();
190 else
191 state.reqstat = REQS_DISABLED;
192 }
193
194 /*
195 * Prepare ``local_data'' structure
196 */
197 (void)yoohoo_set_sysinfo(local_data, rc, THIS->protocol);
198
199 if( yoohoo_send_hello(local_data) && rc == HRC_OK )
200 rc = HRC_OTHER_ERR;
201
202 return rc;
203 }
204
yoohoo_outgoing(s_handshake_protocol * THIS)205 int yoohoo_outgoing(s_handshake_protocol *THIS)
206 {
207 s_yoohoo_sysinfo *remote_data = NULL;
208 s_yoohoo_sysinfo *local_data = NULL;
209
210 ASSERT(THIS);
211 ASSERT(THIS->remote_data);
212 ASSERT(THIS->local_data);
213
214 remote_data = (s_yoohoo_sysinfo *)THIS->remote_data;
215 local_data = (s_yoohoo_sysinfo *)THIS->local_data;
216
217 /*
218 * Set FREQ processor status
219 */
220 session_set_freqs_status();
221
222 /*
223 * Prepare ``local_data'' structure
224 */
225 (void)yoohoo_set_sysinfo(local_data, HRC_OK, THIS->protocol);
226
227 if( yoohoo_send_hello(local_data) )
228 return HRC_OTHER_ERR;
229
230 if( yoohoo_recv_hello(remote_data) )
231 return HRC_OTHER_ERR;
232
233 /*
234 * Put EMSI information to the log
235 */
236 (void)yoohoo_log_sysinfo(remote_data);
237
238 /*
239 * Make sure expected address was presented
240 */
241 if( session_addrs_check_genuine(remote_data->addrs,
242 remote_data->anum,
243 state.node.addr) )
244 return HRC_NO_ADDRESS;
245
246 /*
247 * Check password(s)
248 */
249 if( session_addrs_check(remote_data->addrs, remote_data->anum,
250 remote_data->passwd, NULL, 0) )
251 return HRC_BAD_PASSWD;
252
253 /*
254 * Lock (create BSY) remote addresses
255 */
256 (void)session_addrs_lock(remote_data->addrs,
257 remote_data->anum);
258
259 /*
260 * Set protocol we will use ("options" ignored)
261 */
262 if( remote_data->capabilities & YOOHOO_HYDRA )
263 THIS->protocol = PROT_HYDRA;
264 else if( remote_data->capabilities & YOOHOO_JANUS )
265 THIS->protocol = PROT_JANUS;
266 else if( remote_data->capabilities & YOOHOO_ZEDZAP )
267 THIS->protocol = PROT_ZEDZAP;
268 else if( remote_data->capabilities & YOOHOO_ZMODEM )
269 THIS->protocol = PROT_ZMODEM;
270 else
271 return HRC_NO_PROTOS;
272
273 /*
274 * Show remote status (prot/unprot, listed/unlisted)
275 */
276 session_remote_log_status();
277
278 /*
279 * Set inbound directories
280 */
281 if( session_set_inbound() )
282 return HRC_OTHER_ERR;
283
284 /*
285 * Check EMSI flags and set corresponding local HOLD flags
286 */
287 (void)session_set_send_options();
288
289 /*
290 * Create mail/files queue
291 */
292 session_create_files_queue(remote_data->addrs,
293 remote_data->anum);
294
295 return HRC_OK;
296 }
297
yoohoo_remote_address(s_handshake_protocol * THIS)298 s_faddr *yoohoo_remote_address(s_handshake_protocol *THIS)
299 {
300 ASSERT(THIS);
301 ASSERT(THIS->remote_data);
302
303 if( ((s_yoohoo_sysinfo *)THIS->remote_data)->anum > 0 )
304 return &((s_yoohoo_sysinfo *)THIS->remote_data)->addrs[0].addr;
305
306 return NULL;
307 }
308
yoohoo_remote_password(s_handshake_protocol * THIS)309 char *yoohoo_remote_password(s_handshake_protocol *THIS)
310 {
311 ASSERT(THIS);
312 ASSERT(THIS->remote_data);
313
314 if( ((s_yoohoo_sysinfo *)THIS->remote_data)->passwd[0] )
315 return ((s_yoohoo_sysinfo *)THIS->remote_data)->passwd;
316
317 return NULL;
318 }
319
yoohoo_remote_sysop_name(s_handshake_protocol * THIS)320 char *yoohoo_remote_sysop_name(s_handshake_protocol *THIS)
321 {
322 ASSERT(THIS);
323 ASSERT(THIS->remote_data);
324
325 if( ((s_yoohoo_sysinfo *)THIS->remote_data)->sysop[0] )
326 return ((s_yoohoo_sysinfo *)THIS->remote_data)->sysop;
327
328 return NULL;
329 }
330
yoohoo_remote_system_name(s_handshake_protocol * THIS)331 char *yoohoo_remote_system_name(s_handshake_protocol *THIS)
332 {
333 ASSERT(THIS);
334 ASSERT(THIS->remote_data);
335
336 if( ((s_yoohoo_sysinfo *)THIS->remote_data)->system[0] )
337 return ((s_yoohoo_sysinfo *)THIS->remote_data)->system;
338
339 return NULL;
340 }
341
yoohoo_local_address(s_handshake_protocol * THIS)342 s_faddr *yoohoo_local_address(s_handshake_protocol *THIS)
343 {
344 ASSERT(THIS);
345 ASSERT(THIS->local_data);
346
347 if( ((s_yoohoo_sysinfo *)THIS->local_data)->anum > 0 )
348 return &((s_yoohoo_sysinfo *)THIS->local_data)->addrs[0].addr;
349
350 return NULL;
351 }
352
yoohoo_local_password(s_handshake_protocol * THIS)353 char *yoohoo_local_password(s_handshake_protocol *THIS)
354 {
355 ASSERT(THIS);
356 ASSERT(THIS->local_data);
357
358 if( ((s_yoohoo_sysinfo *)THIS->local_data)->passwd[0] )
359 return ((s_yoohoo_sysinfo *)THIS->local_data)->passwd;
360
361 return NULL;
362 }
363
364