Commit Graph

736 Commits

Author SHA1 Message Date
Werner Koch b7fa4960c2
common: Minor fixes for the new private-keys.c.
* common/private-keys.c (my_error_from_syserror): New.  Use it in
place of gpg_error_from_syserror.
(_pkc_add, pkc_lookup, pke_next_value): Use ascii_strcasecmp.
(pkc_parse): Use xtrystrdup and append_to_strlist_try as intended.

(_pkc_add): Add braces around if-statement.
--

We should have a macro so that we do not need to define a wrapper
function like my_error_from_syserror in files where it is needed.  I
am not sure about a proper name, "my_" seems to be the easiest
replacement.  Note that the global DEFAULT_ERRSOURCE is relatively new
to replace the need to convey the error source in function calls; we
want that function from common/ return the error source of the main
binary.

We require that a key is ASCII and thus we better use ascii_strcasecmp
to avoid problems with strange locales.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-04-25 18:14:12 +02:00
Werner Koch 8776abbe02
common: Use new function to print a failure of xtrymalloc.
* common/miscellaneous.c (xoutofcore): New.
* common/strlist.c (append_to_strlist): Use instead of abort.
(append_to_strlist_try): Use xtrymalloc instead of xmalloc.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-04-25 17:26:57 +02:00
Justus Winter b8cb0973bc common: Drop unused variables, fix warnings.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-04-21 15:35:37 +02:00
Justus Winter 12af2630cf common: Add support for the new extended private key format.
* agent/findkey.c (write_extended_private_key): New function.
(agent_write_private_key): Detect if an existing file is in extended
format and update the key within if it is.
(read_key_file): Handle the new format.
* agent/keyformat.txt: Document the new format.
* common/Makefile.am: Add the new files.
* common/private-keys.c: New file.
* common/private-keys.h: Likewise.
* common/t-private-keys.c: Likewise.
* common/util.h (alphap, alnump): New macros.
* tests/migrations: Add test demonstrating that we can cope with the
new format.

--
GnuPG 2.3+ will use a new format to store private keys that is both
more flexible and easier to read and edit by human beings.  The new
format stores name,value-pairs using the common mail and http header
convention.

This patch adds the parser and support code and prepares GnuPG 2.1 for
the new format.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-04-21 14:38:53 +02:00
Justus Winter c6d1f2f08c common: Add 'free_strlist_wipe' which wipes memory.
* common/strlist.c (free_strlist_wipe): New function.
* common/strlist.h (free_strlist_wipe): New prototype.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-04-21 14:38:53 +02:00
Justus Winter 95303ee11d common: Add 'append_to_strlist_try' which can fail.
* common/strlist.c (append_to_strlist): Use the new function.
(append_to_strlist_try): New function.
* common/strlist.h (append_to_strlist_try): New prototype.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-04-21 14:38:53 +02:00
Werner Koch bd4d65615b
w32: Replace libiconv DLL by iconv feature of libgpg-error.
* configure.ac: Do nor require libiconv for W32.
* common/utf8conv.c [W32]: Do not incluce iconv.h.  Request
libgpg-error iconv macros.
(jnlib_iconv): Use ICONV_CONST macro.
* build-aux/speedo/w32/inst.nsi [!WITH_GUI]: Do not install libiconv.
* build-aux/speedo.mk (speedo_spkgs) [!WITH_GUI]: Likewise.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-04-21 09:17:11 +02:00
Justus Winter f8adf1a323 agent: Sanitize permissions of the private key directory.
* agent/gpg-agent.c (create_private_keys_directory): Set permissions.
* common/sysutils.c (modestr_to_mode): New function.
(gnupg_mkdir): Use new function.
(gnupg_chmod): New function.
* common/sysutils.h (gnupg_chmod): New prototype.
* tests/migrations/from-classic.test: Test migration with existing
directory.

