mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
kbx: Improve keybox_set_flags
* kbx/keybox-defs.h (struct keybox_handle): Add update_mode flag. * kbx/keybox-init.c (_keybox_close_file): Clear update_mode flag. * kbx/keybox-update.c (keybox_set_flags): Avoid a second file handle but make use of the update mode. -- This is mostly useful for gpgsm because it updates some flags in the keyring quite often. Avoiding extra CreateFile calls may help to speed up things in case malware^Dantivirus software is slowing down a Windows system. The locking pattern also change, thus there is some regression risk due to this patch.
This commit is contained in:
parent
2a1e933dd7
commit
30f1eda7d8
@ -77,6 +77,7 @@ struct keybox_handle {
|
||||
KB_NAME kb;
|
||||
int secret; /* this is for a secret keybox */
|
||||
estream_t fp;
|
||||
int update_mode; /* FP is in update mode ("r+b"). */
|
||||
int eof;
|
||||
int error;
|
||||
int ephemeral;
|
||||
|
@ -255,6 +255,7 @@ _keybox_close_file (KEYBOX_HANDLE hd)
|
||||
{
|
||||
es_fclose (roverhd->fp);
|
||||
roverhd->fp = NULL;
|
||||
roverhd->update_mode = 0;
|
||||
}
|
||||
}
|
||||
log_assert (!hd->fp);
|
||||
|
@ -509,6 +509,7 @@ keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value)
|
||||
size_t flag_pos, flag_size;
|
||||
const unsigned char *buffer;
|
||||
size_t length;
|
||||
gpgrt_off_t save_off;
|
||||
|
||||
(void)idx; /* Not yet used. */
|
||||
|
||||
@ -535,11 +536,18 @@ keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value)
|
||||
|
||||
off += flag_pos;
|
||||
|
||||
if (!hd->fp || !hd->update_mode)
|
||||
{
|
||||
_keybox_close_file (hd);
|
||||
fp = es_fopen (hd->kb->fname, "r+b");
|
||||
if (!fp)
|
||||
return gpg_error_from_syserror ();
|
||||
hd->update_mode = 1;
|
||||
}
|
||||
else
|
||||
fp = hd->fp;
|
||||
|
||||
save_off = es_ftello (fp);
|
||||
ec = 0;
|
||||
if (es_fseeko (fp, off, SEEK_SET))
|
||||
ec = gpg_err_code_from_syserror ();
|
||||
@ -566,12 +574,18 @@ keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value)
|
||||
}
|
||||
}
|
||||
|
||||
if (es_fclose (fp))
|
||||
if (es_fflush (fp))
|
||||
{
|
||||
if (!ec)
|
||||
ec = gpg_err_code_from_syserror ();
|
||||
}
|
||||
|
||||
/* Get back to the last offset or close the file on error. */
|
||||
if (save_off == (gpgrt_off_t)(-1) || es_fseeko (fp, save_off, SEEK_SET))
|
||||
{
|
||||
_keybox_close_file (hd);
|
||||
}
|
||||
|
||||
return gpg_error (ec);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user