]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_smtp.c
* fixup @'s in usernames when doing smtpauth client
[citadel.git] / citadel / serv_smtp.c
index 255dfcf2ae7b4d5809a6286a542b27ef30d14730..6aaaa9296a689d119d225894dbf0e33d50fcae36 100644 (file)
@@ -128,7 +128,9 @@ int run_queue_now = 0;      /* Set to 1 to ignore SMTP send retry times */
 /*
  * Here's where our SMTP session begins its happy day.
  */
-void smtp_greeting(void) {
+void smtp_greeting(void)
+{
+       char message_to_spammer[1024];
 
        strcpy(CC->cs_clientname, "SMTP session");
        CC->internal_pgm = 1;
@@ -140,6 +142,29 @@ void smtp_greeting(void) {
        memset(SMTP_RECPS, 0, SIZ);
        memset(SMTP_ROOMS, 0, SIZ);
 
+       /* If this config option is set, reject connections from problem
+        * addresses immediately instead of after they execute a RCPT
+        */
+       if (config.c_rbl_at_greeting) {
+               if (rbl_check(message_to_spammer)) {
+                       cprintf("550 %s\r\n", message_to_spammer);
+                       CC->kill_me = 1;
+                       /* no need to free(valid), it's not allocated yet */
+                       return;
+               }
+       }
+
+       /* Otherwise we're either clean or we check later. */
+
+       if (CC->nologin==1) {
+               cprintf("500 Too many users are already online (maximum is %d)\r\n",
+                       config.c_maxsessions
+               );
+               CC->kill_me = 1;
+               /* no need to free(valid), it's not allocated yet */
+               return;
+       }
+
        cprintf("220 %s ESMTP Citadel server ready.\r\n", config.c_fqdn);
 }
 
@@ -637,12 +662,14 @@ void smtp_rcpt(char *argbuf) {
        }
 
        /* RBL check */
-       if ( (!CC->logged_in)
-          && (!SMTP->is_lmtp) ) {
-               if (rbl_check(message_to_spammer)) {
-                       cprintf("550 %s\r\n", message_to_spammer);
-                       /* no need to free(valid), it's not allocated yet */
-                       return;
+       if ( (!CC->logged_in)   /* Don't RBL authenticated users */
+          && (!SMTP->is_lmtp) ) {      /* Don't RBL LMTP clients */
+               if (config.c_rbl_at_greeting == 0) {    /* Don't RBL again if we already did it */
+                       if (rbl_check(message_to_spammer)) {
+                               cprintf("550 %s\r\n", message_to_spammer);
+                               /* no need to free(valid), it's not allocated yet */
+                               return;
+                       }
                }
        }
 
@@ -678,6 +705,8 @@ void smtp_rcpt(char *argbuf) {
        }
        strcat(SMTP->recipients, recp);
        SMTP->number_of_recipients += 1;
+       if (valid != NULL) 
+               free(valid);
 }
 
 
@@ -688,7 +717,7 @@ void smtp_rcpt(char *argbuf) {
  */
 void smtp_data(void) {
        char *body;
-       struct CtdlMessage *msg;
+       struct CtdlMessage *msg = NULL;
        long msgnum = (-1L);
        char nowstamp[SIZ];
        struct recptypes *valid;
@@ -1063,20 +1092,29 @@ void smtp_try(const char *key, const char *addr, int *status,
 
        sock = (-1);
        for (mx=0; (mx<num_mxhosts && sock < 0); ++mx) {
+               char *endpart;
                extract_token(buf, mxhosts, mx, '|', sizeof buf);
                strcpy(mx_user, "");
                strcpy(mx_pass, "");
                if (num_tokens(buf, '@') > 1) {
-                       extract_token(mx_user, buf, 0, '@', sizeof mx_user);
-                       if (num_tokens(mx_user, ':') > 1) {
-                               extract_token(mx_pass, mx_user, 1, ':', sizeof mx_pass);
-                               remove_token(mx_user, 1, ':');
+                       strcpy (mx_user, buf);
+                       endpart = strrchr(mx_user, '@');
+                       *endpart = '\0';
+                       strcpy (mx_host, endpart + 1);
+                       endpart = strrchr(mx_user, ':');
+                       if (endpart != NULL) {
+                               strcpy(mx_pass, endpart+1);
+                               *endpart = '\0';
                        }
-                       remove_token(buf, 0, '@');
                }
-               extract_token(mx_host, buf, 0, ':', sizeof mx_host);
-               extract_token(mx_port, buf, 1, ':', sizeof mx_port);
-               if (!mx_port[0]) {
+               else
+                       strcpy (mx_host, buf);
+               endpart = strrchr(mx_host, ':');
+               if (endpart != 0){
+                       *endpart = '\0';
+                       strcpy(mx_port, endpart + 1);
+               }               
+               else {
                        strcpy(mx_port, "25");
                }
                lprintf(CTDL_DEBUG, "Trying %s : %s ...\n", mx_host, mx_port);
@@ -1513,7 +1551,7 @@ int smtp_purge_completed_deliveries(char *instr) {
  * Called by smtp_do_queue() to handle an individual message.
  */
 void smtp_do_procmsg(long msgnum, void *userdata) {
-       struct CtdlMessage *msg;
+       struct CtdlMessage *msg = NULL;
        char *instr = NULL;
        char *results = NULL;
        int i;