diff options
author | Werner Koch <wk@gnupg.org> | 2010-03-08 13:22:18 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2010-03-08 13:22:18 +0100 |
commit | 943aaf0cba2c222f740b2f81725739cfb6e6ec72 (patch) | |
tree | 267ee23ec1a0f7257e6e680cc5b0412fd7b7f3cd /sm | |
parent | Changes required to use estream in gpgsm. (diff) | |
download | gnupg2-943aaf0cba2c222f740b2f81725739cfb6e6ec72.tar.xz gnupg2-943aaf0cba2c222f740b2f81725739cfb6e6ec72.zip |
Replace use stdio by estream functions.
Diffstat (limited to 'sm')
-rw-r--r-- | sm/ChangeLog | 130 | ||||
-rw-r--r-- | sm/base64.c | 24 | ||||
-rw-r--r-- | sm/decrypt.c | 19 | ||||
-rw-r--r-- | sm/encrypt.c | 28 | ||||
-rw-r--r-- | sm/export.c | 31 | ||||
-rw-r--r-- | sm/gpgsm.c | 31 | ||||
-rw-r--r-- | sm/gpgsm.h | 14 | ||||
-rw-r--r-- | sm/import.c | 38 | ||||
-rw-r--r-- | sm/server.c | 43 | ||||
-rw-r--r-- | sm/sign.c | 36 | ||||
-rw-r--r-- | sm/verify.c | 34 |
11 files changed, 229 insertions, 199 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog index 6b52cd811..bb979f996 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,29 @@ +2010-03-08 Werner Koch <wk@g10code.com> + + * 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. + * 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. + * 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. + * sign.c (hash_data, hash_and_copy_data): Use estream. + (gpgsm_sign): Change arg OUT_FP to an estream_t. + * verify.c (gpgsm_verify): Rename FP to IN_FP. Change FP and arg + OUT_FP to an estream_t. + (hash_data): Use estream. + * base64.c (struct reader_cb_parm_s): Change FP to an estream_t. + (gpgsm_create_reader): Ditto. + (simple_reader_cb, base64_reader_cb): Adjust accordingly. + * decrypt.c (gpgsm_decrypt): Change OUT_FP and IN_FP to an estream_t. + * encrypt.c (gpgsm_encrypt): Change OUT_FP to an estream_t. Ditto + for DATA_FD. + (encrypt_cb): Use estream. + * gpgsm.c (main) <aEncr, aVerify, aSign, aDecrypt>: Use estream + functions. + 2009-12-14 Werner Koch <wk@g10code.com> * server.c (cmd_passwd): New. @@ -324,7 +350,7 @@ * server.c (cmd_encrypt): Ditto. (cmd_decrypt, cmd_verify, cmd_import, cmd_genkey): Ditto. * call-agent.c (gpgsm_scd_pksign): Ditto. - * call-dirmngr.c (release_dirmngr, release_dirmngr2) + * call-dirmngr.c (release_dirmngr, release_dirmngr2) (run_command_cb): Ditto. * certlist.c (gpgsm_add_cert_to_certlist): Ditto. * certchain.c (find_up_dirmngr): Ditto. @@ -364,7 +390,7 @@ 2008-09-03 Werner Koch <wk@g10code.com> * sign.c (MY_GCRY_MD_SHA224): New, so that we don't need libgcrypt - 1.2. + 1.2. 2008-08-13 Werner Koch <wk@g10code.com> @@ -468,7 +494,7 @@ (gpgsm_walk_cert_chain): Use it here. * gpgsm.c: Add option --no-common-certs-import. - + * certchain.c (find_up_dirmngr, find_up, do_validate_chain) (check_cert_policy): Be more silent with --quiet. @@ -481,8 +507,8 @@ * server.c (option_handler): Add option allow-pinentry-notify. (gpgsm_proxy_pinentry_notify): New. * call-agent.c (default_inq_cb): New. - (gpgsm_agent_pksign, gpgsm_scd_pksign, gpgsm_agent_readkey) - (gpgsm_agent_istrusted, gpgsm_agent_marktrusted) + (gpgsm_agent_pksign, gpgsm_scd_pksign, gpgsm_agent_readkey) + (gpgsm_agent_istrusted, gpgsm_agent_marktrusted) (gpgsm_agent_passwd, gpgsm_agent_get_confirmation): Call it. (struct cipher_parm_s, struct genkey_parm_s): Add field CTRL. (inq_ciphertext_cb): Test keyword and fallback to default_inq_cb. @@ -580,7 +606,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * gpgsm.c (get_status_string): Remove. * gpgsm.h: Include status.h instead of errors.h. - + 2007-10-19 Werner Koch <wk@g10code.com> * qualified.c (gpgsm_qualified_consent): Use i18N-swicth functions. @@ -594,7 +620,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2007-08-24 Werner Koch <wk@g10code.com> - * Makefile.am (common_libs): Swap libkeybox and jnlib. + * Makefile.am (common_libs): Swap libkeybox and jnlib. 2007-08-23 Werner Koch <wk@g10code.com> @@ -614,7 +640,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * import.c (parse_p12): Use gnupg_tmpfile. * export.c (export_p12): Ditto. - + 2007-08-20 Werner Koch <wk@g10code.com> * certreqgen.c (read_parameters): Change FP to an estream_t. @@ -669,7 +695,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2007-08-06 Werner Koch <wk@g10code.com> Implementation of the chain model. - + * gpgsm.h (struct rootca_flags_s): Define new members VALID and CHAIN_MODEL. * call-agent.c (gpgsm_agent_istrusted): Mark ROOTCA_FLAGS valid. @@ -721,7 +747,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> when passing an int value. * server.c (cmd_encrypt, cmd_decrypt, cmd_verify, cmd_import) (cmd_export, cmd_message, cmd_genkey): Translate file descriptors. - + 2007-07-05 Werner Koch <wk@g10code.com> * Makefile.am (common_libs): Changed order of libs. @@ -746,7 +772,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2007-06-24 Werner Koch <wk@g10code.com> * gpgsm.c (open_es_fwrite): Avoid the dup by using the new - es_fdopen_nc(). + es_fdopen_nc(). 2007-06-21 Werner Koch <wk@g10code.com> @@ -849,14 +875,14 @@ h2007-11-22 Werner Koch <wk@g10code.com> the certificate is not available. * gpgsm.c: Add option --p12-charset. - * gpgsm.h (struct opt): Add p12_charset. + * gpgsm.h (struct opt): Add p12_charset. * export.c (popen_protect_tool): Use new option. 2007-03-19 Werner Koch <wk@g10code.com> Changes to let export and key listing use estream to help systems without funopen. - + * keylist.c: Use estream in place of stdio functions. * gpgsm.c (open_es_fwrite): New. (main): Use it for the list commands. @@ -872,7 +898,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> (print_dn_parts): Ditto. * certchain.c (gpgsm_validate_chain): Changed FP to type estream_t. - (do_list, unknown_criticals, allowed_ca, check_cert_policy) + (do_list, unknown_criticals, allowed_ca, check_cert_policy) (is_cert_still_valid): Ditto. * export.c (gpgsm_export): New arg STREAM. @@ -974,7 +1000,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2006-10-17 Werner Koch <wk@g10code.com> - * gpgsm.c: No need for pth.h. + * gpgsm.c: No need for pth.h. (main): or to init it. It used to be hack for W32. * sign.c (gpgsm_get_default_cert): Changed to return only @@ -982,7 +1008,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2006-10-16 Werner Koch <wk@g10code.com> - * certchain.c (already_asked_marktrusted) + * certchain.c (already_asked_marktrusted) (set_already_asked_marktrusted): New. (gpgsm_validate_chain) <not trusted>: Keep track of certificates we already asked for. @@ -1014,7 +1040,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * certchain.c (gpgsm_validate_chain): More changes for the relax feature. Use certificate reference counting instead of the old - explicit tests. Added a missing free. + explicit tests. Added a missing free. 2006-09-25 Werner Koch <wk@g10code.com> @@ -1065,9 +1091,9 @@ h2007-11-22 Werner Koch <wk@g10code.com> Replaced all Assuan error codes by libgpg-error codes. Removed all map_to_assuan_status and map_assuan_err. - + * gpgsm.c (main): Call assuan_set_assuan_err_source to have Assuan - switch to gpg-error codes. + switch to gpg-error codes. * server.c (set_error): Adjusted. 2006-08-29 Werner Koch <wk@g10code.com> @@ -1111,7 +1137,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * keydb.c (keydb_delete): Likewise. Only unlock if this is set. * delete.c (delete_one): Add new argument to invocation of keydb_delete. - + 2006-05-15 Werner Koch <wk@g10code.com> * keylist.c (print_names_raw): Sanitize URI. @@ -1330,7 +1356,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> (run_command_status_cb): Return cancel status if gpgsm_status returned an error. - * server.c (gpgsm_status, gpgsm_status2) + * server.c (gpgsm_status, gpgsm_status2) (gpgsm_status_with_err_code): Return an error code. (gpgsm_status2): Always call va_end(). @@ -1420,7 +1446,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * Makefile.am: Adjusted for gettext 0.14. * keylist.c (list_cert_colon): Make sure that the expired flag has - a higher precedence than the invalid flag. + a higher precedence than the invalid flag. 2004-09-29 Werner Koch <wk@g10code.com> @@ -1455,7 +1481,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * certchain.c (gpgsm_basic_cert_check): Print more detailed error messages. - + * certcheck.c (do_encode_md): Partly support DSA. Add new arg PKALGO. Changed all callers to pass it. (pk_algo_from_sexp): New. @@ -1492,7 +1518,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2004-06-06 Werner Koch <wk@gnupg.org> * certreqgen.c (get_parameter_uint, create_request): Create - an extension for key usage when requested. + an extension for key usage when requested. 2004-05-12 Werner Koch <wk@gnupg.org> @@ -1548,9 +1574,9 @@ h2007-11-22 Werner Koch <wk@g10code.com> * gpgsm.c (main) <gpgconf>: Do not use /dev/null as default config filename. - * call-agent.c (gpgsm_agent_pksign, gpgsm_agent_pkdecrypt) - (gpgsm_agent_genkey, gpgsm_agent_istrusted) - (gpgsm_agent_marktrusted, gpgsm_agent_havekey) + * call-agent.c (gpgsm_agent_pksign, gpgsm_agent_pkdecrypt) + (gpgsm_agent_genkey, gpgsm_agent_istrusted) + (gpgsm_agent_marktrusted, gpgsm_agent_havekey) (gpgsm_agent_passwd): Add new arg CTRL and changed all callers. (start_agent): New arg CTRL. Send progress item when starting a new agent. @@ -1582,7 +1608,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2004-04-08 Werner Koch <wk@gnupg.org> - * decrypt.c (gpgsm_decrypt): Return GPG_ERR_NO_DATA if it is not a + * decrypt.c (gpgsm_decrypt): Return GPG_ERR_NO_DATA if it is not a encrypted message. 2004-04-07 Werner Koch <wk@gnupg.org> @@ -1686,12 +1712,12 @@ h2007-11-22 Werner Koch <wk@g10code.com> * export.c (export_p12, popen_protect_tool) (gpgsm_p12_export): New. - * gpgsm.c (main): New command --export-secret-key-p12. + * gpgsm.c (main): New command --export-secret-key-p12. 2004-02-18 Werner Koch <wk@gnupg.org> * gpgsm.c (set_debug): Set the new --debug-level flags. - (main): New option --gpgconf-list. + (main): New option --gpgconf-list. (main): Do not setup -u and -r keys when not required. (main): Setup the used character set. @@ -1713,7 +1739,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> WITH_VALIDATION. Changed callers to set it. (list_external_cb, list_external_keys): Pass CTRL to the callback. (list_cert_colon): Add arg CTRL. Check validation if requested. - * certchain.c (unknown_criticals, allowed_ca, check_cert_policy) + * certchain.c (unknown_criticals, allowed_ca, check_cert_policy) (gpgsm_validate_chain): New args LISTMODE and FP. (do_list): New helper for info output. (find_up): New arg FIND_NEXT. @@ -1730,7 +1756,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * certcheck.c (gpgsm_create_cms_signature): Format a description for use by the pinentry. * decrypt.c (gpgsm_decrypt): Ditto. Free HEXKEYGRIP. - * certdump.c (format_name_cookie, format_name_writer) + * certdump.c (format_name_cookie, format_name_writer) (gpgsm_format_name): New. (gpgsm_format_serial): New. (gpgsm_format_keydesc): New. @@ -1804,7 +1830,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> (print_dn_part): Do not delimit multiple RDN by " + ". Handle multi-valued RDNs in a special way, i.e. in the order specified by the certificate. - (print_dn_parts): Simplified. + (print_dn_parts): Simplified. 2004-01-16 Werner Koch <wk@gnupg.org> @@ -1892,7 +1918,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2003-08-14 Timo Schulz <twoaday@freakmail.de> * encrypt.c (encode_session_key): Use new Libgcrypt interface. - + 2003-07-31 Werner Koch <wk@gnupg.org> * Makefile.am (gpgsm_LDADD): Added INTLLIBS. @@ -1915,7 +1941,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * verify.c (strtimestamp): Renamed to strtimestamp_r Adjusted for changes in the libgcrypt API. Some more fixes for the - libgpg-error stuff. + libgpg-error stuff. 2003-06-04 Werner Koch <wk@gnupg.org> @@ -1944,7 +1970,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2002-11-25 Werner Koch <wk@gnupg.org> - * verify.c (gpgsm_verify): Handle content-type attribute. + * verify.c (gpgsm_verify): Handle content-type attribute. 2002-11-13 Werner Koch <wk@gnupg.org> @@ -1954,7 +1980,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2002-11-12 Werner Koch <wk@gnupg.org> - * gpgsm.c: New command --call-dirmngr. + * gpgsm.c: New command --call-dirmngr. * call-dirmngr.c (gpgsm_dirmngr_run_command) (run_command_inq_cb,run_command_cb) (run_command_status_cb): New. @@ -1972,7 +1998,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * certcheck.c (gpgsm_check_cert_sig): Add cert hash debugging. - * certchain.c (find_up): Print info when the cert was not found + * certchain.c (find_up): Print info when the cert was not found by the autorithyKeyIdentifier. 2002-09-03 Werner Koch <wk@gnupg.org> @@ -2046,10 +2072,10 @@ h2007-11-22 Werner Koch <wk@g10code.com> * sign.c (gpgsm_sign): New argument SIGNERLIST and implemt multiple signers. * gpgsm.c (main): Support more than one -u. - + * server.c (cmd_recipient): Return reason code 1 for No_Public_Key which is actually what gets returned from add_to_certlist. - + 2002-07-26 Werner Koch <wk@gnupg.org> * certcheck.c (gpgsm_check_cert_sig): Implement proper cleanup. @@ -2151,7 +2177,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2002-06-24 Werner Koch <wk@gnupg.org> * gpgsm.c: Removed duped help entry for --list-keys. - + * gpgsm.c, gpgsm.h: New option --debug-no-path-validation. * certpath.c (gpgsm_validate_path): Use it here instead of the @@ -2194,7 +2220,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * export.c (gpgsm_export): Kludge to export epehmeral certificates. * gpgsm.c (main): New command --list-external-keys. - + 2002-06-17 Werner Koch <wk@gnupg.org> * certreqgen.c (read_parameters): Improved error handling. @@ -2216,7 +2242,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * sign.c (hash_and_copy_data): New. (gpgsm_sign): Implemented normal (non-detached) signatures. * gpgsm.c (main): Ditto. - + * certpath.c (gpgsm_validate_path): Special error handling for no policy match. @@ -2224,7 +2250,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * server.c (get_status_string): Add STATUS_ERROR. - * certpath.c (gpgsm_validate_path): Tweaked the error checking to + * certpath.c (gpgsm_validate_path): Tweaked the error checking to return error codes in a more sensitive way. * verify.c (gpgsm_verify): Send status TRUST_NEVER also for a bad CA certificate and when the certificate has been revoked. Issue @@ -2346,7 +2372,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * export.c: New. * gpgsm.c: Add command --export. * server.c (cmd_export): New. - + 2002-03-13 Werner Koch <wk@gnupg.org> * decrypt.c (gpgsm_decrypt): Allow multiple recipients. @@ -2588,10 +2614,10 @@ h2007-11-22 Werner Koch <wk@g10code.com> print the first item. * keylist.c (list_cert_colon): Ditto. * keydb.c (keydb_search_issuer_sn): Ditto. - * decrypt.c (print_integer_sexp): Removed and made callers + * decrypt.c (print_integer_sexp): Removed and made callers use gpgsm_dump_serial. * verify.c (print_time): Removed, made callers use gpgsm_dump_time. - + 2001-12-19 Marcus Brinkmann <marcus@g10code.de> * call-agent.c (start_agent): Add new argument to assuan_pipe_connect. @@ -2647,7 +2673,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> * base64.c (base64_reader_cb): Reset the linelen when we need to skip the line and adjusted test; I somehow forgot about DeMorgan. - * server.c (cmd_encrypt,cmd_decrypt,cmd_sign,cmd_verify) + * server.c (cmd_encrypt,cmd_decrypt,cmd_sign,cmd_verify) (cmd_import): Close the FDs on success. (close_message_fd): New. (input_notify): Setting autodetect_encoding to 0 after initializing @@ -2671,7 +2697,7 @@ h2007-11-22 Werner Koch <wk@g10code.com> 2001-12-12 Werner Koch <wk@gnupg.org> - * gpgsm.c (main): New options --assume-{armor,base64,binary}. + * gpgsm.c (main): New options --assume-{armor,base64,binary}. * base64.c (base64_reader_cb): Fixed non-autodetection mode. 2001-12-04 Werner Koch <wk@gnupg.org> @@ -2699,9 +2725,9 @@ h2007-11-22 Werner Koch <wk@g10code.com> * server.c (rc_to_assuan_status): New. Use it for all commands. - - Copyright 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009 Free Software Foundation, Inc. + + Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without diff --git a/sm/base64.c b/sm/base64.c index b0c8dc8e8..a3af04ae3 100644 --- a/sm/base64.c +++ b/sm/base64.c @@ -1,5 +1,5 @@ /* base64.c - * Copyright (C) 2001, 2003 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -39,9 +39,10 @@ #define LF "\n" #endif -/* data used by the reader callbacks */ -struct reader_cb_parm_s { - FILE *fp; +/* Data used by the reader callbacks. */ +struct reader_cb_parm_s +{ + estream_t fp; unsigned char line[1024]; int linelen; @@ -69,7 +70,8 @@ struct reader_cb_parm_s { } base64; }; -/* data used by the writer callbacks */ + +/* Data used by the writer callbacks. */ struct writer_cb_parm_s { FILE *fp; /* FP is only used if STREAM is NULL. */ estream_t stream; /* Alternative output if not NULL. */ @@ -179,11 +181,11 @@ base64_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) parm->have_lf = 0; for (n=0; n < DIM(parm->line);) { - c = getc (parm->fp); + c = es_getc (parm->fp); if (c == EOF) { parm->eof_seen = 1; - if (ferror (parm->fp)) + if (es_ferror (parm->fp)) return -1; break; } @@ -382,14 +384,14 @@ simple_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) for (n=0; n < count; n++) { - c = getc (parm->fp); + c = es_getc (parm->fp); if (c == EOF) { parm->eof_seen = 1; - if ( ferror (parm->fp) ) + if (es_ferror (parm->fp)) return -1; if (n) - break; /* return what we have before an EOF */ + break; /* Return what we have before an EOF. */ return -1; } *(byte *)buffer++ = c; @@ -579,7 +581,7 @@ base64_finish_write (struct writer_cb_parm_s *parm) until no more objects were found. */ int gpgsm_create_reader (Base64Context *ctx, - ctrl_t ctrl, FILE *fp, int allow_multi_pem, + ctrl_t ctrl, estream_t fp, int allow_multi_pem, ksba_reader_t *r_reader) { int rc; diff --git a/sm/decrypt.c b/sm/decrypt.c index de025516f..0ac682242 100644 --- a/sm/decrypt.c +++ b/sm/decrypt.c @@ -1,5 +1,5 @@ /* decrypt.c - Decrypt a message - * Copyright (C) 2001, 2003 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -33,7 +33,8 @@ #include "keydb.h" #include "i18n.h" -struct decrypt_filter_parm_s { +struct decrypt_filter_parm_s +{ int algo; int mode; int blklen; @@ -237,7 +238,7 @@ decrypt_filter (void *arg, /* Perform a decrypt operation. */ int -gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp) +gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp) { int rc; Base64Context b64reader = NULL; @@ -248,7 +249,7 @@ gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp) ksba_stop_reason_t stopreason; KEYDB_HANDLE kh; int recp; - FILE *in_fp = NULL; + estream_t in_fp = NULL; struct decrypt_filter_parm_s dfparm; memset (&dfparm, 0, sizeof dfparm); @@ -263,11 +264,10 @@ gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp) goto leave; } - - in_fp = fdopen ( dup (in_fd), "rb"); + in_fp = es_fdopen_nc (in_fd, "rb"); if (!in_fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } @@ -279,7 +279,7 @@ gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp) goto leave; } - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); @@ -576,8 +576,7 @@ gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp) gpgsm_destroy_reader (b64reader); gpgsm_destroy_writer (b64writer); keydb_release (kh); - if (in_fp) - fclose (in_fp); + es_fclose (in_fp); if (dfparm.hd) gcry_cipher_close (dfparm.hd); return rc; diff --git a/sm/encrypt.c b/sm/encrypt.c index a526a649e..2941e49cb 100644 --- a/sm/encrypt.c +++ b/sm/encrypt.c @@ -1,5 +1,6 @@ /* encrypt.c - Encrypt a message - * Copyright (C) 2001, 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2004, 2007, 2008, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -45,8 +46,11 @@ struct dek_s { }; typedef struct dek_s *DEK; -struct encrypt_cb_parm_s { - FILE *fp; + +/* Callback parameters for the encryption. */ +struct encrypt_cb_parm_s +{ + estream_t fp; DEK dek; int eof_seen; int ready; @@ -239,10 +243,10 @@ encrypt_cb (void *cb_value, char *buffer, size_t count, size_t *nread) p = parm->buffer; for (n=parm->buflen; n < parm->bufsize; n++) { - int c = getc (parm->fp); + int c = es_getc (parm->fp); if (c == EOF) { - if (ferror (parm->fp)) + if (es_ferror (parm->fp)) { parm->readerror = errno; return -1; @@ -289,7 +293,7 @@ encrypt_cb (void *cb_value, char *buffer, size_t count, size_t *nread) recipients are take from the certificate given in recplist; if this is NULL it will be encrypted for a default recipient */ int -gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, FILE *out_fp) +gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, estream_t out_fp) { int rc = 0; Base64Context b64writer = NULL; @@ -302,7 +306,7 @@ gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, FILE *out_fp) struct encrypt_cb_parm_s encparm; DEK dek = NULL; int recpno; - FILE *data_fp = NULL; + estream_t data_fp = NULL; certlist_t cl; int count; @@ -337,10 +341,11 @@ gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, FILE *out_fp) goto leave; } - data_fp = fdopen ( dup (data_fd), "rb"); + /* Fixme: We should use the unlocked version of the es functions. */ + data_fp = es_fdopen_nc (data_fd, "rb"); if (!data_fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } @@ -356,7 +361,7 @@ gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, FILE *out_fp) encparm.fp = data_fp; ctrl->pem_name = "ENCRYPTED MESSAGE"; - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); @@ -506,8 +511,7 @@ gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, FILE *out_fp) ksba_reader_release (reader); keydb_release (kh); xfree (dek); - if (data_fp) - fclose (data_fp); + es_fclose (data_fp); xfree (encparm.buffer); return rc; } diff --git a/sm/export.c b/sm/export.c index b194d0dd1..9a05b5176 100644 --- a/sm/export.c +++ b/sm/export.c @@ -1,5 +1,6 @@ /* export.c - Export certificates and private keys. - * Copyright (C) 2002, 2003, 2004, 2007, 2009 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003, 2004, 2007, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -60,7 +61,7 @@ static void print_short_info (ksba_cert_t cert, FILE *fp, estream_t stream); static gpg_error_t export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen, const char *prompt, const char *keygrip, - FILE **retfp); + estream_t *retfp); /* Create a table used to indetify duplicated certificates. */ @@ -341,7 +342,7 @@ gpgsm_p12_export (ctrl_t ctrl, const char *name, FILE *fp) char *prompt; char buffer[1024]; int nread; - FILE *datafp = NULL; + estream_t datafp = NULL; hd = keydb_new (0); @@ -447,16 +448,16 @@ gpgsm_p12_export (ctrl_t ctrl, const char *name, FILE *fp) xfree (prompt); if (rc) goto leave; - rewind (datafp); - while ( (nread = fread (buffer, 1, sizeof buffer, datafp)) > 0 ) + es_rewind (datafp); + while ( (nread = es_fread (buffer, 1, sizeof buffer, datafp)) > 0 ) if ((rc = ksba_writer_write (writer, buffer, nread))) { log_error ("write failed: %s\n", gpg_strerror (rc)); goto leave; } - if (ferror (datafp)) + if (es_ferror (datafp)) { - rc = gpg_error_from_errno (rc); + rc = gpg_error_from_syserror (); log_error ("error reading temporary file: %s\n", gpg_strerror (rc)); goto leave; } @@ -478,8 +479,7 @@ gpgsm_p12_export (ctrl_t ctrl, const char *name, FILE *fp) cert = NULL; leave: - if (datafp) - fclose (datafp); + es_fclose (datafp); gpgsm_destroy_writer (b64writer); ksba_cert_release (cert); xfree (desc); @@ -570,7 +570,7 @@ print_short_info (ksba_cert_t cert, FILE *fp, estream_t stream) static gpg_error_t popen_protect_tool (ctrl_t ctrl, const char *pgmname, - FILE *infile, FILE *outfile, FILE **statusfile, + FILE *infile, estream_t outfile, FILE **statusfile, const char *prompt, const char *keygrip, pid_t *pid) { @@ -614,14 +614,14 @@ popen_protect_tool (ctrl_t ctrl, const char *pgmname, static gpg_error_t export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen, - const char *prompt, const char *keygrip, - FILE **retfp) + const char *prompt, const char *keygrip, estream_t *retfp) { const char *pgmname; gpg_error_t err = 0, child_err = 0; int c, cont_line; unsigned int pos; - FILE *infp = NULL, *outfp = NULL, *fp = NULL; + FILE *infp = NULL, *fp = NULL; + estream_t outfp = NULL; char buffer[1024]; pid_t pid = -1; int bad_pass = 0; @@ -647,7 +647,7 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen, goto cleanup; } - outfp = gnupg_tmpfile (); + outfp = es_tmpfile (); if (!outfp) { err = gpg_error_from_syserror (); @@ -731,8 +731,7 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen, err = child_err; if (err) { - if (outfp) - fclose (outfp); + es_fclose (outfp); } else *retfp = outfp; diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 94cc23dec..8a8c017d9 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -1,6 +1,6 @@ /* gpgsm.c - GnuPG for S/MIME - * Copyright (C) 2001, 2002, 2003, 2004, 2005, - * 2006, 2007, 2008 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -1702,7 +1702,7 @@ main ( int argc, char **argv) case aEncr: /* Encrypt the given file. */ { - FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-"); + estream_t fp = open_es_fwrite (opt.outfile?opt.outfile:"-"); set_binary (stdin); @@ -1713,14 +1713,13 @@ main ( int argc, char **argv) else wrong_args ("--encrypt [datafile]"); - if (fp != stdout) - fclose (fp); + es_fclose (fp); } break; case aSign: /* Sign the given file. */ { - FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-"); + estream_t fp = open_es_fwrite (opt.outfile?opt.outfile:"-"); /* Fixme: We should also allow to concatenate multiple files for signing because that is what gpg does.*/ @@ -1733,8 +1732,7 @@ main ( int argc, char **argv) else wrong_args ("--sign [datafile]"); - if (fp != stdout) - fclose (fp); + es_fclose (fp); } break; @@ -1748,13 +1746,13 @@ main ( int argc, char **argv) case aVerify: { - FILE *fp = NULL; + estream_t fp = NULL; set_binary (stdin); if (argc == 2 && opt.outfile) log_info ("option --output ignored for a detached signature\n"); else if (opt.outfile) - fp = open_fwrite (opt.outfile); + fp = open_es_fwrite (opt.outfile); if (!argc) gpgsm_verify (&ctrl, 0, -1, fp); /* normal signature from stdin */ @@ -1765,14 +1763,13 @@ main ( int argc, char **argv) else wrong_args ("--verify [signature [detached_data]]"); - if (fp && fp != stdout) - fclose (fp); + es_fclose (fp); } break; case aDecrypt: { - FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-"); + estream_t fp = open_es_fwrite (opt.outfile?opt.outfile:"-"); set_binary (stdin); if (!argc) @@ -1781,8 +1778,8 @@ main ( int argc, char **argv) gpgsm_decrypt (&ctrl, open_read (*argv), fp); /* from file */ else wrong_args ("--decrypt [filename]"); - if (fp != stdout) - fclose (fp); + + es_fclose (fp); } break; @@ -2034,9 +2031,9 @@ check_special_filename (const char *fname, int for_write) -/* Open the FILENAME for read and return the filedescriptor. Stop +/* Open the FILENAME for read and return the file descriptor. Stop with an error message in case of problems. "-" denotes stdin and - if special filenames are allowed the given fd is opened instead. */ + if special filenames are allowed the given fd is opened instead. */ static int open_read (const char *filename) { diff --git a/sm/gpgsm.h b/sm/gpgsm.h index c4a261bf2..1a8aab91b 100644 --- a/sm/gpgsm.h +++ b/sm/gpgsm.h @@ -1,5 +1,6 @@ /* gpgsm.h - Global definitions for GpgSM - * Copyright (C) 2001, 2003, 2004, 2007, 2009 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2004, 2007, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -255,7 +256,7 @@ char *gpgsm_get_certid (ksba_cert_t cert); /*-- base64.c --*/ int gpgsm_create_reader (Base64Context *ctx, - ctrl_t ctrl, FILE *fp, int allow_multi_pem, + ctrl_t ctrl, estream_t fp, int allow_multi_pem, ksba_reader_t *r_reader); int gpgsm_reader_eof_seen (Base64Context ctx); void gpgsm_destroy_reader (Base64Context ctx); @@ -350,18 +351,19 @@ void gpgsm_p12_export (ctrl_t ctrl, const char *name, FILE *fp); int gpgsm_delete (ctrl_t ctrl, strlist_t names); /*-- verify.c --*/ -int gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp); +int gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, estream_t out_fp); /*-- sign.c --*/ int gpgsm_get_default_cert (ctrl_t ctrl, ksba_cert_t *r_cert); int gpgsm_sign (ctrl_t ctrl, certlist_t signerlist, - int data_fd, int detached, FILE *out_fp); + int data_fd, int detached, estream_t out_fp); /*-- encrypt.c --*/ -int gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int in_fd, FILE *out_fp); +int gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, + int in_fd, estream_t out_fp); /*-- decrypt.c --*/ -int gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp); +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); diff --git a/sm/import.c b/sm/import.c index bcc2d6d44..b2383d80f 100644 --- a/sm/import.c +++ b/sm/import.c @@ -48,8 +48,8 @@ struct stats_s { }; -static gpg_error_t parse_p12 (ctrl_t ctrl, ksba_reader_t reader, FILE **retfp, - struct stats_s *stats); +static gpg_error_t parse_p12 (ctrl_t ctrl, ksba_reader_t reader, + estream_t *retfp, struct stats_s *stats); @@ -254,14 +254,14 @@ import_one (ctrl_t ctrl, struct stats_s *stats, int in_fd) ksba_reader_t reader; ksba_cert_t cert = NULL; ksba_cms_t cms = NULL; - FILE *fp = NULL; + estream_t fp = NULL; ksba_content_type_t ct; int any = 0; - fp = fdopen ( dup (in_fd), "rb"); + fp = es_fdopen_nc (in_fd, "rb"); if (!fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } @@ -331,7 +331,7 @@ import_one (ctrl_t ctrl, struct stats_s *stats, int in_fd) certificate we included in the p12 file; then we continue to look for other pkcs12 files (works only if they are in PEM format. */ - FILE *certfp; + estream_t certfp; Base64Context b64p12rdr; ksba_reader_t p12rdr; @@ -340,12 +340,12 @@ import_one (ctrl_t ctrl, struct stats_s *stats, int in_fd) { any = 1; - rewind (certfp); + es_rewind (certfp); rc = gpgsm_create_reader (&b64p12rdr, ctrl, certfp, 1, &p12rdr); if (rc) { log_error ("can't create reader: %s\n", gpg_strerror (rc)); - fclose (certfp); + es_fclose (certfp); goto leave; } @@ -366,7 +366,7 @@ import_one (ctrl_t ctrl, struct stats_s *stats, int in_fd) if (gpg_err_code (rc) == GPG_ERR_EOF) rc = 0; gpgsm_destroy_reader (b64p12rdr); - fclose (certfp); + es_fclose (certfp); if (rc) goto leave; } @@ -401,8 +401,7 @@ import_one (ctrl_t ctrl, struct stats_s *stats, int in_fd) ksba_cms_release (cms); ksba_cert_release (cert); gpgsm_destroy_reader (b64reader); - if (fp) - fclose (fp); + es_fclose (fp); return rc; } @@ -585,7 +584,8 @@ gpgsm_import_files (ctrl_t ctrl, int nfiles, char **files, success or an error code. */ static gpg_error_t popen_protect_tool (ctrl_t ctrl, const char *pgmname, - FILE *infile, FILE *outfile, FILE **statusfile, pid_t *pid) + FILE *infile, estream_t outfile, + FILE **statusfile, pid_t *pid) { const char *argv[22]; int i=0; @@ -627,17 +627,18 @@ popen_protect_tool (ctrl_t ctrl, const char *pgmname, certificates from that stupid format. We will also store secret keys. All of the pkcs#12 parsing and key storing is handled by the gpg-protect-tool, we merely have to take care of receiving the - certificates. On success RETFP returns a temporary file with - certificates. */ + certificates. On success RETFP returns a stream to a temporary + file with certificates. */ static gpg_error_t parse_p12 (ctrl_t ctrl, ksba_reader_t reader, - FILE **retfp, struct stats_s *stats) + estream_t *retfp, struct stats_s *stats) { const char *pgmname; gpg_error_t err = 0, child_err = 0; int c, cont_line; unsigned int pos; - FILE *tmpfp, *certfp = NULL, *fp = NULL; + FILE *tmpfp, *fp = NULL; + estream_t certfp = NULL; char buffer[1024]; size_t nread; pid_t pid = -1; @@ -679,7 +680,7 @@ parse_p12 (ctrl_t ctrl, ksba_reader_t reader, goto cleanup; } - certfp = gnupg_tmpfile (); + certfp = es_tmpfile (); if (!certfp) { err = gpg_error_from_syserror (); @@ -780,8 +781,7 @@ parse_p12 (ctrl_t ctrl, ksba_reader_t reader, err = child_err; if (err) { - if (certfp) - fclose (certfp); + es_fclose (certfp); } else *retfp = certfp; diff --git a/sm/server.c b/sm/server.c index de245f5ad..e4de5dca8 100644 --- a/sm/server.c +++ b/sm/server.c @@ -1,6 +1,6 @@ /* server.c - Server mode and main entry point - * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -451,7 +451,7 @@ cmd_encrypt (assuan_context_t ctx, char *line) ctrl_t ctrl = assuan_get_pointer (ctx); certlist_t cl; int inp_fd, out_fd; - FILE *out_fp; + estream_t out_fp; int rc; (void)line; @@ -463,9 +463,9 @@ cmd_encrypt (assuan_context_t ctx, char *line) if (out_fd == -1) return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); - out_fp = fdopen (dup (out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); /* Now add all encrypt-to marked recipients from the default list. */ @@ -483,7 +483,7 @@ cmd_encrypt (assuan_context_t ctx, char *line) rc = gpgsm_encrypt (assuan_get_pointer (ctx), ctrl->server_local->recplist, inp_fd, out_fp); - fclose (out_fp); + es_fclose (out_fp); gpgsm_release_certlist (ctrl->server_local->recplist); ctrl->server_local->recplist = NULL; @@ -508,7 +508,7 @@ cmd_decrypt (assuan_context_t ctx, char *line) { ctrl_t ctrl = assuan_get_pointer (ctx); int inp_fd, out_fd; - FILE *out_fp; + estream_t out_fp; int rc; (void)line; @@ -520,16 +520,16 @@ cmd_decrypt (assuan_context_t ctx, char *line) if (out_fd == -1) return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); - out_fp = fdopen (dup(out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + 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); - fclose (out_fp); + es_fclose (out_fp); - /* close and reset the fd */ + /* Close and reset the fds. */ close_message_fd (ctrl); assuan_close_input_fd (ctx); assuan_close_output_fd (ctx); @@ -554,7 +554,7 @@ cmd_verify (assuan_context_t ctx, char *line) ctrl_t ctrl = assuan_get_pointer (ctx); int fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0); int out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1); - FILE *out_fp = NULL; + estream_t out_fp = NULL; (void)line; @@ -563,19 +563,18 @@ cmd_verify (assuan_context_t ctx, char *line) if (out_fd != -1) { - out_fp = fdopen ( dup(out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); } rc = start_audit_session (ctrl); if (!rc) rc = gpgsm_verify (assuan_get_pointer (ctx), fd, ctrl->server_local->message_fd, out_fp); - if (out_fp) - fclose (out_fp); + es_fclose (out_fp); - /* close and reset the fd */ + /* Close and reset the fd. */ close_message_fd (ctrl); assuan_close_input_fd (ctx); assuan_close_output_fd (ctx); @@ -595,7 +594,7 @@ cmd_sign (assuan_context_t ctx, char *line) { ctrl_t ctrl = assuan_get_pointer (ctx); int inp_fd, out_fd; - FILE *out_fp; + estream_t out_fp; int detached; int rc; @@ -608,7 +607,7 @@ cmd_sign (assuan_context_t ctx, char *line) detached = has_option (line, "--detached"); - out_fp = fdopen ( dup(out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); @@ -616,7 +615,7 @@ cmd_sign (assuan_context_t ctx, char *line) if (!rc) rc = gpgsm_sign (assuan_get_pointer (ctx), ctrl->server_local->signerlist, inp_fd, detached, out_fp); - fclose (out_fp); + es_fclose (out_fp); /* close and reset the fd */ close_message_fd (ctrl); @@ -916,9 +915,9 @@ do_listkeys (assuan_context_t ctx, char *line, int mode) if ( outfd == -1 ) return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); - fp = es_fdopen ( dup (outfd), "w"); + fp = es_fdopen_nc (outfd, "w"); if (!fp) - return set_error (GPG_ERR_ASS_GENERAL, "es_fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "es_fdopen() failed"); } else { @@ -1,5 +1,6 @@ /* sign.c - Sign a message - * Copyright (C) 2001, 2002, 2003, 2008 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2008, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -38,12 +39,12 @@ static int hash_data (int fd, gcry_md_hd_t md) { - FILE *fp; + estream_t fp; char buffer[4096]; int nread; int rc = 0; - fp = fdopen ( dup (fd), "rb"); + fp = es_fdopen_nc (fd, "rb"); if (!fp) { log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno)); @@ -52,40 +53,41 @@ hash_data (int fd, gcry_md_hd_t md) do { - nread = fread (buffer, 1, DIM(buffer), fp); + nread = es_fread (buffer, 1, DIM(buffer), fp); gcry_md_write (md, buffer, nread); } while (nread); - if (ferror (fp)) + if (es_ferror (fp)) { log_error ("read error on fd %d: %s\n", fd, strerror (errno)); rc = -1; } - fclose (fp); + es_fclose (fp); return rc; } + static int hash_and_copy_data (int fd, gcry_md_hd_t md, ksba_writer_t writer) { gpg_error_t err; - FILE *fp; + estream_t fp; char buffer[4096]; int nread; int rc = 0; int any = 0; - fp = fdopen ( dup (fd), "rb"); + fp = es_fdopen_nc (fd, "rb"); if (!fp) { - gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno)); + gpg_error_t tmperr = gpg_error_from_syserror (); log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno)); return tmperr; } do { - nread = fread (buffer, 1, DIM(buffer), fp); + nread = es_fread (buffer, 1, DIM(buffer), fp); if (nread) { any = 1; @@ -99,18 +101,18 @@ hash_and_copy_data (int fd, gcry_md_hd_t md, ksba_writer_t writer) } } while (nread && !rc); - if (ferror (fp)) + if (es_ferror (fp)) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("read error on fd %d: %s\n", fd, strerror (errno)); } - fclose (fp); + es_fclose (fp); if (!any) { /* We can't allow to sign an empty message because it does not - make much sense and more seriously, ksba-cms_build has + make much sense and more seriously, ksba_cms_build has already written the tag for data and now expects an octet - string but an octet string of zeize 0 is illegal. */ + string and an octet string of size 0 is illegal. */ log_error ("cannot sign an empty message\n"); rc = gpg_error (GPG_ERR_NO_DATA); } @@ -310,7 +312,7 @@ add_certificate_list (ctrl_t ctrl, ksba_cms_t cms, ksba_cert_t cert) be used if the value of this argument is NULL. */ int gpgsm_sign (ctrl_t ctrl, certlist_t signerlist, - int data_fd, int detached, FILE *out_fp) + int data_fd, int detached, estream_t out_fp) { int i, rc; gpg_error_t err; @@ -338,7 +340,7 @@ gpgsm_sign (ctrl_t ctrl, certlist_t signerlist, } ctrl->pem_name = "SIGNED MESSAGE"; - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); diff --git a/sm/verify.c b/sm/verify.c index c8663e3e6..e7e9512f8 100644 --- a/sm/verify.c +++ b/sm/verify.c @@ -1,5 +1,6 @@ /* verify.c - Verify a messages signature - * Copyright (C) 2001, 2002, 2003, 2007 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2007, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -52,11 +53,11 @@ static gpg_error_t hash_data (int fd, gcry_md_hd_t md) { gpg_error_t err = 0; - FILE *fp; + estream_t fp; char buffer[4096]; int nread; - fp = fdopen ( dup (fd), "rb"); + fp = es_fdopen_nc (fd, "rb"); if (!fp) { err = gpg_error_from_syserror (); @@ -66,27 +67,27 @@ hash_data (int fd, gcry_md_hd_t md) do { - nread = fread (buffer, 1, DIM(buffer), fp); + nread = es_fread (buffer, 1, DIM(buffer), fp); gcry_md_write (md, buffer, nread); } while (nread); - if (ferror (fp)) + if (es_ferror (fp)) { err = gpg_error_from_syserror (); log_error ("read error on fd %d: %s\n", fd, gpg_strerror (err)); } - fclose (fp); + es_fclose (fp); return err; } -/* Perform a verify operation. To verify detached signatures, data_fd +/* Perform a verify operation. To verify detached signatures, DATA_FD must be different than -1. With OUT_FP given and a non-detached - signature, the signed material is written to that stream. */ + signature, the signed material is written to that stream. */ int -gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp) +gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, estream_t out_fp) { int i, rc; Base64Context b64reader = NULL; @@ -102,7 +103,7 @@ gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp) const char *algoid; int algo; int is_detached; - FILE *fp = NULL; + estream_t in_fp = NULL; char *p; audit_set_type (ctrl->audit, AUDIT_TYPE_VERIFY); @@ -116,15 +117,15 @@ gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp) } - fp = fdopen ( dup (in_fd), "rb"); - if (!fp) + in_fp = es_fdopen_nc (in_fd, "rb"); + if (!in_fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } - rc = gpgsm_create_reader (&b64reader, ctrl, fp, 0, &reader); + rc = gpgsm_create_reader (&b64reader, ctrl, in_fp, 0, &reader); if (rc) { log_error ("can't create reader: %s\n", gpg_strerror (rc)); @@ -133,7 +134,7 @@ gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp) if (out_fp) { - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); @@ -644,8 +645,7 @@ gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp) gpgsm_destroy_writer (b64writer); keydb_release (kh); gcry_md_close (data_md); - if (fp) - fclose (fp); + es_fclose (in_fp); if (rc) { |