[PATCH v12 00/10] imap-send: make it usable again and add OAuth2.0 support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch series does the following things:
Firstly it basically makes the imap-send command usable again since it
was broken because of not being able to correctly parse the config file.

Further it adds support for OAuth2.0 and PLAIN authentication to git
imap-send.

Last, it does some minor improvements including adding the ability to
specify the folder using the command line and ability to list the
available folders by adding a `--list` option.

P.S.: I am surprised this thing even exists xD.

v2:  - Added support for OAuth2.0 with curl.
     - Fixed the memory leak in case auth_cram_md5 fails.
v3:  - Improve wording in first patch
     - Change misleading message if OAuth2.0 is used without OpenSSL
v4:  - Add PLAIN authentication mechanism for OpenSSL
     - Improved wording in the first patch a bit more
v5:  - Add ability to specify destination folder using the command line
     - Add ability to set a default between curl and openssl using the config
v6:  - Fix minor mistakes in --folder documentation
v7:  - Fix spelling and grammar mistakes in logs shown to the user when running imap-send
     - Display port alongwith host when git credential is invoked and asks for a password
     - Display the destination mailbox when sending a message
v8:  - Drop the patch that enabled user to choose between libcurl and openssl using the config
     - Add ability to list the available folders by adding a `--list` option
v9:  - Encourage users to use OAuth2.0 for Gmail (similar change done for send-email docs).
v10: - Fix comment styles
     - Fix failing tests
v11: - Use lower case letters for the first word of a sendtence in an error message
       and avoid using full stops at the end of a sentence.
v12: - Gracefully exit PLAIN, CRAM-MD5, OAUTHBEARER and XOAUTH2 authentication methods
       if OpenSSL support is not compiled in, but is requested by the user.
     - Use backticks for string literals.
     - Wrap documentation text to 75 columns.
     - End the last member of enum CAPABILITY with a trailing comma.

Aditya Garg (10):
  imap-send: fix bug causing cfg->folder being set to NULL
  imap-send: add support for OAuth2.0 authentication
  imap-send: add PLAIN authentication method to OpenSSL
  imap-send: fix memory leak in case auth_cram_md5 fails
  imap-send: gracefully fail if CRAM-MD5 authentication is requested
    without OpenSSL
  imap-send: enable specifying the folder using the command line
  imap-send: fix minor mistakes in the logs
  imap-send: display port alongwith host when git credential is invoked
  imap-send: display the destination mailbox when sending a message
  imap-send: add ability to list the available folders

 Documentation/config/imap.adoc   |  11 +-
 Documentation/git-imap-send.adoc |  68 ++++-
 imap-send.c                      | 425 +++++++++++++++++++++++++++----
 3 files changed, 441 insertions(+), 63 deletions(-)

Range-diff against v11:
 -:  ---------- >  1:  3e3ddf7077 imap-send: fix bug causing cfg->folder being set to NULL
 1:  02037873a1 !  2:  ab12f713d2 imap-send: add support for OAuth2.0 authentication
    @@ Documentation/config/imap.adoc: imap.authMethod::
      	than 7.34.0, or if you're running git-imap-send with the `--no-curl`
     -	option, the only supported method is 'CRAM-MD5'. If this is not set
     -	then 'git imap-send' uses the basic IMAP plaintext LOGIN command.
    -+	option, the only supported methods are 'CRAM-MD5', 'OAUTHBEARER' and
    -+	'XOAUTH2'. If this is not set then `git imap-send` uses the basic IMAP
    -+	plaintext LOGIN command.
    ++	option, the only supported methods are `CRAM-MD5`, `OAUTHBEARER` and
    ++	`XOAUTH2`. If this is not set then `git imap-send` uses the basic IMAP
    ++	plaintext `LOGIN` command.
     
      ## Documentation/git-imap-send.adoc ##
     @@ Documentation/git-imap-send.adoc: Using Gmail's IMAP interface:
    @@ Documentation/git-imap-send.adoc: Using Gmail's IMAP interface:
      ---------
      
     +Gmail does not allow using your regular password for `git imap-send`.
    -+If you have multi-factor authentication set up on your Gmail account, you can generate
    -+an app-specific password for use with `git imap-send`.
    -+Visit https://security.google.com/settings/security/apppasswords to create it.
    -+Alternatively, use OAuth2.0 authentication as described below.
    ++If you have multi-factor authentication set up on your Gmail account, you
    ++can generate an app-specific password for use with `git imap-send`.
    ++Visit https://security.google.com/settings/security/apppasswords to create
    ++it. Alternatively, use OAuth2.0 authentication as described below.
     +
      [NOTE]
      You might need to instead use: `folder = "[Google Mail]/Drafts"` if you get an error
    @@ Documentation/git-imap-send.adoc: that the "Folder doesn't exist".
      If your Gmail account is set to another language than English, the name of the "Drafts"
      folder will be localized.
      
    -+If you want to use OAuth2.0 based authentication, you can specify `OAUTHBEARER`
    -+or `XOAUTH2` mechanism in your config. It is more secure than using app-specific
    -+passwords, and also does not enforce the need of having multi-factor authentication.
    -+You will have to use an OAuth2.0 access token in place of your password when using this
    -+authentication.
    ++If you want to use OAuth2.0 based authentication, you can specify
    ++`OAUTHBEARER` or `XOAUTH2` mechanism in your config. It is more secure
    ++than using app-specific passwords, and also does not enforce the need of
    ++having multi-factor authentication. You will have to use an OAuth2.0
    ++access token in place of your password when using this authentication.
     +
     +---------
     +[imap]
    @@ imap-send.c: enum CAPABILITY {
     -	AUTH_CRAM_MD5
     +	AUTH_CRAM_MD5,
     +	AUTH_OAUTHBEARER,
    -+	AUTH_XOAUTH2
    ++	AUTH_XOAUTH2,
      };
      
      static const char *cap_list[] = {
    @@ imap-send.c: static char *cram(const char *challenge_64, const char *user, const
     +	return b64;
     +}
     +
    - #else
    - 
    - static char *cram(const char *challenge_64 UNUSED,
    -@@ imap-send.c: static char *cram(const char *challenge_64 UNUSED,
    - 	    "you have to build git-imap-send with OpenSSL library.");
    - }
    - 
    -+static char *oauthbearer_base64(const char *user UNUSED,
    -+		  const char *access_token UNUSED)
    -+{
    -+	die("You are trying to use OAUTHBEARER authenticate method "
    -+	    "with OpenSSL library, but its support has not been compiled in.");
    -+}
    -+
    -+static char *xoauth2_base64(const char *user UNUSED,
    -+		  const char *access_token UNUSED)
    -+{
    -+	die("You are trying to use XOAUTH2 authenticate method "
    -+	    "with OpenSSL library, but its support has not been compiled in.");
    -+}
    -+
    - #endif
    - 
    - static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
    -@@ imap-send.c: static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
    - 	return 0;
    - }
    - 
     +static int auth_oauthbearer(struct imap_store *ctx, const char *prompt UNUSED)
     +{
     +	int ret;
    @@ imap-send.c: static int auth_cram_md5(struct imap_store *ctx, const char *prompt
     +	return 0;
     +}
     +
    - static void server_fill_credential(struct imap_server_conf *srvc, struct credential *cred)
    - {
    - 	if (srvc->user && srvc->pass)
    + #else
    + 
    + static char *cram(const char *challenge_64 UNUSED,
    +@@ imap-send.c: static char *cram(const char *challenge_64 UNUSED,
    + 	    "you have to build git-imap-send with OpenSSL library.");
    + }
    + 
    ++#define auth_oauthbearer NULL
    ++#define auth_xoauth2 NULL
    ++
    + #endif
    + 
    + static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
     @@ imap-send.c: static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
      					fprintf(stderr, "IMAP error: AUTHENTICATE CRAM-MD5 failed\n");
      					goto bail;
    @@ imap-send.c: static struct imap_store *imap_open_store(struct imap_server_conf *
     +						"but %s doesn't support it.\n", srvc->host);
     +					goto bail;
     +				}
    ++
    ++				#ifdef NO_OPENSSL
    ++				fprintf(stderr, "You are trying to use OAUTHBEARER authentication mechanism "
    ++					"with OpenSSL library, but its support has not been compiled in.");
    ++				goto bail;
    ++				#endif
    ++
     +				/* OAUTHBEARER */
     +
     +				memset(&cb, 0, sizeof(cb));
    @@ imap-send.c: static struct imap_store *imap_open_store(struct imap_server_conf *
     +						"but %s doesn't support it.\n", srvc->host);
     +					goto bail;
     +				}
    ++
    ++				#ifdef NO_OPENSSL
    ++				fprintf(stderr, "You are trying to use XOAUTH2 authentication mechanism "
    ++					"with OpenSSL library, but its support has not been compiled in.");
    ++				goto bail;
    ++				#endif
    ++
     +				/* XOAUTH2 */
     +
     +				memset(&cb, 0, sizeof(cb));
 2:  3a0be43838 !  3:  ba9c3fb756 imap-send: add PLAIN authentication method to OpenSSL
    @@ Documentation/config/imap.adoc: imap.authMethod::
      	Specify the authentication method for authenticating with the IMAP server.
      	If Git was built with the NO_CURL option, or if your curl version is older
      	than 7.34.0, or if you're running git-imap-send with the `--no-curl`
    --	option, the only supported methods are 'CRAM-MD5', 'OAUTHBEARER' and
    --	'XOAUTH2'. If this is not set then `git imap-send` uses the basic IMAP
    -+	option, the only supported methods are 'PLAIN', 'CRAM-MD5', 'OAUTHBEARER'
    -+	and 'XOAUTH2'. If this is not set then `git imap-send` uses the basic IMAP
    - 	plaintext LOGIN command.
    +-	option, the only supported methods are `CRAM-MD5`, `OAUTHBEARER` and
    +-	`XOAUTH2`. If this is not set then `git imap-send` uses the basic IMAP
    ++	option, the only supported methods are `PLAIN`, `CRAM-MD5`, `OAUTHBEARER`
    ++	and `XOAUTH2`. If this is not set then `git imap-send` uses the basic IMAP
    + 	plaintext `LOGIN` command.
     
      ## imap-send.c ##
     @@ imap-send.c: enum CAPABILITY {
    @@ imap-send.c: enum CAPABILITY {
     +	AUTH_PLAIN,
      	AUTH_CRAM_MD5,
      	AUTH_OAUTHBEARER,
    - 	AUTH_XOAUTH2
    + 	AUTH_XOAUTH2,
     @@ imap-send.c: static const char *cap_list[] = {
      	"LITERAL+",
      	"NAMESPACE",
    @@ imap-send.c: static char hexchar(unsigned int b)
      {
      	int i, resp_len, encoded_len, decoded_len;
     @@ imap-send.c: static char *xoauth2_base64(const char *user, const char *access_token)
    - 
    - #else
    - 
    -+static char *plain_base64(const char *user UNUSED,
    -+		  const char *access_token UNUSED)
    -+{
    -+	die("You are trying to use PLAIN authenticate method "
    -+	    "with OpenSSL library, but its support has not been compiled in.");
    -+}
    -+
    - static char *cram(const char *challenge_64 UNUSED,
    - 		  const char *user UNUSED,
    - 		  const char *pass UNUSED)
    -@@ imap-send.c: static char *xoauth2_base64(const char *user UNUSED,
    - 
    - #endif
    + 	return b64;
    + }
      
     +static int auth_plain(struct imap_store *ctx, const char *prompt UNUSED)
     +{
    @@ imap-send.c: static char *xoauth2_base64(const char *user UNUSED,
     +	return 0;
     +}
     +
    - static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
    + static int auth_oauthbearer(struct imap_store *ctx, const char *prompt UNUSED)
      {
      	int ret;
    +@@ imap-send.c: static char *cram(const char *challenge_64 UNUSED,
    + 	    "you have to build git-imap-send with OpenSSL library.");
    + }
    + 
    ++#define auth_plain NULL
    + #define auth_oauthbearer NULL
    + #define auth_xoauth2 NULL
    + 
     @@ imap-send.c: static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
      		if (srvc->auth_method) {
      			struct imap_cmd_cb cb;
    @@ imap-send.c: static struct imap_store *imap_open_store(struct imap_server_conf *
     +						"but %s doesn't support it.\n", srvc->host);
     +					goto bail;
     +				}
    ++
    ++				#ifdef NO_OPENSSL
    ++				fprintf(stderr, "You are trying to use PLAIN authentication mechanism "
    ++					"with OpenSSL library, but its support has not been compiled in.");
    ++				goto bail;
    ++				#endif
    ++
     +				/* PLAIN */
     +
     +				memset(&cb, 0, sizeof(cb));
 3:  45f5b3f1ff =  4:  3d1a66da57 imap-send: fix memory leak in case auth_cram_md5 fails
 -:  ---------- >  5:  70bb9388b8 imap-send: gracefully fail if CRAM-MD5 authentication is requested without OpenSSL
 4:  8899f686d7 !  6:  0d00a5e135 imap-send: enable specifying the folder using the command line
    @@ Documentation/config/imap.adoc
      	The folder to drop the mails into, which is typically the Drafts
     -	folder. For example: "INBOX.Drafts", "INBOX/Drafts" or
     -	"[Gmail]/Drafts". Required.
    -+	folder. For example: 'INBOX.Drafts', 'INBOX/Drafts' or
    -+	'[Gmail]/Drafts'. Required if `--folder` argument is not used. If
    -+	set and `--folder` is also used, `--folder` will be preferred.
    ++	folder. For example: `INBOX.Drafts`, `INBOX/Drafts` or
    ++	`[Gmail]/Drafts`. The IMAP folder to interact with MUST be specified;
    ++	the value of this configuration variable is used as the fallback
    ++	default value when the `--folder` option is not given.
      
      imap.tunnel::
      	Command used to set up a tunnel to the IMAP server through which
    @@ Documentation/git-imap-send.adoc: git-imap-send - Send a collection of patches f
      other email is when using mail clients that cannot read mailbox
      files directly. The command also works with any general mailbox
     -in which emails have the fields "From", "Date", and "Subject" in
    -+in which emails have the fields 'From', 'Date', and 'Subject' in
    ++in which emails have the fields `From`, `Date`, and `Subject` in
      that order.
      
      Typical usage is something like:
 5:  c2dfd0178c =  7:  999c65438f imap-send: fix minor mistakes in the logs
 6:  4e1b51acd5 =  8:  d0315aebd4 imap-send: display port alongwith host when git credential is invoked
 7:  85c40d8491 =  9:  73352a18cf imap-send: display the destination mailbox when sending a message
 8:  5e24c6cde8 ! 10:  36d50d01f0 imap-send: add ability to list the available folders
    @@ Documentation/git-imap-send.adoc: OPTIONS
      
      CONFIGURATION
      -------------
    -@@ Documentation/git-imap-send.adoc: Alternatively, use OAuth2.0 authentication as described below.
    +@@ Documentation/git-imap-send.adoc: it. Alternatively, use OAuth2.0 authentication as described below.
      
      [NOTE]
      You might need to instead use: `folder = "[Google Mail]/Drafts"` if you get an error
-- 
2.49.0.639.g36d50d01f0





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux