comparison src/context.cpp @ 311:f5547e7b3a09

enable smtp verify logging
author Carl Byington <carl@five-ten-sg.com>
date Mon, 19 Sep 2016 09:11:30 -0700
parents 802e2b779ed1
children ef5a6099cbe7
comparison
equal deleted inserted replaced
310:802e2b779ed1 311:f5547e7b3a09
173 if (r == 0) return 0; // failed to read any bytes 173 if (r == 0) return 0; // failed to read any bytes
174 if ((r > 4) && (buffer[3] == '-')) { 174 if ((r > 4) && (buffer[3] == '-')) {
175 flush_line(r); 175 flush_line(r);
176 continue; 176 continue;
177 } 177 }
178 log("read_response() sees line with %s", buffer);
178 return atoi(buffer); 179 return atoi(buffer);
179 } 180 }
180 return 0; 181 return 0;
181 } 182 }
182 183
214 // except in the case of an empty return path, which was left as the two 215 // except in the case of an empty return path, which was left as the two
215 // character string <>. 216 // character string <>.
216 if (strncmp(efrom, f, maxlen)) { 217 if (strncmp(efrom, f, maxlen)) {
217 rset(); 218 rset();
218 strncpy(efrom, f, maxlen); 219 strncpy(efrom, f, maxlen);
220 efrom[maxlen-1] = '\0'; // ensure null termination
219 init(); 221 init();
220 append("MAIL FROM:<"); 222 append("MAIL FROM:<");
221 if (*f != '<') append(f); 223 if (*f != '<') append(f);
222 append(">"); 224 append(">");
223 return cmd(NULL); 225 return cmd(NULL);
244 shutdown(fd, SHUT_RDWR); 246 shutdown(fd, SHUT_RDWR);
245 close(fd); 247 close(fd);
246 } 248 }
247 249
248 250
249 #ifdef VERIFY_DEBUG 251 void SMTP::log(const char *m, int v) {
250 void SMTP::log(const char *m, int v) { 252 char buf[maxlen];
251 char buf[maxlen]; 253 snprintf(buf, maxlen, m, v);
252 snprintf(buf, maxlen, m, v); 254 my_syslog(queueid, buf);
253 my_syslog(queueid, buf); 255 }
254 } 256
255 257
256 258 void SMTP::log(const char *m, const char *v) {
257 void SMTP::log(const char *m, const char *v) { 259 char buf[maxlen];
258 char buf[maxlen]; 260 snprintf(buf, maxlen, m, v);
259 snprintf(buf, maxlen, m, v); 261 my_syslog(queueid, buf);
260 my_syslog(queueid, buf); 262 }
261 }
262 #endif
263 263
264 264
265 //////////////////////////////////////////////// 265 ////////////////////////////////////////////////
266 // smtp verifier so backup mx machines can see the valid users 266 // smtp verifier so backup mx machines can see the valid users
267 // 267 //
302 } 302 }
303 } 303 }
304 } 304 }
305 305
306 306
307 SMTP* VERIFY::get_connection() { 307 SMTP* VERIFY::get_connection(const char *queueid) {
308 SMTP *conn = NULL; 308 SMTP *conn = NULL;
309 pthread_mutex_lock(&mutex); 309 pthread_mutex_lock(&mutex);
310 if (!connections.empty()) { 310 if (!connections.empty()) {
311 conn = connections.front(); 311 conn = connections.front();
312 conn->set_id(queueid);
312 connections.pop_front(); 313 connections.pop_front();
313 #ifdef VERIFY_DEBUG 314 #ifdef VERIFY_DEBUG
314 conn->log("get_connection() %d from cache", conn->get_fd()); 315 conn->log("get_connection() %d from cache", conn->get_fd());
315 #endif 316 #endif
316 } 317 }
339 } 340 }
340 else last_err = time(NULL); 341 else last_err = time(NULL);
341 } 342 }
342 if (sock != NULL_SOCKET) { 343 if (sock != NULL_SOCKET) {
343 conn = new SMTP(sock); 344 conn = new SMTP(sock);
345 conn->set_id(queueid);
344 #ifdef VERIFY_DEBUG 346 #ifdef VERIFY_DEBUG
345 conn->log("get_connection() %d new socket", conn->get_fd()); 347 conn->log("get_connection() %d new socket", conn->get_fd());
346 #endif 348 #endif
347 if (conn->helo() == 250) return conn; 349 int rc = conn->helo();
350 conn->log("verify::get_connection() helo sees %d", rc);
351 if (rc == 250) return conn;
348 delete conn; 352 delete conn;
349 } 353 }
350 return NULL; 354 return NULL;
351 } 355 }
352 356
371 } 375 }
372 376
373 377
374 bool VERIFY::ok(const char *queueid, const char *from, const char *to) { 378 bool VERIFY::ok(const char *queueid, const char *from, const char *to) {
375 if (host == token_myhostname) return true; 379 if (host == token_myhostname) return true;
376 SMTP *conn = get_connection(); 380 SMTP *conn = get_connection(queueid);
377 if (!conn) return true; // cannot verify right now, we have socket errors 381 if (!conn) return true; // cannot verify right now, we have socket errors
378 int rc; 382 int rc;
379 conn->set_id(queueid);
380 rc = conn->from(from); 383 rc = conn->from(from);
381 #ifdef VERIFY_DEBUG 384 conn->log("verify::ok() from sees %d", rc);
382 conn->log("verify::ok() from sees %d", rc);
383 #endif
384 if (rc != 250) { 385 if (rc != 250) {
385 conn->rset();
386 put_connection(conn); 386 put_connection(conn);
387 return (rc >= 500) ? false : true; 387 return (rc >= 500) ? false : true;
388 } 388 }
389 rc = conn->rcpt(to); 389 rc = conn->rcpt(to);
390 #ifdef VERIFY_DEBUG 390 conn->log("verify::ok() rcpt sees %d", rc);
391 conn->log("verify::ok() rcpt sees %d", rc);
392 #endif
393 put_connection(conn); 391 put_connection(conn);
394 return (rc >= 500) ? false : true; 392 return (rc >= 500) ? false : true;
395 } 393 }
396 394
397 395