imap-send: use run-command API for tunneling
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
7a7796e9a7
commit
c94d2dd080
37
imap-send.c
37
imap-send.c
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "exec_cmd.h"
|
#include "exec_cmd.h"
|
||||||
|
#include "run-command.h"
|
||||||
#ifdef NO_OPENSSL
|
#ifdef NO_OPENSSL
|
||||||
typedef void *SSL;
|
typedef void *SSL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -940,8 +941,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
|
||||||
struct imap_store *ctx;
|
struct imap_store *ctx;
|
||||||
struct imap *imap;
|
struct imap *imap;
|
||||||
char *arg, *rsp;
|
char *arg, *rsp;
|
||||||
int s = -1, a[2], preauth;
|
int s = -1, preauth;
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
ctx = xcalloc(sizeof(*ctx), 1);
|
ctx = xcalloc(sizeof(*ctx), 1);
|
||||||
|
|
||||||
|
@ -952,29 +952,24 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
|
||||||
/* open connection to IMAP server */
|
/* open connection to IMAP server */
|
||||||
|
|
||||||
if (srvc->tunnel) {
|
if (srvc->tunnel) {
|
||||||
|
const char *argv[4];
|
||||||
|
struct child_process tunnel = {0};
|
||||||
|
|
||||||
imap_info("Starting tunnel '%s'... ", srvc->tunnel);
|
imap_info("Starting tunnel '%s'... ", srvc->tunnel);
|
||||||
|
|
||||||
if (socketpair(PF_UNIX, SOCK_STREAM, 0, a)) {
|
argv[0] = "sh";
|
||||||
perror("socketpair");
|
argv[1] = "-c";
|
||||||
exit(1);
|
argv[2] = srvc->tunnel;
|
||||||
}
|
argv[3] = NULL;
|
||||||
|
|
||||||
pid = fork();
|
tunnel.argv = argv;
|
||||||
if (pid < 0)
|
tunnel.in = -1;
|
||||||
_exit(127);
|
tunnel.out = -1;
|
||||||
if (!pid) {
|
if (start_command(&tunnel))
|
||||||
if (dup2(a[0], 0) == -1 || dup2(a[0], 1) == -1)
|
die("cannot start proxy %s", argv[0]);
|
||||||
_exit(127);
|
|
||||||
close(a[0]);
|
|
||||||
close(a[1]);
|
|
||||||
execl("/bin/sh", "sh", "-c", srvc->tunnel, NULL);
|
|
||||||
_exit(127);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(a[0]);
|
imap->buf.sock.fd[0] = tunnel.out;
|
||||||
|
imap->buf.sock.fd[1] = tunnel.in;
|
||||||
imap->buf.sock.fd[0] = a[1];
|
|
||||||
imap->buf.sock.fd[1] = dup(a[1]);
|
|
||||||
|
|
||||||
imap_info("ok\n");
|
imap_info("ok\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue