/* for EHLO responses */ static CURLcode smtp_state_ehlo_resp(struct connectdata *conn, int smtpcode, smtpstate instate) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; (void)instate; /* no use for this yet */ if(smtpcode/100 != 2) { if((data->set.ftp_ssl <= CURLUSESSL_TRY || conn->ssl[FIRSTSOCKET].use) && !conn->bits.user_passwd) result = smtp_state_helo(conn); else { failf(data, "Access denied: %d", smtpcode); result = CURLE_LOGIN_DENIED; } } else if(data->set.ftp_ssl && !conn->ssl[FIRSTSOCKET].use) { /* We don't have a SSL/TLS connection yet, but SSL is requested. Switch to TLS connection now */ result = Curl_pp_sendf(&conn->proto.smtpc.pp, "STARTTLS"); state(conn, SMTP_STARTTLS); } else result = smtp_authenticate(conn); return result; }
/* for STARTTLS responses */ static CURLcode smtp_state_starttls_resp(struct connectdata *conn, int smtpcode, smtpstate instate) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; (void)instate; /* no use for this yet */ if(smtpcode != 220) { if(data->set.ftp_ssl != CURLUSESSL_TRY) { failf(data, "STARTTLS denied. %c", smtpcode); result = CURLE_LOGIN_DENIED; } else result = smtp_authenticate(conn); } else { /* Curl_ssl_connect is BLOCKING */ result = Curl_ssl_connect(conn, FIRSTSOCKET); if(CURLE_OK == result) { conn->protocol |= PROT_SMTPS; result = smtp_state_ehlo(conn); } } return result; }
/* For STARTTLS responses */ static CURLcode smtp_state_starttls_resp(struct connectdata *conn, int smtpcode, smtpstate instate) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; (void)instate; /* no use for this yet */ if(smtpcode != 220) { if(data->set.use_ssl != CURLUSESSL_TRY) { failf(data, "STARTTLS denied. %c", smtpcode); result = CURLE_USE_SSL_FAILED; } else result = smtp_authenticate(conn); } else { if(data->state.used_interface == Curl_if_multi) { state(conn, SMTP_UPGRADETLS); result = smtp_state_upgrade_tls(conn); } else { result = Curl_ssl_connect(conn, FIRSTSOCKET); if(CURLE_OK == result) { smtp_to_smtps(conn); result = smtp_state_ehlo(conn); } } } return result; }
static int authenticate (const char *mech) { if (args_info.imap_flag) return imap_authenticate (mech); if (args_info.smtp_flag) return smtp_authenticate (mech); if (!args_info.quiet_given) fprintf (stderr, _("Using mechanism:\n")); puts (mech); return 1; }
/* For EHLO responses */ static CURLcode smtp_state_ehlo_resp(struct connectdata *conn, int smtpcode, smtpstate instate) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; struct smtp_conn *smtpc = &conn->proto.smtpc; (void)instate; /* no use for this yet */ if(smtpcode/100 != 2) { if((data->set.use_ssl <= CURLUSESSL_TRY || conn->ssl[FIRSTSOCKET].use) && !conn->bits.user_passwd) result = smtp_state_helo(conn); else { failf(data, "Remote access denied: %d", smtpcode); result = CURLE_REMOTE_ACCESS_DENIED; } } else if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { /* We don't have a SSL/TLS connection yet, but SSL is requested */ if(smtpc->tls_supported) /* Switch to TLS connection now */ result = smtp_state_starttls(conn); else if(data->set.use_ssl == CURLUSESSL_TRY) /* Fallback and carry on with authentication */ result = smtp_authenticate(conn); else { failf(data, "STARTTLS not supported."); result = CURLE_USE_SSL_FAILED; } } else result = smtp_authenticate(conn); return result; }
/* For STARTTLS responses */ static CURLcode smtp_state_starttls_resp(struct connectdata *conn, int smtpcode, smtpstate instate) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; (void)instate; /* no use for this yet */ if(smtpcode != 220) { if(data->set.use_ssl != CURLUSESSL_TRY) { failf(data, "STARTTLS denied. %c", smtpcode); result = CURLE_USE_SSL_FAILED; } else result = smtp_authenticate(conn); } else result = smtp_state_upgrade_tls(conn); return result; }