~ubuntu-branches/debian/squeeze/nginx/squeeze

« back to all changes in this revision

Viewing changes to src/mail/ngx_mail_auth_http_module.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2009-05-31 18:38:56 UTC
  • mfrom: (1.1.10 upstream) (4.1.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20090531183856-3xhvf6wd0bw5556i
Tags: 0.7.59-1
* New upstream release, first in Debian for the 0.7 branch. Among other
  issues, it also fixes the problem with wildcard dns names used with SSL.
  (Closes: #515904)
* debian/watch: updated.
* debian/postinst: fixed a bashism. (Closes: #507913)
* debian/conf/nginx.conf: removed default_type. (Closes: #509390)
* debian/control: updated Standards-Version to 3.8.1, no changes needed.
* debian/NEWS.Debian: documented the issues with
  server_names_hash_bucket_size. (Closes: #524785)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    ngx_mail_auth_http_handler_pt   handler;
41
41
 
42
42
    ngx_uint_t                      state;
43
 
    ngx_uint_t                      hash;   /* no needed ? */
44
43
 
45
44
    u_char                         *header_name_start;
46
45
    u_char                         *header_name_end;
140
139
static ngx_str_t   ngx_mail_auth_http_method[] = {
141
140
    ngx_string("plain"),
142
141
    ngx_string("plain"),
 
142
    ngx_string("plain"),
143
143
    ngx_string("apop"),
144
 
    ngx_string("cram-md5")
 
144
    ngx_string("cram-md5"),
 
145
    ngx_string("none")
145
146
};
146
147
 
147
148
static ngx_str_t   ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
268
269
                ngx_del_timer(wev);
269
270
            }
270
271
 
271
 
            if (ngx_handle_write_event(wev, 0) == NGX_ERROR) {
 
272
            if (ngx_handle_write_event(wev, 0) != NGX_OK) {
272
273
                ngx_close_connection(c);
273
274
                ngx_destroy_pool(ctx->pool);
274
275
                ngx_mail_session_internal_server_error(s);
528
529
                    continue;
529
530
                }
530
531
 
531
 
                p = ngx_pcalloc(s->connection->pool, size);
 
532
                p = ngx_pnalloc(s->connection->pool, size);
532
533
                if (p == NULL) {
533
534
                    ngx_close_connection(ctx->peer.connection);
534
535
                    ngx_destroy_pool(ctx->pool);
593
594
            {
594
595
                s->login.len = ctx->header_end - ctx->header_start;
595
596
 
596
 
                s->login.data = ngx_palloc(s->connection->pool, s->login.len);
 
597
                s->login.data = ngx_pnalloc(s->connection->pool, s->login.len);
597
598
                if (s->login.data == NULL) {
598
599
                    ngx_close_connection(ctx->peer.connection);
599
600
                    ngx_destroy_pool(ctx->pool);
614
615
            {
615
616
                s->passwd.len = ctx->header_end - ctx->header_start;
616
617
 
617
 
                s->passwd.data = ngx_palloc(s->connection->pool, s->passwd.len);
 
618
                s->passwd.data = ngx_pnalloc(s->connection->pool,
 
619
                                             s->passwd.len);
618
620
                if (s->passwd.data == NULL) {
619
621
                    ngx_close_connection(ctx->peer.connection);
620
622
                    ngx_destroy_pool(ctx->pool);
651
653
            {
652
654
                ctx->errcode.len = ctx->header_end - ctx->header_start;
653
655
 
654
 
                ctx->errcode.data = ngx_palloc(s->connection->pool,
655
 
                                               ctx->errcode.len);
 
656
                ctx->errcode.data = ngx_pnalloc(s->connection->pool,
 
657
                                                ctx->errcode.len);
656
658
                if (ctx->errcode.data == NULL) {
657
659
                    ngx_close_connection(ctx->peer.connection);
658
660
                    ngx_destroy_pool(ctx->pool);
691
693
                    ctx->err.len = ctx->errcode.len + ctx->errmsg.len
692
694
                                   + sizeof(" " CRLF) - 1;
693
695
 
694
 
                    p = ngx_palloc(s->connection->pool, ctx->err.len);
 
696
                    p = ngx_pnalloc(s->connection->pool, ctx->err.len);
695
697
                    if (p == NULL) {
696
698
                        ngx_close_connection(ctx->peer.connection);
697
699
                        ngx_destroy_pool(ctx->pool);
769
771
                return;
770
772
            }
771
773
 
 
774
            /* AF_INET only */
 
775
 
772
776
            sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in));
773
777
            if (sin == NULL) {
774
778
                ngx_destroy_pool(ctx->pool);
810
814
 
811
815
            peer->name.len = len;
812
816
 
813
 
            peer->name.data = ngx_palloc(s->connection->pool, len);
 
817
            peer->name.data = ngx_pnalloc(s->connection->pool, len);
814
818
            if (peer->name.data == NULL) {
815
819
                ngx_destroy_pool(ctx->pool);
816
820
                ngx_mail_session_internal_server_error(s);
893
897
            return;
894
898
        }
895
899
 
896
 
        if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
 
900
        if (ngx_handle_read_event(rev, 0) != NGX_OK) {
897
901
            ngx_mail_close_connection(c);
898
902
        }
899
903
 
901
905
    }
902
906
 
903
907
    if (rev->active) {
904
 
        if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
 
908
        if (ngx_handle_read_event(rev, 0) != NGX_OK) {
905
909
            ngx_mail_close_connection(c);
906
910
        }
907
911
    }
913
917
    ngx_mail_auth_http_ctx_t *ctx)
914
918
{
915
919
    u_char      c, ch, *p;
916
 
    ngx_uint_t  hash;
917
920
    enum {
918
921
        sw_start = 0,
919
922
        sw_name,
925
928
    } state;
926
929
 
927
930
    state = ctx->state;
928
 
    hash = ctx->hash;
929
931
 
930
932
    for (p = ctx->response->pos; p < ctx->response->last; p++) {
931
933
        ch = *p;
949
951
 
950
952
                c = (u_char) (ch | 0x20);
951
953
                if (c >= 'a' && c <= 'z') {
952
 
                    hash = c;
953
954
                    break;
954
955
                }
955
956
 
956
957
                if (ch >= '0' && ch <= '9') {
957
 
                    hash = ch;
958
958
                    break;
959
959
                }
960
960
 
966
966
        case sw_name:
967
967
            c = (u_char) (ch | 0x20);
968
968
            if (c >= 'a' && c <= 'z') {
969
 
                hash += c;
970
969
                break;
971
970
            }
972
971
 
977
976
            }
978
977
 
979
978
            if (ch == '-') {
980
 
                hash += ch;
981
979
                break;
982
980
            }
983
981
 
984
982
            if (ch >= '0' && ch <= '9') {
985
 
                hash += ch;
986
983
                break;
987
984
            }
988
985
 
1079
1076
 
1080
1077
    ctx->response->pos = p;
1081
1078
    ctx->state = state;
1082
 
    ctx->hash = hash;
1083
1079
 
1084
1080
    return NGX_AGAIN;
1085
1081
 
1087
1083
 
1088
1084
    ctx->response->pos = p + 1;
1089
1085
    ctx->state = sw_start;
1090
 
    ctx->hash = hash;
1091
1086
 
1092
1087
    return NGX_OK;
1093
1088
 
1110
1105
    ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
1111
1106
                   "mail auth http block read");
1112
1107
 
1113
 
    if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
 
1108
    if (ngx_handle_read_event(rev, 0) != NGX_OK) {
1114
1109
        c = rev->data;
1115
1110
        s = c->data;
1116
1111
 
1164
1159
                + sizeof(CRLF) - 1
1165
1160
          + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
1166
1161
                + sizeof(CRLF) - 1
 
1162
          + sizeof("Client-Host: ") - 1 + s->host.len + sizeof(CRLF) - 1
 
1163
          + sizeof("Auth-SMTP-Helo: ") - 1 + s->smtp_helo.len
 
1164
          + sizeof("Auth-SMTP-From: ") - 1 + s->smtp_from.len
 
1165
          + sizeof("Auth-SMTP-To: ") - 1 + s->smtp_to.len
1167
1166
          + ahcf->header.len
1168
1167
          + sizeof(CRLF) - 1;
1169
1168
 
1215
1214
 
1216
1215
    b->last = ngx_cpymem(b->last, "Client-IP: ", sizeof("Client-IP: ") - 1);
1217
1216
    b->last = ngx_copy(b->last, s->connection->addr_text.data,
1218
 
                         s->connection->addr_text.len);
 
1217
                       s->connection->addr_text.len);
1219
1218
    *b->last++ = CR; *b->last++ = LF;
1220
1219
 
 
1220
    if (s->host.len) {
 
1221
        b->last = ngx_cpymem(b->last, "Client-Host: ",
 
1222
                             sizeof("Client-Host: ") - 1);
 
1223
        b->last = ngx_copy(b->last, s->host.data, s->host.len);
 
1224
        *b->last++ = CR; *b->last++ = LF;
 
1225
    }
 
1226
 
 
1227
    if (s->auth_method == NGX_MAIL_AUTH_NONE) {
 
1228
 
 
1229
        /* HELO, MAIL FROM, and RCPT TO can't contain CRLF, no need to escape */
 
1230
 
 
1231
        b->last = ngx_cpymem(b->last, "Auth-SMTP-Helo: ",
 
1232
                             sizeof("Auth-SMTP-Helo: ") - 1);
 
1233
        b->last = ngx_copy(b->last, s->smtp_helo.data, s->smtp_helo.len);
 
1234
        *b->last++ = CR; *b->last++ = LF;
 
1235
 
 
1236
        b->last = ngx_cpymem(b->last, "Auth-SMTP-From: ",
 
1237
                             sizeof("Auth-SMTP-From: ") - 1);
 
1238
        b->last = ngx_copy(b->last, s->smtp_from.data, s->smtp_from.len);
 
1239
        *b->last++ = CR; *b->last++ = LF;
 
1240
 
 
1241
        b->last = ngx_cpymem(b->last, "Auth-SMTP-To: ",
 
1242
                             sizeof("Auth-SMTP-To: ") - 1);
 
1243
        b->last = ngx_copy(b->last, s->smtp_to.data, s->smtp_to.len);
 
1244
        *b->last++ = CR; *b->last++ = LF;
 
1245
 
 
1246
    }
 
1247
 
1221
1248
    if (ahcf->header.len) {
1222
1249
        b->last = ngx_copy(b->last, ahcf->header.data, ahcf->header.len);
1223
1250
    }
1255
1282
 
1256
1283
    escaped->len = text->len + n * 2;
1257
1284
 
1258
 
    p = ngx_palloc(pool, escaped->len);
 
1285
    p = ngx_pnalloc(pool, escaped->len);
1259
1286
    if (p == NULL) {
1260
1287
        return NGX_ERROR;
1261
1288
    }
1326
1353
            len += header[i].key.len + 2 + header[i].value.len + 2;
1327
1354
        }
1328
1355
 
1329
 
        p = ngx_palloc(cf->pool, len);
 
1356
        p = ngx_pnalloc(cf->pool, len);
1330
1357
        if (p == NULL) {
1331
1358
            return NGX_CONF_ERROR;
1332
1359
        }