[Commits] [SCM] claws branch, master, updated. 4.1.1-43-g48086e4e8

paul at claws-mail.org paul at claws-mail.org
Tue Feb 21 16:44:42 UTC 2023


The branch, master has been updated
       via  48086e4e82e033b2403af63b9ffb9ca2dd7b696f (commit)
       via  c61593c30a4b7c2f5a170bde54c27af2d09a0868 (commit)
      from  9e1cb8b14041fb17e06a9709b82e60b849f9381b (commit)

Summary of changes:
 AUTHORS           |  1 +
 src/gtk/authors.h |  1 +
 src/oauth2.c      | 70 ++++++++++++++++++++++++++++---------------------------
 3 files changed, 38 insertions(+), 34 deletions(-)


- Log -----------------------------------------------------------------
commit 48086e4e82e033b2403af63b9ffb9ca2dd7b696f
Author: Paul <paul at claws-mail.org>
Date:   Tue Feb 21 16:44:38 2023 +0000

    fix bug 4664, 'OAUTH2 overwrites passwords even for plaintext logins'
    
    based on patch by Roland Haas

diff --git a/AUTHORS b/AUTHORS
index 2eb6b0d77..b822e4772 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -344,3 +344,4 @@ contributors (in addition to the above; based on Changelog)
 	Frank Mueller
 	JP Guillonneau
 	Viatrix
+	Roland Haas
diff --git a/src/gtk/authors.h b/src/gtk/authors.h
index c1c3044bf..609a0cd7c 100644
--- a/src/gtk/authors.h
+++ b/src/gtk/authors.h
@@ -164,6 +164,7 @@ static char *CONTRIBS_LIST[] = {
 "Mitko Haralanov",
 "Alexander Lyons Harkness",
 "Hashimoto",
+"Roland Haas",
 "Jacob Head",
 "Federico Heinz",
 "Geir Helland",
diff --git a/src/oauth2.c b/src/oauth2.c
index e80bf88cd..f9bd47802 100644
--- a/src/oauth2.c
+++ b/src/oauth2.c
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <errno.h>
 
+#include "imap.h"
 #include "oauth2.h"
 #include "md5.h"
 #include "utils.h"
@@ -653,7 +654,9 @@ gint oauth2_check_passwds (PrefsAccount *ac_prefs)
 	if (ret)
 		log_message(LOG_PROTOCOL, _("OAuth2 access token not obtained\n"));
 	else {
-		passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_RECV, OAUTH2Data->access_token, FALSE);
+		if (ac_prefs->imap_auth_type == IMAP_AUTH_OAUTH2 ||
+		    (ac_prefs->use_pop_auth && ac_prefs->pop_auth_type == POPAUTH_OAUTH2))
+			passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_RECV, OAUTH2Data->access_token, FALSE);
 		if (ac_prefs->use_smtp_auth && ac_prefs->smtp_auth_type == SMTPAUTH_OAUTH2)
 			passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_SEND, OAUTH2Data->access_token, FALSE);
 		passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY, OAUTH2Data->expiry_str, FALSE);

commit c61593c30a4b7c2f5a170bde54c27af2d09a0868
Author: Paul <paul at claws-mail.org>
Date:   Tue Feb 21 16:41:18 2023 +0000

    code style

diff --git a/src/oauth2.c b/src/oauth2.c
index c3065d82c..e80bf88cd 100644
--- a/src/oauth2.c
+++ b/src/oauth2.c
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
- * Copyright (C) 2021-2022 the Claws Mail team
+ * Copyright (C) 2021-2023 the Claws Mail team
  *
  * 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
@@ -626,45 +626,44 @@ gint oauth2_check_passwds (PrefsAccount *ac_prefs)
 	OAUTH2Data->custom_client_id = ac_prefs->oauth2_client_id;
 	OAUTH2Data->custom_client_secret = ac_prefs->oauth2_client_secret;
 	
