aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_smtp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_smtp.c')
-rw-r--r--src/transport/plugin_transport_smtp.c151
1 files changed, 64 insertions, 87 deletions
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c
index 074bc16fc..1b9f5fb72 100644
--- a/src/transport/plugin_transport_smtp.c
+++ b/src/transport/plugin_transport_smtp.c
@@ -145,8 +145,8 @@ static GNUNET_CronTime last_transmission;
145/** ******************** Base64 encoding ***********/ 145/** ******************** Base64 encoding ***********/
146 146
147#define FILLCHAR '=' 147#define FILLCHAR '='
148static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 148static char *cvt =
149 "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; 149 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
150 150
151/** 151/**
152 * Encode into Base64. 152 * Encode into Base64.
@@ -171,8 +171,10 @@ base64_encode (const char *data, unsigned int len, char **output)
171 (*output)[ret++] = '\n'; \ 171 (*output)[ret++] = '\n'; \
172 } 172 }
173 ret = 0; 173 ret = 0;
174 opt = GNUNET_malloc (2 + (((len * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2)) / 174 opt =
175 MAX_CHAR_PER_LINE); 175 GNUNET_malloc (2 +
176 (((len * 4 / 3) + 8) * (MAX_CHAR_PER_LINE +
177 2)) / MAX_CHAR_PER_LINE);
176 /* message must start with \r\n for libesmtp */ 178 /* message must start with \r\n for libesmtp */
177 *output = opt; 179 *output = opt;
178 opt[0] = '\r'; 180 opt[0] = '\r';
@@ -361,17 +363,14 @@ listenAndDistribute (void *unused)
361 if (ntohs (mp->header.size) != size) 363 if (ntohs (mp->header.size) != size)
362 { 364 {
363 GNUNET_GE_LOG (ectx, 365 GNUNET_GE_LOG (ectx,
364 GNUNET_GE_WARNING | GNUNET_GE_BULK | 366 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
365 GNUNET_GE_USER, 367 _("Received malformed message via %s. Ignored.\n"),
366 _
367 ("Received malformed message via %s. Ignored.\n"),
368 "SMTP"); 368 "SMTP");
369#if DEBUG_SMTP 369#if DEBUG_SMTP
370 GNUNET_GE_LOG (ectx, 370 GNUNET_GE_LOG (ectx,
371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | 371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
372 GNUNET_GE_USER, 372 "Size returned by base64=%d, in the msg=%d.\n", size,
373 "Size returned by base64=%d, in the msg=%d.\n", 373 ntohl (mp->size));
374 size, ntohl (mp->size));
375#endif 374#endif
376 GNUNET_free (out); 375 GNUNET_free (out);
377 goto END; 376 goto END;
@@ -384,8 +383,7 @@ listenAndDistribute (void *unused)
384 coreMP->tsession = NULL; 383 coreMP->tsession = NULL;
385 coreMP->sender = mp->sender; 384 coreMP->sender = mp->sender;
386#if DEBUG_SMTP 385#if DEBUG_SMTP
387 GNUNET_GE_LOG (ectx, 386 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
388 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
389 "SMTP message passed to the core.\n"); 387 "SMTP message passed to the core.\n");
390#endif 388#endif
391 389
@@ -393,8 +391,7 @@ listenAndDistribute (void *unused)
393 } 391 }
394END: 392END:
395#if DEBUG_SMTP 393#if DEBUG_SMTP
396 GNUNET_GE_LOG (ectx, 394 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
397 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
398 "SMTP message processed.\n"); 395 "SMTP message processed.\n");
399#endif 396#endif
400 if (fdes != NULL) 397 if (fdes != NULL)
@@ -423,8 +420,9 @@ api_verify_hello (const GNUNET_MessageHello * hello)
423 maddr = (const EmailAddress *) &hello[1]; 420 maddr = (const EmailAddress *) &hello[1];
424 if ((ntohs (hello->header.size) != 421 if ((ntohs (hello->header.size) !=
425 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) || 422 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) ||
426 (maddr->senderAddress[ntohs (hello->senderAddressSize) - 1 - 423 (maddr->
427 FILTER_STRING_SIZE] != '\0')) 424 senderAddress[ntohs (hello->senderAddressSize) - 1 -
425 FILTER_STRING_SIZE] != '\0'))
428 { 426 {
429 GNUNET_GE_BREAK (ectx, 0); 427 GNUNET_GE_BREAK (ectx, 0);
430 return GNUNET_SYSERR; /* obviously invalid */ 428 return GNUNET_SYSERR; /* obviously invalid */
@@ -449,13 +447,11 @@ api_create_hello ()
449 EmailAddress *haddr; 447 EmailAddress *haddr;
450 int i; 448 int i;
451 449
452 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 450 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, "SMTP", "FILTER",
453 "SMTP", "FILTER",
454 "X-mailer: GNUnet", &filter); 451 "X-mailer: GNUnet", &filter);
455 if (NULL == strstr (filter, ": ")) 452 if (NULL == strstr (filter, ": "))
456 { 453 {
457 GNUNET_GE_LOG (ectx, 454 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
458 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
459 _("SMTP filter string to invalid, lacks ': '\n")); 455 _("SMTP filter string to invalid, lacks ': '\n"));
460 GNUNET_free (filter); 456 GNUNET_free (filter);
461 return NULL; 457 return NULL;
@@ -464,8 +460,7 @@ api_create_hello ()
464 if (strlen (filter) > FILTER_STRING_SIZE) 460 if (strlen (filter) > FILTER_STRING_SIZE)
465 { 461 {
466 filter[FILTER_STRING_SIZE] = '\0'; 462 filter[FILTER_STRING_SIZE] = '\0';
467 GNUNET_GE_LOG (ectx, 463 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
468 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
469 _("SMTP filter string to long, capped to `%s'\n"), filter); 464 _("SMTP filter string to long, capped to `%s'\n"), filter);
470 } 465 }
471 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */ 466 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */
@@ -521,8 +516,8 @@ get_message (void **buf, int *len, void *cls)
521 * @return GNUNET_SYSERR on error, GNUNET_OK on success 516 * @return GNUNET_SYSERR on error, GNUNET_OK on success
522 */ 517 */
523static int 518static int
524api_send (GNUNET_TSession * tsession, 519api_send (GNUNET_TSession * tsession, const void *msg, const unsigned int size,
525 const void *msg, const unsigned int size, int important) 520 int important)
526{ 521{
527 const GNUNET_MessageHello *hello; 522 const GNUNET_MessageHello *hello;
528 const EmailAddress *haddr; 523 const EmailAddress *haddr;
@@ -561,10 +556,9 @@ api_send (GNUNET_TSession * tsession,
561 { 556 {
562 GNUNET_GE_LOG (ectx, 557 GNUNET_GE_LOG (ectx,
563 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 558 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
564 GNUNET_GE_IMMEDIATE, 559 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"),
565 _("SMTP: `%s' failed: %s.\n"), 560 "smtp_create_session", smtp_strerror (smtp_errno (), ebuf,
566 "smtp_create_session", 561 EBUF_LEN));
567 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
568 GNUNET_mutex_unlock (lock); 562 GNUNET_mutex_unlock (lock);
569 return GNUNET_SYSERR; 563 return GNUNET_SYSERR;
570 } 564 }
@@ -572,10 +566,9 @@ api_send (GNUNET_TSession * tsession,
572 { 566 {
573 GNUNET_GE_LOG (ectx, 567 GNUNET_GE_LOG (ectx,
574 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 568 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
575 GNUNET_GE_IMMEDIATE, 569 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"),
576 _("SMTP: `%s' failed: %s.\n"), 570 "smtp_set_server", smtp_strerror (smtp_errno (), ebuf,
577 "smtp_set_server", 571 EBUF_LEN));
578 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
579 smtp_destroy_session (session); 572 smtp_destroy_session (session);
580 GNUNET_mutex_unlock (lock); 573 GNUNET_mutex_unlock (lock);
581 return GNUNET_SYSERR; 574 return GNUNET_SYSERR;
@@ -586,10 +579,9 @@ api_send (GNUNET_TSession * tsession,
586 { 579 {
587 GNUNET_GE_LOG (ectx, 580 GNUNET_GE_LOG (ectx,
588 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 581 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
589 GNUNET_GE_BULK, 582 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
590 _("SMTP: `%s' failed: %s.\n"), 583 "smtp_add_message", smtp_strerror (smtp_errno (), ebuf,
591 "smtp_add_message", 584 EBUF_LEN));
592 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
593 smtp_destroy_session (session); 585 smtp_destroy_session (session);
594 GNUNET_mutex_unlock (lock); 586 GNUNET_mutex_unlock (lock);
595 return GNUNET_SYSERR; 587 return GNUNET_SYSERR;
@@ -606,10 +598,9 @@ api_send (GNUNET_TSession * tsession,
606 { 598 {
607 GNUNET_GE_LOG (ectx, 599 GNUNET_GE_LOG (ectx,
608 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 600 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
609 GNUNET_GE_BULK, 601 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
610 _("SMTP: `%s' failed: %s.\n"), 602 "smtp_set_header", smtp_strerror (smtp_errno (), ebuf,
611 "smtp_set_header", 603 EBUF_LEN));
612 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
613 smtp_destroy_session (session); 604 smtp_destroy_session (session);
614 GNUNET_mutex_unlock (lock); 605 GNUNET_mutex_unlock (lock);
615 GNUNET_free (filter); 606 GNUNET_free (filter);
@@ -630,19 +621,17 @@ api_send (GNUNET_TSession * tsession,
630 { 621 {
631 GNUNET_GE_LOG (ectx, 622 GNUNET_GE_LOG (ectx,
632 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 623 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
633 GNUNET_GE_BULK, 624 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
634 _("SMTP: `%s' failed: %s.\n"), 625 "smtp_size_set_estimate", smtp_strerror (smtp_errno (), ebuf,
635 "smtp_size_set_estimate", 626 EBUF_LEN));
636 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
637 } 627 }
638 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls)) 628 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls))
639 { 629 {
640 GNUNET_GE_LOG (ectx, 630 GNUNET_GE_LOG (ectx,
641 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 631 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
642 GNUNET_GE_BULK, 632 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
643 _("SMTP: `%s' failed: %s.\n"), 633 "smtp_set_messagecb", smtp_strerror (smtp_errno (), ebuf,
644 "smtp_set_messagecb", 634 EBUF_LEN));
645 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
646 smtp_destroy_session (session); 635 smtp_destroy_session (session);
647 GNUNET_mutex_unlock (lock); 636 GNUNET_mutex_unlock (lock);
648 GNUNET_free (gm_cls.ebody); 637 GNUNET_free (gm_cls.ebody);
@@ -653,10 +642,9 @@ api_send (GNUNET_TSession * tsession,
653 { 642 {
654 GNUNET_GE_LOG (ectx, 643 GNUNET_GE_LOG (ectx,
655 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 644 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
656 GNUNET_GE_BULK, 645 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
657 _("SMTP: `%s' failed: %s.\n"), 646 "smtp_add_recipient", smtp_strerror (smtp_errno (), ebuf,
658 "smtp_add_recipient", 647 EBUF_LEN));
659 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
660 smtp_destroy_session (session); 648 smtp_destroy_session (session);
661 GNUNET_mutex_unlock (lock); 649 GNUNET_mutex_unlock (lock);
662 return GNUNET_SYSERR; 650 return GNUNET_SYSERR;
@@ -665,10 +653,9 @@ api_send (GNUNET_TSession * tsession,
665 { 653 {
666 GNUNET_GE_LOG (ectx, 654 GNUNET_GE_LOG (ectx,
667 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 655 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
668 GNUNET_GE_BULK, 656 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
669 _("SMTP: `%s' failed: %s.\n"), 657 "smtp_start_session", smtp_strerror (smtp_errno (), ebuf,
670 "smtp_start_session", 658 EBUF_LEN));
671 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
672 smtp_destroy_session (session); 659 smtp_destroy_session (session);
673 GNUNET_mutex_unlock (lock); 660 GNUNET_mutex_unlock (lock);
674 GNUNET_free (gm_cls.ebody); 661 GNUNET_free (gm_cls.ebody);
@@ -694,8 +681,8 @@ api_send (GNUNET_TSession * tsession,
694 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 681 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
695 */ 682 */
696static int 683static int
697api_connect (const GNUNET_MessageHello * hello, 684api_connect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
698 GNUNET_TSession ** tsessionPtr, int may_reuse) 685 int may_reuse)
699{ 686{
700 GNUNET_TSession *tsession; 687 GNUNET_TSession *tsession;
701 688
@@ -739,8 +726,8 @@ api_start_transport_server ()
739 if (dispatchThread == NULL) 726 if (dispatchThread == NULL)
740 { 727 {
741 GNUNET_GE_DIE_STRERROR (ectx, 728 GNUNET_GE_DIE_STRERROR (ectx,
742 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 729 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
743 GNUNET_GE_FATAL, "pthread_create"); 730 "pthread_create");
744 return GNUNET_SYSERR; 731 return GNUNET_SYSERR;
745 } 732 }
746 return GNUNET_OK; 733 return GNUNET_OK;
@@ -765,8 +752,8 @@ api_stop_transport_server ()
765 * Convert SMTP hello to an IP address (always fails). 752 * Convert SMTP hello to an IP address (always fails).
766 */ 753 */
767static int 754static int
768api_hello_to_address (const GNUNET_MessageHello * hello, 755api_hello_to_address (const GNUNET_MessageHello * hello, void **sa,
769 void **sa, unsigned int *sa_len) 756 unsigned int *sa_len)
770{ 757{
771 return GNUNET_SYSERR; 758 return GNUNET_SYSERR;
772} 759}
@@ -807,42 +794,34 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
807 ectx = core->ectx; 794 ectx = core->ectx;
808 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL")) 795 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL"))
809 { 796 {
810 GNUNET_GE_LOG (ectx, 797 GNUNET_GE_LOG (ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
811 GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
812 _ 798 _
813 ("No email-address specified, can not start SMTP transport.\n")); 799 ("No email-address specified, can not start SMTP transport.\n"));
814 return NULL; 800 return NULL;
815 } 801 }
816 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, 802 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, "SMTP", "MTU", 1200,
817 "SMTP",
818 "MTU",
819 1200,
820 SMTP_MESSAGE_SIZE, 803 SMTP_MESSAGE_SIZE,
821 SMTP_MESSAGE_SIZE, &mtu); 804 SMTP_MESSAGE_SIZE, &mtu);
822 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, 805 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, "SMTP", "RATELIMIT",
823 "SMTP",
824 "RATELIMIT",
825 0, 0, 1024 * 1024, &rate_limit); 806 0, 0, 1024 * 1024, &rate_limit);
826 stats = coreAPI->service_request ("stats"); 807 stats = coreAPI->service_request ("stats");
827 if (stats != NULL) 808 if (stats != NULL)
828 { 809 {
829 stat_bytesReceived 810 stat_bytesReceived =
830 = stats->create (gettext_noop ("# bytes received via SMTP")); 811 stats->create (gettext_noop ("# bytes received via SMTP"));
831 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP")); 812 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
832 stat_bytesDropped 813 stat_bytesDropped =
833 = stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); 814 stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
834 } 815 }
835 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg, 816 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg, "SMTP", "PIPE",
836 "SMTP",
837 "PIPE",
838 GNUNET_DEFAULT_DAEMON_VAR_DIRECTORY 817 GNUNET_DEFAULT_DAEMON_VAR_DIRECTORY
839 "/smtp-pipe", &pipename); 818 "/smtp-pipe", &pipename);
840 UNLINK (pipename); 819 UNLINK (pipename);
841 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 820 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
842 { 821 {
843 GNUNET_GE_LOG_STRERROR (ectx, 822 GNUNET_GE_LOG_STRERROR (ectx,
844 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 823 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
845 GNUNET_GE_FATAL, "mkfifo"); 824 "mkfifo");
846 GNUNET_free (pipename); 825 GNUNET_free (pipename);
847 coreAPI->service_release (stats); 826 coreAPI->service_release (stats);
848 stats = NULL; 827 stats = NULL;
@@ -854,12 +833,10 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
854 GNUNET_GE_LOG_STRERROR (ectx, 833 GNUNET_GE_LOG_STRERROR (ectx,
855 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 834 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
856 GNUNET_GE_WARNING, "chmod"); 835 GNUNET_GE_WARNING, "chmod");
857 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 836 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, "SMTP", "EMAIL", NULL,
858 "SMTP", "EMAIL", NULL, &email); 837 &email);
859 lock = GNUNET_mutex_create (GNUNET_NO); 838 lock = GNUNET_mutex_create (GNUNET_NO);
860 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 839 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, "SMTP", "SERVER",
861 "SMTP",
862 "SERVER",
863 "localhost:25", &smtp_server_name); 840 "localhost:25", &smtp_server_name);
864 sa.sa_handler = SIG_IGN; 841 sa.sa_handler = SIG_IGN;
865 sigemptyset (&sa.sa_mask); 842 sigemptyset (&sa.sa_mask);