From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
Here's the 5th iteration of my patches for
Windows-compatibility in imap-send.
- Patch 1-3 is about getting rid of or rewriting
code with portability issues.
- Patch 4 fixes a compilation error on Windows
- Patch 5 enables compilation of imap-send
- Patch 6-7 enables SSL-suport for mingw
- Patch 8 enables imap-send and SSL for msvc
The only change compared to the previous iteration
is that patch 7 and 8 enables NEEDS_CRYPTO_WITH_SSL.
Please note that I haven't tested Patch 8 with
NEEDS_CRYPTO_WITH_SSL under MSVC, as I don't have a
working setup with both msysgit and MSVC installed.
I'd love it if someone with such a working setup
could verify that it works, preferrably also with
BLK_SHA1 enabled.
Erik Faye-Lund (6):
imap-send: use separate read and write fds
imap-send: use run-command API for tunneling
imap-send: fix compilation-error on Windows
imap-send: build imap-send on Windows
mingw: wrap SSL_set_(w|r)fd to call _get_osfhandle
mingw: enable OpenSSL
Jeff King (1):
imap-send: remove useless uid code
Marius Storm-Olsen (1):
MSVC: Enable OpenSSL, and translate -lcrypto
Makefile | 6 +-
compat/mingw.h | 21 ++++
compat/vcbuild/scripts/clink.pl | 3 +
contrib/buildsystems/engine.pl | 3 +
imap-send.c | 226 +++++++++------------------------------
5 files changed, 79 insertions(+), 180 deletions(-)
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
From: Jeff King <redacted>
The imap-send code is based on code from isync, a program
for syncing imap mailboxes. Because of this, it has
inherited some code that makes sense for isync, but not for
imap-send.
In particular, when storing a message, it does one of:
- if the server supports it, note the server-assigned
unique identifier (UID) given to each message
- otherwise, assigned a random UID and store it in the
message header as X-TUID
Presumably this is used in isync to be able to synchronize
mailstores multiple times without duplication. But for
imap-send, the values are useless; we never do anything
with them and simply forget them at the end of the program.
This patch removes the useless code. Not only is it nice for
maintainability to get rid of dead code, but the removed
code relied on the existence of /dev/urandom, which made it
a portability problem for non-Unix platforms.
Signed-off-by: Jeff King <redacted>
Signed-off-by: Erik Faye-Lund <redacted>
---
imap-send.c | 155 ++++------------------------------------------------------
1 files changed, 11 insertions(+), 144 deletions(-)
@@ -489,52 +486,6 @@ static int nfsnprintf(char *buf, int blen, const char *fmt, ...)returnret;}-staticstruct{-unsignedchari,j,s[256];-}rs;--staticvoidarc4_init(void)-{-inti,fd;-unsignedcharj,si,dat[128];--if((fd=open("/dev/urandom",O_RDONLY))<0&&(fd=open("/dev/random",O_RDONLY))<0){-fprintf(stderr,"Fatal: no random number source available.\n");-exit(3);-}-if(read_in_full(fd,dat,128)!=128){-fprintf(stderr,"Fatal: cannot read random number source.\n");-exit(3);-}-close(fd);--for(i=0;i<256;i++)-rs.s[i]=i;-for(i=j=0;i<256;i++){-si=rs.s[i];-j+=si+dat[i&127];-rs.s[i]=rs.s[j];-rs.s[j]=si;-}-rs.i=rs.j=0;--for(i=0;i<256;i++)-arc4_getbyte();-}--staticunsignedchararc4_getbyte(void)-{-unsignedcharsi,sj;--rs.i++;-si=rs.s[rs.i];-rs.j+=si;-sj=rs.s[rs.j];-rs.s[rs.i]=sj;-rs.s[rs.j]=si;-returnrs.s[(si+sj)&0xff];-}-staticstructimap_cmd*v_issue_imap_cmd(structimap_store*ctx,structimap_cmd_cb*cb,constchar*fmt,va_listap)
@@ -1288,26 +1171,14 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)}flagstr[d]=0;-if(!uid){-box=gctx->conf->trash;-prefix=ctx->prefix;-cb.create=1;-if(ctx->trashnc)-imap->caps=imap->rcaps&~(1<<LITERALPLUS);-}else{-box=gctx->name;-prefix=!strcmp(box,"INBOX")?"":ctx->prefix;-cb.create=0;-}-cb.ctx=uid;+box=gctx->name;+prefix=!strcmp(box,"INBOX")?"":ctx->prefix;+cb.create=0;ret=imap_exec_m(ctx,&cb,"APPEND \"%s%s\" %s",prefix,box,flagstr);imap->caps=imap->rcaps;if(ret!=DRV_OK)returnret;-if(!uid)-ctx->trashnc=0;-else-gctx->count++;+gctx->count++;returnDRV_OK;}
@@ -1483,7 +1354,6 @@ int main(int argc, char **argv){structmsg_dataall_msgs,msg;structstore*ctx=NULL;-intuid=0;intofs=0;intr;inttotal,n=0;
@@ -1491,9 +1361,6 @@ int main(int argc, char **argv)git_extract_argv0_path(argv[0]);-/* init the random number generator */-arc4_init();-setup_git_directory_gently(&nongit_ok);git_config(git_imap_config,NULL);
@@ -1540,7 +1407,7 @@ int main(int argc, char **argv)break;if(server.use_html)wrap_in_html(&msg);-r=imap_store_msg(ctx,&msg,&uid);+r=imap_store_msg(ctx,&msg);if(r!=DRV_OK)break;n++;
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
Since the POSIX-specific tunneling code has been replaced
by the run-command API (and a compile-error has been
cleaned away), we can now enable imap-send on Windows
builds.
Signed-off-by: Erik Faye-Lund <redacted>
---
Makefile | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
SSL_set_fd (and friends) expects a OS file handle on Windows, not
a file descriptor as on UNIX(-ish).
This patch makes the Windows version of SSL_set_fd behave like the
UNIX versions, by calling _get_osfhandle on it's input.
Signed-off-by: Erik Faye-Lund <redacted>
---
compat/mingw.h | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
From: Marius Storm-Olsen <redacted>
We don't use crypto, but rather require libeay32 and
ssleay32. handle it in both the Makefile msvc linker
script, and the buildsystem generator.
Signed-off-by: Marius Storm-Olsen <redacted>
Signed-off-by: Erik Faye-Lund <redacted>
---
Makefile | 2 +-
compat/vcbuild/scripts/clink.pl | 3 +++
contrib/buildsystems/engine.pl | 3 +++
3 files changed, 7 insertions(+), 1 deletions(-)
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
Since we have OpenSSL in msysgit now, enable it to support SSL
encryption for imap-send.
Signed-off-by: Erik Faye-Lund <redacted>
---
Makefile | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
This is a patch that enables us to use the run-command
API, which is supported on Windows.
Signed-off-by: Erik Faye-Lund <redacted>
---
imap-send.c | 37 +++++++++++++++++++++++--------------
1 files changed, 23 insertions(+), 14 deletions(-)
@@ -301,8 +301,12 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int vessl_socket_perror("SSL_new");return-1;}-if(!SSL_set_fd(sock->ssl,sock->fd)){-ssl_socket_perror("SSL_set_fd");+if(!SSL_set_rfd(sock->ssl,sock->fd[0])){+ssl_socket_perror("SSL_set_rfd");+return-1;+}+if(!SSL_set_wfd(sock->ssl,sock->fd[1])){+ssl_socket_perror("SSL_set_wfd");return-1;}
@@ -324,11 +328,12 @@ static int socket_read(struct imap_socket *sock, char *buf, int len)n=SSL_read(sock->ssl,buf,len);else#endif-n=xread(sock->fd,buf,len);+n=xread(sock->fd[0],buf,len);if(n<=0){socket_perror("read",sock,n);-close(sock->fd);-sock->fd=-1;+close(sock->fd[0]);+close(sock->fd[1]);+sock->fd[0]=sock->fd[1]=-1;}returnn;}
@@ -341,11 +346,12 @@ static int socket_write(struct imap_socket *sock, const char *buf, int len)n=SSL_write(sock->ssl,buf,len);else#endif-n=write_in_full(sock->fd,buf,len);+n=write_in_full(sock->fd[1],buf,len);if(n!=len){socket_perror("write",sock,n);-close(sock->fd);-sock->fd=-1;+close(sock->fd[0]);+close(sock->fd[1]);+sock->fd[0]=sock->fd[1]=-1;}returnn;}
@@ -939,7 +946,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)ctx=xcalloc(sizeof(*ctx),1);ctx->imap=imap=xcalloc(sizeof(*imap),1);-imap->buf.sock.fd=-1;+imap->buf.sock.fd[0]=imap->buf.sock.fd[1]=-1;imap->in_progress_append=&imap->in_progress;/* open connection to IMAP server */
@@ -966,7 +973,8 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)close(a[0]);-imap->buf.sock.fd=a[1];+imap->buf.sock.fd[0]=a[1];+imap->buf.sock.fd[1]=dup(a[1]);imap_info("ok\n");}else{
@@ -1043,7 +1051,8 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)gotobail;}-imap->buf.sock.fd=s;+imap->buf.sock.fd[0]=s;+imap->buf.sock.fd[1]=dup(s);if(srvc->use_ssl&&ssl_socket_connect(&imap->buf.sock,0,srvc->ssl_verify)){
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:35
mmsystem.h (included from windows.h) defines DRV_OK to 1. To avoid
an error due to DRV_OK redefenition, this patch undefines the old
definition (i.e the one from mmsystem.h) before defining DRV_OK.
Signed-off-by: Erik Faye-Lund <redacted>
---
imap-send.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:47:36
Hi,
On Wed, 21 Oct 2009, Erik Faye-Lund wrote:
Here's the 5th iteration of my patches for Windows-compatibility in
imap-send.
- Patch 1-3 is about getting rid of or rewriting
code with portability issues.
- Patch 4 fixes a compilation error on Windows
- Patch 5 enables compilation of imap-send
- Patch 6-7 enables SSL-suport for mingw
- Patch 8 enables imap-send and SSL for msvc
The only change compared to the previous iteration
is that patch 7 and 8 enables NEEDS_CRYPTO_WITH_SSL.
Please note that I haven't tested Patch 8 with
NEEDS_CRYPTO_WITH_SSL under MSVC, as I don't have a
working setup with both msysgit and MSVC installed.
I'd love it if someone with such a working setup
could verify that it works, preferrably also with
BLK_SHA1 enabled.
If there are no objections, I will apply them tomorrow.
Ciao,
Dscho
From: Johannes Sixt <hidden> Date: 2016-06-15 22:47:36
Since NO_OPENSSL is no longer defined on Windows, BLK_SHA1 is not defined
anymore implicitly. Define it explicitly.
As a nice side-effect, we no longer link against libcrypto.dll, which has
non-trivial startup costs because it depends on 6 otherwise unneeded
DLLs.
Signed-off-by: Johannes Sixt <redacted>
---
On Donnerstag, 22. Oktober 2009, Johannes Sixt wrote:
... and I have one more patch to be applied on top of the series.
Here it is. I haven't tested the MSVC aspect of the patch. I would
appreciate feedback in this regard.
-- Hannes
Makefile | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:47:37
Hi,
On Thu, 22 Oct 2009, Johannes Sixt wrote:
Since NO_OPENSSL is no longer defined on Windows, BLK_SHA1 is not defined
anymore implicitly. Define it explicitly.
As a nice side-effect, we no longer link against libcrypto.dll, which has
non-trivial startup costs because it depends on 6 otherwise unneeded
DLLs.
Signed-off-by: Johannes Sixt <redacted>
---
On Donnerstag, 22. Oktober 2009, Johannes Sixt wrote:
quoted
... and I have one more patch to be applied on top of the series.
Here it is. I haven't tested the MSVC aspect of the patch. I would
appreciate feedback in this regard.
For better visibility, I pushed it to the work/msys-imap branch in
4msysgit.git (but I could not even compile-test it today, due to lack of
access to a Windows machine).
If nobody complains by the end of the week, I will merge it into
4msysgit.git's 'devel' branch (I can only compile-test by then).
Ciao,
Dscho
From: Johannes Sixt <hidden> Date: 2016-06-15 22:47:37
Johannes Schindelin schrieb:
For better visibility, I pushed it to the work/msys-imap branch in
4msysgit.git (but I could not even compile-test it today, due to lack of
access to a Windows machine).
If nobody complains by the end of the week, I will merge it into
4msysgit.git's 'devel' branch (I can only compile-test by then).
Ugh, I totally forgot: I have this branch ready for Junio to pull:
git://repo.or.cz/git/mingw/j6t.git ef/imap-send-windows
Only the top 3 commits are different from what is currently in pu: I added
my ACK, and reworded the commit message of my patch that is at the tip.
Content-wise it is identical to the series in pu.
I haven't seen an ACK from Marius regarding the changes that touch MSVC
parts, but there was plenty of time to test, and the changes look obvious
enough.
Junio, please pull.
-- Hannes