From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:32
Here's the 3rd 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
Changes in this iteration compared to v2 are as
follows:
- A typo has been corrected in the commit message
for 1/8
- some unneeded preprocessor directives has been
deleted from patch 4/8
Thanks to Matt Kraai for reviewing v2
P.S:
Perhaps some people are only on the msysgit mailing
list and wonders where v2 went -- I forgot to CC
you guys last round, sorry about that! If you're
interrested, you can read the discussion here:
http://thread.gmane.org/gmane.comp.version-control.git/129471
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 | 4 +-
compat/mingw.h | 21 ++++
compat/vcbuild/scripts/clink.pl | 3 +
contrib/buildsystems/engine.pl | 3 +
imap-send.c | 226 +++++++++------------------------------
5 files changed, 77 insertions(+), 180 deletions(-)
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:32
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:32
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:32
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(-)
@@ -365,6 +365,7 @@ PROGRAMS += git-show-index$XPROGRAMS+=git-unpack-file$XPROGRAMS+=git-upload-pack$XPROGRAMS+=git-var$X+PROGRAMS+=git-imap-send$X# List built-in command $C whose implementation cmd_$C() is not in# builtin-$C.o but is linked in as part of some other command.
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:32
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: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:32
Since we have OpenSSL in msysgit now, enable it to support SSL
encryption for imap-send.
Signed-off-by: Erik Faye-Lund <redacted>
---
Makefile | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:32
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:32
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 | 1 -
compat/vcbuild/scripts/clink.pl | 3 +++
contrib/buildsystems/engine.pl | 3 +++
3 files changed, 6 insertions(+), 1 deletions(-)
Is there a particular reason that you run "/bin/sh" with a path? I doubt that
this works on Windows.
-- Hannes
It doesn't - I was being conservative. Getting tunneling to work on
Windows hasn't been a part of my priorities (even though I did
briefly test it at some point and got it working, provided a patch
that changed the path to sh to a windows-path). Changing it to "sh -c"
(as was suggested earlier) could AFAIK break something for people who
have other 'sh's in path before /bin -- not that I think it would
matter terribly much.
If I were to fix this, I'd prefer not using sh at all on Windows. I've
seen that connect.c doesn't prepend "/bin/sh -c" at all, requiring
tunnels to be self-contained scripts or native binaries, unless I'm
mistaken. I'm not sure if this works at all on Windows, though. I just
think that the assumption that sh is the shell that is going to run
the tunnel is wrong to make, especially on Windows.
I'm really unsure if it's worth the hassle.
--
Erik "kusma" Faye-Lund
From: Johannes Sixt <hidden> Date: 2016-06-15 22:47:33
On Dienstag, 13. Oktober 2009, Erik Faye-Lund wrote:
If I were to fix this, I'd prefer not using sh at all on Windows. I've
seen that connect.c doesn't prepend "/bin/sh -c" at all, requiring
tunnels to be self-contained scripts or native binaries, unless I'm
mistaken. I'm not sure if this works at all on Windows, though. I just
think that the assumption that sh is the shell that is going to run
the tunnel is wrong to make, especially on Windows.
I'm really unsure if it's worth the hassle.
We already depend on the existence of a Bourne shell for our scripted
commands. There are already more places in the code that run "sh"
than "/bin/sh".
-- Hannes
From: Erik Faye-Lund <hidden> Date: 2016-06-15 22:47:34
Sorry about the late reply, lots of things to do.
On Wed, Oct 14, 2009 at 9:58 PM, Johannes Sixt [off-list ref] wrote:
On Dienstag, 13. Oktober 2009, Erik Faye-Lund wrote:
quoted
I'm really unsure if it's worth the hassle.
We already depend on the existence of a Bourne shell for our scripted
commands. There are already more places in the code that run "sh"
than "/bin/sh".
OK, you've got me convinced. I'll update the patch with this tweak.
--
Erik "kusma" Faye-Lund