]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_smtp.c
* Replaced all "Citadel/UX" references with "Citadel"
[citadel.git] / citadel / serv_smtp.c
index 80a9934f7ef3c7fcc2a9b52c9c6db4aa07ca00dd..6f23e086a978214a10844200d82553186cfe5066 100644 (file)
@@ -135,7 +135,7 @@ void smtp_greeting(void) {
        snprintf(SMTP_RECPS, SIZ, "%s", "");
        snprintf(SMTP_ROOMS, SIZ, "%s", "");
 
-       cprintf("220 %s ESMTP Citadel/UX server ready.\r\n", config.c_fqdn);
+       cprintf("220 %s ESMTP Citadel server ready.\r\n", config.c_fqdn);
 }
 
 /*
@@ -197,12 +197,21 @@ void smtp_hello(char *argbuf, int which_command) {
                }
                cprintf("250-HELP\r\n");
                cprintf("250-SIZE %ld\r\n", config.c_maxmsglen);
-               cprintf("250-PIPELINING\r\n");
-               cprintf("250-AUTH LOGIN PLAIN\r\n");
-               cprintf("250-AUTH=LOGIN PLAIN\r\n");
+
+               /* Only offer the PIPELINING command if TLS is inactive, because
+                * of flow control issues.  Also, avoid offering TLS if TLS is
+                * already active.
+                */
+               if (!CC->redirect_ssl) {
+                       cprintf("250-PIPELINING\r\n");
 #ifdef HAVE_OPENSSL
-               cprintf("250-STARTTLS\r\n");
+                       cprintf("250-STARTTLS\r\n");
 #endif
+               }
+
+               cprintf("250-AUTH LOGIN PLAIN\r\n");
+               cprintf("250-AUTH=LOGIN PLAIN\r\n");
+
                cprintf("250 ENHANCEDSTATUSCODES\r\n");
        }
 }
