mirror of
https://github.com/nginx/nginx.git
synced 2024-12-23 15:40:03 -06:00
Mail: extensible auth methods in pop3 module.
This commit is contained in:
parent
948a18ed54
commit
a747089a1d
@ -33,19 +33,13 @@ static ngx_conf_bitmask_t ngx_mail_pop3_auth_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static ngx_str_t ngx_mail_pop3_auth_plain_capability =
|
static ngx_str_t ngx_mail_pop3_auth_methods_names[] = {
|
||||||
ngx_string("+OK methods supported:" CRLF
|
ngx_string("PLAIN"),
|
||||||
"LOGIN" CRLF
|
ngx_string("LOGIN"),
|
||||||
"PLAIN" CRLF
|
ngx_null_string, /* APOP */
|
||||||
"." CRLF);
|
ngx_string("CRAM-MD5"),
|
||||||
|
ngx_null_string /* NONE */
|
||||||
|
};
|
||||||
static ngx_str_t ngx_mail_pop3_auth_cram_md5_capability =
|
|
||||||
ngx_string("+OK methods supported:" CRLF
|
|
||||||
"LOGIN" CRLF
|
|
||||||
"PLAIN" CRLF
|
|
||||||
"CRAM-MD5" CRLF
|
|
||||||
"." CRLF);
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_mail_protocol_t ngx_mail_pop3_protocol = {
|
static ngx_mail_protocol_t ngx_mail_pop3_protocol = {
|
||||||
@ -140,13 +134,17 @@ ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
u_char *p;
|
u_char *p;
|
||||||
size_t size, stls_only_size;
|
size_t size, stls_only_size;
|
||||||
ngx_str_t *c, *d;
|
ngx_str_t *c, *d;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i, m;
|
||||||
|
|
||||||
ngx_conf_merge_bitmask_value(conf->auth_methods,
|
ngx_conf_merge_bitmask_value(conf->auth_methods,
|
||||||
prev->auth_methods,
|
prev->auth_methods,
|
||||||
(NGX_CONF_BITMASK_SET
|
(NGX_CONF_BITMASK_SET
|
||||||
|NGX_MAIL_AUTH_PLAIN_ENABLED));
|
|NGX_MAIL_AUTH_PLAIN_ENABLED));
|
||||||
|
|
||||||
|
if (conf->auth_methods & NGX_MAIL_AUTH_PLAIN_ENABLED) {
|
||||||
|
conf->auth_methods |= NGX_MAIL_AUTH_LOGIN_ENABLED;
|
||||||
|
}
|
||||||
|
|
||||||
if (conf->capabilities.nelts == 0) {
|
if (conf->capabilities.nelts == 0) {
|
||||||
conf->capabilities = prev->capabilities;
|
conf->capabilities = prev->capabilities;
|
||||||
}
|
}
|
||||||
@ -179,11 +177,15 @@ ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
stls_only_size += c[i].len + sizeof(CRLF) - 1;
|
stls_only_size += c[i].len + sizeof(CRLF) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED) {
|
size += sizeof("SASL") - 1 + sizeof(CRLF) - 1;
|
||||||
size += sizeof("SASL LOGIN PLAIN CRAM-MD5" CRLF) - 1;
|
|
||||||
|
|
||||||
} else {
|
for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
|
||||||
size += sizeof("SASL LOGIN PLAIN" CRLF) - 1;
|
m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED;
|
||||||
|
m <<= 1, i++)
|
||||||
|
{
|
||||||
|
if (m & conf->auth_methods) {
|
||||||
|
size += 1 + ngx_mail_pop3_auth_methods_names[i].len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ngx_pnalloc(cf->pool, size);
|
p = ngx_pnalloc(cf->pool, size);
|
||||||
@ -202,15 +204,21 @@ ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
*p++ = CR; *p++ = LF;
|
*p++ = CR; *p++ = LF;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED) {
|
p = ngx_cpymem(p, "SASL", sizeof("SASL") - 1);
|
||||||
p = ngx_cpymem(p, "SASL LOGIN PLAIN CRAM-MD5" CRLF,
|
|
||||||
sizeof("SASL LOGIN PLAIN CRAM-MD5" CRLF) - 1);
|
|
||||||
|
|
||||||
} else {
|
for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
|
||||||
p = ngx_cpymem(p, "SASL LOGIN PLAIN" CRLF,
|
m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED;
|
||||||
sizeof("SASL LOGIN PLAIN" CRLF) - 1);
|
m <<= 1, i++)
|
||||||
|
{
|
||||||
|
if (m & conf->auth_methods) {
|
||||||
|
*p++ = ' ';
|
||||||
|
p = ngx_cpymem(p, ngx_mail_pop3_auth_methods_names[i].data,
|
||||||
|
ngx_mail_pop3_auth_methods_names[i].len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*p++ = CR; *p++ = LF;
|
||||||
|
|
||||||
*p++ = '.'; *p++ = CR; *p = LF;
|
*p++ = '.'; *p++ = CR; *p = LF;
|
||||||
|
|
||||||
|
|
||||||
@ -231,13 +239,43 @@ ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
*p++ = '.'; *p++ = CR; *p = LF;
|
*p++ = '.'; *p++ = CR; *p = LF;
|
||||||
|
|
||||||
|
|
||||||
if (conf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED) {
|
size = sizeof("+OK methods supported:" CRLF) - 1
|
||||||
conf->auth_capability = ngx_mail_pop3_auth_cram_md5_capability;
|
+ sizeof("." CRLF) - 1;
|
||||||
|
|
||||||
} else {
|
for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
|
||||||
conf->auth_capability = ngx_mail_pop3_auth_plain_capability;
|
m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED;
|
||||||
|
m <<= 1, i++)
|
||||||
|
{
|
||||||
|
if (m & conf->auth_methods) {
|
||||||
|
size += ngx_mail_pop3_auth_methods_names[i].len
|
||||||
|
+ sizeof(CRLF) - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p = ngx_pnalloc(cf->pool, size);
|
||||||
|
if (p == NULL) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->auth_capability.data = p;
|
||||||
|
conf->auth_capability.len = size;
|
||||||
|
|
||||||
|
p = ngx_cpymem(p, "+OK methods supported:" CRLF,
|
||||||
|
sizeof("+OK methods supported:" CRLF) - 1);
|
||||||
|
|
||||||
|
for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
|
||||||
|
m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED;
|
||||||
|
m <<= 1, i++)
|
||||||
|
{
|
||||||
|
if (m & conf->auth_methods) {
|
||||||
|
p = ngx_cpymem(p, ngx_mail_pop3_auth_methods_names[i].data,
|
||||||
|
ngx_mail_pop3_auth_methods_names[i].len);
|
||||||
|
*p++ = CR; *p++ = LF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*p++ = '.'; *p++ = CR; *p = LF;
|
||||||
|
|
||||||
|
|
||||||
p = ngx_pnalloc(cf->pool, stls_only_size);
|
p = ngx_pnalloc(cf->pool, stls_only_size);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user