GnuPG-bug-id: 2312
Signed-off-by: Justus Winter <justus@g10code.com>
2016-04-20 15:02:37 +02:00
Werner Koch 100b413d7f
doc: Note that the persistant passphrase format is unimplemented.
--
2016-04-12 14:38:44 +02:00
Werner Koch 96bcd4220f
Now build "gpg" binary but install as "gpg2"
* configure.ac (USE_GPG2_HACK): New ac_define am_conditional.
* common/homedir.c (gnupg_module_name): Replace use of macro
NAME_OF_INSTALLED_GPG.
* g10/keygen.c (generate_keypair): Ditto.
* g10/Makefile.am (bin_PROGRAMS): Remove.
(noinst_PROGRAMS): Add gpg or gpg2 and gpgv or gpg2.
(gpg2_hack_list): New.
(use_gpg2_hack): New.
(gpg2_SOURCES): Rename to gpg_SOURCES.
(gpgv2_SOURCES): Rename to gpgv_SOURCES.
(gpg2_LDADD): Rename to gpg_LDADD.
(gpgv2_LDADD): Rename to gpgv_LDADD.
(gpg2_LDFLAGS): Rename to gpg_LDFLAGS.
(gpgv2_LDFLAGS): Rename to gpgv2_LDFLAGS.
(install-exec-hook): Remove WinCE specific rules and add new rules.
(uninstall-local): Uninstall gpg/gpg2 and gpgv/gpgv2.
* tests/openpgp/Makefile.am (required_pgms): s/gpg2/gpg/.
* tests/openpgp/defs.inc: Ditto.
* tests/openpgp/gpgtar.test: Ditto.
* tests/openpgp/mkdemodirs: Ditto.
* tests/openpgp/signdemokey: Ditto.

* Makefile.am (DISTCHECK_CONFIGURE_FLAGS): Remove obsolete
--enable-mailto, add --enable-gpg2-is-gpg.
--

Although we need to duplicate some automake generated code this method
allows to easily switch the name of the installed target using the
configure option "--enable-gpg2-is-gpg".

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-04-04 18:40:25 +02:00
Neal H. Walfield 24e0f1d56e common: Provide a function for mapping packet types to strings.
* common/openpgpdefs.h (pkttype_str): New function.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-03-02 20:36:17 +01:00
Neal H. Walfield 1463f9b962 gpg: Rename pop_filter to iobuf_pop_filter and export it.
* common/iobuf.c (pop_filter): Rename from this...
(iobuf_pop_filter): ... to this.  Don't mark it as static.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-03-02 20:36:16 +01:00
Justus Winter 50995d2608 common: Update README.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-03-02 14:27:30 +01:00
Justus Winter e77c85577d common: Consolidate Assuan server argument handling.
* common/Makefile.am (common_sources): Add new files.
* common/server-help.c: New file.
* common/server-help.h: Likewise.
* agent/command.c: Drop argument handling primitives in favor of using
the consolidated ones.
* dirmngr/server.c: Likewise.
* g10/server.c: Likewise.
* g13/server.c: Likewise.
* scd/command.c: Likewise.
* sm/server.c: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-03-02 14:14:33 +01:00
Neal H. Walfield 75861b663b common: Reduce buffer size.
* common/iobuf.c (iobuf_copy): Change buffer size from 1 MB to 32 KB.