@@ -408,8 +417,8 @@ void smtp_expn(char *argbuf) {
 /*
  * Implements the RSET (reset state) command.
  * Currently this just zeroes out the state buffer.  If pointers to data
- * allocated with mallok() are ever placed in the state buffer, we have to
- * be sure to phree() them first!
+ * allocated with malloc() are ever placed in the state buffer, we have to
+ * be sure to free() them first!
  *
  * Set do_response to nonzero to output the SMTP RSET response code.
  */
@@ -557,7 +566,7 @@ void smtp_rcpt(char *argbuf) {
           && (!SMTP->is_lmtp) ) {
                if (rbl_check(message_to_spammer)) {
                        cprintf("550 %s\r\n", message_to_spammer);
-                       /* no need to phree(valid), it's not allocated yet */
+                       /* no need to free(valid), it's not allocated yet */
                        return;
                }
        }
@@ -565,15 +574,25 @@ void smtp_rcpt(char *argbuf) {
        valid = validate_recipients(recp);
        if (valid->num_error > 0) {
                cprintf("599 5.1.1 Error: %s\r\n", valid->errormsg);
-               phree(valid);
+               free(valid);
                return;
        }
 
+       if (valid->num_internet > 0) {
+               if (CC->logged_in) {
+                        if (CtdlCheckInternetMailPermission(&CC->user)==0) {
+                               cprintf("551 5.7.1 <%s> - you do not have permission to send Internet mail\r\n", recp);
+                                free(valid);
+                                return;
+                        }
+                }
+       }
+
        if (valid->num_internet > 0) {
                if ( (SMTP->message_originated_locally == 0)
                   && (SMTP->is_lmtp == 0) ) {
                        cprintf("551 5.7.1 <%s> - relaying denied\r\n", recp);
-                       phree(valid);
+                       free(valid);
                        return;
                }
        }
@@ -615,7 +634,7 @@ void smtp_data(void) {
        cprintf("354 Transmit message now - terminate with '.' by itself\r\n");
        
        datestring(nowstamp, sizeof nowstamp, time(NULL), DATESTRING_RFC822);
-       body = mallok(4096);
+       body = malloc(4096);
 
        if (body != NULL) snprintf(body, 4096,
                "Received: from %s (%s [%s])\n"
@@ -647,16 +666,16 @@ void smtp_data(void) {
         * is read with a Citadel client.
         */
        if ( (CC->logged_in) && (config.c_rfc822_strict_from == 0) ) {
-               if (msg->cm_fields['A'] != NULL) phree(msg->cm_fields['A']);
-               if (msg->cm_fields['N'] != NULL) phree(msg->cm_fields['N']);
-               if (msg->cm_fields['H'] != NULL) phree(msg->cm_fields['H']);
-               if (msg->cm_fields['F'] != NULL) phree(msg->cm_fields['F']);
-               if (msg->cm_fields['O'] != NULL) phree(msg->cm_fields['O']);
-               msg->cm_fields['A'] = strdoop(CC->user.fullname);
-               msg->cm_fields['N'] = strdoop(config.c_nodename);
-               msg->cm_fields['H'] = strdoop(config.c_humannode);
-               msg->cm_fields['F'] = strdoop(CC->cs_inet_email);
-               msg->cm_fields['O'] = strdoop(MAILROOM);
+               if (msg->cm_fields['A'] != NULL) free(msg->cm_fields['A']);
+               if (msg->cm_fields['N'] != NULL) free(msg->cm_fields['N']);
+               if (msg->cm_fields['H'] != NULL) free(msg->cm_fields['H']);
+               if (msg->cm_fields['F'] != NULL) free(msg->cm_fields['F']);
+               if (msg->cm_fields['O'] != NULL) free(msg->cm_fields['O']);
+               msg->cm_fields['A'] = strdup(CC->user.fullname);
+               msg->cm_fields['N'] = strdup(config.c_nodename);
+               msg->cm_fields['H'] = strdup(config.c_humannode);
+               msg->cm_fields['F'] = strdup(CC->cs_inet_email);
+               msg->cm_fields['O'] = strdup(MAILROOM);
        }
 
        /* Submit the message into the Citadel system. */
@@ -671,7 +690,7 @@ void smtp_data(void) {
        if (scan_errors > 0) {  /* We don't want this message! */
 
                if (msg->cm_fields['0'] == NULL) {
-                       msg->cm_fields['0'] = strdoop(
+                       msg->cm_fields['0'] = strdup(
                                "5.7.1 Message rejected by filter");
                }
 
@@ -704,7 +723,7 @@ void smtp_data(void) {
        }
 
        CtdlFreeMessage(msg);
-       phree(valid);
+       free(valid);
        smtp_data_clear();      /* clear out the buffers now */
 }
 
@@ -738,10 +757,8 @@ void smtp_starttls(void)
 void smtp_command_loop(void) {
        char cmdbuf[SIZ];
 
-       lprintf(CTDL_DEBUG, "Start of SMTP command loop\n");
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
-       lprintf(CTDL_DEBUG, "Awaiting SMTP command...\n");
        if (client_gets(cmdbuf) < 1) {
                lprintf(CTDL_CRIT, "SMTP socket is broken.  Ending session.\n");
                CC->kill_me = 1;
@@ -787,9 +804,7 @@ void smtp_command_loop(void) {
        }
 
        else if (!strncasecmp(cmdbuf, "MAIL", 4)) {
-               lprintf(CTDL_DEBUG, "Performing MAIL command\n");
                smtp_mail(&cmdbuf[5]);
-               lprintf(CTDL_DEBUG, "Finished MAIL command\n");
        }
 
        else if (!strncasecmp(cmdbuf, "NOOP", 4)) {
@@ -822,7 +837,6 @@ void smtp_command_loop(void) {
                cprintf("502 5.0.0 I'm afraid I can't do that.\r\n");
        }
 
-       lprintf(CTDL_DEBUG, "End of SMTP command loop\n");
 
 }
 
@@ -1162,24 +1176,24 @@ void smtp_do_bounce(char *instr) {
 
 
 
-       bmsg = (struct CtdlMessage *) mallok(sizeof(struct CtdlMessage));
+       bmsg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
        if (bmsg == NULL) return;
        memset(bmsg, 0, sizeof(struct CtdlMessage));
 
         bmsg->cm_magic = CTDLMESSAGE_MAGIC;
         bmsg->cm_anon_type = MES_NORMAL;
         bmsg->cm_format_type = 1;
-        bmsg->cm_fields['A'] = strdoop("Citadel");
-        bmsg->cm_fields['O'] = strdoop(MAILROOM);
-        bmsg->cm_fields['N'] = strdoop(config.c_nodename);
+        bmsg->cm_fields['A'] = strdup("Citadel");
+        bmsg->cm_fields['O'] = strdup(MAILROOM);
+        bmsg->cm_fields['N'] = strdup(config.c_nodename);
 
-       if (give_up) bmsg->cm_fields['M'] = strdoop(
+       if (give_up) bmsg->cm_fields['M'] = strdup(
 "A message you sent could not be delivered to some or all of its recipients\n"
 "due to prolonged unavailability of its destination(s).\n"
 "Giving up on the following addresses:\n\n"
 );
 
-        else bmsg->cm_fields['M'] = strdoop(
+        else bmsg->cm_fields['M'] = strdup(
 "A message you sent could not be delivered to some or all of its recipients.\n"
 "The following addresses were undeliverable:\n\n"
 );
@@ -1220,7 +1234,7 @@ void smtp_do_bounce(char *instr) {
                                        "(%s:%d)\n", __FILE__, __LINE__);
                        }
 
-                       bmsg->cm_fields['M'] = reallok(bmsg->cm_fields['M'],
+                       bmsg->cm_fields['M'] = realloc(bmsg->cm_fields['M'],
                                strlen(bmsg->cm_fields['M']) + 1024 );
                        strcat(bmsg->cm_fields['M'], addr);
                        strcat(bmsg->cm_fields['M'], ": ");
@@ -1260,7 +1274,7 @@ void smtp_do_bounce(char *instr) {
 
                /* Free up the memory we used */
                if (valid != NULL) {
-                       phree(valid);
+                       free(valid);
                }
        }
 
@@ -1341,13 +1355,13 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
 
        lprintf(CTDL_DEBUG, "smtp_do_procmsg(%ld)\n", msgnum);
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) {
                lprintf(CTDL_ERR, "SMTP: tried %ld but no such message!\n", msgnum);
                return;
        }
 
-       instr = strdoop(msg->cm_fields['M']);
+       instr = strdup(msg->cm_fields['M']);
        CtdlFreeMessage(msg);
 
        /* Strip out the headers amd any other non-instruction line */
@@ -1389,7 +1403,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
         */
        if (((time(NULL) - last_attempted) < retry) && (run_queue_now == 0)) {
                lprintf(CTDL_DEBUG, "Retry time not yet reached.\n");
-               phree(instr);
+               free(instr);
                return;
        }
 
@@ -1399,7 +1413,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
         */
        if (text_msgid < 0L) {
                lprintf(CTDL_ERR, "SMTP: no 'msgid' directive found!\n");
-               phree(instr);
+               free(instr);
                return;
        }
 
@@ -1432,11 +1446,11 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                        smtp_try(key, addr, &status, dsn, sizeof dsn, text_msgid);
                        if (status != 2) {
                                if (results == NULL) {
-                                       results = mallok(1024);
+                                       results = malloc(1024);
                                        memset(results, 0, 1024);
                                }
                                else {
-                                       results = reallok(results,
+                                       results = realloc(results,
                                                strlen(results) + 1024);
                                }
                                snprintf(&results[strlen(results)], 1024,
@@ -1447,9 +1461,9 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
        }
 
        if (results != NULL) {
-               instr = reallok(instr, strlen(instr) + strlen(results) + 2);
+               instr = realloc(instr, strlen(instr) + strlen(results) + 2);
                strcat(instr, results);
-               phree(results);
+               free(results);
        }
 
 
@@ -1477,7 +1491,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
         */
        if (incomplete_deliveries_remaining > 0) {
                CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, msgnum, "");
-               msg = mallok(sizeof(struct CtdlMessage));
+               msg = malloc(sizeof(struct CtdlMessage));
                memset(msg, 0, sizeof(struct CtdlMessage));
                msg->cm_magic = CTDLMESSAGE_MAGIC;
                msg->cm_anon_type = MES_NORMAL;
@@ -1489,7 +1503,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                        "attempted|%ld\n"
                        "retry|%ld\n",
                        SPOOLMIME, instr, (long)time(NULL), (long)retry );
-               phree(instr);
+               free(instr);
                CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM);
                CtdlFreeMessage(msg);
        }
@@ -1610,12 +1624,14 @@ char *serv_smtp_init(void)
        CtdlRegisterServiceHook(config.c_smtp_port,     /* On the net... */
                                NULL,
                                smtp_greeting,
-                               smtp_command_loop);
+                               smtp_command_loop,
+                               NULL);
 
        CtdlRegisterServiceHook(0,                      /* ...and locally */
                                "lmtp.socket",
                                lmtp_greeting,
-                               smtp_command_loop);
+                               smtp_command_loop,
+                               NULL);
 
        smtp_init_spoolout();
        CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);