Re: [PATCH] IMAP: ensure_password: increase password buffer size

2019-10-03 Thread Oswald Buddenhagen
a corresponding patch is already in the 1.3 branch for quite a while.  
forward-merge to master is now also done.



___
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel


[commit] master: Merge branch '1.3'

2019-10-03 Thread Oswald Buddenhagen via isync-devel
Skipped 15 existing revision(s) on branch 'master'.

commit 462fed556a4ccb57c1259570583d846d343cc628
Merge: a310e7e d0a8551
Author: Oswald Buddenhagen 
Date:   Thu Oct 3 20:17:54 2019 +0200

Merge branch '1.3'

 configure.ac |   6 +--
 src/common.h |   1 +
 src/drv_imap.c   |  28 +++
 src/drv_proxy_gen.pl |   1 +
 src/mbsync.1 |  15 +++---
 src/socket.c | 111 ---
 6 files changed, 114 insertions(+), 48 deletions(-)


= Full diff against 1st parent =

diff --git a/configure.ac b/configure.ac
index 880f17c..a4c002d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,14 +18,14 @@ fi
 
 need_perl=5.14
 AC_CACHE_CHECK([whether perl is recent enough], ob_cv_perl_ver, [
-if $PERL -e "use v$need_perl;"; then
+if $PERL -e "use v$need_perl;" 2> /dev/null; then
 ob_cv_perl_ver=yes
 else
 ob_cv_perl_ver=no
 fi
 ])
 if test "x$ob_cv_perl_ver" = "xno"; then
-AC_MSG_ERROR([perl is too old])
+AC_MSG_ERROR([perl is too old, need v$need_perl])
 fi
 
 AC_CACHE_CHECK([whether strftime supports %z], ob_cv_strftime_z,
@@ -94,7 +94,7 @@ if test "x$ob_cv_with_ssl" != xno; then
 sav_LDFLAGS=$LDFLAGS
 LDFLAGS="$LDFLAGS $SSL_LDFLAGS"
 AC_CHECK_LIB(dl, dlopen, [LIBDL=-ldl])
-AC_CHECK_LIB(crypto, CRYPTO_lock, [LIBCRYPTO=-lcrypto])
+AC_CHECK_LIB(crypto, X509_cmp, [LIBCRYPTO=-lcrypto])
 AC_CHECK_LIB(ssl, SSL_connect,
  [SSL_LIBS="-lssl $LIBCRYPTO $LIBDL" have_ssl_paths=yes])
 LDFLAGS=$sav_LDFLAGS
diff --git a/src/common.h b/src/common.h
index c731126..d45929c 100644
--- a/src/common.h
+++ b/src/common.h
@@ -33,6 +33,7 @@
 typedef unsigned char uchar;
 typedef unsigned short ushort;
 typedef unsigned int uint;
+typedef unsigned long ulong;
 
 #define as(ar) (sizeof(ar)/sizeof(ar[0]))
 
diff --git a/src/drv_imap.c b/src/drv_imap.c
index 58fc9d3..7bc88f6 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -953,7 +953,7 @@ parse_date( const char *str )
struct tm datetime;
 
memset( &datetime, 0, sizeof(datetime) );
-   if (!(end = strptime( str, "%d-%b-%Y %H:%M:%S ", &datetime )))
+   if (!(end = strptime( str, "%e-%b-%Y %H:%M:%S ", &datetime )))
return -1;
if ((date = timegm( &datetime )) == -1)
return -1;
@@ -1203,17 +1203,16 @@ parse_response_code( imap_store_t *ctx, imap_cmd_t 
*cmd, char *s )
return RESP_OK;
 }
 
+static int parse_list_rsp_p1( imap_store_t *, list_t *, char * );
 static int parse_list_rsp_p2( imap_store_t *, list_t *, char * );
 
 static int
 parse_list_rsp( imap_store_t *ctx, list_t *list, char *cmd )
 {
-   char *arg;
list_t *lp;
 
if (!is_list( list )) {
free_list( list );
- bad_list:
error( "IMAP error: malformed LIST response\n" );
return LIST_BAD;
}
@@ -1223,10 +1222,19 @@ parse_list_rsp( imap_store_t *ctx, list_t *list, char 
*cmd )
return LIST_OK;
}
free_list( list );
-   if (!(arg = next_arg( &cmd )))
-   goto bad_list;
-   if (!ctx->delimiter[0])
-   ctx->delimiter[0] = arg[0];
+   return parse_list( ctx, cmd, parse_list_rsp_p1 );
+}
+
+static int
+parse_list_rsp_p1( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED )
+{
+   if (!is_opt_atom( list )) {
+   error( "IMAP error: malformed LIST response\n" );
+   free_list( list );
+   return LIST_BAD;
+   }
+   if (!ctx->delimiter[0] && is_atom( list ))
+   ctx->delimiter[0] = list->val[0];
return parse_list( ctx, cmd, parse_list_rsp_p2 );
 }
 
@@ -1873,7 +1881,7 @@ ensure_password( imap_server_conf_t *srvc )
if (cmd) {
FILE *fp;
int ret;
-   char buffer[80];
+   char buffer[2048];  // Hopefully more than enough room for 
XOAUTH2, etc. tokens
 
if (*cmd == '+') {
flushn();
@@ -2079,7 +2087,7 @@ done_sasl_auth( imap_store_t *ctx, imap_cmd_t *cmd 
ATTR_UNUSED, int response )
int rc = sasl_client_step( ctx->sasl, NULL, 0, &interact, &out, 
&out_len );
if (process_sasl_step( ctx, rc, NULL, 0, interact, &out, 
&out_len ) < 0)
warn( "Warning: SASL reported failure despite 
successful IMAP authentication. Ignoring...\n" );
-   else if (out)
+   else if (out_len > 0)
warn( "Warning: SASL wants more steps despite 
successful IMAP authentication. Ignoring...\n" );
}
 
@@ -2180,7 +2188,7 @@ imap_open_store_authenticate2( imap_store_t *ctx )
free( enc );
return;
  notsasl:
-   if (!ctx->sasl || sasl_listmech( ctx->sasl, NULL, "", "", "", 
&saslavail, NULL, NULL ) != SASL_OK)
+   if (!ctx->sasl || sasl_listmech( ctx-

[PATCH] IMAP: ensure_password: increase password buffer size

2019-10-03 Thread Matthias Maennich via isync-devel
When using PassCmd in combination with XOAUTH2, the token generated
might exceed 80 characters and hence would not fit in the buffer
anymore. That leads to a truncated password and an authentication error
later on:
  !Error: IMAP wants more steps despite successful SASL authentication.

Increase the size of the buffer to accomodate larger authentication
tokens.

Signed-off-by: Matthias Maennich 
---
 src/drv_imap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/drv_imap.c b/src/drv_imap.c
index 58fc9d3e4e87..4b780f60413a 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -1873,7 +1873,7 @@ ensure_password( imap_server_conf_t *srvc )
if (cmd) {
FILE *fp;
int ret;
-   char buffer[80];
+   char buffer[256];
 
if (*cmd == '+') {
flushn();
-- 
2.23.0.581.g78d2f28ef7-goog



___
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel