git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v13 02/10] imap-send: add support for OAuth2.0 authentication
@ 2025-06-06  6:59 Aditya Garg
  2025-06-06  7:16 ` Aditya Garg
  2025-06-06 16:38 ` Junio C Hamano
  0 siblings, 2 replies; 15+ messages in thread
From: Aditya Garg @ 2025-06-06  6:59 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git@vger.kernel.org, Eric Sunshine, Zi Yao, brian m carlson,
	Jeff King, Ben Knoble, Phillip Wood




> On 6 Jun 2025, at 12:18 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Aditya Garg <gargaditya08@live.com> writes:
> 
>> Might look less ugly, but will result in a compiler warning that this will always
>> be true if compiled with NO_OPENSSL. If you are fine with that, good. Else tbh
>> I am out of ideas :(.
> 
> Sounds like a good place to use NOT_CONSTANT(), it seems?

Ok so I was wrong here. The warning actually comes when we compile
WITHOUT NO_OPENSSL, since auth_oauthbearer is a function there, and
will attract waddress warnings,

And NOT_CONSTANT doesn't help here.
> 
>    if (NOT_CONSTANT(!auth_oauthbearer)) {
>        ... skip the thing ...
>    }
> 
> 
>>>>    server_fill_credential(srvc, cred);
>>>>    curl_easy_setopt(curl, CURLOPT_USERNAME, srvc->user);
>>>> -    curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
>>>> +
>>>> +    if (!srvc->auth_method ||
>>>> +        (strcmp(srvc->auth_method, "XOAUTH2") &&
>>>> +        strcmp(srvc->auth_method, "OAUTHBEARER")))
>>>> +        curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
>>> Can we clarify this part, possibly with an in-code comment?
>>> "Unless XOAUTH2 or OAUTHBEARER, use the password" sounds a bit
>>> strange.  What about methods other than these two that are not a
>>> plain simple password authentication?  Will we remember extending
>>> this code when we add yet another one to exclude it like XOAUTH2 and
>>> OAUTHBEARER are excluded with this patch?
> 
>> Let me answer this first. CURLOPT_PASSWORD is for plain or login type
>> authentication, and if srvc->auth_method is not defined, curl's behaviour
>> defaults to them.
> 
> Which makes it sound like if (!srvc->auth_method) is enough?
> 
>> OAUTHBEARER and XOAUTH2 use CURLOPT_XOAUTH2_BEARER
>> in curl, which can use either of them based on what server says.
> 
> That is what we can read from the updated code.
> 
> The question is what happens when the user sets srvc->auth_method to
> something other than NULL (unused---use plain password), "XOAUTH2"
> or "OAUTHBEARER".
> 
> If the answer to that question is ...
> 
>> Other auth methods
>> are not supported yet in this code, and this is the reason CRAM_MD5 is supported
>> by only OpenSSL.
> 
> ... "with srvc->auth_method set to other methods like CRAM_MD5, the
> control would never enter this codepath, as they are implemented
> elsewhere", then I think it would make more sense to write the above
> like this:
> 
>    if (!srvc->auth_method)
>        curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
>    else if (strcmp(srvc->auth_method, "XOAUTH2") &&
>         strcmp(srvc->auth_method, "OAUTHBEARER"))
>        BUG("we only support XOAUTH2 and OAUTHBEARER in this codepath");
> 
> Or the code is not protecting this code path so control can reach
> with auth_method set to CRAM_MD5 here (e.g. when built without
> OpenSSL)?  If so, replace BUG("message") with die(_("message"))
> above.
> 
> On the other hand, if you are trying to fall back to plain password
> when other unhandled methods are specified, I would expect that the
> code to read more like:
> 
>    if (srvc->auth_method &&
>            (!strcmp(srvc->auth_method, "XOAUTH2") ||
>             !strcmp(srvc->auth_method, "OAUTHBEARER")))
>        ;
>    else {
>        if (srvc->auth_method)
>            warning("auth method %s not supported,
>                     falling back to plain password",
>                                srvc->auth_method);
>        curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
>    }
> 
> I cannot quite tell which one you meant, but I am guessing that the
> former is the case from your explanation.
> 
> Thanks.

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH v13 00/10] imap-send: make it usable again and add OAuth2.0 support
@ 2025-06-05  8:42 Aditya Garg
  2025-06-05  8:42 ` [PATCH v13 02/10] imap-send: add support for OAuth2.0 authentication Aditya Garg
  0 siblings, 1 reply; 15+ messages in thread
From: Aditya Garg @ 2025-06-05  8:42 UTC (permalink / raw)
  To: Junio C Hamano, git@vger.kernel.org
  Cc: Eric Sunshine, Zi Yao, brian m . carlson, Jeff King, Ben Knoble,
	Phillip Wood

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.
v13: - Fix logic error which was using || instead of && when checking if
       the authentication method is neither XOAUTH2 nor OAUTHBEARER.

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 v12:
 -:  ---------- >  1:  3e3ddf7077 imap-send: fix bug causing cfg->folder being set to NULL
 1:  ab12f713d2 !  2:  0d28e337cf imap-send: add support for OAuth2.0 authentication
    @@ imap-send.c: static CURL *setup_curl(struct imap_server_conf *srvc, struct crede
     -	curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
     +
     +	if (!srvc->auth_method ||
    -+	    strcmp(srvc->auth_method, "XOAUTH2") ||
    -+	    strcmp(srvc->auth_method, "OAUTHBEARER"))
    ++	    (strcmp(srvc->auth_method, "XOAUTH2") &&
    ++	    strcmp(srvc->auth_method, "OAUTHBEARER")))
     +		curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
      
      	strbuf_addstr(&path, srvc->use_ssl ? "imaps://" : "imap://");
 2:  ba9c3fb756 =  3:  d934bdcb82 imap-send: add PLAIN authentication method to OpenSSL
 3:  3d1a66da57 =  4:  f2773c646f imap-send: fix memory leak in case auth_cram_md5 fails
 4:  70bb9388b8 =  5:  c111ee6bc1 imap-send: gracefully fail if CRAM-MD5 authentication is requested without OpenSSL
 5:  0d00a5e135 =  6:  f12713f24b imap-send: enable specifying the folder using the command line
 6:  999c65438f =  7:  d38caeae5e imap-send: fix minor mistakes in the logs
 7:  d0315aebd4 =  8:  3ba02f2b0c imap-send: display port alongwith host when git credential is invoked
 8:  73352a18cf =  9:  6dbd0bf0bc imap-send: display the destination mailbox when sending a message
 9:  36d50d01f0 = 10:  f77f2423e1 imap-send: add ability to list the available folders
-- 
2.49.0.639.gf77f2423e1


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-06-06 20:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06  6:59 [PATCH v13 02/10] imap-send: add support for OAuth2.0 authentication Aditya Garg
2025-06-06  7:16 ` Aditya Garg
2025-06-06 16:38 ` Junio C Hamano
2025-06-06 16:50   ` Aditya Garg
2025-06-06 17:03     ` Junio C Hamano
2025-06-06 17:12       ` Aditya Garg
2025-06-06 20:08   ` Aditya Garg
  -- strict thread matches above, loose matches on Subject: below --
2025-06-05  8:42 [PATCH v13 00/10] imap-send: make it usable again and add OAuth2.0 support Aditya Garg
2025-06-05  8:42 ` [PATCH v13 02/10] imap-send: add support for OAuth2.0 authentication Aditya Garg
2025-06-05 16:33   ` Junio C Hamano
2025-06-05 17:16     ` Aditya Garg
2025-06-05 18:48       ` Junio C Hamano
2025-06-06  3:28         ` Aditya Garg
2025-06-06  4:04           ` Aditya Garg
2025-06-06  4:35           ` Junio C Hamano
2025-06-06  4:40             ` Aditya Garg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).