1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-17 00:39:50 +02:00

gpg: Use gnupg_fd_t for decryption and sign.

* g10/decrypt.c (decrypt_message_fd): Use gnupg_fd_t.
* g10/plaintext.c (hash_datafile_by_fd): Use  gnupg_fd_t.
* g10/main.h: Fix the declarations.
* g10/mainproc.c (struct mainproc_context): Use gnupg_fd_t for
DATA_FD.
(proc_compressed_cb, proc_signature_packets): Follow the change.
(proc_signature_packets_by_fd): Use gnupg_fd_t.
* g10/packet.h: Fix the declaration.

--

GnuPG-bug-id: 6580
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2023-07-05 10:21:23 +09:00
parent 2c2516f03a
commit 3fb69641e8
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054
5 changed files with 30 additions and 18 deletions

View File

@ -100,7 +100,8 @@ decrypt_message (ctrl_t ctrl, const char *filename)
/* Same as decrypt_message but takes a file descriptor for input and /* Same as decrypt_message but takes a file descriptor for input and
output. */ output. */
gpg_error_t gpg_error_t
decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd) decrypt_message_fd (ctrl_t ctrl, gnupg_fd_t input_fd,
gnupg_fd_t output_fd)
{ {
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
/* No server mode yet. */ /* No server mode yet. */
@ -113,6 +114,7 @@ decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd)
IOBUF fp; IOBUF fp;
armor_filter_context_t *afx = NULL; armor_filter_context_t *afx = NULL;
progress_filter_context_t *pfx; progress_filter_context_t *pfx;
es_syshd_t syshd;
if (opt.outfp) if (opt.outfp)
return gpg_error (GPG_ERR_BUG); return gpg_error (GPG_ERR_BUG);
@ -138,13 +140,20 @@ decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd)
return err; return err;
} }
opt.outfp = es_fdopen_nc (output_fd, "wb"); #ifdef HAVE_W32_SYSTEM
syshd.type = ES_SYSHD_HANDLE;
syshd.u.handle = output_fd;
#else
syshd.type = ES_SYSHD_FD;
syshd.u.fd = output_fd;
#endif
opt.outfp = es_sysopen_nc (&syshd, "w");
if (!opt.outfp) if (!opt.outfp)
{ {
char xname[64]; char xname[64];
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
snprintf (xname, sizeof xname, "[fd %d]", output_fd); snprintf (xname, sizeof xname, "[fd %d]", (int)(intprt_t)output_fd);
log_error (_("can't open '%s': %s\n"), xname, gpg_strerror (err)); log_error (_("can't open '%s': %s\n"), xname, gpg_strerror (err));
iobuf_close (fp); iobuf_close (fp);
release_progress_context (pfx); release_progress_context (pfx);

View File

@ -498,14 +498,15 @@ void check_assert_signer_list (const char *mainpkhex, const char *pkhex);
/*-- decrypt.c --*/ /*-- decrypt.c --*/
int decrypt_message (ctrl_t ctrl, const char *filename ); int decrypt_message (ctrl_t ctrl, const char *filename );
gpg_error_t decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd); gpg_error_t decrypt_message_fd (ctrl_t ctrl, gnupg_fd_t input_fd,
gnupg_fd_t output_fd);
void decrypt_messages (ctrl_t ctrl, int nfiles, char *files[]); void decrypt_messages (ctrl_t ctrl, int nfiles, char *files[]);
/*-- plaintext.c --*/ /*-- plaintext.c --*/
int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2, int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2,
strlist_t files, const char *sigfilename, int textmode); strlist_t files, const char *sigfilename, int textmode);
int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd, int hash_datafile_by_fd (gcry_md_hd_t md, gcry_md_hd_t md2,
int textmode ); gnupg_fd_t data_fd, int textmode);
PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf); PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
/*-- server.c --*/ /*-- server.c --*/

View File

