]> diplodocus.org Git - nmh/blobdiff - mts/smtp/smtp.c
lock_file.c: close(2) file descriptor on failure, avoiding leak.
[nmh] / mts / smtp / smtp.c
index 69477b6c57920f04bc3b04d758a5ce1213a1a096..80dabb7831ead6f2c274ee51e17673609c121bd7 100644 (file)
@@ -13,6 +13,7 @@
 #include <h/netsec.h>
 
 #include <sys/socket.h>
+#include "sbr/base64.h"
 
 /*
  * This module implements an interface to SendMail very similar
  * RP_-style codes.
  */
 
-/*
- * On older 4.2BSD machines without the POSIX function `sigaction',
- * the alarm handing stuff for time-outs will NOT work due to the way
- * syscalls get restarted.  This is not really crucial, since SendMail
- * is generally well-behaved in this area.
- */
-
-#ifdef SENDMAILBUG
-/*
- * It appears that some versions of Sendmail will return Code 451
- * when they don't really want to indicate a failure.
- * "Code 451 almost always means sendmail has deferred; we don't
- * really want bomb out at this point since sendmail will rectify
- * things later."  So, if you define SENDMAILBUG, Code 451 is
- * considered the same as Code 250.  Yuck!
- */
-#endif
-
 #define        NBITS ((sizeof (int)) * 8)
 
 /* Timeout in seconds for SMTP commands.
@@ -55,7 +38,7 @@
 static int sm_addrs = 0;
 static int sm_child = NOTOK;
 static int sm_debug = 0;
-static int sm_nl = TRUE;
+static bool sm_nl = true;
 static int sm_verbose = 0;
 static netsec_context *nsc = NULL;
 
@@ -77,12 +60,12 @@ static int sendmail_init (char *, int, int, int, int, const char *,
                          const char *);
 
 static int rclient (char *, char *, char **);
-static int sm_ierror (const char *fmt, ...);
+static int sm_ierror (const char *fmt, ...) CHECK_PRINTF(1, 2);
 static int sm_nerror (char *);
-static int smtalk (int time, char *fmt, ...);
+static int smtalk (int time, char *fmt, ...) CHECK_PRINTF(2, 3);
 static int sm_wstream (char *, int);
 static int smhear (void);
-static char *EHLOset (char *);
+static char *EHLOset (char *) PURE;
 static int sm_sasl_callback(enum sasl_message_type, unsigned const char *,
                            unsigned int, unsigned char **, unsigned int *,
                            char **);
@@ -109,7 +92,7 @@ smtp_init (char *client, char *server, char *port, int watch, int verbose,
     char *errstr, *chosen_server;
 
     if (watch)
-       verbose = TRUE;
+       verbose = true;
 
     sm_verbose = verbose;
     sm_debug = debug;
@@ -280,7 +263,7 @@ sendmail_init (char *client, int watch, int verbose, int debug, int sasl,
     char *vec[15], *errstr;
 
     if (watch)
-       verbose = TRUE;
+       verbose = true;
 
     sm_verbose = verbose;
     sm_debug = debug;
@@ -324,9 +307,7 @@ sendmail_init (char *client, int watch, int verbose, int debug, int sasl,
        return sm_ierror ("no pipes");
     }
 
-    for (i = 0; (sm_child = fork ()) == NOTOK && i < 5; i++)
-       sleep (5);
-
+    sm_child = fork();
     switch (sm_child) {
        case NOTOK: 
            close (pdo[0]);
@@ -366,7 +347,7 @@ sendmail_init (char *client, int watch, int verbose, int debug, int sasl,
            close (pdi[1]);
            close (pdo[0]);
 
-           netsec_set_fd(nsc, pdi[i], pdo[1]);
+           netsec_set_fd(nsc, pdi[0], pdo[1]);
            netsec_set_timeout(nsc, SM_OPEN);
            result = smhear ();
            switch (result) {
@@ -500,10 +481,6 @@ sm_wadr (char *mbox, char *host, char *path)
            return RP_OK;
 
        case 451: 
-#ifdef SENDMAILBUG
-           sm_addrs++;
-           return RP_OK;
-#endif /* SENDMAILBUG */
        case 421: 
        case 450: 
        case 452: 
@@ -530,14 +507,10 @@ sm_waend (void)
 {
     switch (smtalk (SM_DATA, "DATA")) {
        case 354: 
-           sm_nl = TRUE;
+           sm_nl = true;
            return RP_OK;
 
        case 451: 
-#ifdef SENDMAILBUG
-           sm_nl = TRUE;
-           return RP_OK;
-#endif /* SENDMAILBUG */
        case 421: 
            return RP_NO;
 
@@ -576,9 +549,6 @@ sm_wtend (void)
            return RP_OK;
 
        case 451: 
-#ifdef SENDMAILBUG
-           return RP_OK;
-#endif /* SENDMAILBUG */
        case 452: 
        default: 
            return RP_NO;
@@ -748,7 +718,7 @@ sm_wstream (char *buffer, int len)
     for (bp = buffer; bp && len > 0; bp++, len--) {
        switch (*bp) {
            case '\n': 
-               sm_nl = TRUE;
+               sm_nl = true;
                if (netsec_write(nsc, "\r", 1, &errstr) != OK) {
                    sm_nerror(errstr);
                    return NOTOK;
@@ -764,7 +734,7 @@ sm_wstream (char *buffer, int len)
                /* FALLTHRU */
 
            default: 
-               sm_nl = FALSE;
+               sm_nl = false;
        }
        if (netsec_write(nsc, bp, 1, &errstr) != OK) {
            sm_nerror(errstr);
@@ -781,7 +751,8 @@ sm_wstream (char *buffer, int len)
 static int
 smhear (void)
 {
-    int i, code, cont, more;
+    int i, code;
+    bool cont, more;
     size_t buflen, rc;
     unsigned char *bp;
     char *rp;
@@ -813,7 +784,7 @@ again: ;
     rp = sm_reply.text;
     rc = sizeof(sm_reply.text) - 1;
 
-    for (more = FALSE; (buffer = netsec_readline(nsc, &buflen,
+    for (more = false; (buffer = netsec_readline(nsc, &buflen,
                                                 &errstr)) != NULL ; ) {
 
        if (doingEHLO
@@ -839,13 +810,13 @@ again: ;
        for (; buflen > 0 && (!isascii (*bp) || !isdigit (*bp)); bp++, buflen--)
            continue;
 
-       cont = FALSE;
+       cont = false;
        code = atoi ((char *) bp);
        bp += 3, buflen -= 3;
        for (; buflen > 0 && isspace (*bp); bp++, buflen--)
            continue;
        if (buflen > 0 && *bp == '-') {
-           cont = TRUE;
+           cont = true;
            bp++, buflen--;
            for (; buflen > 0 && isspace (*bp); bp++, buflen--)
                continue;
@@ -854,7 +825,7 @@ again: ;
        if (more) {
            if (code != sm_reply.code || cont)
                continue;
-           more = FALSE;
+           more = false;
        } else {
            sm_reply.code = code;
            more = cont;
@@ -899,7 +870,8 @@ char *
 rp_string (int code)
 {
     char *text;
-    static char buffer[BUFSIZ];
+    /* The additional space is to avoid warning from gcc -Wformat-truncation. */
+    static char buffer[BUFSIZ + 19];
 
     switch (sm_reply.code != NOTOK ? code : NOTOK) {
        case RP_AOK: