Re: [Patch] IMAP Code Simplifications



Hi Peter:

Am 11.04.17 19:01 schrieb(en) Peter Bloomfield:
But it fails to build --with-gss.

Ooooops - I forgot to enable this option, and to grep through the sources...  Thanks a lot for testing, and 
for pointing me to it!

The attached patch should fix the issue.  It is somewhat inelegant as the newly allocated GLib results are 
copied to the fixed buffers, but I didn't want to refactor the whole code.  Unfortunately, I have no chance 
at all to test it, but as the changes are limited, they look logical to me.

Anyone out there using an imap server w/ gssapi authentication, who could verify the changes?

Cheers,
Albrecht.
diff --git a/libbalsa/imap/auth-gssapi.c b/libbalsa/imap/auth-gssapi.c
index 5a19707..7da29b3 100644
--- a/libbalsa/imap/auth-gssapi.c
+++ b/libbalsa/imap/auth-gssapi.c
@@ -218,6 +218,7 @@ ag_get_token(gss_ctx_id_t *context, gss_name_t target, gss_buffer_t sec_token,
     OM_uint32 state, min_stat;
     gss_buffer_desc send_token;
     unsigned cflags;
+    gchar *b64buf;
     
     *client_token = '\0';
     state = gss_init_sec_context
@@ -229,8 +230,9 @@ ag_get_token(gss_ctx_id_t *context, gss_name_t target, gss_buffer_t sec_token,
     if (state != GSS_S_COMPLETE && state != GSS_S_CONTINUE_NEEDED)
         return state;
 
-    lit_conv_to_base64(client_token, send_token.value, send_token.length,
-                       token_sz);
+    b64buf = g_base64_encode(send_token.value, send_token.length);
+    strncpy(client_token, b64buf, (size_t) token_sz);
+    g_free(b64buf);
     gss_release_buffer(&min_stat, &send_token);
     return state;
 }
@@ -240,8 +242,12 @@ ag_parse_request(ImapMboxHandle *handle, char *buf, ssize_t buf_sz,
                  gss_buffer_desc *request)
 {
     char line[LONG_STRING];
+    guchar *rawbuf;
+
     sio_gets(handle->sio, line, LONG_STRING); /* FIXME: error checking */
-    request->length = lit_conv_from_base64(buf, line);
+    rawbuf = g_base64_decode(line, &request->length);
+    memcpy(buf, rawbuf, request->length);
+    g_free(rawbuf);
     request->value = buf;
 }
 
@@ -261,6 +267,7 @@ ag_negotiate_parameters(ImapMboxHandle *handle, const char * user,
     char server_conf_flags;
     unsigned char *t;
     unsigned long buf_size;
+    gchar *b64buf;
 
     ag_parse_request(handle, buf, sizeof(buf), &request_buf);
     state = gss_unwrap(&min_stat, context, &request_buf, &send_token,
@@ -307,9 +314,9 @@ ag_negotiate_parameters(ImapMboxHandle *handle, const char * user,
         return FALSE;
     }
     
-    lit_conv_to_base64(buf, send_token.value, send_token.length,
-                       sizeof(buf));
-    sio_printf(handle->sio, "%s\r\n", buf); imap_handle_flush(handle);
+    b64buf = g_base64_encode(send_token.value, send_token.length);
+    sio_printf(handle->sio, "%s\r\n", b64buf); imap_handle_flush(handle);
+    g_free(b64buf);
     
     WAIT_FOR_PROMPT(*rc,handle,cmdno,buf,sizeof(buf));
     if (*rc == IMR_RESPOND)

Attachment: pgprtARqaxraI.pgp
Description: PGP signature



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