@ -81,7 +81,7 @@ struct mainproc_context
struct struct
{ {
/* A file descriptor of the signed data. Only used if not -1. */ /* A file descriptor of the signed data. Only used if not -1. */
int data_fd; gnupg_fd_t data_fd;
/* A list of filenames with the data files or NULL. This is only /* A list of filenames with the data files or NULL. This is only
used if DATA_FD is -1. */ used if DATA_FD is -1. */
strlist_t data_names; strlist_t data_names;
@ -1093,7 +1093,7 @@ static int
proc_compressed_cb (iobuf_t a, void *info) proc_compressed_cb (iobuf_t a, void *info)
{ {
if ( ((CTX)info)->signed_data.used if ( ((CTX)info)->signed_data.used
&& ((CTX)info)->signed_data.data_fd != -1) && ((CTX)info)->signed_data.data_fd != GNUPG_INVALID_FD)
return proc_signature_packets_by_fd (((CTX)info)->ctrl, info, a, return proc_signature_packets_by_fd (((CTX)info)->ctrl, info, a,
((CTX)info)->signed_data.data_fd); ((CTX)info)->signed_data.data_fd);
else else
@ -1515,7 +1515,7 @@ proc_signature_packets (ctrl_t ctrl, void *anchor, iobuf_t a,
c->anchor = anchor; c->anchor = anchor;
c->sigs_only = 1; c->sigs_only = 1;
c->signed_data.data_fd = -1; c->signed_data.data_fd = GNUPG_INVALID_FD;
c->signed_data.data_names = signedfiles; c->signed_data.data_names = signedfiles;
c->signed_data.used = !!signedfiles; c->signed_data.used = !!signedfiles;
@ -1545,8 +1545,8 @@ proc_signature_packets (ctrl_t ctrl, void *anchor, iobuf_t a,
int int
proc_signature_packets_by_fd (ctrl_t ctrl, proc_signature_packets_by_fd (ctrl_t ctrl, void *anchor, iobuf_t a,
void *anchor, iobuf_t a, int signed_data_fd ) gnupg_fd_t signed_data_fd)
{ {
int rc; int rc;
CTX c; CTX c;
@ -1561,7 +1561,7 @@ proc_signature_packets_by_fd (ctrl_t ctrl,
c->signed_data.data_fd = signed_data_fd; c->signed_data.data_fd = signed_data_fd;
c->signed_data.data_names = NULL; c->signed_data.data_names = NULL;
c->signed_data.used = (signed_data_fd != -1); c->signed_data.used = (signed_data_fd != GNUPG_INVALID_FD);
rc = do_proc_packets (c, a); rc = do_proc_packets (c, a);
@ -2627,7 +2627,8 @@ proc_tree (CTX c, kbnode_t node)
/* Ask for file and hash it. */ /* Ask for file and hash it. */
if (c->sigs_only) if (c->sigs_only)
{ {
if (c->signed_data.used && c->signed_data.data_fd != -1) if (c->signed_data.used
&& c->signed_data.data_fd != GNUPG_INVALID_FD)
rc = hash_datafile_by_fd (c->mfx.md, NULL, rc = hash_datafile_by_fd (c->mfx.md, NULL,
c->signed_data.data_fd, c->signed_data.data_fd,
use_textmode); use_textmode);
@ -2771,7 +2772,8 @@ proc_tree (CTX c, kbnode_t node)
if (c->sigs_only) if (c->sigs_only)
{ {
if (c->signed_data.used && c->signed_data.data_fd != -1) if (c->signed_data.used
&& c->signed_data.data_fd != GNUPG_INVALID_FD)
rc = hash_datafile_by_fd (c->mfx.md, c->mfx.md2, rc = hash_datafile_by_fd (c->mfx.md, c->mfx.md2,
c->signed_data.data_fd, c->signed_data.data_fd,
(sig->sig_class == 0x01)); (sig->sig_class == 0x01));

View File

@ -634,8 +634,8 @@ void reset_literals_seen(void);
int proc_packets (ctrl_t ctrl, void *ctx, iobuf_t a ); int proc_packets (ctrl_t ctrl, void *ctx, iobuf_t a );
int proc_signature_packets (ctrl_t ctrl, void *ctx, iobuf_t a, int proc_signature_packets (ctrl_t ctrl, void *ctx, iobuf_t a,
strlist_t signedfiles, const char *sigfile ); strlist_t signedfiles, const char *sigfile );
int proc_signature_packets_by_fd (ctrl_t ctrl, int proc_signature_packets_by_fd (ctrl_t ctrl, void *anchor, IOBUF a,
void *anchor, IOBUF a, int signed_data_fd ); gnupg_fd_t signed_data_fd);
int proc_encryption_packets (ctrl_t ctrl, void *ctx, iobuf_t a); int proc_encryption_packets (ctrl_t ctrl, void *ctx, iobuf_t a);
int list_packets( iobuf_t a ); int list_packets( iobuf_t a );

View File

@ -728,8 +728,8 @@ hash_datafiles (gcry_md_hd_t md, gcry_md_hd_t md2, strlist_t files,
/* Hash the data from file descriptor DATA_FD and append the hash to hash /* Hash the data from file descriptor DATA_FD and append the hash to hash
contexts MD and MD2. */ contexts MD and MD2. */
int int
hash_datafile_by_fd (gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd, hash_datafile_by_fd (gcry_md_hd_t md, gcry_md_hd_t md2,
int textmode) gnupg_fd_t data_fd, int textmode)
{ {
progress_filter_context_t *pfx = new_progress_context (); progress_filter_context_t *pfx = new_progress_context ();
iobuf_t fp; iobuf_t fp;