aboutsummaryrefslogtreecommitdiffstats
path: root/g10/tofu.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* g10: If a key has no valid user ids, change TOFU to return TRUST_NEVER.Neal H. Walfield2016-08-301-1/+16
| | | | | | | | * g10/tofu.c (tofu_get_validity): If a key has no valid (non-expired) user ids, change TOFU to return TRUST_NEVER. -- Signed-off-by: Neal H. Walfield <[email protected]>
* g10: Change tofu_register & tofu_get_validity to process multiple uids.Neal H. Walfield2016-08-301-136/+168
| | | | | | | | | | | | | * g10/tofu.c (tofu_register): Take a list of user ids, not a single user id. Only register the bindings, don't compute the trust. Thus, change return type to an int and remove the may_ask parameter. Update callers. (tofu_get_validity): Take a list of user ids, not a single user id. Update callers. Observe signatures made by expired user ids, but don't include them in the trust calculation. -- Signed-off-by: Neal H. Walfield <[email protected]>
* g10: Support nested transactions on the TOFU DB.Neal H. Walfield2016-08-301-20/+21
| | | | | | | | | | | | | | | | * g10/gpg.h (struct server_control_s): New field in_transaction. * g10/tofu.c (struct tofu_dbs_s): Remove fields savepoint_inner and savepoint_inner_commit. (begin_transaction): Increment CTRL->TOFU.IN_TRANSACTION. Name the savepoint according to the nesting level. (end_transaction): Name the savepoint according to the nesting level. Decrement CTRL->TOFU.IN_TRANSACTION. (rollback_transaction): Likewise. Only ever rollback a non-batch transaction. (opendbs): Assert that there are no outstanding transactions. -- Signed-off-by: Neal H. Walfield <[email protected]>
* g10: Print the info text in more situations.Neal H. Walfield2016-08-301-1/+2
| | | | | | | | * g10/tofu.c (ask_about_binding): Print the info text when the policy is ask and there are multiple bindings with the email address. -- Signed-off-by: Neal H. Walfield <[email protected]>
* g10: Print the formatted text.Neal H. Walfield2016-08-301-1/+1
| | | | | | | | * g10/tofu.c (ask_about_binding): Print the formatted text, not the unformatted text. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: New option --with-tofu-info.Werner Koch2016-08-251-14/+58
| | | | | | | | | | | | | | | | | | | | | * g10/gpg.c (oWithTofuInfo): New. (opts): Add --with-tofu-info. (main): Set opt.with_tofu_info. * g10/options.h (struct opt): Add field WITH_TOFU_INFO. * g10/tofu.c (show_statistics): Add optional arg OUTFP and enter special mode if not NULL. Change all callers. (tofu_write_tfs_record): New. * g10/keylist.c (list_keyblock_colon): Do not print the tofu policy as part of the "uid" record. Print a new "tfs" record if the new option is set. * tests/openpgp/tofu.scm (getpolicy): Change from UID to TFS record. -- A separate option is required to avoid slowing down key listings. Foer example the current code takes for a keylisting in tofu+pgp mode 17 seconds while it takes more than 5 minutes if the option is used. Signed-off-by: Werner Koch <[email protected]>
* gpg: Change TOFU_STATS to return timestamps.Werner Koch2016-08-241-32/+59
| | | | | | | | | * g10/tofu.c (write_stats_status): Add arg FP to print a colon formated line. Adjust for changed TOFU_STATS interface. (show_statistics): Let the query return timestamps and use gnupg_get-time to compute the "time ago" values. Signed-off-by: Werner Koch <[email protected]>
* gpg: Remove tofu database format "split".Werner Koch2016-08-101-709/+160
| | | | | | | | | | | | | | | | | | | | | | | | | | * g10/options.h (struct opt): Remove field tofu_db_format. * g10/gpg.h (server_control_s): Add fields tofu.batch_update_ref and tofu.batch_update_started. * g10/gpg.c (parse_tofu_db_format): Remove. (main): Make option --tofu-db-format obsolete. * g10/tofu.c: Major rework. Remove the pretty complicated and slower split format and with that all the caching. Use the dbs struct directly. Move global vars for batch update into CTRL. Change calling conventions of some function to take CTRL or DBS pointers instead of the former low-level database pointer. -- The split database format might have been nice for use with Unison but it bypasses the concept of a relational database by doing parts of this itself and also risking deadlocks. Working with the Tofu database for debugging or experiments is also not possible with parts of the database logic implemented in gpg. The Tofu support is quite new and we can assume that it is not in real use now. Thus we better remove that now so that we do not need to maintain it for all future. Signed-off-by: Werner Koch <[email protected]>
* g10: Fix error handling.Justus Winter2016-07-211-3/+3
| | | | | | | * g10/tofu.c (show_statistics): Fix error handling, 0 is a valid duration. Signed-off-by: Justus Winter <[email protected]>
* g10: Drop superfluous begin transaction.Justus Winter2016-07-211-7/+1
| | | | | | | * g10/tofu.c (record_binding): We only need a transaction for the split format. Signed-off-by: Justus Winter <[email protected]>
* g10: Fix crash.Justus Winter2016-07-211-2/+10
| | | | | | | | * g10/tofu.c (tofu_closedbs): Fix freeing database handles up to the cache limit. Previously, this would crash if db_cache_count == count. Reported-by: Ben Kibbey <[email protected]> Signed-off-by: Justus Winter <[email protected]>
* gpg: Avoid endless loop in a tofu error case.Werner Koch2016-06-141-1/+1
| | | | | | | * g10/tofu.c (get_trust): Do not jump to out. -- Signed-off-by: Werner Koch <[email protected]>
* gpg: Split tofu's get_trust function into several smaller ones.Werner Koch2016-06-141-434/+480
| | | | | | | | | * g10/tofu.c (get_trust): Factor code out to ... (format_conflict_msg_part1): new and to ... (ask_about_binding): new. -- Signed-off-by: Werner Koch <[email protected]>
* Replace use of opt.homedir by accessor functions.Werner Koch2016-06-071-5/+5
| | | | | | | | | | | | | | | | | | | * common/homedir.c (the_gnupg_homedir): New var. (gnupg_set_homedir): New. (gnupg_homedir): New. * g10/options.h (struct opt): Remove 'homedir' and replace all users by the new accessor functions. * g13/g13-common.h (struct opt): Ditto. * scd/scdaemon.h (struct opt): Ditto. * sm/gpgsm.h (struct opt): Ditto. * dirmngr/dirmngr.h (struct opt): Ditto. * agent/preset-passphrase.c (opt_homedir): Ditto. * agent/protect-tool.c (opt_homedir): Ditto. -- This will make detection of a non-default homedir easier. Signed-off-by: Werner Koch <[email protected]>
* gpg: Speed up key listing in Tofu mode.Werner Koch2016-05-211-50/+18
| | | | | | | | | | | | | | | | | | * g10/tofu.c (get_trust): Add arg PK. Uses this instead of a an extra lookup of the public key by fingerrpint. (tofu_register): Pass PK to get_trust. (tofu_get_validity): Ditto. *g10/tofu.c (tofu_register): Remove unused FINGERPRINT_PP. -- With my test keybox I see a speedup of 10 times (33s to 3.1s). The reason for this was the extra key lookup which I hacked in at some point to make the extraction of a keyid correct also for non v4 keys. However our caller already has the public key and thus can easily pass it to get_trust along with the fingerprint. Signed-off-by: Werner Koch <[email protected]>
* gpg: Avoid name spaces clash with future sqlite versions.Werner Koch2016-05-211-19/+19
| | | | | | | | | | | | | | * g10/sqlite.c: Rename to gpgsql.c. Change function prefixes to gpgsql_. * g10/sqlite.h: Rename to gpgsql.h. * g10/tofu.c: Adjust for changes. -- We used for our own extensions symbols with an sqlite_ names prefix. This may in theory lead to duplicated symbols but more important, it is harder to understand what is from gpg and what is from libsqlite. Signed-off-by: Werner Koch <[email protected]>
* gpg: Explicitly close a combined Tofu DB.Werner Koch2016-05-211-3/+8
| | | | * g10/tofu.c (tofu_closedbs): Close combined DB.
* gpg: Store the Tofu meta handle for databases in CTRL.Werner Koch2016-05-211-35/+38
| | | | | | | | | | | | | | | | | | * g10/gpg.h (struct tofu_dbs_s, tofu_dbs_t): New declarations. (struct server_control_s): Add field tofu.dbs. * g10/tofu.c (struct dbs): Rename to tofu_dbs_s. Replace all users by by tofu_dbs_t. (opendbs): Add arg CTRL. Cache the DBS in CTRL. (closedbs): Rename to tofu_closedbs and make global. Add arg CTRL. (tofu_register): Add arg CTRL. Change all callers. Do not call closedbs. (tofu_get_validity): Ditto. (tofu_set_policy): Ditto. (tofu_get_policy): Ditto. (tofu_set_policy_by_keyid): Add arg CTRL. * g10/gpg.c (gpg_deinit_default_ctrl): Call tofu_closedbs. Signed-off-by: Werner Koch <[email protected]>
* gpg: Fix the TOFU_STATS_LONG status.Werner Koch2016-05-211-4/+7
| | | | | | | | | | | * g10/tofu.c (show_statistics): Print TOFU STATS with formatting characters. -- We better leave the non-breaking space character in the status messages so that the caller can make use of them. Signed-off-by: Werner Koch <[email protected]>
* gpg: Fix const char pointer mismatch with gettext.Werner Koch2016-05-041-3/+4
| | | | | | * g10/tofu.c (get_trust): Use const char *. Signed-off-by: Werner Koch <[email protected]>
* gpg: Emit status lines TOFU_STATS and TOFU_STATS_LONG.Werner Koch2016-05-031-8/+61
| | | | | | | | | * g10/tofu.c (NO_WARNING_THRESHOLD): Rename to BASIC_TRUST_THRESHOLD. (FULL_TRUST_THRESHOLD): New. (write_stats_status): New. (show_statistics): Call new function. Print TOFU_STATS_LONG. Signed-off-by: Werner Koch <[email protected]>
* gpg: Extend TRUST_foo status lines with the trust model.Werner Koch2016-05-021-4/+17
| | | | | | | | | | | * g10/trustdb.h (TRUST_FLAG_TOFU_BASED): New. * g10/trustdb.c (trust_model_string): Lowercase the strings. Add arg "model" and change callers to call with OPT.TRUST_MODEL. * g10/tofu.c (tofu_wot_trust_combine): Set TRUST_FLAG_TOFU_BASED. * g10/pkclist.c (write_trust_status): New. (check_signatures_trust): Call new function. Signed-off-by: Werner Koch <[email protected]>
* gpg: Improve line wrapping for a tofu message.Werner Koch2016-05-021-8/+14
| | | | | | | * g10/tofu.c (time_ago_str): Mark non-breakable spaces. (show_statistics): Remove marks. Signed-off-by: Werner Koch <[email protected]>
* gpg: Re-format some tofu messages.Werner Koch2016-05-021-107/+151
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * common/status.h (STATUS_TOFU_USER, STATUS_TOFU_STATS) (STATUS_TOFU_STATS_SHORT, STATUS_TOFU_STATS_LONG): New. * g10/tofu.c (NO_WARNING_THRESHOLD): New. (record_binding, tofu_register): Take care of --dry-run. (show_statistics): Print STATUS_TOFU_USER. Reformat some messages. Fix the ngettext/strcmp thing. Use log_string instead of log_info. Use NO_WARNING_THRESHOLD constant. (get_trust): Use format_text and print a compact fingerprint. -- The use of log_string makes long messages better readable; instead of gpg: Warning: if you think you've seen more[...] key, then this key might be a forgery! Car[...] address for small variations. If the key i[...] we now have gpg: Warning: if you think you've seen more[...] key, then this key might be a forgery![...] address for small variations. If the [...] We also put the key information after the message and not between the user id and the last used info like here: gpg: Verified 7 messages signed by "Werner Koch <[email protected]>" in the past 4 days, 16 hours. The most recent message was verified 3 days, 13 hours ago. (key: 8061 5870 F5BA D690 3336 [...] 1E42 B367, policy: auto) This also makes the key info a separate translatable string. Further a compact version of the fingerprint (hex w/o spaces) is printed in some messages. Signed-off-by: Werner Koch <[email protected]>
* gpg: Factor some code code out of tofu.cWerner Koch2016-04-291-82/+82
| | | | | | | | | | | | | | | | * g10/tofu.c (string_to_long): New. (string_to_ulong): New. (get_single_unsigned_long_cb): Replace strtol/strtoul by new function. (get_single_long_cb): Ditto. (signature_stats_collect_cb): Ditto. (get_policy): Ditto. (show_statistics): Ditto. Uese es_free instead of free. -- There is one minor semantic change: We now accept "nnn.0" always. The old code did not checked for ".0: in show_statistics. Signed-off-by: Werner Koch <[email protected]>
* gpg: Remove all assert.h and s/assert/log_assert/.Werner Koch2016-04-291-61/+60
| | | | Signed-off-by: Werner Koch <[email protected]>
* g10: Use gpg-error abstraction of sched_yield.Justus Winter2016-03-311-2/+1
| | | | | | * g10/tofu.c (begin_transaction): Use 'gpgrt_yield'. Signed-off-by: Justus Winter <[email protected]>
* gpg: Fix NULL-segv for missing tofu DB.Werner Koch2016-03-291-1/+2
| | | | | | | | | | | * g10/tofu.c (opendb): Guard call to timeout function. -- GnuPG-bug-id: 2294 Fix not tested but is pretty obvious. Signed-off-by: Werner Koch <[email protected]>
* gpg: Streamline use of error messages in tofu.cWerner Koch2016-01-191-123/+134
| | | | | | | | * g10/tofu.c: Make use of print_further_info to reduce the number of different error messages to be translated. Also streamline some messages. Signed-off-by: Werner Koch <[email protected]>
* g10: Improve strings printed by tofu.c.Werner Koch2016-01-181-128/+132
| | | | | | | | | | | | | | | | | | | * g10/tofu.c: Include ttyio.h. Change many strings to help translating. Make use of ngettext wehere needed. (CONTROL_L): New. (TIME_AGO_UNIT_SMALL_NAME): Remove this and all similar *_NAME macros. (time_ago_unit): Remove. (get_trust): Use tty_prints and cpr_get only for the actual prompt. Add Ctrl-L hack. (show_statistics): Use two English strings for singular and plural. * po/POTFILES.in: Add tofu.c. -- These changes are required for proper translation. More to changes may be needed, though. Signed-off-by: Werner Koch <[email protected]>
* gpg: Avoid warnings about possible NULL deref.Werner Koch2016-01-071-0/+6
| | | | | | | | | | | | | * g10/getkey.c (cache_public_key): Protect deref of CE which actually can't happen. * g10/keygen.c (quickgen_set_para): s/sprintf/snprintf/. * g10/tofu.c (end_transaction, rollback_transaction): Allow NULL for DB. * g10/trustdb.c (update_min_ownertrust): Remove useless clearling of ERR. -- Signed-off-by: Werner Koch <[email protected]>
* gpg: Improve documentation.Neal H. Walfield2015-12-021-2/+1
| | | | | | | * g10/tofu.c (initdb): Improve documentation. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Fix type mismatch resulting in a buffer overflow.Neal H. Walfield2015-12-021-1/+4
| | | | | | | | | | | * g10/tofu.c (record_binding): Change policy_old's type from an enum tofu_policy to a long: this variable is passed by reference and a long is expected. -- Signed-off-by: Neal H. Walfield <[email protected]> Reported-by: Justus Winter <[email protected]> Fixes-commit: f77913e
* gpg: Reflow long texts.Neal H. Walfield2015-11-231-4/+12
| | | | | | | | | | | * common/stringhelp.c (format_text): New function. * common/t-stringhelp.c (stresc): New function. (test_format_text): New function. Test format_text. * g10/tofu.c (get_trust): Use format_text to reflow long texts. (show_statistics): Likewise. -- Signed-off-by: Neal H. Walfield <[email protected]>
* Fix typos found using codespell.Justus Winter2015-11-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * agent/cache.c: Fix typos. * agent/call-pinentry.c: Likewise. * agent/call-scd.c: Likewise. * agent/command-ssh.c: Likewise. * agent/command.c: Likewise. * agent/divert-scd.c: Likewise. * agent/findkey.c: Likewise. * agent/gpg-agent.c: Likewise. * agent/w32main.c: Likewise. * common/argparse.c: Likewise. * common/audit.c: Likewise. * common/audit.h: Likewise. * common/convert.c: Likewise. * common/dotlock.c: Likewise. * common/exechelp-posix.c: Likewise. * common/exechelp-w32.c: Likewise. * common/exechelp-w32ce.c: Likewise. * common/exechelp.h: Likewise. * common/helpfile.c: Likewise. * common/i18n.h: Likewise. * common/iobuf.c: Likewise. * common/iobuf.h: Likewise. * common/localename.c: Likewise. * common/logging.c: Likewise. * common/openpgp-oid.c: Likewise. * common/session-env.c: Likewise. * common/sexputil.c: Likewise. * common/sysutils.c: Likewise. * common/t-sexputil.c: Likewise. * common/ttyio.c: Likewise. * common/util.h: Likewise. * dirmngr/cdblib.c: Likewise. * dirmngr/certcache.c: Likewise. * dirmngr/crlcache.c: Likewise. * dirmngr/dirmngr-client.c: Likewise. * dirmngr/dirmngr.c: Likewise. * dirmngr/dirmngr_ldap.c: Likewise. * dirmngr/dns-stuff.c: Likewise. * dirmngr/http.c: Likewise. * dirmngr/ks-engine-hkp.c: Likewise. * dirmngr/ks-engine-ldap.c: Likewise. * dirmngr/ldap-wrapper.c: Likewise. * dirmngr/ldap.c: Likewise. * dirmngr/misc.c: Likewise. * dirmngr/ocsp.c: Likewise. * dirmngr/validate.c: Likewise. * g10/encrypt.c: Likewise. * g10/getkey.c: Likewise. * g10/gpg.c: Likewise. * g10/gpgv.c: Likewise. * g10/import.c: Likewise. * g10/keydb.c: Likewise. * g10/keydb.h: Likewise. * g10/keygen.c: Likewise. * g10/keyid.c: Likewise. * g10/keylist.c: Likewise. * g10/keyring.c: Likewise. * g10/mainproc.c: Likewise. * g10/misc.c: Likewise. * g10/options.h: Likewise. * g10/packet.h: Likewise. * g10/parse-packet.c: Likewise. * g10/pkclist.c: Likewise. * g10/pkglue.c: Likewise. * g10/plaintext.c: Likewise. * g10/server.c: Likewise. * g10/sig-check.c: Likewise. * g10/sqlite.c: Likewise. * g10/tdbio.c: Likewise. * g10/test-stubs.c: Likewise. * g10/tofu.c: Likewise. * g10/trust.c: Likewise. * g10/trustdb.c: Likewise. * g13/create.c: Likewise. * g13/mountinfo.c: Likewise. * kbx/keybox-blob.c: Likewise. * kbx/keybox-file.c: Likewise. * kbx/keybox-init.c: Likewise. * kbx/keybox-search-desc.h: Likewise. * kbx/keybox-search.c: Likewise. * kbx/keybox-update.c: Likewise. * scd/apdu.c: Likewise. * scd/app-openpgp.c: Likewise. * scd/app-p15.c: Likewise. * scd/app.c: Likewise. * scd/ccid-driver.c: Likewise. * scd/command.c: Likewise. * scd/iso7816.c: Likewise. * sm/base64.c: Likewise. * sm/call-agent.c: Likewise. * sm/call-dirmngr.c: Likewise. * sm/certchain.c: Likewise. * sm/gpgsm.c: Likewise. * sm/import.c: Likewise. * sm/keydb.c: Likewise. * sm/minip12.c: Likewise. * sm/qualified.c: Likewise. * sm/server.c: Likewise. * tools/gpg-check-pattern.c: Likewise. * tools/gpgconf-comp.c: Likewise. * tools/gpgkey2ssh.c: Likewise. * tools/gpgparsemail.c: Likewise. * tools/gpgtar.c: Likewise. * tools/rfc822parse.c: Likewise. * tools/symcryptrun.c: Likewise. Signed-off-by: Justus Winter <[email protected]>
* gpg: Use only one fingerprint formatting function.Werner Koch2015-11-141-50/+11
| | | | | | | | | | | | * g10/gpg.h (MAX_FORMATTED_FINGERPRINT_LEN): New. * g10/keyid.c (hexfingerprint): Add optional args BUFFER and BUFLEN. Change all callers. (format_hexfingerprint): New. * g10/keylist.c (print_fingerprint): Change to use hexfingerprint. * g10/tofu.c (fingerprint_format): Remove. Replace calls by format_hexfingerprint. Signed-off-by: Werner Koch <[email protected]>
* gpg: Simplify the tofu interface by using the public key packet.Werner Koch2015-11-131-28/+9
| | | | | | | | | | | | | | | | * g10/tofu.c (fingerprint_str): Remove. (tofu_register): Take a public key instead of a fingerprint as arg. Use hexfingerprint() to get a fpr from the PK. (tofu_get_validity): Ditto. (tofu_set_policy, tofu_get_policy): Simplify by using hexfingerprint. * g10/trustdb.c (tdb_get_validity_core): Pass the primary key PK to instead of the fingerprint to the tofu functions. -- This change has the advantage that we are not bound to a specific fingerprint length and will thus helps us to implement rfc4880bis. Signed-off-by: Werner Koch <[email protected]>
* gpg: Make trusted-key override for Tofu robust against swapped tofu.db.Werner Koch2015-11-131-19/+31
| | | | | | | | | | | | | | | * g10/tofu.c (get_trust): For the UTK check lookup the key by fingerprint. -- Extracting the keyid form the fingerprint is not a good idea because that only works for v4 keys. It is also better to first read the key and then extract the keyid from the actual available key. The entire trusted-key stuff should be reworked to make use of fingerprints. Signed-off-by: Werner Koch <[email protected]>
* gpg: Default to the flat TOFU DB format.Neal H. Walfield2015-11-101-2/+2
| | | | | | | | * g10/tofu.c (opendbs): If the TOFU DB format is set to auto and there is no TOFU DB, default to the flat format. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Change out of core error message.Werner Koch2015-11-031-19/+28
| | | | | | | | | | | | | | | * g10/tofu.c (fingerprint_str): Die with the error code returned by the failed function. (time_ago_str): Ditto. Do not make a comma translatable. (fingerprint_format): Use "%zu" for a size_t. -- Also wrapped some long strings. In general we should not use log_fatal or use xmalloc functions but properly return an error code and use xtrymalloc like functions. Signed-off-by: Werner Koch <[email protected]>
* gpg: Also show when the most recently signed message was observed.Neal H. Walfield2015-11-031-1/+23
| | | | | | | | | * g10/tofu.c (show_statistics): Also show when the most recently signed message was observed. -- Signed-off-by: Neal H. Walfield <[email protected]>. Suggested-by: MFPA <[email protected]>
* gpg: Split a utility function out of a large function.Neal H. Walfield2015-11-031-134/+157
| | | | | | | | | * g10/tofu.c (show_statistics): Break the time delta to string code into... (time_ago_str): ... this new function. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Fix message formatting.Neal H. Walfield2015-11-031-2/+2
| | | | | | | * g10/tofu.c (get_trust): Fix message formatting. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Don't store formatting fingerprints in the TOFU DB.Neal H. Walfield2015-11-031-77/+100
| | | | | | | | | | | | | | | | | * g10/tofu.c (fingerprint_pp): Split this function into... (fingerprint_str): ... this function... (fingerprint_format): ... and this function. (record_binding): Store the unformatted fingerprint in the DB. Only use the formatting fingerprint when displaying a message to the user. (get_trust): Likewise. (show_statistics): Likewise. (tofu_register): Likewise. (tofu_get_validity): Likewise. (tofu_set_policy): Likewise. (tofu_get_policy): Likewise. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Change sqlite3_stepx to pass the sqlite3_stmt * to the callback.Neal H. Walfield2015-10-291-6/+31
| | | | | | | | | | | * g10/sqlite.h (enum sqlite_arg_type): Add SQLITE_ARG_BLOB. (sqlite3_stepx_callback): New declaration. (sqlite3_stepx): Change the callback's type to sqlite3_stepx_callback, which passes an additional parameter, the sqlite3_stmt *. Update users. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Move sqlite helper functions into their own file.Neal H. Walfield2015-10-291-223/+1
| | | | | | | | | | | | | | * g10/tofu.c (sqlite3_exec_printf): Move from here... * g10/sqlite.c (sqlite3_exec_printf): ... to this new file. Don't mark as static. * g10/tofu.c (sqlite3_stepx): Move from here... * g10/sqlite.c (sqlite3_stepx): ... to this new file. Don't mark as static. * g10/tofu.c (enum sqlite_arg_type): Move from here... * g10/sqlite.h (enum sqlite_arg_type): ... to this new file. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Make sure we only have a single SQL statement.Neal H. Walfield2015-10-261-1/+16
| | | | | | | | * g10/tofu.c (sqlite3_stepx): Make sure SQL only contains a single SQL statement. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: When the TOFU DB is in batch mode, periodically drop the locks.Neal H. Walfield2015-10-261-0/+30
| | | | | | | | | | | | * g10/tofu.c: Include <sched.h>. (batch_update_started): New variable. (begin_transaction): If we've been in batch mode for a while, then commit any extant batch transactions. (tofu_begin_batch_update): If we are not in batch mode, initialize batch_update_started. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Provide an interface to patch TOFU updates.Neal H. Walfield2015-10-231-53/+209
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * g10/tofu.c (struct db): Rename begin_transaction to savepoint_batch. Rename end_transaction to savepoint_batch_commit. Update users. Remove field rollback. Add fields savepoint_inner and savepoint_inner_commit. Add field batch_update. (dump_cache): New function. (batch_update): New variable. (begin_transaction). New function. (end_transaction): New function. (rollback_transaction): New function. (tofu_begin_batch_update): New function. (tofu_end_batch_update): New function. (closedb): End any pending batch transaction. (closedbs): Assert that none of the DBs have a started batch transaction if we not in batch mode. (record_binding): Use the begin_transaction, end_transaction and rollback_transaction functions instead of including the SQL inline. Also start a batch mode transaction if we are using the flat format. (tofu_register): Use the begin_transaction, end_transaction and rollback_transaction functions instead of including the SQL inline. * g10/gpgv.c (tofu_begin_batch_update): New function. (tofu_end_batch_update): New function. * g10/test-stubs.c (tofu_begin_batch_update): New function. (tofu_end_batch_update): New function. -- Signed-off-by: Neal H. Walfield <[email protected]>
* gpg: Cache prepared SQL queries and open DB connections.Neal H. Walfield2015-10-231-211/+518
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * g10/tofu.c: Include <stdarg.h>. (prepares_saved) [DEBUG_TOFU_CACHE]: New variable. (queries) [DEBUG_TOFU_CACHE]: New variable. (struct db): Add fields prevp, begin_transaction, end_transaction, rollback, record_binding_get_old_policy, record_binding_update, record_binding_update2, get_policy_select_policy_and_conflict, get_trust_bindings_with_this_email, get_trust_gather_other_user_ids, get_trust_gather_other_keys, register_already_seen, and register_insert. [DEBUG_TOFU_CACHE]: Add field hits. (STRINGIFY): New macro. (STRINGIFY2): New macro. (enum sqlite_arg_type): New enum. (sqlite3_stepx): New function. (combined_db): Remove variable. (opendb): Don't cache the combined db. (struct dbs): New struct. Update users to use this as the head of the local DB list rather than overloading struct db. (unlink_db): New function. (link_db): New function. (db_cache): New variable. (db_cache_count): New variable. (DB_CACHE_ENTRIES): Define. (getdb): If the dbs specific cache doesn't include the DB, look at DB_CACHE. Only if that also doesn't include the DB open the corresponding DB. (closedb): New function. (opendbs): Don't open the combined DB. Just return an initialized struct dbs. (closedbs): Don't close the dbs specific dbs. Attach them to the front of DB_CACHE. If DB_CACHE contains more than DB_CACHE_ENTRIES, close enough dbs from the end of the DB_CACHE list such that DB_CACHE only contains DB_CACHE_ENTRIES. Don't directly close the dbs, instead use the new closedb function. [DEBUG_TOFU_CACHE]: Print out some statistics. (record_binding): Use sqlite3_stepx instead of sqlite3_exec or sqlite3_exec_printf. (get_policy): Likewise. (get_trust): Likewise. (tofu_register): Likewise. -- Signed-off-by: Neal H. Walfield <[email protected]>