diff options
author | Werner Koch <[email protected]> | 2023-11-21 07:34:04 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2023-11-21 07:37:41 +0000 |
commit | cf2d3f7ba0b7ffd0f1c014186fb60630c132dba1 (patch) | |
tree | ab35e6ce0810bfdb0e881ef7ac67f8cd020ac99f /agent/findkey.c | |
parent | scd: New option --debug-allow-pin-logging. (diff) | |
download | gnupg-cf2d3f7ba0b7ffd0f1c014186fb60630c132dba1.tar.gz gnupg-cf2d3f7ba0b7ffd0f1c014186fb60630c132dba1.zip |
agent: Update the key file only if not changed.
* common/name-value.c (struct name_value_container): Add flag
"modified".
(nvc_modified): New.
(nvc_new): Set flag.
(_nvc_add): Set flag.
(nvc_delete): Set flag.
(nvc_set): Set flag unless value did not change.
(nve_set): Add arg PK. Change the caller.
* agent/findkey.c (agent_write_private_key): Update only if modified.
--
This helps software which uses a file system watcher to track changes
to private keys. In particular smartcard triggered changes are a
problem for such software because this may at worst trigger another
smartcard read.
GnuPG-bug-id: 6829
Diffstat (limited to 'agent/findkey.c')
-rw-r--r-- | agent/findkey.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/agent/findkey.c b/agent/findkey.c index a5f022574..9e5550225 100644 --- a/agent/findkey.c +++ b/agent/findkey.c @@ -146,6 +146,8 @@ agent_write_private_key (const unsigned char *grip, } } + nvc_modified (pk, 1); /* Clear that flag after a read. */ + if (!pk) { /* Key is still in the old format or does not exist - create a @@ -242,7 +244,7 @@ agent_write_private_key (const unsigned char *grip, ; /* No need to update Token entry. */ else { - err = nve_set (item, token); + err = nve_set (pk, item, token); if (err) goto leave; } @@ -263,6 +265,13 @@ agent_write_private_key (const unsigned char *grip, goto leave; } + /* Check whether we need to write the file at all. */ + if (!nvc_modified (pk, 0)) + { + err = 0; + goto leave; + } + /* Create a temporary file for writing. */ tmpfname = fname_from_keygrip (grip, 1); fp = tmpfname ? es_fopen (tmpfname, "wbx,mode=-rw") : NULL; |