--
Change suggested by Werner based on the observation that other buffers
are of a similar size.

Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-02-23 22:39:58 +01:00
Neal H. Walfield 14d27b2cad common: Improve a function's documentation and comments.
* common/iobuf.c (iobuf_set_partial_body_length_mode): Fix
documentation and comment.  Add an assert.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-02-23 21:28:24 +01:00
Neal H. Walfield f57a91afb6 common: Add log_assert.
* common/logging.h (log_assert): New macro.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-02-23 21:14:21 +01:00
Neal H. Walfield 33ac735a78 gpg: Use higher-level functions.
* g10/build-packet.c (do_symkey_enc): Use iobuf_write instead of
iobuf_put in a loop.  Use iobuf_copy instead of iobuf_read and
iobuf_write in a loop.  Move the memory wiping from here...
* common/iobuf.c (iobuf_copy): ... to here.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-02-23 21:10:51 +01:00
Neal H. Walfield 8066f8a347 common: Check for an error before reading.
* common/iobuf.c (iobuf_copy): If DEST has a pending error, don't
start copying.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-02-23 21:04:29 +01:00
Neal H. Walfield 903466e124 common: More accurately name function.
* common/iobuf.c (iobuf_set_partial_block_mode): Rename from this...
(iobuf_set_partial_body_length_mode): ... to this.  Update callers.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-02-23 20:49:47 +01:00
Justus Winter 5ba4f6047b common/exechelp: Provide a way to wait for multiple processes.
* common/exechelp-posix.c (gnupg_wait_process): Generalize to
'gnupg_wait_processes'.
* common/exechelp-w32.c (gnupg_wait_process): Likewise.
* common/exechelp-w32ce.c (gnupg_wait_process): New function stub.
* common/exechelp.h (gnupg_wait_process): New prototype.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:52 +01:00
Justus Winter 9f4a8d4ea1 common/exechelp: Add general pipe function.
* common/exechelp-posix.c (gnupg_create_pipe): New function.
* common/exechelp-w32.c (INHERIT_{READ,WRITE,BOTH}): New macros.
(create_inheritable_pipe): Generalize so that both ends can be
inherited.
(do_create_pipe): Rename argument accordingly.
(gnupg_create_{in,out}bound_pipe): Use new flags.
(gnupg_create_pipe): New function.
(gnupg_spawn_process): Use new flags.
* common/exechelp-w32ce.c (gnupg_create_pipe): New stub.
* common/exechelp.h (gnupg_create_pipe): New prototype.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:52 +01:00
Justus Winter 54acc87c1e common/exechelp: Mute the Windows version.
* common/exechelp-w32.c (gnupg_wait_process): Do not print an error if
the exit code can be returned.  This makes the Windows version behave
like the POSIX version.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:20 +01:00
Justus Winter 709e2a7e9a common/exechelp: Avoid magic numbers.
* common/exechelp-w32.c (do_create_pipe): Use symbolic names.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:20 +01:00
Justus Winter 5d8f7b16c8 common/exechelp: Disable debugging by default.
* common/exechelp-w32.c (DEBUG_W32_SPAWN): Set to 0.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:20 +01:00
Justus Winter dd670366d7 common/exechelp: Fix handle leak.
* common/exechelp-w32.c (gnupg_spawn_process_detached): Close process
handle.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:20 +01:00
Justus Winter 8857590006 common/exechelp: Fix opening the 'nul' device.
* common/exechelp-w32.c (gnupg_spawn_process): Fix opening the 'nul'
device.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:20 +01:00
Justus Winter f5a4b6a3a3 common/exechelp: Fix error handling.
* common/exechelp-w32.c (gnupg_spawn_process): Close the right handle.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:20 +01:00
Justus Winter b0125ae985 common/exechelp: Fix pipe creation.
* common/exechelp-w32.c (gnupg_spawn_process): Fix the creation of the
input pipe.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-02-23 11:58:20 +01:00
Werner Koch 44b02e1beb
w32: Do not error out if gpgconf is not installed.
* common/homedir.c (check_portable_app): Remove error message.
--

It is sometimes useful to install just gpgv and no other parts.  Our
test for a portable application returned an error if gpgconf is not
installed.  That error is not required but was merely a debug aid.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-02-16 16:07:44 +01:00
NIIBE Yutaka ea9cfcfbf7 common, g10: Fix indentation to silence GCC-6.
* common/iobuf.c (iobuf_ioctl): Fix.
* g10/encrypt.c (encrypt_filter): Likewise.
* g10/keyring.c (prepare_search): Likewise.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-02-15 11:05:29 +09:00
Neal H. Walfield ad43dc6cfc common: Fix comment.
* common/iobuf.c (iobuf_flush_temp): Fix comment.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-02-14 14:46:16 +01:00
Werner Koch d19d6e1856
common: Make gnupg_exec_tool conform to spec.
* common/exectool.c (gnupg_exec_tool): Allocate extra byte.  Allow
zero length read.  Append hidden byte.  Release memory on error.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-02-13 17:06:38 +01:00
Neal H. Walfield acac103ba5 common: Change simple_query to ignore status messages.
* common/simple-pwquery.c (simple_query): Ignore status messages.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 2229
2016-02-12 22:12:21 +01:00
Werner Koch 7313c5fd5a
Update copyright years.
--
2016-01-26 13:20:59 +01:00
Andre Heinecke 3e50236d4e
gpgtar,w32: Fix gpgtar 8 bit encoding handling on W32
* common/utf8conv.c (wchar_to_utf8): Factor code out to ...
(wchar_to_cp): new.
(utf8_to_wchar): Factor code out to ...
(cp_to_wchar): new.
(wchar_to_native): New.
(native_to_wchar): New.
* tools/gpgtar-create.c (fillup_entry_w32): Use native_to_wchar.
(scan_directory): Use wchar_to_native.
--

