aboutsummaryrefslogtreecommitdiffstats
path: root/sm/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sm/server.c')
-rw-r--r--sm/server.c66
1 files changed, 48 insertions, 18 deletions
diff --git a/sm/server.c b/sm/server.c
index 3e012f1e6..a8b12c057 100644
--- a/sm/server.c
+++ b/sm/server.c
@@ -451,20 +451,25 @@ cmd_encrypt (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
certlist_t cl;
- int inp_fd;
+ gnupg_fd_t inp_fd;
gnupg_fd_t out_fd;
+ estream_t inp_fp;
estream_t out_fp;
int rc;
(void)line;
- inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
- if (inp_fd == -1)
+ inp_fd = assuan_get_input_fd (ctx);
+ if (inp_fd == GNUPG_INVALID_FD)
return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
out_fd = assuan_get_output_fd (ctx);
if (out_fd == GNUPG_INVALID_FD)
return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
+ inp_fp = open_stream_nc (inp_fd, "r");
+ if (!inp_fp)
+ return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
+
out_fp = open_stream_nc (out_fd, "w");
if (!out_fp)
return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
@@ -484,7 +489,8 @@ cmd_encrypt (assuan_context_t ctx, char *line)
if (!rc)
rc = gpgsm_encrypt (assuan_get_pointer (ctx),
ctrl->server_local->recplist,
- inp_fd, out_fp);
+ inp_fp, out_fp);
+ es_fclose (inp_fp);
es_fclose (out_fp);
gpgsm_release_certlist (ctrl->server_local->recplist);
@@ -509,27 +515,33 @@ static gpg_error_t
cmd_decrypt (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
- int inp_fd;
+ gnupg_fd_t inp_fd;
gnupg_fd_t out_fd;
+ estream_t inp_fp;
estream_t out_fp;
int rc;
(void)line;
- inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
- if (inp_fd == -1)
+ inp_fd = assuan_get_input_fd (ctx);
+ if (inp_fd == GNUPG_INVALID_FD)
return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
out_fd = assuan_get_output_fd (ctx);
if (out_fd == GNUPG_INVALID_FD)
return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
+ inp_fp = open_stream_nc (inp_fd, "r");
+ if (!inp_fp)
+ return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
+
out_fp = open_stream_nc (out_fd, "w");
if (!out_fp)
return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
rc = start_audit_session (ctrl);
if (!rc)
- rc = gpgsm_decrypt (ctrl, inp_fd, out_fp);
+ rc = gpgsm_decrypt (ctrl, inp_fp, out_fp);
+ es_fclose (inp_fp);
es_fclose (out_fp);
/* Close and reset the fds. */
@@ -555,15 +567,20 @@ cmd_verify (assuan_context_t ctx, char *line)
{
int rc;
ctrl_t ctrl = assuan_get_pointer (ctx);
- int fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
+ gnupg_fd_t fd = assuan_get_input_fd (ctx);
gnupg_fd_t out_fd = assuan_get_output_fd (ctx);
+ estream_t fp = NULL;
estream_t out_fp = NULL;
(void)line;
- if (fd == -1)
+ if (fd == GNUPG_INVALID_FD)
return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
+ fp = open_stream_nc (fd, "r");
+ if (!fp)
+ return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
+
if (out_fd != GNUPG_INVALID_FD)
{
out_fp = open_stream_nc (out_fd, "w");
@@ -573,8 +590,9 @@ cmd_verify (assuan_context_t ctx, char *line)
rc = start_audit_session (ctrl);
if (!rc)
- rc = gpgsm_verify (assuan_get_pointer (ctx), fd,
+ rc = gpgsm_verify (assuan_get_pointer (ctx), fp,
ctrl->server_local->message_fp, out_fp);
+ es_fclose (fp);
es_fclose (out_fp);
/* Close and reset the fp and the fd. */
@@ -596,14 +614,15 @@ static gpg_error_t
cmd_sign (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
- int inp_fd;
+ gnupg_fd_t inp_fd;
gnupg_fd_t out_fd;
+ estream_t inp_fp;
estream_t out_fp;
int detached;
int rc;
- inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
- if (inp_fd == -1)
+ inp_fd = assuan_get_input_fd (ctx);
+ if (inp_fd == GNUPG_INVALID_FD)
return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
out_fd = assuan_get_output_fd (ctx);
if (out_fd == GNUPG_INVALID_FD)
@@ -611,6 +630,10 @@ cmd_sign (assuan_context_t ctx, char *line)
detached = has_option (line, "--detached");
+ inp_fp = open_stream_nc (inp_fd, "r");
+ if (!inp_fp)
+ return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
+
out_fp = open_stream_nc (out_fd, "w");
if (!out_fp)
return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
@@ -618,7 +641,8 @@ cmd_sign (assuan_context_t ctx, char *line)
rc = start_audit_session (ctrl);
if (!rc)
rc = gpgsm_sign (assuan_get_pointer (ctx), ctrl->server_local->signerlist,
- inp_fd, detached, out_fp);
+ inp_fp, detached, out_fp);
+ es_fclose (inp_fp);
es_fclose (out_fp);
/* close and reset the fp and the fds */
@@ -647,15 +671,21 @@ cmd_import (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
int rc;
- int fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
+ gnupg_fd_t fd = assuan_get_input_fd (ctx);
int reimport = has_option (line, "--re-import");
+ estream_t fp;
(void)line;
- if (fd == -1)
+ if (fd == GNUPG_INVALID_FD)
return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
- rc = gpgsm_import (assuan_get_pointer (ctx), fd, reimport);
+ fp = open_stream_nc (fd, "rb");
+ if (!fp)
+ return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
+
+ rc = gpgsm_import (assuan_get_pointer (ctx), fp, reimport);
+ es_fclose (fp);
/* close and reset the fp and the fds */
close_message_fp (ctrl);