[Commits] [SCM] claws branch, gtk2, updated. 3.20.0-30-gf3aad9310

miras at claws-mail.org miras at claws-mail.org
Mon Jan 8 23:24:46 UTC 2024


The branch, gtk2 has been updated
       via  f3aad9310c8c293d5ad2e929bc4c00817da0eb64 (commit)
       via  0c5565c5f41deb7fffb86ec68b934fe7d24c7bbd (commit)
       via  3a83a37f24ac915927686fbadcd28b47f9991463 (commit)
      from  4306848d87fdb43af024a17e3f25cfd5135833c7 (commit)

Summary of changes:
 src/oauth2.c | 97 +++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 50 insertions(+), 47 deletions(-)


- Log -----------------------------------------------------------------
commit f3aad9310c8c293d5ad2e929bc4c00817da0eb64
Author: Michael Rasmussen <mir at datanom.net>
Date:   Tue Jan 9 00:22:00 2024 +0100

    Revert "Fix bug #4730. Patch by Olaf Hering"
    
    This reverts commit 4306848d87fdb43af024a17e3f25cfd5135833c7.

diff --git a/src/oauth2.c b/src/oauth2.c
index c26415cc9..43da8b9d5 100644
--- a/src/oauth2.c
+++ b/src/oauth2.c
@@ -129,6 +129,7 @@ static gchar *OAUTH2CodeMarker[5][2] = {
 static gint oauth2_post_request (gchar *buf, gchar *host, gchar *resource, gchar *header, gchar *body);
 static gint oauth2_filter_refresh (gchar *json, gchar *refresh_token);
 static gint oauth2_filter_access (gchar *json, gchar *access_token, gint *expiry);
+static gint oauth2_contact_server (SockInfo *sock, gchar *request, gchar *response);
 
 
 static gint oauth2_post_request (gchar *buf, gchar *host, gchar *resource, gchar *header, gchar *body)
@@ -213,47 +214,6 @@ static gchar* oauth2_get_token_from_response(Oauth2Service provider, const gchar
 	return token;
 }
 
-static gchar *oauth2_contact_server(SockInfo *sock, const gchar *request)
-{
-	gboolean got_some_data, timeout;
-	gint ret;
-	char buf[1024];
-	GString *response = g_string_sized_new(sizeof(buf));
-	time_t end_time = time(NULL);
-
-	end_time += prefs_common_get_prefs()->io_timeout_secs;
-
-	if (!response)
-		return NULL;
-
-	if (sock_write(sock, request, strlen(request)) < 0) {
-		log_message(LOG_PROTOCOL, _("OAuth2 socket write error\n"));
-		return NULL;
-	}
-
-	do {
-		ret = sock_read(sock, buf, sizeof(buf) - 1);
-		got_some_data = ret > 0;
-		timeout = time(NULL) > end_time;
-
-		if (timeout)
-			break;
-
-		if (ret < 0 && errno == EAGAIN)
-			continue;
-
-		if (!got_some_data)
-			break;
-
-		buf[ret] = '\0';
-		g_string_append_len(response, buf, ret);
-	} while (ret);
-
-	if (timeout)
-		log_message(LOG_PROTOCOL, _("OAuth2 socket timeout error\n"));
-
-	return g_string_free(response, !got_some_data || timeout);
-}
 int oauth2_obtain_tokens (Oauth2Service provider, OAUTH2Data *OAUTH2Data, const gchar *authcode)
 {
 	gchar *request;
@@ -306,6 +266,7 @@ int oauth2_obtain_tokens (Oauth2Service provider, OAUTH2Data *OAUTH2Data, const
 	refresh_token = g_malloc(OAUTH2BUFSIZE+1);	
 	access_token = g_malloc(OAUTH2BUFSIZE+1);
 	request = g_malloc(OAUTH2BUFSIZE+1);
+	response = g_malloc0(OAUTH2BUFSIZE+1);
 
 	if(OAUTH2Data->custom_client_id)
 	  client_id = g_strdup(OAUTH2Data->custom_client_id);
@@ -369,9 +330,9 @@ int oauth2_obtain_tokens (Oauth2Service provider, OAUTH2Data *OAUTH2Data, const
 
         debug_print("Complete body: %s\n", body);
 	oauth2_post_request (request, OAUTH2info[i][OA2_BASE_URL], OAUTH2info[i][OA2_ACCESS_RESOURCE], header, body);
-	response = oauth2_contact_server (sock, request);
+	ret = oauth2_contact_server (sock, request, response);
 
-	if(response && oauth2_filter_access (response, access_token, &expiry) == 0){
+	if(oauth2_filter_access (response, access_token, &expiry) == 0){
 	  OAUTH2Data->access_token = g_strdup(access_token);
 	  OAUTH2Data->expiry = expiry;
 	  OAUTH2Data->expiry_str = g_strdup_printf ("%i", expiry);
@@ -383,7 +344,7 @@ int oauth2_obtain_tokens (Oauth2Service provider, OAUTH2Data *OAUTH2Data, const
 	  ret = 1;
 	}
 
-	if(response && oauth2_filter_refresh (response, refresh_token) == 0){
+	if(oauth2_filter_refresh (response, refresh_token) == 0){
 	  OAUTH2Data->refresh_token = g_strdup(refresh_token);
 	  log_message(LOG_PROTOCOL, _("OAuth2 refresh token obtained\n"));
 	}else{
@@ -446,6 +407,7 @@ gint oauth2_use_refresh_token (Oauth2Service provider, OAUTH2Data *OAUTH2Data)
 	access_token = g_malloc(OAUTH2BUFSIZE+1);
 	refresh_token = g_malloc(OAUTH2BUFSIZE+1);
 	request = g_malloc(OAUTH2BUFSIZE+1);
+	response = g_malloc(OAUTH2BUFSIZE+1);
 
 	if(OAUTH2Data->custom_client_id)
 	  client_id = g_strdup(OAUTH2Data->custom_client_id);
@@ -504,9 +466,9 @@ gint oauth2_use_refresh_token (Oauth2Service provider, OAUTH2Data *OAUTH2Data)
 	}
 
 	oauth2_post_request (request, OAUTH2info[i][OA2_BASE_URL], OAUTH2info[i][OA2_REFRESH_RESOURCE], header, body);
-	response = oauth2_contact_server (sock, request);
+	ret = oauth2_contact_server (sock, request, response);
 
-	if(response && oauth2_filter_access (response, access_token, &expiry) == 0){
+	if(oauth2_filter_access (response, access_token, &expiry) == 0){
 	  OAUTH2Data->access_token = g_strdup(access_token);
 	  OAUTH2Data->expiry = expiry;
 	  OAUTH2Data->expiry_str = g_strdup_printf ("%i", expiry);
@@ -518,7 +480,7 @@ gint oauth2_use_refresh_token (Oauth2Service provider, OAUTH2Data *OAUTH2Data)
 	  ret = 1;
 	}
 
-	if (response && oauth2_filter_refresh (response, refresh_token) == 0) {
+	if (oauth2_filter_refresh (response, refresh_token) == 0) {
 		OAUTH2Data->refresh_token = g_strdup(refresh_token);
 		log_message(LOG_PROTOCOL, _("OAuth2 replacement refresh token provided\n"));
 	} else
@@ -540,6 +502,47 @@ gint oauth2_use_refresh_token (Oauth2Service provider, OAUTH2Data *OAUTH2Data)
 	return (ret);
 }
 
+static gint oauth2_contact_server (SockInfo *sock, gchar *request, gchar *response)
+{
+	gint ret;
+	gchar *token;
+	gint toread = OAUTH2BUFSIZE;	
+	time_t startplus = time(NULL);
+	gchar *tmp;
+	
+	gint timeout_secs = prefs_common_get_prefs()->io_timeout_secs;
+	startplus += timeout_secs;
+	
+	if (sock_write (sock, request, strlen(request)) < 0) {
+	  log_message(LOG_PROTOCOL, _("OAuth2 socket write error\n"));
+	  return (1);
+	}
+	
+	token = g_strconcat ("", NULL);
+	do {
+	  
+	  ret = sock_read  (sock, response, OAUTH2BUFSIZE);
+	  if (ret < 0 && errno == EAGAIN)
+	    continue;
+	  if (ret < 0) 
+	    break;
+	  if (ret == 0)
+	    break;
+	  
+	  toread -= ret;
+	  tmp = g_strconcat(token, response, NULL);
+	  g_free(token);
+	  token = tmp;
+	} while ((toread > 0) && (time(NULL) < startplus)); 
+	
+	if(time(NULL) >= startplus)
+	  log_message(LOG_PROTOCOL, _("OAuth2 socket timeout error\n"));
+	
+	g_free(token);
+	
+	return (0);
+}
+
 gint oauth2_authorisation_url (Oauth2Service provider, gchar **url, const gchar *custom_client_id)
 {
 	gint i;

commit 0c5565c5f41deb7fffb86ec68b934fe7d24c7bbd
Author: Michael Rasmussen <mir at datanom.net>
Date:   Tue Jan 9 00:20:27 2024 +0100

    Reapply "Fix Bug #4728. Patch provided by Olaf Hering"
    
    This reverts commit 3a83a37f24ac915927686fbadcd28b47f9991463.

diff --git a/src/common/socket.c b/src/common/socket.c
index 6e8bb745b..e9d50184b 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1256,6 +1256,7 @@ static gint ssl_read(gnutls_session_t ssl, gchar *buf, gint len)
 	}
 
 	while (1) {
+		errno = 0;
 		r = gnutls_record_recv(ssl, buf, len);
 		if (r > 0)
 			return r;
@@ -1273,7 +1274,10 @@ static gint ssl_read(gnutls_session_t ssl, gchar *buf, gint len)
 		case GNUTLS_E_INTERRUPTED:
 			errno = EAGAIN;
 			return -1;
-
+		case GNUTLS_E_PREMATURE_TERMINATION:
+			if (errno == 0)
+				return 0;
+			/* fall through */
 		default:
 			debug_print("Unexpected TLS read result %d\n", r);
 			errno = EIO;

commit 3a83a37f24ac915927686fbadcd28b47f9991463
Author: Michael Rasmussen <mir at datanom.net>
Date:   Tue Jan 9 00:18:07 2024 +0100

    Revert "Fix Bug #4728. Patch provided by Olaf Hering"
    
    This reverts commit 56df50d25385eea8eb1af1a167c17a32e0575156.

diff --git a/src/common/socket.c b/src/common/socket.c
index e9d50184b..6e8bb745b 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1256,7 +1256,6 @@ static gint ssl_read(gnutls_session_t ssl, gchar *buf, gint len)
 	}
 
 	while (1) {
-		errno = 0;
 		r = gnutls_record_recv(ssl, buf, len);
 		if (r > 0)
 			return r;
@@ -1274,10 +1273,7 @@ static gint ssl_read(gnutls_session_t ssl, gchar *buf, gint len)
 		case GNUTLS_E_INTERRUPTED:
 			errno = EAGAIN;
 			return -1;
-		case GNUTLS_E_PREMATURE_TERMINATION:
-			if (errno == 0)
-				return 0;
-			/* fall through */
+
 		default:
 			debug_print("Unexpected TLS read result %d\n", r);
 			errno = EIO;

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


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list