Gpgtar needs to handle filenames in the local 8 bit encoding on
Windows as it uses the 8 bit file io functions.

GnuPG-bug-id: 1624, 1746

Patch from bug 1624 modified to fit into GnuPG 2.1 by wk.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-26 09:53:42 +01:00
Werner Koch 8b7f64f9df
common: Add substitute code for libgpg-error < 1.22.
* common/util.h (GPG_ERR_DB_CORRUPTED): New.
2016-01-19 16:26:28 +01:00
Werner Koch 4aceebf36f
common: Make sure dotlock functions set a proper ERRNO.
* common/dotlock.c (map_w32_to_errno): New.
(read_lockfile): Return a proper ERRNO.
(dotlock_create_unix): Do not let log functions clobber ERRNO.
(dotlock_take_unix): Ditto.
(dotlock_release_unix): Ditto.
(dotlock_create_w32): Set proper ERRNO.
(dotlock_take_w32): Ditto.
(dotlock_release_w32): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-13 14:42:12 +01:00
NIIBE Yutaka 4b4639b0b0 common: Fix iobuf API of filter function for alignment.
* common/iobuf.h: Fix comment.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-01-12 11:45:31 +09:00
NIIBE Yutaka 3f52c7da39 common: Fix iobuf API of filter function for alignment.
* common/iobuf.h (IOBUFCTRL_DESC): Change the call semantics.
* common/iobuf.c (iobuf_desc): Add the second argument DESC.
(print_chain, iobuf_close, do_open, iobuf_sockopen, iobuf_ioctl)
(iobuf_push_filter2, pop_filter, iobuf_write_temp): Change calls
of iobuf_desc.
(file_filter, file_es_filter, sock_filter, block_filter): Fill the
description.
* common/t-iobuf.c (every_other_filter, double_filter): Likewise.
* g10/armor.c, g10/cipher.c, g10/compress-bz2.c, g10/compress.c,
g10/decrypt-data.c, g10/encrypt.c, g10/mdfilter.c, g10/progress.c,
g10/textfilter.c: Likewise.

--

Newer GCC warns against possible alignment difference of pointers.
This change can silence those warnings.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-01-12 10:32:20 +09:00
Werner Koch 2aa42baaf3
Print warnings if old daemon versions are used.
* common/status.h (STATUS_WARNING): New.
* g10/call-agent.c (warn_version_mismatch): New.
(start_agent): Call warn function.
* g10/call-dirmngr.c: Include status.h.
(warn_version_mismatch): New.
(create_context): Call warn function.
* sm/call-agent.c (warn_version_mismatch): New.
(start_agent): Call warn function.
(gpgsm_agent_learn): Call warn function.
* sm/call-dirmngr.c (warn_version_mismatch): New.
(prepare_dirmngr): Call warn function.
--

We have seen too often bug reports which are due to still running old
versions of the daemons.  To catch this problematic use we now print
warning messages and also provide the warning via the status
interface.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-08 10:33:19 +01:00
Werner Koch 4d7ac43ff7
common: New function compare_version_strings.
* common/stringhelp.c (parse_version_number): New.
(parse_version_string): New.
(compare_version_strings): New.
* common/t-stringhelp.c (test_compare_version_strings): New.
(main): Call test.  Return ERRCOUNT instead of 0.
--

