changeset 404:481e8f936572

Mail: rename "unauth" to "none".
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 23 Jul 2007 23:30:01 +0000
parents d4cac61d8e95
children 05c02cbce7be
files src/mail/ngx_mail.h src/mail/ngx_mail_auth_http_module.c src/mail/ngx_mail_core_module.c src/mail/ngx_mail_handler.c src/mail/ngx_mail_proxy_module.c
diffstat 5 files changed, 58 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/mail/ngx_mail.h
+++ b/src/mail/ngx_mail.h
@@ -68,6 +68,7 @@ typedef struct {
     ngx_array_t             listen;      /* ngx_mail_listen_t */
 } ngx_mail_core_main_conf_t;
 
+typedef void (*ngx_mail_handler_pt)(ngx_connection_t *c);
 
 #define NGX_MAIL_POP3_PROTOCOL  0
 #define NGX_MAIL_IMAP_PROTOCOL  1
@@ -107,6 +108,34 @@ typedef struct {
     ngx_array_t             imap_capabilities;
     ngx_array_t             smtp_capabilities;
 
+    /*
+     * Handlers:
+     *
+     *   - handler_init_session
+     *
+     *     Init new session after client connects. Protocol greetings printed
+     *     from here, so you need to define this if you need custom greeting
+     *     (or pause before greeting printed).
+     *
+     *   - handler_init_protocol
+     *
+     *     Initialize protocol-specific data after client sent first command.
+     *     Notably, this is re-called after STARTTLS negotiation.
+     *
+     *   - handler_read
+     *
+     *     Read client command. Could be the only handler used by simple
+     *     modules.
+     *
+     *     NB: handler_read is re-used after auth_http module work (if it was
+     *     called throgh ngx_mail_auth_http_init()) in case of error returned
+     *     by auth server, so you should set this if you use auth_http.
+     */
+
+    ngx_mail_handler_pt     handler_init_session;
+    ngx_event_handler_pt    handler_init_protocol;
+    ngx_event_handler_pt    handler_read;
+
     /* server ctx */
     ngx_mail_conf_ctx_t    *ctx;
 } ngx_mail_core_srv_conf_t;
@@ -152,8 +181,12 @@ typedef enum {
     ngx_smtp_auth_plain,
     ngx_smtp_auth_cram_md5,
     ngx_smtp_helo,
-    ngx_smtp_noxclient,
-    ngx_smtp_xclient
+    ngx_smtp_helo_xclient,
+    ngx_smtp_helo_from,
+    ngx_smtp_xclient,
+    ngx_smtp_xclient_from,
+    ngx_smtp_from,
+    ngx_smtp_to
 } ngx_smtp_state_e;
 
 
@@ -187,7 +220,7 @@ typedef struct {
     unsigned                no_sync_literal:1;
     unsigned                starttls:1;
     unsigned                esmtp:1;
-    unsigned                auth_method:2;
+    unsigned                auth_method:3;
     unsigned                auth_wait:1;
 
     ngx_str_t               login;
@@ -199,6 +232,8 @@ typedef struct {
 
     ngx_str_t              *addr_text;
     ngx_str_t               smtp_helo;
+    ngx_str_t               smtp_from;
+    ngx_str_t               smtp_to;
 
     ngx_uint_t              command;
     ngx_array_t             args;
@@ -268,12 +303,14 @@ typedef struct {
 #define NGX_MAIL_AUTH_LOGIN     1
 #define NGX_MAIL_AUTH_APOP      2
 #define NGX_MAIL_AUTH_CRAM_MD5  3
+#define NGX_MAIL_AUTH_NONE      4
 
 
 #define NGX_MAIL_AUTH_PLAIN_ENABLED     0x0002
 #define NGX_MAIL_AUTH_LOGIN_ENABLED     0x0004
 #define NGX_MAIL_AUTH_APOP_ENABLED      0x0008
 #define NGX_MAIL_AUTH_CRAM_MD5_ENABLED  0x0010
+#define NGX_MAIL_AUTH_NONE_ENABLED      0x0020
 
 
 #define NGX_MAIL_PARSE_INVALID_COMMAND  20
@@ -312,10 +349,15 @@ void ngx_smtp_auth_state(ngx_event_t *re
 void ngx_mail_close_connection(ngx_connection_t *c);
 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s);
 
+ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s);
+
 ngx_int_t ngx_pop3_parse_command(ngx_mail_session_t *s);
 ngx_int_t ngx_imap_parse_command(ngx_mail_session_t *s);
 ngx_int_t ngx_smtp_parse_command(ngx_mail_session_t *s);
 
+#if (NGX_MAIL_SSL)
+void ngx_mail_starttls_handler(ngx_event_t *rev);
+#endif
 
 /* STUB */
 void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer);
--- a/src/mail/ngx_mail_auth_http_module.c
+++ b/src/mail/ngx_mail_auth_http_module.c
@@ -138,7 +138,7 @@ static ngx_str_t   ngx_mail_auth_http_me
     ngx_string("plain"),
     ngx_string("apop"),
     ngx_string("cram-md5"),
-    ngx_string("unauth")
+    ngx_string("none")
 };
 
 static ngx_str_t   ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
