mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-11 22:01:08 +02:00
kbx: Add a few macros for easier readability.
* kbx/keybox-update.c (FILECOPY_INSERT) (FILECOPY_DELETE, FILECOPY_UPDATE): New macros. Replace numbers by them. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
fdbf76eee6
commit
3adfaa9bee
@ -31,6 +31,10 @@
|
|||||||
|
|
||||||
#define EXTSEP_S "."
|
#define EXTSEP_S "."
|
||||||
|
|
||||||
|
#define FILECOPY_INSERT 1
|
||||||
|
#define FILECOPY_DELETE 2
|
||||||
|
#define FILECOPY_UPDATE 3
|
||||||
|
|
||||||
|
|
||||||
#if !defined(HAVE_FSEEKO) && !defined(fseeko)
|
#if !defined(HAVE_FSEEKO) && !defined(fseeko)
|
||||||
|
|
||||||
@ -208,9 +212,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
|
|||||||
|
|
||||||
|
|
||||||
/* Perform insert/delete/update operation.
|
/* Perform insert/delete/update operation.
|
||||||
mode 1 = insert
|
MODE is one of FILECOPY_INSERT, FILECOPY_DELETE, FILECOPY_UPDATE.
|
||||||
2 = delete
|
|
||||||
3 = update
|
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
||||||
@ -229,7 +231,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
|
|
||||||
fp = fopen (fname, "rb");
|
fp = fopen (fname, "rb");
|
||||||
if (mode == 1 && !fp && errno == ENOENT)
|
if (mode == FILECOPY_INSERT && !fp && errno == ENOENT)
|
||||||
{
|
{
|
||||||
/* Insert mode but file does not exist:
|
/* Insert mode but file does not exist:
|
||||||
Create a new keybox file. */
|
Create a new keybox file. */
|
||||||
@ -271,7 +273,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* prepare for insert */
|
/* prepare for insert */
|
||||||
if (mode == 1)
|
if (mode == FILECOPY_INSERT)
|
||||||
{
|
{
|
||||||
/* Copy everything to the new file. */
|
/* Copy everything to the new file. */
|
||||||
while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
|
while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
|
||||||
@ -290,7 +292,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare for delete or update. */
|
/* Prepare for delete or update. */
|
||||||
if ( mode == 2 || mode == 3 )
|
if ( mode == FILECOPY_DELETE || mode == FILECOPY_UPDATE )
|
||||||
{
|
{
|
||||||
off_t current = 0;
|
off_t current = 0;
|
||||||
|
|
||||||
@ -324,7 +326,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do an insert or update. */
|
/* Do an insert or update. */
|
||||||
if ( mode == 1 || mode == 3 )
|
if ( mode == FILECOPY_INSERT || mode == FILECOPY_UPDATE )
|
||||||
{
|
{
|
||||||
rc = _keybox_write_blob (blob, newfp);
|
rc = _keybox_write_blob (blob, newfp);
|
||||||
if (rc)
|
if (rc)
|
||||||
@ -332,7 +334,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the rest of the packet for an delete or update. */
|
/* Copy the rest of the packet for an delete or update. */
|
||||||
if (mode == 2 || mode == 3)
|
if (mode == FILECOPY_DELETE || mode == FILECOPY_UPDATE)
|
||||||
{
|
{
|
||||||
while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
|
while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
|
||||||
{
|
{
|
||||||
@ -407,7 +409,7 @@ keybox_insert_keyblock (KEYBOX_HANDLE hd, const void *image, size_t imagelen,
|
|||||||
_keybox_destroy_openpgp_info (&info);
|
_keybox_destroy_openpgp_info (&info);
|
||||||
if (!err)
|
if (!err)
|
||||||
{
|
{
|
||||||
err = blob_filecopy (1, fname, blob, hd->secret, 0);
|
err = blob_filecopy (FILECOPY_INSERT, fname, blob, hd->secret, 0);
|
||||||
_keybox_release_blob (blob);
|
_keybox_release_blob (blob);
|
||||||
/* if (!rc && !hd->secret && kb_offtbl) */
|
/* if (!rc && !hd->secret && kb_offtbl) */
|
||||||
/* { */
|
/* { */
|
||||||
@ -456,7 +458,7 @@ keybox_insert_cert (KEYBOX_HANDLE hd, ksba_cert_t cert,
|
|||||||
rc = _keybox_create_x509_blob (&blob, cert, sha1_digest, hd->ephemeral);
|
rc = _keybox_create_x509_blob (&blob, cert, sha1_digest, hd->ephemeral);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
rc = blob_filecopy (1, fname, blob, hd->secret, 0);
|
rc = blob_filecopy (FILECOPY_INSERT, fname, blob, hd->secret, 0);
|
||||||
_keybox_release_blob (blob);
|
_keybox_release_blob (blob);
|
||||||
/* if (!rc && !hd->secret && kb_offtbl) */
|
/* if (!rc && !hd->secret && kb_offtbl) */
|
||||||
/* { */
|
/* { */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user