httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From soc-r...@apache.org
Subject svn commit: r373596 - in /httpd/mod_smtpd/trunk: modules/rcpt/ok/mod_smtpd_rcpt_ok.c src/mod_smtpd.h src/smtp_protocol.c
Date Mon, 30 Jan 2006 21:29:18 GMT
Author: soc-rian
Date: Mon Jan 30 13:29:15 2006
New Revision: 373596

URL: http://svn.apache.org/viewcvs?rev=373596&view=rev
Log:
Made disconnect booleans type-safe, added options for action hooks
to disconnect (by RFC 2821 standards).

Updated rcpt_ok module to correspond with current api.


Modified:
    httpd/mod_smtpd/trunk/modules/rcpt/ok/mod_smtpd_rcpt_ok.c
    httpd/mod_smtpd/trunk/src/mod_smtpd.h
    httpd/mod_smtpd/trunk/src/smtp_protocol.c

Modified: httpd/mod_smtpd/trunk/modules/rcpt/ok/mod_smtpd_rcpt_ok.c
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/modules/rcpt/ok/mod_smtpd_rcpt_ok.c?rev=373596&r1=373595&r2=373596&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/modules/rcpt/ok/mod_smtpd_rcpt_ok.c (original)
+++ httpd/mod_smtpd/trunk/modules/rcpt/ok/mod_smtpd_rcpt_ok.c Mon Jan 30 13:29:15 2006
@@ -10,8 +10,9 @@
 
 module AP_MODULE_DECLARE_DATA smtpd_rcpt_ok_module;
 