@@ -1231,7 +1231,7 @@ ngx_mail_auth_http_create_request(ngx_ma
                          s->connection->addr_text.len);
     *b->last++ = CR; *b->last++ = LF;
 
-    if (s->auth_method == NGX_MAIL_AUTH_UNAUTH) {
+    if (s->auth_method == NGX_MAIL_AUTH_NONE) {
 
         /* HELO / MAIL FROM / RCPT TO can't contain CRLF, no need to escape */
 
--- a/src/mail/ngx_mail_core_module.c
+++ b/src/mail/ngx_mail_core_module.c
@@ -66,7 +66,7 @@ static ngx_conf_bitmask_t  ngx_smtp_auth
     { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED },
     { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED },
     { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED },
-    { ngx_string("unauth"), NGX_MAIL_AUTH_UNAUTH_ENABLED },
+    { ngx_string("none"), NGX_MAIL_AUTH_NONE_ENABLED },
     { ngx_null_string, 0 }
 };
 
@@ -76,7 +76,7 @@ static ngx_str_t  ngx_imap_auth_methods_
     ngx_string("AUTH=LOGIN"),
     ngx_null_string,  /* APOP */
     ngx_string("AUTH=CRAM-MD5"),
-    ngx_null_string   /* UNAUTH */
+    ngx_null_string   /* NONE */
 };
 
 
@@ -85,7 +85,7 @@ static ngx_str_t  ngx_smtp_auth_methods_
     ngx_string("LOGIN"),
     ngx_null_string,  /* APOP */
     ngx_string("CRAM-MD5"),
-    ngx_null_string   /* UNAUTH */
+    ngx_null_string   /* NONE */
 };
 
 
--- a/src/mail/ngx_mail_handler.c
+++ b/src/mail/ngx_mail_handler.c
@@ -1727,7 +1727,7 @@ ngx_smtp_auth_state(ngx_event_t *rev)
 
                 if (s->connection->log->log_level >= NGX_LOG_INFO
                     || (cscf->smtp_auth_methods
-                        & NGX_MAIL_AUTH_UNAUTH_ENABLED))
+                        & NGX_MAIL_AUTH_NONE_ENABLED))
                 {
                     l.len = s->buffer->last - s->buffer->start;
                     l.data = s->buffer->start;
@@ -1753,7 +1753,7 @@ ngx_smtp_auth_state(ngx_event_t *rev)
                     l.len = i;
 
                     if (!(cscf->smtp_auth_methods
-                          & NGX_MAIL_AUTH_UNAUTH_ENABLED))
+                          & NGX_MAIL_AUTH_NONE_ENABLED))
                     {
                         ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
                                       "client was rejected: \"%V\"", &l);
@@ -1761,14 +1761,14 @@ ngx_smtp_auth_state(ngx_event_t *rev)
 
                 }
 
-                if (!(cscf->smtp_auth_methods & NGX_MAIL_AUTH_UNAUTH_ENABLED))
+                if (!(cscf->smtp_auth_methods & NGX_MAIL_AUTH_NONE_ENABLED))
                 {
                     text = smtp_auth_required;
                     size = sizeof(smtp_auth_required) - 1;
                     break;
                 }
 
-                /* allow unauth */
+                /* auth none */
 
                 if (s->smtp_from.len) {
                     text = smtp_bad_sequence;
@@ -1831,7 +1831,7 @@ ngx_smtp_auth_state(ngx_event_t *rev)
 
                 ngx_memcpy(s->smtp_to.data, l.data, l.len);
 
-                s->auth_method = NGX_MAIL_AUTH_UNAUTH;
+                s->auth_method = NGX_MAIL_AUTH_NONE;
 
                 ngx_mail_do_auth(s);
                 return;
--- a/src/mail/ngx_mail_proxy_module.c
+++ b/src/mail/ngx_mail_proxy_module.c
@@ -518,7 +518,7 @@ ngx_mail_proxy_smtp_handler(ngx_event_t 
         *p++ = CR; *p = LF;
 
         s->mail_state = pcf->xclient ? ngx_smtp_helo_xclient :
-                        s->auth_method == NGX_MAIL_AUTH_UNAUTH ?
+                        s->auth_method == NGX_MAIL_AUTH_NONE ?
                         ngx_smtp_helo_from : ngx_smtp_helo;
 
         break;
@@ -549,7 +549,7 @@ ngx_mail_proxy_smtp_handler(ngx_event_t 
                        (s->login.len ? " LOGIN=" : ""), &s->login)
                    - line.data;
 
-        s->mail_state = s->auth_method == NGX_MAIL_AUTH_UNAUTH ?
+        s->mail_state = s->auth_method == NGX_MAIL_AUTH_NONE ?
                         ngx_smtp_xclient_from : ngx_smtp_xclient;
 
         break;
@@ -599,7 +599,7 @@ ngx_mail_proxy_smtp_handler(ngx_event_t 
     case ngx_smtp_xclient:
     case ngx_smtp_to:
 
-        if (s->auth_method == NGX_MAIL_AUTH_UNAUTH) {
+        if (s->auth_method == NGX_MAIL_AUTH_NONE) {
             ngx_memcpy(s->proxy->buffer->start, smtp_ok, sizeof(smtp_ok) - 1);
             s->proxy->buffer->last = s->proxy->buffer->start
                 + sizeof(smtp_ok) - 1;