-	if(passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_EXPIRY)) {
-	  acc = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY);
-	  expiry = atoi(acc);
-	  g_free(acc);
-	  if (expiry >  (g_get_real_time () / G_USEC_PER_SEC)){
-	    g_free(OAUTH2Data);
-	    log_message(LOG_PROTOCOL, _("OAuth2 access token still fresh\n"));
-	    g_free(uid);
-	    return (0);
-	  }
+	if (passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_EXPIRY)) {
+		acc = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY);
+		expiry = atoi(acc);
+		g_free(acc);
+		if (expiry >  (g_get_real_time () / G_USEC_PER_SEC)) {
+			g_free(OAUTH2Data);
+			log_message(LOG_PROTOCOL, _("OAuth2 access token still fresh\n"));
+			g_free(uid);
+			return (0);
+		}
 	}
 	
-	if(passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_REFRESH)) {
-	  log_message(LOG_PROTOCOL, _("OAuth2 obtaining access token using refresh token\n"));
-	  OAUTH2Data->refresh_token = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_REFRESH);
-	  ret = oauth2_use_refresh_token (ac_prefs->oauth2_provider, OAUTH2Data);
-	}else if (passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_AUTH)) {
-	  log_message(LOG_PROTOCOL, _("OAuth2 trying for fresh access token with authorization code\n"));
-	  acc = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_AUTH);
-	  ret = oauth2_obtain_tokens (ac_prefs->oauth2_provider, OAUTH2Data, acc);
-	  g_free(acc);
-	}else{
-	  ret = 1;
-	}
+	if (passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_REFRESH)) {
+		log_message(LOG_PROTOCOL, _("OAuth2 obtaining access token using refresh token\n"));
+		OAUTH2Data->refresh_token = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_REFRESH);
+		ret = oauth2_use_refresh_token (ac_prefs->oauth2_provider, OAUTH2Data);
+	} else if (passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_AUTH)) {
+		log_message(LOG_PROTOCOL, _("OAuth2 trying for fresh access token with authorization code\n"));
+		acc = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_AUTH);
+		ret = oauth2_obtain_tokens (ac_prefs->oauth2_provider, OAUTH2Data, acc);
+		g_free(acc);
+	} else
+		ret = 1;
 	
-	if (ret){
-	  log_message(LOG_PROTOCOL, _("OAuth2 access token not obtained\n"));
-	}else{
-	  passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_RECV, OAUTH2Data->access_token, FALSE);
-      if (ac_prefs->use_smtp_auth && ac_prefs->smtp_auth_type == SMTPAUTH_OAUTH2)
-	        passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_SEND, OAUTH2Data->access_token, FALSE);
-	  passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY, OAUTH2Data->expiry_str, FALSE);
-	  //Some providers issue replacement refresh tokens with each access token. Re-store whether replaced or not. 
-	  passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_REFRESH, OAUTH2Data->refresh_token, FALSE);
-	  log_message(LOG_PROTOCOL, _("OAuth2 access and refresh token updated\n"));  
+	if (ret)
+		log_message(LOG_PROTOCOL, _("OAuth2 access token not obtained\n"));
+	else {
+		passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_RECV, OAUTH2Data->access_token, FALSE);
+		if (ac_prefs->use_smtp_auth && ac_prefs->smtp_auth_type == SMTPAUTH_OAUTH2)
+			passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_SEND, OAUTH2Data->access_token, FALSE);
+		passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY, OAUTH2Data->expiry_str, FALSE);
+		//Some providers issue replacement refresh tokens with each access token. Re-store whether replaced or not. 
+		passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_REFRESH, OAUTH2Data->refresh_token, FALSE);
+		log_message(LOG_PROTOCOL, _("OAuth2 access and refresh token updated\n"));  
 	}
 
 	g_free(OAUTH2Data);
-    g_free(uid);
+	g_free(uid);
 	
 	return (ret);
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list