-static smtpd_retcode default_rcpt(smtpd_conn_rec *scr, smtpd_return_data *out,
-                                  char *address, apr_table_t *rcpt_param)
+static smtpd_retcode default_rcpt(smtpd_session_rec *scr, char *address,
+                                  apr_table_t *rcpt_param,
+                                  smtpd_return_data **out_data)
 {
     rcpt_ok_config *pConfig =
       ap_get_module_config(scr->s->module_config,

Modified: httpd/mod_smtpd/trunk/src/mod_smtpd.h
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/src/mod_smtpd.h?rev=373596&r1=373595&r2=373596&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/src/mod_smtpd.h (original)
+++ httpd/mod_smtpd/trunk/src/mod_smtpd.h Mon Jan 30 13:29:15 2006
@@ -53,10 +53,8 @@
     SMTPD_DECLINED,
     SMTPD_DENY,
     SMTPD_DENYSOFT,
-    SMTPD_DENY_DISCONNECT,
-    SMTPD_DENYSOFT_DISCONNECT,
+    SMTPD_DISCONNECT,
     SMTPD_DONE,
-    SMTPD_DONE_DISCONNECT,
     SMTPD_OK
 } smtpd_retcode;
 

Modified: httpd/mod_smtpd/trunk/src/smtp_protocol.c
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/src/smtp_protocol.c?rev=373596&r1=373595&r2=373596&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/src/smtp_protocol.c (original)
+++ httpd/mod_smtpd/trunk/src/smtp_protocol.c Mon Jan 30 13:29:15 2006
@@ -46,14 +46,14 @@
 extern ap_regex_t *rcpt_compiled_regex;
 extern ap_regex_t *vrfy_compiled_regex;
 
-static int smtpd_handler_helo(smtpd_session_rec *, char *, int);
-static int smtpd_handler_mail(smtpd_session_rec *, char *);
-static int smtpd_handler_rcpt(smtpd_session_rec *, char *);
-static int smtpd_handler_data(smtpd_session_rec *, char *);
-static int smtpd_handler_rset(smtpd_session_rec *, char *);
-static int smtpd_handler_quit(smtpd_session_rec *, char *);
-static int smtpd_handler_vrfy(smtpd_session_rec *, char *);
-static int smtpd_handle_unrecognized_command(smtpd_session_rec *, char *, char *);
+static smtpd_bool smtpd_handler_helo(smtpd_session_rec *, char *, smtpd_bool);
+static smtpd_bool smtpd_handler_mail(smtpd_session_rec *, char *);
+static smtpd_bool smtpd_handler_rcpt(smtpd_session_rec *, char *);
+static smtpd_bool smtpd_handler_data(smtpd_session_rec *, char *);
+static smtpd_bool smtpd_handler_rset(smtpd_session_rec *, char *);
+static smtpd_bool smtpd_handler_quit(smtpd_session_rec *, char *);
+static smtpd_bool smtpd_handler_vrfy(smtpd_session_rec *, char *);
+static smtpd_bool smtpd_handle_unrecognized_command(smtpd_session_rec *, char *, char *);
 
 static void smtpd_respond_msgs(smtpd_session_rec *scr, int status,
                                char *default_string, apr_array_header_t *msgs)
@@ -83,7 +83,7 @@
     char cmdbuff[BUFFER_STR_LEN];
     char *buffer = cmdbuff;
     char *command;
-    int disconnect;
+    smtpd_bool disconnect;
     smtpd_return_data *out_data;
 
     smtpd_run_on_connect(scr);
@@ -117,10 +117,10 @@
         ap_str_tolower(command);
 
         if (ap_strcmp_match("ehlo", command) == 0) {
-            disconnect = smtpd_handler_helo(scr, buffer, 1);
+            disconnect = smtpd_handler_helo(scr, buffer, SMTPD_TRUE);
         }
         else if (ap_strcmp_match("helo", command) == 0) {
-            disconnect = smtpd_handler_helo(scr, buffer, 0);
+            disconnect = smtpd_handler_helo(scr, buffer, SMTPD_FALSE);
         }
         else if (ap_strcmp_match("mail", command) == 0) {
             disconnect = smtpd_handler_mail(scr, buffer);
@@ -136,7 +136,7 @@
         }
         else if (ap_strcmp_match("noop", command) == 0) {
             smtpd_respond_oneline(scr, 250, "Ok");
-            disconnect = 0;
+            disconnect = SMTPD_FALSE;
         }
         else if (ap_strcmp_match("vrfy", command) == 0) {
             disconnect = smtpd_handler_vrfy(scr, buffer);
@@ -149,7 +149,7 @@
               smtpd_handle_unrecognized_command(scr, command, buffer);
         }
         
-        if (disconnect)
+        if (disconnect == SMTPD_TRUE)
             break;
 
         buffer = cmdbuff;
@@ -158,11 +158,10 @@
     return;
 }
 
-static int smtpd_handle_unrecognized_command(smtpd_session_rec *scr,
-                                             char *command,
-                                             char *data)
+static smtpd_bool smtpd_handle_unrecognized_command(smtpd_session_rec *scr,
+                                              char *command,
+                                              char *data)
 {
-    int disconnect = 0;
     smtpd_return_data *out_data;
     
     switch(smtpd_run_unrecognized_command(scr, command, data, &out_data)) {
@@ -179,10 +178,10 @@
         break;
     }
 
-    return disconnect;
+    return SMTPD_FALSE;
 }
 
-static int smtpd_default_ehlo(smtpd_session_rec *scr, char *buffer)
+static void smtpd_default_ehlo(smtpd_session_rec *scr, char *buffer)
 {
     /* RFC 2821 states that when ehlo or helo is received, reset */
     /* state */
@@ -205,10 +204,9 @@
         smtpd_respond_oneline(scr, 250, scr->helo);
     }
 
-    return 0;
 }
 
-static int smtpd_default_helo(smtpd_session_rec *scr, char *buffer)
+static void smtpd_default_helo(smtpd_session_rec *scr, char *buffer)
 {
     /* RFC 2821 states that when ehlo or helo is received, reset */
     /* state */
@@ -219,16 +217,15 @@
     scr->protocol_type = SMTPD_PROTOCOL_SMTP;
 
     smtpd_respond_oneline(scr, 250, scr->helo);
-
-    return 0;
 }
 
 
