1
0

patch-ssmtp_c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. --- ssmtp-2.61.orig/ssmtp.c 2004-07-23 07:58:48.000000000 +0200
  2. +++ ssmtp-2.61/ssmtp.c 2011-01-17 14:46:46.000000000 +0100
  3. @@ -93,6 +93,7 @@ SSL *ssl;
  4. static char hextab[]="0123456789abcdef";
  5. #endif
  6. +ssize_t outbytes;
  7. /*
  8. log_event() -- Write event to syslog (or log file if defined)
  9. @@ -129,7 +130,7 @@ void log_event(int priority, char *forma
  10. #endif
  11. }
  12. -void smtp_write(int fd, char *format, ...);
  13. +ssize_t smtp_write(int fd, char *format, ...);
  14. int smtp_read(int fd, char *response);
  15. int smtp_read_all(int fd, char *response);
  16. int smtp_okay(int fd, char *response);
  17. @@ -150,7 +151,7 @@ void dead_letter(void)
  18. if(isatty(fileno(stdin))) {
  19. if(log_level > 0) {
  20. log_event(LOG_ERR,
  21. - "stdin is a TTY - not saving to %s/dead.letter, pw->pw_dir");
  22. + "stdin is a TTY - not saving to %s/dead.letter", pw->pw_dir);
  23. }
  24. return;
  25. }
  26. @@ -964,6 +965,17 @@ bool_t read_config()
  27. log_event(LOG_INFO, "Set AuthMethod=\"%s\"\n", auth_method);
  28. }
  29. }
  30. + else if (strcasecmp(p, "Debug") == 0)
  31. + {
  32. + if (strcasecmp(q, "YES") == 0)
  33. + {
  34. + log_level = 1;
  35. + }
  36. + else
  37. + {
  38. + log_level = 0;
  39. + }
  40. + }
  41. else {
  42. log_event(LOG_INFO, "Unable to set %s=\"%s\"\n", p, q);
  43. }
  44. @@ -1232,10 +1244,11 @@ ssize_t fd_puts(int fd, const void *buf,
  45. /*
  46. smtp_write() -- A printf to an fd and append <CR/LF>
  47. */
  48. -void smtp_write(int fd, char *format, ...)
  49. +ssize_t smtp_write(int fd, char *format, ...)
  50. {
  51. char buf[(BUF_SZ + 1)];
  52. va_list ap;
  53. + ssize_t outbytes = 0;
  54. va_start(ap, format);
  55. if(vsnprintf(buf, (BUF_SZ - 2), format, ap) == -1) {
  56. @@ -1252,7 +1265,9 @@ void smtp_write(int fd, char *format, ..
  57. }
  58. (void)strcat(buf, "\r\n");
  59. - (void)fd_puts(fd, buf, strlen(buf));
  60. + outbytes = fd_puts(fd, buf, strlen(buf));
  61. +
  62. + return (outbytes >= 0) ? outbytes : 0;
  63. }
  64. /*
  65. @@ -1282,6 +1297,8 @@ int ssmtp(char *argv[])
  66. int i, sock;
  67. uid_t uid;
  68. + outbytes = 0;
  69. +
  70. uid = getuid();
  71. if((pw = getpwuid(uid)) == (struct passwd *)NULL) {
  72. die("Could not find password entry for UID %d", uid);
  73. @@ -1335,10 +1352,10 @@ int ssmtp(char *argv[])
  74. /* If user supplied username and password, then try ELHO */
  75. if(auth_user) {
  76. - smtp_write(sock, "EHLO %s", hostname);
  77. + outbytes += smtp_write(sock, "EHLO %s", hostname);
  78. }
  79. else {
  80. - smtp_write(sock, "HELO %s", hostname);
  81. + outbytes += smtp_write(sock, "HELO %s", hostname);
  82. }
  83. (void)alarm((unsigned) MEDWAIT);
  84. @@ -1354,7 +1371,7 @@ int ssmtp(char *argv[])
  85. }
  86. if(strcasecmp(auth_method, "cram-md5") == 0) {
  87. - smtp_write(sock, "AUTH CRAM-MD5");
  88. + outbytes += smtp_write(sock, "AUTH CRAM-MD5");
  89. (void)alarm((unsigned) MEDWAIT);
  90. if(smtp_read(sock, buf) != 3) {
  91. @@ -1369,7 +1386,7 @@ int ssmtp(char *argv[])
  92. #endif
  93. memset(buf, 0, sizeof(buf));
  94. to64frombits(buf, auth_user, strlen(auth_user));
  95. - smtp_write(sock, "AUTH LOGIN %s", buf);
  96. + outbytes += smtp_write(sock, "AUTH LOGIN %s", buf);
  97. (void)alarm((unsigned) MEDWAIT);
  98. if(smtp_read(sock, buf) != 3) {
  99. @@ -1381,7 +1398,7 @@ int ssmtp(char *argv[])
  100. #ifdef MD5AUTH
  101. }
  102. #endif
  103. - smtp_write(sock, "%s", buf);
  104. + outbytes += smtp_write(sock, "%s", buf);
  105. (void)alarm((unsigned) MEDWAIT);
  106. if(smtp_okay(sock, buf) == False) {
  107. @@ -1390,7 +1407,7 @@ int ssmtp(char *argv[])
  108. }
  109. /* Send "MAIL FROM:" line */
  110. - smtp_write(sock, "MAIL FROM:<%s>", uad);
  111. + outbytes += smtp_write(sock, "MAIL FROM:<%s>", uad);
  112. (void)alarm((unsigned) MEDWAIT);
  113. @@ -1408,7 +1425,7 @@ int ssmtp(char *argv[])
  114. while(rt->next) {
  115. p = rcpt_remap(rt->string);
  116. - smtp_write(sock, "RCPT TO:<%s>", p);
  117. + outbytes += smtp_write(sock, "RCPT TO:<%s>", p);
  118. (void)alarm((unsigned)MEDWAIT);
  119. @@ -1425,7 +1442,7 @@ int ssmtp(char *argv[])
  120. while(p) {
  121. /* RFC822 Address -> "foo@bar" */
  122. q = rcpt_remap(addr_parse(p));
  123. - smtp_write(sock, "RCPT TO:<%s>", q);
  124. + outbytes += smtp_write(sock, "RCPT TO:<%s>", q);
  125. (void)alarm((unsigned) MEDWAIT);
  126. @@ -1439,7 +1456,7 @@ int ssmtp(char *argv[])
  127. }
  128. /* Send DATA */
  129. - smtp_write(sock, "DATA");
  130. + outbytes += smtp_write(sock, "DATA");
  131. (void)alarm((unsigned) MEDWAIT);
  132. if(smtp_read(sock, buf) != 3) {
  133. @@ -1447,45 +1464,45 @@ int ssmtp(char *argv[])
  134. die("%s", buf);
  135. }
  136. - smtp_write(sock,
  137. + outbytes += smtp_write(sock,
  138. "Received: by %s (sSMTP sendmail emulation); %s", hostname, arpadate);
  139. if(have_from == False) {
  140. - smtp_write(sock, "From: %s", from);
  141. + outbytes += smtp_write(sock, "From: %s", from);
  142. }
  143. if(have_date == False) {
  144. - smtp_write(sock, "Date: %s", arpadate);
  145. + outbytes += smtp_write(sock, "Date: %s", arpadate);
  146. }
  147. #ifdef HASTO_OPTION
  148. if(have_to == False) {
  149. - smtp_write(sock, "To: postmaster");
  150. + outbytes += smtp_write(sock, "To: postmaster");
  151. }
  152. #endif
  153. ht = &headers;
  154. while(ht->next) {
  155. - smtp_write(sock, "%s", ht->string);
  156. + outbytes += smtp_write(sock, "%s", ht->string);
  157. ht = ht->next;
  158. }
  159. (void)alarm((unsigned) MEDWAIT);
  160. /* End of headers, start body */
  161. - smtp_write(sock, "");
  162. + outbytes += smtp_write(sock, "");
  163. while(fgets(buf, sizeof(buf), stdin)) {
  164. /* Trim off \n, double leading .'s */
  165. standardise(buf);
  166. - smtp_write(sock, "%s", buf);
  167. + outbytes += smtp_write(sock, "%s", buf);
  168. (void)alarm((unsigned) MEDWAIT);
  169. }
  170. /* End of body */
  171. - smtp_write(sock, ".");
  172. + outbytes += smtp_write(sock, ".");
  173. (void)alarm((unsigned) MAXWAIT);
  174. if(smtp_okay(sock, buf) == 0) {
  175. @@ -1495,11 +1512,12 @@ int ssmtp(char *argv[])
  176. /* Close conection */
  177. (void)signal(SIGALRM, SIG_IGN);
  178. - smtp_write(sock, "QUIT");
  179. + outbytes += smtp_write(sock, "QUIT");
  180. (void)smtp_okay(sock, buf);
  181. (void)close(sock);
  182. - log_event(LOG_INFO, "Sent mail for %s (%s)", from_strip(uad), buf);
  183. + log_event(LOG_INFO, "Sent mail for %s (%s) uid=%d username=%s outbytes=%d",
  184. + from_strip(uad), buf, uid, pw->pw_name, outbytes);
  185. return(0);
  186. }