mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
Removed almost al dup calls.
This commit is contained in:
parent
40a78fab0c
commit
6216d33e8c
14 changed files with 89 additions and 84 deletions
10
sm/ChangeLog
10
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>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
|
|
23
sm/export.c
23
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));
|
||||
|
|
15
sm/gpgsm.c
15
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;
|
||||
|
||||
|
|
|
@ -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 --*/
|
||||
|
|
26
sm/server.c
26
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue