summaryrefslogtreecommitdiffstats
path: root/sm
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2010-03-08 19:19:21 +0100
committerWerner Koch <wk@gnupg.org>2010-03-08 19:19:21 +0100
commit6216d33e8cc1c2d01533b3e9b97dc7009b4f3553 (patch)
tree062bf701637025088b83a9e8684aa7a1eae68fb5 /sm
parentUse macros for iobuf ioctls. (diff)
downloadgnupg2-6216d33e8cc1c2d01533b3e9b97dc7009b4f3553.tar.xz
gnupg2-6216d33e8cc1c2d01533b3e9b97dc7009b4f3553.zip
Removed almost al dup calls.
Diffstat (limited to 'sm')
-rw-r--r--sm/ChangeLog10
-rw-r--r--sm/certreqgen-ui.c6
-rw-r--r--sm/certreqgen.c7
-rw-r--r--sm/export.c23
-rw-r--r--sm/gpgsm.c15
-rw-r--r--sm/gpgsm.h6
-rw-r--r--sm/server.c26
7 files changed, 47 insertions, 46 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog
index bb979f996..ba5047a82 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,11 +1,20 @@
2010-03-08 Werner Koch <wk@g10code.com>
+ * certreqgen.c (gpgsm_genkey): Change OUT_FP to an estream_t
+ OUT_STREAM.
+ * certreqgen-ui.c (gpgsm_gencertreq_tty): ditto.
+
+ * server.c (cmd_genkey): Close IN_STREAM.
+
* server.c (cmd_encrypt, cmd_decrypt, cmd_verify, cmd_sign): Avoid
dup call by using es_fdopen_nc.
(do_listkeys): Use es_fdopen_nc instead of dup and es_fdopen.
+ (cmd_export): Ditto.
+ (cmd_genkey): Ditto.
* export.c (popen_protect_tool): Change OUTFILE to an estream_t.
(export_p12): Change OUTFP and arg RETFP to an estream_t.
(gpgsm_p12_export): Change DATAFP to an estream_t.
+ (gpgsm_export): Remove arg FP.
* import.c (import_one): Change CERTFP and arg FP to an estream_t.
(popen_protect_tool): Ditto for OUTFILE.
(parse_p12): Change CERTFP to an estream_t.
@@ -23,6 +32,7 @@
(encrypt_cb): Use estream.
* gpgsm.c (main) <aEncr, aVerify, aSign, aDecrypt>: Use estream
functions.
+ (main) <aExport, aKeygen>: Use open_es_fwrite.
2009-12-14 Werner Koch <wk@g10code.com>
diff --git a/sm/certreqgen-ui.c b/sm/certreqgen-ui.c
index 3e98b660f..3dabb654e 100644
--- a/sm/certreqgen-ui.c
+++ b/sm/certreqgen-ui.c
@@ -1,5 +1,5 @@
/* certreqgen-ui.c - Simple user interface for certreqgen.c
- * Copyright (C) 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2007, 2010 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -125,7 +125,7 @@ check_keygrip (ctrl_t ctrl, const char *hexgrip)
and thus is not suitable for the Windows port. So here is the
re-implementation. */
void
-gpgsm_gencertreq_tty (ctrl_t ctrl, FILE *output_fp)
+gpgsm_gencertreq_tty (ctrl_t ctrl, estream_t output_stream)
{
gpg_error_t err;
char *answer;
@@ -391,7 +391,7 @@ gpgsm_gencertreq_tty (ctrl_t ctrl, FILE *output_fp)
{
int save_pem = ctrl->create_pem;
ctrl->create_pem = 1; /* Force creation of PEM. */
- err = gpgsm_genkey (ctrl, fp, output_fp);
+ err = gpgsm_genkey (ctrl, fp, output_stream);
ctrl->create_pem = save_pem;
}
if (!err)
diff --git a/sm/certreqgen.c b/sm/certreqgen.c
index 7026a303f..043226a44 100644
--- a/sm/certreqgen.c
+++ b/sm/certreqgen.c
@@ -1,5 +1,6 @@
/* certreqgen.c - Generate a key and a certification request
- * Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2003, 2005, 2007,
+ * 2010 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -846,14 +847,14 @@ create_request (ctrl_t ctrl,
/* Create a new key by reading the parameters from IN_FP. Multiple
keys may be created */
int
-gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, FILE *out_fp)
+gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, estream_t out_stream)
{
int rc;
Base64Context b64writer = NULL;
ksba_writer_t writer;
ctrl->pem_name = "CERTIFICATE REQUEST";
- rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer);
+ rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_stream, &writer);
if (rc)
{
log_error ("can't create writer: %s\n", gpg_strerror (rc));
diff --git a/sm/export.c b/sm/export.c
index 9a05b5176..2c8e57b5d 100644
--- a/sm/export.c
+++ b/sm/export.c
@@ -125,12 +125,10 @@ insert_duptable (duptable_t *table, unsigned char *fpr, int *exists)
}
-
-
-/* Export all certificates or just those given in NAMES. If STREAM is
- not NULL the output is send to this extended stream. */
+/* Export all certificates or just those given in NAMES. The output
+ is written to STREAM. */
void
-gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp, estream_t stream)
+gpgsm_export (ctrl_t ctrl, strlist_t names, estream_t stream)
{
KEYDB_HANDLE hd = NULL;
KEYDB_SEARCH_DESC *desc = NULL;
@@ -256,24 +254,17 @@ gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp, estream_t stream)
if (ctrl->create_pem)
{
if (count)
- {
- if (stream)
- es_putc ('\n', stream);
- else
- putc ('\n', fp);
- }
- print_short_info (cert, fp, stream);
- if (stream)
es_putc ('\n', stream);
- else
- putc ('\n', fp);
+ print_short_info (cert, NULL, stream);
+ es_putc ('\n', stream);
}
count++;
if (!b64writer)
{
ctrl->pem_name = "CERTIFICATE";
- rc = gpgsm_create_writer (&b64writer, ctrl, fp, stream, &writer);
+ rc = gpgsm_create_writer (&b64writer, ctrl,
+ NULL, stream, &writer);
if (rc)
{
log_error ("can't create writer: %s\n", gpg_strerror (rc));
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index 8a8c017d9..39de29181 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -1829,7 +1829,7 @@ main ( int argc, char **argv)
case aKeygen: /* Generate a key; well kind of. */
{
estream_t fpin = NULL;
- FILE *fpout;
+ estream_t fpout;
if (opt.batch)
{
@@ -1841,15 +1841,14 @@ main ( int argc, char **argv)
wrong_args ("--gen-key --batch [parmfile]");
}
- fpout = open_fwrite (opt.outfile?opt.outfile:"-");
+ fpout = open_es_fwrite (opt.outfile?opt.outfile:"-");
if (fpin)
gpgsm_genkey (&ctrl, fpin, fpout);
else
gpgsm_gencertreq_tty (&ctrl, fpout);
- if (fpout != stdout)
- fclose (fpout);
+ es_fclose (fpout);
}
break;
@@ -1860,14 +1859,14 @@ main ( int argc, char **argv)
case aExport:
{
- FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-");
+ estream_t fp;
+ fp = open_es_fwrite (opt.outfile?opt.outfile:"-");
for (sl=NULL; argc; argc--, argv++)
add_to_strlist (&sl, *argv);
- gpgsm_export (&ctrl, sl, fp, NULL);
+ gpgsm_export (&ctrl, sl, fp);
free_strlist(sl);
- if (fp != stdout)
- fclose (fp);
+ es_fclose (fp);
}
break;
diff --git a/sm/gpgsm.h b/sm/gpgsm.h
index 1a8aab91b..7e0353060 100644
--- a/sm/gpgsm.h
+++ b/sm/gpgsm.h
@@ -344,7 +344,7 @@ int gpgsm_import_files (ctrl_t ctrl, int nfiles, char **files,
int (*of)(const char *fname));
/*-- export.c --*/
-void gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp, estream_t stream);
+void gpgsm_export (ctrl_t ctrl, strlist_t names, estream_t stream);
void gpgsm_p12_export (ctrl_t ctrl, const char *name, FILE *fp);
/*-- delete.c --*/
@@ -366,10 +366,10 @@ int gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist,
int gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp);
/*-- certreqgen.c --*/
-int gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, FILE *out_fp);
+int gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, estream_t out_stream);
/*-- certreqgen-ui.c --*/
-void gpgsm_gencertreq_tty (ctrl_t ctrl, FILE *out_fp);
+void gpgsm_gencertreq_tty (ctrl_t ctrl, estream_t out_stream);
/*-- qualified.c --*/
diff --git a/sm/server.c b/sm/server.c
index e4de5dca8..42cadcca1 100644
--- a/sm/server.c
+++ b/sm/server.c
@@ -723,28 +723,28 @@ cmd_export (assuan_context_t ctx, char *line)
return set_error (GPG_ERR_ASS_GENERAL,
"error setting up a data stream");
}
- gpgsm_export (ctrl, list, NULL, stream);
+ gpgsm_export (ctrl, list, stream);
es_fclose (stream);
}
else
{
int fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
- FILE *out_fp;
+ estream_t out_fp;
if (fd == -1)
{
free_strlist (list);
return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
}
- out_fp = fdopen ( dup(fd), "w");
+ out_fp = es_fdopen_nc (fd, "w");
if (!out_fp)
{
free_strlist (list);
- return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
+ return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
}
- gpgsm_export (ctrl, list, out_fp, NULL);
- fclose (out_fp);
+ gpgsm_export (ctrl, list, out_fp);
+ es_fclose (out_fp);
}
free_strlist (list);
@@ -977,9 +977,8 @@ cmd_genkey (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
int inp_fd, out_fd;
- FILE *out_fp;
+ estream_t in_stream, out_stream;
int rc;
- estream_t in_stream;
(void)line;
@@ -994,14 +993,15 @@ cmd_genkey (assuan_context_t ctx, char *line)
if (!in_stream)
return set_error (GPG_ERR_ASS_GENERAL, "es_fdopen failed");
- out_fp = fdopen ( dup(out_fd), "w");
- if (!out_fp)
+ out_stream = es_fdopen_nc (out_fd, "w");
+ if (!out_stream)
{
es_fclose (in_stream);
- return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
+ return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
}
- rc = gpgsm_genkey (ctrl, in_stream, out_fp);
- fclose (out_fp);
+ rc = gpgsm_genkey (ctrl, in_stream, out_stream);
+ es_fclose (out_stream);
+ es_fclose (in_stream);
/* close and reset the fds */
assuan_close_input_fd (ctx);