| 1 |
From fcf61fc6c490fd8bf65f8726463870c24b54969b Mon Sep 17 00:00:00 2001 |
| 2 |
From: Stephen Paul Weber <[email protected]> |
| 3 |
Date: Wed, 18 Mar 2015 10:47:28 -0500 |
| 4 |
Subject: [PATCH 07/10] Send data down using a pipe |
| 5 |
|
| 6 |
--- |
| 7 |
src/core/tools.c | 21 +++++++++++---------- |
| 8 |
1 file changed, 11 insertions(+), 10 deletions(-) |
| 9 |
|
| 10 |
diff --git a/src/core/tools.c b/src/core/tools.c |
| 11 |
index 7628162..a8019b3 100644 |
| 12 |
--- a/src/core/tools.c |
| 13 |
+++ b/src/core/tools.c |
| 14 |
@@ -37,7 +37,7 @@ static const char *utf8_charset = "UTF-8"; |
| 15 |
|
| 16 |
char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 17 |
int get_stderr, int snip_data, unsigned round) { |
| 18 |
- int pipefd[2], rwepipe[3], childpid, tmp2_fd = 0, in_data = !snip_data; |
| 19 |
+ int pipefd[2], pipefd2[2], rwepipe[3], childpid, in_data = !snip_data; |
| 20 |
FILE* cstream; |
| 21 |
char *cmd, *output = NULL; |
| 22 |
size_t output_size = 0; |
| 23 |
@@ -55,18 +55,19 @@ char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 24 |
if(close(pipefd[1])) goto pgp_error; |
| 25 |
} |
| 26 |
|
| 27 |
- if(input2) { /* NOTE for security it might be better if this were a named pipe */ |
| 28 |
- if((tmp2_fd = mkstemp("irssi-xmpp-gpgXXXXXX")) == -1) goto pgp_error; |
| 29 |
- if(write(tmp2_fd, input2, strlen(input2)) < 0) goto pgp_error; |
| 30 |
+ if(input2) { |
| 31 |
+ if(pipe(pipefd2)) goto pgp_error; |
| 32 |
+ if(write(pipefd2[1], input2, strlen(input2)) < 0) goto pgp_error; |
| 33 |
+ if(close(pipefd2[1])) goto pgp_error; |
| 34 |
} |
| 35 |
|
| 36 |
cmd = malloc(sizeof("gpg --enable-special-filenames -u ''" \ |
| 37 |
"--passphrase-fd '' --trust-model always" \ |
| 38 |
" -qo - --batch --no-tty - '' -&") \ |
| 39 |
- +1+strlen(switches)+5+ /* 5 is for passphrase-fd */ \ |
| 40 |
+ +1+strlen(switches)+ \ |
| 41 |
(keyid ? strlen(keyid) : 0)+ \ |
| 42 |
- (keyid ? strlen(keyid) : 0)+ \ |
| 43 |
- (tmp2_fd ? 5 : 0)); |
| 44 |
+ (send_password ? 5 : 0)+ \ |
| 45 |
+ (input2 ? 5 : 0)); |
| 46 |
if(keyid) { |
| 47 |
strcpy(cmd, "gpg -u '"); |
| 48 |
strcat(cmd, keyid); |
| 49 |
@@ -81,8 +82,8 @@ char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 50 |
strcat(cmd, " --enable-special-filenames --trust-model always -qo -" \ |
| 51 |
" --batch --no-tty - "); |
| 52 |
|
| 53 |
- if(tmp2_fd) { |
| 54 |
- sprintf(cmd+strlen(cmd), "-&%d", tmp2_fd); |
| 55 |
+ if(input2) { |
| 56 |
+ sprintf(cmd+strlen(cmd), "-&%d", pipefd2[0]); |
| 57 |
} |
| 58 |
|
| 59 |
fflush(NULL); |
| 60 |
@@ -136,8 +137,8 @@ char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 61 |
} |
| 62 |
|
| 63 |
done: |
| 64 |
- if(tmp2_fd) close(tmp2_fd); |
| 65 |
if(send_password) close(pipefd[0]); |
| 66 |
+ if(input2) close(pipefd2[0]); |
| 67 |
free(cmd); |
| 68 |
|
| 69 |
return output; |
| 70 |
-- |
| 71 |
2.1.4 |
| 72 |
|