move use_imaps out of server_conf_t

it doesn't belong there - it's a property of imap_server_conf_t.
the port setup is now done while reading the config.

this makes socket.[hc] imap-agnostic.
This commit is contained in:
Oswald Buddenhagen 2014-07-06 10:06:40 +02:00
parent 3742fc475b
commit aa4f7a7d00
3 changed files with 19 additions and 19 deletions

View File

@ -46,6 +46,7 @@ typedef struct imap_server_conf {
int max_in_progress; int max_in_progress;
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
char use_ssl; char use_ssl;
char use_imaps;
char require_ssl; char require_ssl;
char require_cram; char require_cram;
#endif #endif
@ -1531,7 +1532,7 @@ imap_open_store_connected( int ok, void *aux )
if (!ok) if (!ok)
imap_open_store_bail( ctx ); imap_open_store_bail( ctx );
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
else if (srvc->sconf.use_imaps) else if (srvc->use_imaps)
socket_start_tls( &ctx->conn, imap_open_store_tlsstarted1 ); socket_start_tls( &ctx->conn, imap_open_store_tlsstarted1 );
#endif #endif
} }
@ -1581,7 +1582,7 @@ imap_open_store_authenticate( imap_store_t *ctx )
if (ctx->greeting != GreetingPreauth) { if (ctx->greeting != GreetingPreauth) {
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
if (!srvc->sconf.use_imaps && srvc->use_ssl) { if (!srvc->use_imaps && srvc->use_ssl) {
/* always try to select SSL support if available */ /* always try to select SSL support if available */
if (CAP(STARTTLS)) { if (CAP(STARTTLS)) {
imap_exec( ctx, 0, imap_open_store_authenticate_p2, "STARTTLS" ); imap_exec( ctx, 0, imap_open_store_authenticate_p2, "STARTTLS" );
@ -1600,7 +1601,7 @@ imap_open_store_authenticate( imap_store_t *ctx )
imap_open_store_authenticate2( ctx ); imap_open_store_authenticate2( ctx );
} else { } else {
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
if (!srvc->sconf.use_imaps && srvc->require_ssl) { if (!srvc->use_imaps && srvc->require_ssl) {
error( "IMAP error: SSL support not available\n" ); error( "IMAP error: SSL support not available\n" );
imap_open_store_bail( ctx ); imap_open_store_bail( ctx );
return; return;
@ -2272,7 +2273,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
if (starts_with( cfg->val, -1, "imaps:", 6 )) { if (starts_with( cfg->val, -1, "imaps:", 6 )) {
cfg->val += 6; cfg->val += 6;
server->sconf.use_imaps = 1; server->use_imaps = 1;
server->sconf.use_sslv2 = 1; server->sconf.use_sslv2 = 1;
server->sconf.use_sslv3 = 1; server->sconf.use_sslv3 = 1;
} else } else
@ -2310,7 +2311,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
} else if (!strcasecmp( "RequireSSL", cfg->cmd )) } else if (!strcasecmp( "RequireSSL", cfg->cmd ))
server->require_ssl = parse_bool( cfg ); server->require_ssl = parse_bool( cfg );
else if (!strcasecmp( "UseIMAPS", cfg->cmd )) else if (!strcasecmp( "UseIMAPS", cfg->cmd ))
server->sconf.use_imaps = parse_bool( cfg ); server->use_imaps = parse_bool( cfg );
else if (!strcasecmp( "UseSSLv2", cfg->cmd )) else if (!strcasecmp( "UseSSLv2", cfg->cmd ))
server->sconf.use_sslv2 = parse_bool( cfg ); server->sconf.use_sslv2 = parse_bool( cfg );
else if (!strcasecmp( "UseSSLv3", cfg->cmd )) else if (!strcasecmp( "UseSSLv3", cfg->cmd ))
@ -2377,6 +2378,12 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
return 1; return 1;
} }
#endif #endif
if (!server->sconf.port)
server->sconf.port =
#ifdef HAVE_LIBSSL
server->use_imaps ? 993 :
#endif
143;
} }
if (store) { if (store) {
if (!store->server) { if (!store->server) {

View File

@ -312,7 +312,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) )
sock->callbacks.connect = cb; sock->callbacks.connect = cb;
/* open connection to IMAP server */ /* open connection to server */
if (conf->tunnel) { if (conf->tunnel) {
int a[2]; int a[2];
@ -352,7 +352,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) )
hints.ai_flags = AI_ADDRCONFIG; hints.ai_flags = AI_ADDRCONFIG;
infon( "Resolving %s... ", conf->host ); infon( "Resolving %s... ", conf->host );
if ((gaierr = getaddrinfo( conf->host, NULL, &hints, &sock->addrs ))) { if ((gaierr = getaddrinfo( conf->host, NULL, &hints, &sock->addrs ))) {
error( "IMAP error: Cannot resolve server '%s': %s\n", conf->host, gai_strerror( gaierr ) ); error( "Error: Cannot resolve server '%s': %s\n", conf->host, gai_strerror( gaierr ) );
socket_connect_bail( sock ); socket_connect_bail( sock );
return; return;
} }
@ -365,7 +365,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) )
infon( "Resolving %s... ", conf->host ); infon( "Resolving %s... ", conf->host );
he = gethostbyname( conf->host ); he = gethostbyname( conf->host );
if (!he) { if (!he) {
error( "IMAP error: Cannot resolve server '%s': %s\n", conf->host, hstrerror( h_errno ) ); error( "Error: Cannot resolve server '%s': %s\n", conf->host, hstrerror( h_errno ) );
socket_connect_bail( sock ); socket_connect_bail( sock );
return; return;
} }
@ -381,7 +381,6 @@ static void
socket_connect_one( conn_t *sock ) socket_connect_one( conn_t *sock )
{ {
int s; int s;
ushort port;
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
struct addrinfo *ai; struct addrinfo *ai;
#else #else
@ -400,18 +399,13 @@ socket_connect_one( conn_t *sock )
return; return;
} }
port = sock->conf->port ? sock->conf->port :
#ifdef HAVE_LIBSSL
sock->conf->use_imaps ? 993 :
#endif
143;
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
if (ai->ai_family == AF_INET6) { if (ai->ai_family == AF_INET6) {
struct sockaddr_in6 *in6 = ((struct sockaddr_in6 *)ai->ai_addr); struct sockaddr_in6 *in6 = ((struct sockaddr_in6 *)ai->ai_addr);
char sockname[64]; char sockname[64];
in6->sin6_port = htons( port ); in6->sin6_port = htons( sock->conf->port );
nfasprintf( &sock->name, "%s ([%s]:%hu)", nfasprintf( &sock->name, "%s ([%s]:%hu)",
sock->conf->host, inet_ntop( AF_INET6, &in6->sin6_addr, sockname, sizeof(sockname) ), port ); sock->conf->host, inet_ntop( AF_INET6, &in6->sin6_addr, sockname, sizeof(sockname) ), sock->conf->port );
} else } else
#endif #endif
{ {
@ -421,9 +415,9 @@ socket_connect_one( conn_t *sock )
in->sin_family = AF_INET; in->sin_family = AF_INET;
in->sin_addr.s_addr = *((int *)*sock->curr_addr); in->sin_addr.s_addr = *((int *)*sock->curr_addr);
#endif #endif
in->sin_port = htons( port ); in->sin_port = htons( sock->conf->port );
nfasprintf( &sock->name, "%s (%s:%hu)", nfasprintf( &sock->name, "%s (%s:%hu)",
sock->conf->host, inet_ntoa( in->sin_addr ), port ); sock->conf->host, inet_ntoa( in->sin_addr ), sock->conf->port );
} }
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6

View File

@ -34,7 +34,6 @@ typedef struct server_conf {
int port; int port;
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
char *cert_file; char *cert_file;
char use_imaps;
char use_sslv2, use_sslv3, use_tlsv1, use_tlsv11, use_tlsv12; char use_sslv2, use_sslv3, use_tlsv1, use_tlsv11, use_tlsv12;
/* these are actually variables and are leaked at the end */ /* these are actually variables and are leaked at the end */