From: Richard Russon Date: Mon, 3 Sep 2018 13:58:34 +0000 (+0100) Subject: tidy upstream changes X-Git-Tag: 2019-10-25~666^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5101a16f5773d6034ef65f01ffddb3bfd32c7bbf;p=neomutt tidy upstream changes --- diff --git a/imap/auth_oauth.c b/imap/auth_oauth.c index dde34ae88..2d5861d5b 100644 --- a/imap/auth_oauth.c +++ b/imap/auth_oauth.c @@ -1,23 +1,31 @@ -/* +/** + * @file + * IMAP OAUTH authentication method + * + * @authors * Copyright (C) 1999-2001,2005 Brendan Cully * Copyright (C) 2018 Brandon Long - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . */ -/* IMAP login/authentication code */ +/** + * @page imap_auth_oauth IMAP OAUTH authentication method + * + * IMAP OAUTH authentication method + */ #include "config.h" #include "imap_private.h" @@ -30,7 +38,12 @@ #include "mutt_socket.h" #include "muttlib.h" -/* imap_auth_oauth: AUTH=OAUTHBEARER support. See RFC 7628 */ +/** + * imap_auth_oauth - Authenticate an IMAP connection using OAUTHBEARER + * @param idata Server data + * @param method Name of this authentication method (UNUSED) + * @retval num Result, e.g. #IMAP_AUTH_SUCCESS + */ enum ImapAuthRes imap_auth_oauth(struct ImapData *idata, const char *method) { char *ibuf = NULL; @@ -41,13 +54,15 @@ enum ImapAuthRes imap_auth_oauth(struct ImapData *idata, const char *method) /* For now, we only support SASL_IR also and over TLS */ if (!mutt_bit_isset(idata->capabilities, AUTH_OAUTHBEARER) || !mutt_bit_isset(idata->capabilities, SASL_IR) || !idata->conn->ssf) + { return IMAP_AUTH_UNAVAIL; + } mutt_message(_("Authenticating (OAUTHBEARER)...")); /* We get the access token from the imap_oauth_refresh_command */ oauthbearer = mutt_account_getoauthbearer(&idata->conn->account); - if (oauthbearer == NULL) + if (!oauthbearer) return IMAP_AUTH_FAILURE; ilen = mutt_str_strlen(oauthbearer) + 30; @@ -78,6 +93,5 @@ enum ImapAuthRes imap_auth_oauth(struct ImapData *idata, const char *method) } mutt_error(_("OAUTHBEARER authentication failed.")); - mutt_sleep(2); return IMAP_AUTH_FAILURE; } diff --git a/mutt_account.c b/mutt_account.c index aa5b43636..bd7b7d51c 100644 --- a/mutt_account.c +++ b/mutt_account.c @@ -41,14 +41,15 @@ /* These Config Variables are only used in mutt_account.c */ char *ImapLogin; ///< Config: (imap) Login name for the IMAP server (defaults to ImapUser) -char *ImapOauthRefreshCmd; +char *ImapOauthRefreshCmd; ///< Config: (imap) External command to generate OAUTH refresh token char *ImapPass; ///< Config: (imap) Password for the IMAP server char *NntpPass; ///< Config: (nntp) Password for the news server char *NntpUser; ///< Config: (nntp) Username for the news server +char *PopOauthRefreshCmd; ///< Config: (pop) External command to generate OAUTH refresh token char *PopPass; ///< Config: (pop) Password of the POP server char *PopUser; ///< Config: (pop) Username of the POP server +char *SmtpOauthRefreshCmd; ///< Config: (smtp) External command to generate OAUTH refresh token char *SmtpPass; ///< Config: (smtp) Password for the SMTP server -char *SmtpOauthRefreshCmd; /** * mutt_account_match - Compare account info (host/port/user) @@ -335,11 +336,16 @@ void mutt_account_unsetpass(struct Account *account) account->flags &= ~MUTT_ACCT_PASS; } -/* mutt_account_getoauthbearer: call external command to generate the - * oauth refresh token for this ACCOUNT, then create and encode the - * OAUTHBEARER token based on RFC 7628. Returns NULL on failure. - * Resulting token is dynamically allocated and should be FREE'd by the - * caller. +/** + * mutt_account_getoauthbearer - Get an OAUTHBEARER token + * @param account Account to use + * @retval ptr OAuth token + * @retval NULL Error + * + * Run an external command to generate the oauth refresh token for an account, + * then create and encode the OAUTHBEARER token based on RFC7628. + * + * @note Caller should free the token */ char *mutt_account_getoauthbearer(struct Account *account) { @@ -370,35 +376,33 @@ char *mutt_account_getoauthbearer(struct Account *account) cmd = SmtpOauthRefreshCmd; #endif - if (cmd == NULL) + if (!cmd) { mutt_error( _("mutt_account_getoauthbearer: No OAUTH refresh command defined")); return NULL; } - if ((pid = mutt_create_filter(cmd, NULL, &fp, NULL)) < 0) + pid = mutt_create_filter(cmd, NULL, &fp, NULL); + if (pid < 0) { mutt_perror( _("mutt_account_getoauthbearer: Unable to run refresh command")); return NULL; } - /* read line */ token = mutt_file_read_line(NULL, &token_size, fp, NULL, 0); mutt_file_fclose(&fp); mutt_wait_filter(pid); - if (token == NULL || *token == '\0') + if (!token || *token == '\0') { mutt_error(_("mutt_account_getoauthbearer: Command returned empty string")); FREE(&token); return NULL; } - /* Determine the length of the keyed message digest, add 50 for - * overhead. - */ + /* Determine the length of the keyed message digest, add 50 for overhead. */ oalen = strlen(account->login) + strlen(account->host) + strlen(token) + 50; oauthbearer = mutt_mem_malloc(oalen); diff --git a/mutt_account.h b/mutt_account.h index 492f2a14a..d88d14116 100644 --- a/mutt_account.h +++ b/mutt_account.h @@ -34,10 +34,11 @@ extern char *ImapOauthRefreshCmd; extern char *ImapPass; extern char *NntpPass; extern char *NntpUser; +extern char *PopOauthRefreshCmd; extern char *PopPass; extern char *PopUser; -extern char *SmtpPass; extern char *SmtpOauthRefreshCmd; +extern char *SmtpPass; /** * enum AccountType - account types diff --git a/pop/pop.c b/pop/pop.c index 185711f9a..e204720f6 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -67,7 +67,6 @@ struct BodyCache; short PopCheckinterval; ///< Config: (pop) Interval between checks for new mail unsigned char PopDelete; ///< Config: (pop) After downloading POP messages, delete them on the server char *PopHost; ///< Config: (pop) Url of the POP server -char *PopOauthRefreshCmd; bool PopLast; ///< Config: (pop) Use the 'LAST' command to fetch new mail #ifdef USE_HCACHE diff --git a/pop/pop.h b/pop/pop.h index 41163f9b1..35d6a86eb 100644 --- a/pop/pop.h +++ b/pop/pop.h @@ -42,7 +42,6 @@ extern short PopCheckinterval; extern unsigned char PopDelete; extern char * PopHost; -extern char *PopOauthRefreshCmd; extern bool PopLast; /* These Config Variables are only used in pop/pop_auth.c */ diff --git a/pop/pop_auth.c b/pop/pop_auth.c index 56e88ca3e..568f5c694 100644 --- a/pop/pop_auth.c +++ b/pop/pop_auth.c @@ -335,7 +335,12 @@ static enum PopAuthRes pop_auth_user(struct PopData *pop_data, const char *metho return POP_A_FAILURE; } -/* OAUTHBEARER authenticator */ +/** + * pop_auth_oauth - Authenticate a POP connection using OAUTHBEARER + * @param pop_data POP Server data + * @param method Name of this authentication method (UNUSED) + * @retval num Result, e.g. #POP_A_SUCCESS + */ static enum PopAuthRes pop_auth_oauth(struct PopData *pop_data, const char *method) { char *oauthbearer = NULL; @@ -348,7 +353,7 @@ static enum PopAuthRes pop_auth_oauth(struct PopData *pop_data, const char *meth mutt_message(_("Authenticating (OAUTHBEARER)...")); oauthbearer = mutt_account_getoauthbearer(&pop_data->conn->account); - if (oauthbearer == NULL) + if (!oauthbearer) return POP_A_FAILURE; auth_cmd_len = strlen(oauthbearer) + 30; @@ -359,7 +364,7 @@ static enum PopAuthRes pop_auth_oauth(struct PopData *pop_data, const char *meth ret = pop_query_d(pop_data, auth_cmd, strlen(auth_cmd), #ifdef DEBUG /* don't print the bearer token unless we're at the ungodly debugging level */ - DebugLevel < MUTT_SOCK_LOG_FULL ? "AUTH OAUTHBEARER *\r\n" : + (DebugLevel < MUTT_SOCK_LOG_FULL) ? "AUTH OAUTHBEARER *\r\n" : #endif NULL); FREE(&auth_cmd); @@ -373,8 +378,7 @@ static enum PopAuthRes pop_auth_oauth(struct PopData *pop_data, const char *meth } /* The error response was a SASL continuation, so "continue" it. - * See RFC 7628 3.2.3 - */ + * See RFC7628 3.2.3 */ mutt_socket_send(pop_data->conn, "\001"); err = pop_data->err_msg; diff --git a/smtp.c b/smtp.c index 330892451..1b7b71589 100644 --- a/smtp.c +++ b/smtp.c @@ -503,26 +503,25 @@ fail: } #endif -/* smtp_auth_oauth: AUTH=OAUTHBEARER support. See RFC 7628 */ +/** + * smtp_auth_oauth - Authenticate an SMTP connection using OAUTHBEARER + * @param conn Connection info + * @retval num Result, e.g. #SMTP_AUTH_SUCCESS + */ static int smtp_auth_oauth(struct Connection *conn) { - char *ibuf = NULL; - char *oauthbearer = NULL; - int ilen; - int rc; - mutt_message(_("Authenticating (OAUTHBEARER)...")); /* We get the access token from the smtp_oauth_refresh_command */ - oauthbearer = mutt_account_getoauthbearer(&conn->account); - if (oauthbearer == NULL) + char *oauthbearer = mutt_account_getoauthbearer(&conn->account); + if (!oauthbearer) return SMTP_AUTH_FAIL; - ilen = strlen(oauthbearer) + 30; - ibuf = mutt_mem_malloc(ilen); + size_t ilen = strlen(oauthbearer) + 30; + char *ibuf = mutt_mem_malloc(ilen); snprintf(ibuf, ilen, "AUTH OAUTHBEARER %s\r\n", oauthbearer); - rc = mutt_socket_send(conn, ibuf); + int rc = mutt_socket_send(conn, ibuf); FREE(&oauthbearer); FREE(&ibuf); @@ -560,7 +559,7 @@ static int smtp_auth(struct Connection *conn) mutt_debug(2, "Trying method %s\n", method); - if (!strcmp(method, "oauthbearer")) + if (strcmp(method, "oauthbearer") == 0) { r = smtp_auth_oauth(conn); }