1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-11 22:52:47 +01:00

gpg: Use gnupg_fd_t for encrypt_crypt and gpg_verify.

* common/iobuf.h (iobuf_fdopen_nc): Use gnupg_t.
* common/iobuf.c (iobuf_fdopen_nc): Use gnupg_t.
* g10/main.h (encrypt_crypt, gpg_verify): Use gnupg_fd_t.
* g10/encrypt.c (encrypt_crypt): Use gnupg_fd_t.
(encrypt_crypt_files): Follow the change.
* g10/gpg.c (main): Follow the change.
* g10/verify.c (gpg_verify): Use gnupg_fd_t.

--

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

View File

@ -1531,9 +1531,8 @@ iobuf_fdopen (int fd, const char *mode)
} }
iobuf_t iobuf_t
iobuf_fdopen_nc (int fd, const char *mode) iobuf_fdopen_nc (gnupg_fd_t fp, const char *mode)
{ {
gnupg_fd_t fp = INT2FD (fd);
return do_iobuf_fdopen (fp, mode, 1); return do_iobuf_fdopen (fp, mode, 1);
} }

View File

@ -337,7 +337,7 @@ iobuf_t iobuf_fdopen (int fd, const char *mode);
/* Like iobuf_fdopen, but doesn't close the file descriptor when the /* Like iobuf_fdopen, but doesn't close the file descriptor when the
filter is destroyed. */ filter is destroyed. */
iobuf_t iobuf_fdopen_nc (int fd, const char *mode); iobuf_t iobuf_fdopen_nc (gnupg_fd_t fd, const char *mode);
/* Create a filter using an existing estream. If MODE contains the /* Create a filter using an existing estream. If MODE contains the
letter 'w', creates an output filter. Otherwise, creates an input letter 'w', creates an output filter. Otherwise, creates an input

View File

@ -764,9 +764,9 @@ write_symkey_enc (STRING2KEY *symkey_s2k, aead_algo_t aead_algo,
* not yet finished server.c. * not yet finished server.c.
*/ */
int int
encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename, encrypt_crypt (ctrl_t ctrl, gnupg_fd_t filefd, const char *filename,
strlist_t remusr, int use_symkey, pk_list_t provided_keys, strlist_t remusr, int use_symkey, pk_list_t provided_keys,
int outputfd) gnupg_fd_t outputfd)
{ {
iobuf_t inp = NULL; iobuf_t inp = NULL;
iobuf_t out = NULL; iobuf_t out = NULL;
@ -784,7 +784,7 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
PK_LIST pk_list; PK_LIST pk_list;
int do_compress; int do_compress;
if (filefd != -1 && filename) if (filefd != GNUPG_INVALID_FD && filename)
return gpg_error (GPG_ERR_INV_ARG); /* Both given. */ return gpg_error (GPG_ERR_INV_ARG); /* Both given. */
do_compress = !!opt.compress_algo; do_compress = !!opt.compress_algo;
@ -815,7 +815,7 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
/* Prepare iobufs. */ /* Prepare iobufs. */
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
if (filefd == -1) if (filefd == GNUPG_INVALID_FD)
inp = iobuf_open (filename); inp = iobuf_open (filename);
else else
{ {
@ -823,7 +823,7 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
gpg_err_set_errno (ENOSYS); gpg_err_set_errno (ENOSYS);
} }
#else #else
if (filefd == -1) if (filefd == GNUPG_INVALID_FD)
inp = iobuf_open (filename); inp = iobuf_open (filename);
else else
inp = iobuf_fdopen_nc (filefd, "rb"); inp = iobuf_fdopen_nc (filefd, "rb");
@ -841,7 +841,7 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
char xname[64]; char xname[64];
rc = gpg_error_from_syserror (); rc = gpg_error_from_syserror ();
if (filefd != -1) if (filefd != GNUPG_INVALID_FD)
snprintf (xname, sizeof xname, "[fd %d]", filefd); snprintf (xname, sizeof xname, "[fd %d]", filefd);
else if (!filename) else if (!filename)
strcpy (xname, "[stdin]"); strcpy (xname, "[stdin]");
@ -1225,7 +1225,8 @@ encrypt_crypt_files (ctrl_t ctrl, int nfiles, char **files, strlist_t remusr)
} }
line[strlen(line)-1] = '\0'; line[strlen(line)-1] = '\0';
print_file_status(STATUS_FILE_START, line, 2); print_file_status(STATUS_FILE_START, line, 2);
rc = encrypt_crypt (ctrl, -1, line, remusr, 0, NULL, -1); rc = encrypt_crypt (ctrl, GNUPG_INVALID_FD, line, remusr,
0, NULL, GNUPG_INVALID_FD);
if (rc) if (rc)
log_error ("encryption of '%s' failed: %s\n", log_error ("encryption of '%s' failed: %s\n",
print_fname_stdin(line), gpg_strerror (rc) ); print_fname_stdin(line), gpg_strerror (rc) );
@ -1237,7 +1238,8 @@ encrypt_crypt_files (ctrl_t ctrl, int nfiles, char **files, strlist_t remusr)
while (nfiles--) while (nfiles--)
{ {
print_file_status(STATUS_FILE_START, *files, 2); print_file_status(STATUS_FILE_START, *files, 2);
if ( (rc = encrypt_crypt (ctrl, -1, *files, remusr, 0, NULL, -1)) ) if ((rc = encrypt_crypt (ctrl, GNUPG_INVALID_FD, *files, remusr,
0, NULL, GNUPG_INVALID_FD)))
log_error("encryption of '%s' failed: %s\n", log_error("encryption of '%s' failed: %s\n",
print_fname_stdin(*files), gpg_strerror (rc) ); print_fname_stdin(*files), gpg_strerror (rc) );
write_status( STATUS_FILE_DONE ); write_status( STATUS_FILE_DONE );

View File

@ -4408,7 +4408,8 @@ main (int argc, char **argv)
{ {
if( argc > 1 ) if( argc > 1 )
wrong_args("--encrypt [filename]"); wrong_args("--encrypt [filename]");
if( (rc = encrypt_crypt (ctrl, -1, fname, remusr, 0, NULL, -1)) ) if ((rc = encrypt_crypt (ctrl, GNUPG_INVALID_FD, fname, remusr,
0, NULL, GNUPG_INVALID_FD)))
{ {
write_status_failure ("encrypt", rc); write_status_failure ("encrypt", rc);
log_error("%s: encryption failed: %s\n", log_error("%s: encryption failed: %s\n",
@ -4433,7 +4434,8 @@ main (int argc, char **argv)
gnupg_compliance_option_string (opt.compliance)); gnupg_compliance_option_string (opt.compliance));
else else
{ {
if( (rc = encrypt_crypt (ctrl, -1, fname, remusr, 1, NULL, -1)) ) if ((rc = encrypt_crypt (ctrl, GNUPG_INVALID_FD, fname, remusr,
1, NULL, GNUPG_INVALID_FD)))
{ {
write_status_failure ("encrypt", rc); write_status_failure ("encrypt", rc);
log_error ("%s: encryption failed: %s\n", log_error ("%s: encryption failed: %s\n",

View File

@ -242,9 +242,9 @@ aead_algo_t use_aead (pk_list_t pk_list, int algo);
int use_mdc (pk_list_t pk_list,int algo); int use_mdc (pk_list_t pk_list,int algo);
int encrypt_symmetric (const char *filename ); int encrypt_symmetric (const char *filename );
int encrypt_store (const char *filename ); int encrypt_store (const char *filename );
int encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename, int encrypt_crypt (ctrl_t ctrl, gnupg_fd_t filefd, const char *filename,
strlist_t remusr, int use_symkey, pk_list_t provided_keys, strlist_t remusr, int use_symkey, pk_list_t provided_keys,
int outputfd); gnupg_fd_t outputfd);
void encrypt_crypt_files (ctrl_t ctrl, void encrypt_crypt_files (ctrl_t ctrl,
int nfiles, char **files, strlist_t remusr); int nfiles, char **files, strlist_t remusr);
int encrypt_filter (void *opaque, int control, int encrypt_filter (void *opaque, int control,
@ -492,7 +492,8 @@ void print_key_line (ctrl_t ctrl, estream_t fp, PKT_public_key *pk, int secret);
void print_file_status( int status, const char *name, int what ); void print_file_status( int status, const char *name, int what );
int verify_signatures (ctrl_t ctrl, int nfiles, char **files ); int verify_signatures (ctrl_t ctrl, int nfiles, char **files );
int verify_files (ctrl_t ctrl, int nfiles, char **files ); int verify_files (ctrl_t ctrl, int nfiles, char **files );
int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp); int gpg_verify (ctrl_t ctrl, gnupg_fd_t sig_fd, gnupg_fd_t data_fd,
estream_t out_fp);
void check_assert_signer_list (const char *mainpkhex, const char *pkhex); void check_assert_signer_list (const char *mainpkhex, const char *pkhex);
/*-- decrypt.c --*/ /*-- decrypt.c --*/

View File

@ -240,7 +240,8 @@ verify_files (ctrl_t ctrl, int nfiles, char **files )
FIXME: OUTFP is not yet implemented. FIXME: OUTFP is not yet implemented.
*/ */
int int
gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp) gpg_verify (ctrl_t ctrl, gnupg_fd_t sig_fd, gnupg_fd_t data_fd,
estream_t out_fp)
{ {
int rc; int rc;
iobuf_t fp; iobuf_t fp;