mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-02 12:01:32 +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;
|
KB_NAME kb;
|
||||||
int secret; /* this is for a secret keybox */
|
int secret; /* this is for a secret keybox */
|
||||||
estream_t fp;
|
estream_t fp;
|
||||||
|
int update_mode; /* FP is in update mode ("r+b"). */
|
||||||
int eof;
|
int eof;
|
||||||
int error;
|
int error;
|
||||||
int ephemeral;
|
int ephemeral;
|
||||||
|
@ -255,6 +255,7 @@ _keybox_close_file (KEYBOX_HANDLE hd)
|
|||||||
{
|
{
|
||||||
es_fclose (roverhd->fp);
|
es_fclose (roverhd->fp);
|
||||||
roverhd->fp = NULL;
|
roverhd->fp = NULL;
|
||||||
|
roverhd->update_mode = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log_assert (!hd->fp);
|
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;
|
size_t flag_pos, flag_size;
|
||||||
const unsigned char *buffer;
|
const unsigned char *buffer;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
gpgrt_off_t save_off;
|
||||||
|
|
||||||
(void)idx; /* Not yet used. */
|
(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;
|
off += flag_pos;
|
||||||
|
|
||||||
_keybox_close_file (hd);
|
if (!hd->fp || !hd->update_mode)
|
||||||
fp = es_fopen (hd->kb->fname, "r+b");
|
{
|
||||||
if (!fp)
|
_keybox_close_file (hd);
|
||||||
return gpg_error_from_syserror ();
|
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;
|
ec = 0;
|
||||||
if (es_fseeko (fp, off, SEEK_SET))
|
if (es_fseeko (fp, off, SEEK_SET))
|
||||||
ec = gpg_err_code_from_syserror ();
|
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)
|
if (!ec)
|
||||||
ec = gpg_err_code_from_syserror ();
|
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);
|
return gpg_error (ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user