The code for that function is based on code from libgcrypt.  Similar
code is in all GnuPG related libraries this function is
a candidates for inclusion in libgpg-error.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-08 08:58:21 +01:00
Werner Koch 496643291e
common: New function get_assuan_server_version.
* common/asshelp.c: Include membuf.h.
(get_assuan_server_version): New.
* g10/call-agent.c (agent_get_version): Use new function.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-08 06:42:29 +01:00
Werner Koch 833ba5faa1
common: New put_membuf_cb to replace static membuf_data_cb.
* common/membuf.c (put_membuf_cb): New.
* agent/call-scd.c (membuf_data_cb): Remove.  Change callers to use
put_membuf_cb.
* common/get-passphrase.c (membuf_data_cb): Ditto.
* g10/call-agent.c (membuf_data_cb): Ditto.
* sm/call-agent.c (membuf_data_cb): Ditto.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-08 06:33:27 +01:00
Werner Koch e64317c15e
common: Avoid warnings about useless assignments.
* common/b64enc.c (b64enc_finish): Remove var assignment which is not
used later.
* common/iobuf.c (file_filter): Ditto.
* common/tlv.c (do_find_tlv): Ditto.
* common/userids.c (classify_user_id): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-06 08:35:56 +01:00
Werner Koch 0a00115ee2
common: Do not deref vars in tests after a fail().
* common/t-convert.c (test_bin2hex): Turn if conditions into if-else
chains to avoid accessing unchecked data.
(test_bin2hexcolon): Ditto.
* common/t-mapstrings.c (test_map_static_macro_string): Ditto.
* common/t-stringhelp.c (test_percent_escape): Ditto.
(test_make_filename_try): Ditto.
(test_make_absfilename_try): Ditto.
* common/t-timestuff.c (test_timegm): Ditto.
--

Note that these dereference only occur after failed regression tests.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-01-06 08:31:38 +01:00
Werner Koch 98f9e14323
common: New file fwddecl.h.
* common/util.h (server_control_s, ctrl_t): Move to ...
* common/fwddecl.h: New file.
* common/call-gpg.h: Replace typedef by fwddecl.h.  Change include
protection macro name.
* common/Makefile.am (common_sources): Add fwddecl.h.
--

It seems some compilers do not grok a re-declaration.  Thus we factor
it out into a separate file and use the include protection macro to
protect against re-declaration.

GnuPG-bug-id: 2200
Signed-off-by: Werner Koch <wk@gnupg.org>
2015-12-21 11:37:21 +01:00
Werner Koch 4ffe44c587
common: Use default_errsource for call-gpg and exectool.
* common/call-gpg.c (my_error_from_syserror, my_error_from_errno): New.
Use these wrappers.
* common/exectool.c (my_error_from_syserror): New.  Use these
wrappers.
--

Function in common should use the error source of the component which
links them.  The global variable DEFAULT_ERRSOURCE is set early by
each component to make this possible.

Signed-off-by: Werner Koch <wk@gnupg.org>
2015-12-15 13:40:10 +01:00
Werner Koch 7baca03307
common: Change license of isascii.c to all-premissive,
* common/isascii.c: Change.
--

Actually this code is too trivial to claim any copyright at all.
2015-12-14 16:21:19 +01:00
Werner Koch 7d129a7391
common: Change license of some modules to LGPLv3+/GPLv2+.
* common/status.c: Change from GPLv3 to LGPLv3+/GPLv2+.
* common/status.h: Ditto.
* common/yesno.c: Ditto.
* common/common-defs.h: Ditto.
* common/gettime.h: Ditto.
* common/keyserver.h: Ditto.
--

This is shared code and trivial enough to allow use under GPLv2+ so to
allow use by GPLv2only software.  Some of the headers are simply
adjusted to the license of their implementation.

Signed-off-by: Werner Koch <wk@gnupg.org>
2015-12-14 16:21:19 +01:00