aboutsummaryrefslogtreecommitdiffstats
path: root/kbx/keybox-update.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2002-07-22 10:21:04 +0000
committerWerner Koch <[email protected]>2002-07-22 10:21:04 +0000
commit508ce100c975692648325cdd839d9b49496659d6 (patch)
treefd5ed7741a7c880902be499be71a4fcbb9c295cf /kbx/keybox-update.c
parent* fseeko.c, ftello.c: New. (diff)
downloadgnupg-508ce100c975692648325cdd839d9b49496659d6.tar.gz
gnupg-508ce100c975692648325cdd839d9b49496659d6.zip
* keybox-defs.h: New BLOBTYPTE_EMPTY.
* keybox-dump.c (_keybox_dump_blob): Handle new type. * keybox-file.c (_keybox_read_blob): Skip over empty blobs. Store the file offset. * keybox-blob.c (_keybox_new_blob): Add new arg OFF. (_keybox_get_blob_fileoffset): New. * keybox-update.c (keybox_delete): Implemented.
Diffstat (limited to 'kbx/keybox-update.c')
-rw-r--r--kbx/keybox-update.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/kbx/keybox-update.c b/kbx/keybox-update.c
index 96a30b9c1..8b189bbed 100644
--- a/kbx/keybox-update.c
+++ b/kbx/keybox-update.c
@@ -384,7 +384,50 @@ keybox_update_cert (KEYBOX_HANDLE hd, KsbaCert cert,
int
keybox_delete (KEYBOX_HANDLE hd)
{
- return -1;
+ off_t off;
+ const char *fname;
+ FILE *fp;
+ int rc;
+
+ if (!hd)
+ return KEYBOX_Invalid_Value;
+ if (!hd->found.blob)
+ return KEYBOX_Nothing_Found;
+ if (!hd->kb)
+ return KEYBOX_Invalid_Handle;
+ fname = hd->kb->fname;
+ if (!fname)
+ return KEYBOX_Invalid_Handle;
+
+ off = _keybox_get_blob_fileoffset (hd->found.blob);
+ if (off == (off_t)-1)
+ return KEYBOX_General_Error;
+ off += 4;
+
+ if (hd->fp)
+ {
+ fclose (hd->fp);
+ hd->fp = NULL;
+ }
+
+ fp = fopen (hd->kb->fname, "r+b");
+ if (!fp)
+ return KEYBOX_File_Open_Error;
+
+ if (fseeko (fp, off, SEEK_SET))
+ rc = KEYBOX_Write_Error;
+ else if (putc (0, fp) == EOF)
+ rc = KEYBOX_Write_Error;
+ else
+ rc = 0;
+
+ if (fclose (fp))
+ {
+ if (!rc)
+ rc = KEYBOX_File_Close_Error;
+ }
+
+ return rc;
}