-static int smtpd_handler_helo(smtpd_session_rec *scr, char *buffer, int esmtp)
+static smtpd_bool smtpd_handler_helo(smtpd_session_rec *scr, char *buffer,
+                                     smtpd_bool esmtp)
 {
     int error;
-    int disconnect = 0;
     smtpd_return_data *out_data = NULL;
+    smtpd_bool disconnect = SMTPD_FALSE;
 
     if (buffer == NULL) {
         goto syntax_error;
@@ -238,17 +235,21 @@
 
     if (error) {
     syntax_error:
-        smtpd_respond_oneline(scr, 501, esmtp
+        smtpd_respond_oneline(scr, 501, esmtp == SMTPD_TRUE
                               ? "Syntax: EHLO hostname"
                               : "Syntax: HELO hostname");
         return disconnect;
     }
     
-    switch(esmtp
+    switch(esmtp == SMTPD_TRUE
            ? smtpd_run_ehlo(scr, buffer, &out_data)
            : smtpd_run_helo(scr, buffer, &out_data)) {
     case SMTPD_DONE:
         break;
+    case SMTPD_DISCONNECT:
+        disconnect = SMTPD_TRUE;
+        smtpd_respond(scr, 421, "Error: Internal", out_data);
+        break;
     case SMTPD_DENY:
         smtpd_respond(scr, 550, "Denied", out_data);
         break;
@@ -256,11 +257,15 @@
         smtpd_respond(scr, 450, "Temporarily Denied", out_data);
         break;
     default:
-        disconnect = esmtp
-          ? smtpd_default_helo(scr, buffer)
-          : smtpd_default_ehlo(scr, buffer);
+        if (esmtp == SMTPD_TRUE) {
+            smtpd_default_helo(scr, buffer);
+        }
+        else {
+            smtpd_default_ehlo(scr, buffer);
+        }
         break;
     }
+
     return disconnect;
 }
 
@@ -290,7 +295,7 @@
     }
 }
 
-static int smtpd_default_mail(smtpd_session_rec *scr, char *email_address,
+static void smtpd_default_mail(smtpd_session_rec *scr, char *email_address,
                               apr_table_t *mail_parameters)
 {
     smtpd_envelope_rec *str = scr->envelope;
@@ -306,17 +311,15 @@
                       APR_OVERLAP_TABLES_SET);
     str->trans_state = SMTPD_STATE_GOT_MAIL;
     smtpd_respond_oneline(scr, 250, "Ok");
-
-    return 0;
 }   
 
-static int smtpd_handler_mail(smtpd_session_rec *scr, char *buffer)
+static smtpd_bool smtpd_handler_mail(smtpd_session_rec *scr, char *buffer)
 {
     char *email_address;
     int error;
-    int disconnect = 0;
     apr_table_t *mail_parameters;
     smtpd_return_data *out_data = NULL;
+    smtpd_bool disconnect = SMTPD_FALSE;
 
     /* already got mail */
     if (scr->envelope->trans_state == SMTPD_STATE_GOT_MAIL) {
@@ -334,7 +337,7 @@
     syntax_error:
         smtpd_respond_oneline(scr, 501, "Syntax: MAIL FROM:<reverse-path> "
                               "mail-parameters");
-        return disconnect;
+        return SMTPD_FALSE;
     }
 
     /* logging will be robustified later 
@@ -360,6 +363,10 @@
     switch(smtpd_run_mail(scr, email_address, mail_parameters, &out_data)) {
     case SMTPD_DONE:
         break;
+    case SMTPD_DISCONNECT:
+        disconnect = SMTPD_TRUE;
+        smtpd_respond(scr, 421, "Error: Internal", out_data);
+        break;
     case SMTPD_DENY:
         ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, scr->s,
                      "deny mail from %s (%s)", email_address,
@@ -373,14 +380,14 @@
         smtpd_respond(scr, 450, "Temporarily denied", out_data);
         break;
     default:
-        disconnect = smtpd_default_mail(scr, email_address, mail_parameters);
+        smtpd_default_mail(scr, email_address, mail_parameters);
         break;
     }
     
     return disconnect;
 }
 
-static int smtpd_default_rcpt(smtpd_session_rec *scr, char *email_address,
+static void smtpd_default_rcpt(smtpd_session_rec *scr, char *email_address,
                               apr_table_t *rcpt_parameters)
 {
     smtpd_envelope_rec *str = scr->envelope;
@@ -393,17 +400,15 @@
       apr_pstrdup(str->p, email_address);
     str->trans_state = SMTPD_STATE_GOT_RCPT;
     smtpd_respond_oneline(scr, 250, "Ok");
- 
-    return 0;
 }
 
-static int smtpd_handler_rcpt(smtpd_session_rec *scr, char *buffer)
+static smtpd_bool smtpd_handler_rcpt(smtpd_session_rec *scr, char *buffer)
 {
     char *email_address;
     int error;
-    int disconnect = 0;
     apr_table_t *rcpt_parameters;
     smtpd_return_data *out_data = NULL;
+    smtpd_bool disconnect = SMTPD_FALSE;
         
     /* need mail first */
     if ((scr->envelope->trans_state != SMTPD_STATE_GOT_MAIL) &&
@@ -443,6 +448,10 @@
     switch(smtpd_run_rcpt(scr, email_address, rcpt_parameters, &out_data)) {
     case SMTPD_DONE:
         break;
+    case SMTPD_DISCONNECT:
+        disconnect = SMTPD_TRUE;
+        smtpd_respond(scr, 421, "Error: Internal", out_data);
+        break;
     case SMTPD_DENY:
         smtpd_respond(scr, 550, "Relaying denied", out_data);
         break;
@@ -450,7 +459,7 @@
         smtpd_respond(scr, 450, "Relaying temporarily denied", out_data);
         break;
     case SMTPD_OK: /* recipient is okay */
-        disconnect = smtpd_default_rcpt(scr, email_address, rcpt_parameters);
+        smtpd_default_rcpt(scr, email_address, rcpt_parameters);
         break;
     default:
         smtpd_respond_oneline(scr, 450,
@@ -462,14 +471,12 @@
 }
 
 
-static int smtpd_queue(smtpd_session_rec *scr)
+static void smtpd_queue(smtpd_session_rec *scr)
 {
     smtpd_run_on_queue(scr);
 
     /* simple for now */
     smtpd_respond_msgs(scr, 220, "Queued", scr->queued_greeting);
-
-    return 0;
 }
 
 /* for debugging
@@ -531,13 +538,13 @@
     apr_pool_destroy(p);
 }
 
-static int smtpd_default_data(smtpd_session_rec *scr)
+static smtpd_bool smtpd_default_data(smtpd_session_rec *scr)
 {
     int rv;
-    int disconnect = 0;
     apr_file_t *tfp;
     smtpd_envelope_rec *str = scr->envelope;
     smtpd_header_filter_ctx header_ctx = {0, scr, NULL, NULL};
+    smtpd_bool disconnect = SMTPD_FALSE;
    
     /* get temporary file pointer */
     {
@@ -547,8 +554,7 @@
         rv = apr_temp_dir_get(&tempdir, scr->per_command_pool);
         if (rv) {
             smtpd_respond_oneline(scr, 421, "Error: Internal");
-            disconnect = 1;
-            return disconnect;
+            return SMTPD_TRUE;
         }
 
         tempfile = apr_psprintf(scr->per_command_pool, "%s/tmp.XXXXXX", tempdir);
@@ -559,8 +565,7 @@
         if (rv != APR_SUCCESS) {
             smtpd_respond_oneline(scr, 421, "Error: Internal");
             /* file error close connection */
-            disconnect = 1;
-            return disconnect;
+            return SMTPD_TRUE;
         }
     }
 
@@ -640,6 +645,10 @@
         switch(smtpd_run_data_post(scr, &out_data)) {
         case SMTPD_DONE:
             break;
+        case SMTPD_DISCONNECT:
+            disconnect = SMTPD_TRUE;
+            smtpd_respond(scr, 421, "Error: Internal", out_data);
+            break;
         case SMTPD_DENY:
             smtpd_respond(scr, 552, "Message denied", out_data);
             smtpd_reset_envelope(scr);
@@ -649,7 +658,7 @@
             smtpd_reset_envelope(scr);
             break;
         default:
-            disconnect = smtpd_queue(scr);
+            smtpd_queue(scr);
             smtpd_reset_envelope(scr);
             break;
         }
@@ -659,9 +668,9 @@
     return disconnect;
 }
 
-static int smtpd_handler_data(smtpd_session_rec *scr, char *buffer)
+static smtpd_bool smtpd_handler_data(smtpd_session_rec *scr, char *buffer)
 {
-    int disconnect = 0;
+    smtpd_bool disconnect = SMTPD_FALSE;
     smtpd_return_data *out_data = NULL;
 
     /* qpsmtpd does this after calling smtpd_run_data()
@@ -680,6 +689,10 @@
     switch(smtpd_run_data(scr, &out_data)) {
     case SMTPD_DONE:
         break;
+    case SMTPD_DISCONNECT:
+        disconnect = SMTPD_TRUE;
+        smtpd_respond(scr, 421, "Error: Internal", out_data);
+        break;
     case SMTPD_DENY:
         /* REVIEW: should we reset state here? */
         /* smtpd_clear_request_rec(sr); */
@@ -698,38 +711,40 @@
     return disconnect;
 }
 
-static int smtpd_handler_rset(smtpd_session_rec *scr, char *buffer)
+static smtpd_bool smtpd_handler_rset(smtpd_session_rec *scr, char *buffer)
 {
     if (buffer != NULL) {
         smtpd_respond_oneline(scr, 501, "Syntax: RSET");
-        return 501;
     }
-
-    smtpd_reset_envelope(scr);
-    smtpd_respond_oneline(scr, 250, "Ok");
+    else {
+        smtpd_reset_envelope(scr);
+        smtpd_respond_oneline(scr, 250, "Ok");
+    }
     
-    return 250;
+    return SMTPD_FALSE;
 }
 
-static int smtpd_handler_quit(smtpd_session_rec *scr, char *buffer)
+static smtpd_bool smtpd_handler_quit(smtpd_session_rec *scr, char *buffer)
 {
+    smtpd_bool disconnect = SMTPD_FALSE;
+
     if (buffer != NULL) {
         smtpd_respond_oneline(scr, 501, "Syntax: QUIT");
-        return 501;
+    }
+    else {
+        smtpd_run_on_quit(scr);
+        smtpd_respond_msgs(scr, 221, "Bye", scr->quit_greeting);
+        disconnect = SMTPD_TRUE;
     }
 
-    smtpd_run_on_quit(scr);
-
-    smtpd_respond_msgs(scr, 221, "Bye", scr->quit_greeting);
-
-    return 1;
+    return disconnect;
 }
 
-static int smtpd_handler_vrfy(smtpd_session_rec *scr, char *buffer)
+static smtpd_bool smtpd_handler_vrfy(smtpd_session_rec *scr, char *buffer)
 {
     int error;
-    int disconnect = 0;
     smtpd_return_data *out_data = NULL;
+    smtpd_bool disconnect = SMTPD_FALSE;
     
     if (buffer == NULL) {
         goto syntax_error;
@@ -745,6 +760,10 @@
 
     switch(smtpd_run_vrfy(scr, buffer, &out_data)) {
     case SMTPD_DONE:
+        break;
+    case SMTPD_DISCONNECT:
+        disconnect = SMTPD_TRUE;
+        smtpd_respond(scr, 421, "Error: Internal", out_data);
         break;
     case SMTPD_DENY:
         smtpd_respond(scr, 554, "Address denied", out_data);



Mime
View raw message