mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Make use of libgpg-error
This commit is contained in:
parent
7c9855aaa2
commit
c3cdaeeff7
58 changed files with 1110 additions and 684 deletions
|
@ -1,3 +1,11 @@
|
|||
2003-06-03 Werner Koch <wk@gnupg.org>
|
||||
|
||||
Changed all error codes in all files to the new libgpg-error scheme.
|
||||
|
||||
* keybox-defs.h: Include gpg-error.h .
|
||||
(KeyboxError): Removed.
|
||||
* Makefile.am: Removed keybox-error.c stuff.
|
||||
|
||||
2002-11-14 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* keybox-search.c (blob_cmp_name) <compare all names>: Fixed
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Keybox Makefile
|
||||
# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is part of GnuPG.
|
||||
#
|
||||
|
@ -24,7 +24,6 @@ INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
|
|||
|
||||
EXTRA_DIST = mkerrors
|
||||
AM_CPPFLAGS = $(KSBA_CFLAGS) $(LIBGCRYPT_CFLAGS)
|
||||
BUILT_SOURCES = keybox-errors.c
|
||||
|
||||
noinst_LIBRARIES = libkeybox.a
|
||||
bin_PROGRAMS = kbxutil
|
||||
|
@ -32,7 +31,6 @@ bin_PROGRAMS = kbxutil
|
|||
common_sources = \
|
||||
keybox.h keybox-defs.h keybox-search-desc.h \
|
||||
keybox-util.c \
|
||||
keybox-errors.c \
|
||||
keybox-init.c \
|
||||
keybox-blob.c \
|
||||
keybox-file.c \
|
||||
|
@ -44,10 +42,7 @@ common_sources = \
|
|||
libkeybox_a_SOURCES = $(common_sources)
|
||||
|
||||
kbxutil_SOURCES = kbxutil.c $(common_sources)
|
||||
kbxutil_LDADD = ../jnlib/libjnlib.a $(KSBA_LIBS) $(LIBGCRYPT_LIBS)
|
||||
|
||||
keybox-errors.c : keybox.h mkerrors
|
||||
$(srcdir)/mkerrors < $(srcdir)/keybox.h > keybox-errors.c
|
||||
kbxutil_LDADD = ../jnlib/libjnlib.a $(KSBA_LIBS) $(LIBGCRYPT_LIBS) -lgpg-error
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* keybox-blob.c - KBX Blob handling
|
||||
* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -489,7 +489,7 @@ x509_create_blob_cert (KEYBOXBLOB blob, KsbaCert cert)
|
|||
|
||||
image = ksba_cert_get_image (cert, &length);
|
||||
if (!image)
|
||||
return KEYBOX_General_Error;
|
||||
return gpg_error (GPG_ERR_GENERAL);
|
||||
put_membuf (a, image, length);
|
||||
|
||||
add_fixup (blob, 12, a->len - kbstart);
|
||||
|
@ -651,7 +651,7 @@ create_blob_finish (KEYBOXBLOB blob)
|
|||
/* get the memory area */
|
||||
p = get_membuf (a, &n);
|
||||
if (!p)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (GPG_ERR_ENOMEM);
|
||||
assert (n >= 20);
|
||||
|
||||
/* fixup the length */
|
||||
|
@ -659,7 +659,7 @@ create_blob_finish (KEYBOXBLOB blob)
|
|||
|
||||
/* do the fixups */
|
||||
if (blob->fixup_out_of_core)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (GPG_ERR_ENOMEM);
|
||||
|
||||
{
|
||||
struct fixup_list *fl;
|
||||
|
@ -678,7 +678,7 @@ create_blob_finish (KEYBOXBLOB blob)
|
|||
|
||||
pp = xtrymalloc (n);
|
||||
if ( !pp )
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
memcpy (pp , p, n);
|
||||
blob->blob = pp;
|
||||
blob->bloblen = n;
|
||||
|
@ -698,8 +698,8 @@ _keybox_create_pgp_blob (KEYBOXBLOB *r_blob, KBNODE keyblock, int as_ephemeral)
|
|||
|
||||
*r_blob = NULL;
|
||||
blob = xtrycalloc (1, sizeof *blob);
|
||||
if( !blob )
|
||||
return KEYBOX_Out_Of_Core;
|
||||
if (!blob)
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
|
||||
/* fixme: Do some sanity checks on the keyblock */
|
||||
|
||||
|
@ -723,7 +723,7 @@ _keybox_create_pgp_blob (KEYBOXBLOB *r_blob, KBNODE keyblock, int as_ephemeral)
|
|||
blob->sigs = xtrycalloc (blob->nsigs, sizeof *blob->sigs );
|
||||
if (!blob->keys || !blob->uids || !blob->sigs)
|
||||
{
|
||||
rc = KEYBOX_Out_Of_Core;
|
||||
rc = gpg_error (GPG_ERR_ENOMEM);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
|
@ -818,7 +818,7 @@ _keybox_create_x509_blob (KEYBOXBLOB *r_blob, KsbaCert cert,
|
|||
*r_blob = NULL;
|
||||
blob = xtrycalloc (1, sizeof *blob);
|
||||
if( !blob )
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
|
||||
p = ksba_cert_get_serial (cert);
|
||||
if (p)
|
||||
|
@ -828,7 +828,7 @@ _keybox_create_x509_blob (KEYBOXBLOB *r_blob, KsbaCert cert,
|
|||
if (n < 2)
|
||||
{
|
||||
xfree (p);
|
||||
return KEYBOX_General_Error;
|
||||
return gpg_error (GPG_ERR_GENERAL);
|
||||
}
|
||||
blob->serialbuf = p;
|
||||
p++; n--; /* skip '(' */
|
||||
|
@ -838,7 +838,7 @@ _keybox_create_x509_blob (KEYBOXBLOB *r_blob, KsbaCert cert,
|
|||
{
|
||||
xfree (blob->serialbuf);
|
||||
blob->serialbuf = NULL;
|
||||
return KEYBOX_General_Error;
|
||||
return gpg_error (GPG_ERR_GENERAL);
|
||||
}
|
||||
p++;
|
||||
blob->serial = p;
|
||||
|
@ -853,13 +853,13 @@ _keybox_create_x509_blob (KEYBOXBLOB *r_blob, KsbaCert cert,
|
|||
names = xtrymalloc (max_names * sizeof *names);
|
||||
if (!names)
|
||||
{
|
||||
rc = KEYBOX_Out_Of_Core;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
p = ksba_cert_get_issuer (cert, 0);
|
||||
if (!p)
|
||||
{
|
||||
rc = KEYBOX_Missing_Value;
|
||||
rc = gpg_error (GPG_ERR_MISSING_VALUE);
|
||||
goto leave;
|
||||
}
|
||||
names[blob->nuids++] = p;
|
||||
|
@ -874,7 +874,7 @@ _keybox_create_x509_blob (KEYBOXBLOB *r_blob, KsbaCert cert,
|
|||
tmp = xtryrealloc (names, max_names * sizeof *names);
|
||||
if (!tmp)
|
||||
{
|
||||
rc = KEYBOX_Out_Of_Core;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
|
@ -891,7 +891,7 @@ _keybox_create_x509_blob (KEYBOXBLOB *r_blob, KsbaCert cert,
|
|||
blob->sigs = xtrycalloc (blob->nsigs, sizeof *blob->sigs );
|
||||
if (!blob->keys || !blob->uids || !blob->sigs)
|
||||
{
|
||||
rc = KEYBOX_Out_Of_Core;
|
||||
rc = gpg_error (GPG_ERR_ENOMEM);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
|
@ -964,7 +964,7 @@ _keybox_new_blob (KEYBOXBLOB *r_blob, char *image, size_t imagelen, off_t off)
|
|||
*r_blob = NULL;
|
||||
blob = xtrycalloc (1, sizeof *blob);
|
||||
if (!blob)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
|
||||
blob->blob = image;
|
||||
blob->bloblen = imagelen;
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
#include <sys/types.h> /* off_t */
|
||||
#include "keybox.h"
|
||||
|
||||
#ifdef GPG_ERR_SOURCE_DEFAULT
|
||||
#error GPG_ERR_SOURCE_DEFAULT already defined
|
||||
#endif
|
||||
#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_KEYBOX
|
||||
#include <gpg-error.h>
|
||||
|
||||
|
||||
#ifndef HAVE_BYTE_TYPEDEF
|
||||
typedef unsigned char byte; /* fixme */
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* keybox-dump.c - Debug helpers
|
||||
* Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -322,8 +322,9 @@ _keybox_dump_file (const char *filename, FILE *outfp)
|
|||
fp = fopen (filename, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
fprintf (outfp, "can't open `%s': %s\n", filename, strerror(errno));
|
||||
return KEYBOX_File_Error;
|
||||
return tmperr;
|
||||
}
|
||||
|
||||
while ( !(rc = _keybox_read_blob (&blob, fp)) )
|
||||
|
@ -337,8 +338,7 @@ _keybox_dump_file (const char *filename, FILE *outfp)
|
|||
if (rc == -1)
|
||||
rc = 0;
|
||||
if (rc)
|
||||
fprintf (outfp, "error reading `%s': %s\n", filename,
|
||||
rc == KEYBOX_Read_Error? keybox_strerror(rc):strerror (errno));
|
||||
fprintf (outfp, "error reading `%s': %s\n", filename, gpg_strerror (rc));
|
||||
|
||||
if (fp != stdin)
|
||||
fclose (fp);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* keybox-file.c - file oeprations
|
||||
* Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -22,6 +22,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "keybox-defs.h"
|
||||
|
||||
|
@ -40,7 +41,7 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp)
|
|||
*r_blob = NULL;
|
||||
off = ftello (fp);
|
||||
if (off == (off_t)-1)
|
||||
return KEYBOX_Read_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
|
||||
if ((c1 = getc (fp)) == EOF
|
||||
|| (c2 = getc (fp)) == EOF
|
||||
|
@ -50,33 +51,34 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp)
|
|||
{
|
||||
if ( c1 == EOF && !ferror (fp) )
|
||||
return -1; /* eof */
|
||||
return KEYBOX_Read_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
}
|
||||
|
||||
imagelen = (c1 << 24) | (c2 << 16) | (c3 << 8 ) | c4;
|
||||
if (imagelen > 500000) /* sanity check */
|
||||
return KEYBOX_Blob_Too_Large;
|
||||
return gpg_error (GPG_ERR_TOO_LARGE);
|
||||
|
||||
if (imagelen < 5)
|
||||
return KEYBOX_Blob_Too_Short;
|
||||
return gpg_error (GPG_ERR_TOO_SHORT);
|
||||
|
||||
if (!type)
|
||||
{
|
||||
/* special treatment for empty blobs. */
|
||||
if (fseek (fp, imagelen-5, SEEK_CUR))
|
||||
return KEYBOX_Read_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto again;
|
||||
}
|
||||
|
||||
image = xtrymalloc (imagelen);
|
||||
if (!image)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
|
||||
image[0] = c1; image[1] = c2; image[2] = c3; image[3] = c4; image[4] = type;
|
||||
if (fread (image+5, imagelen-5, 1, fp) != 1)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
xfree (image);
|
||||
return KEYBOX_Read_Error;
|
||||
return tmperr;
|
||||
}
|
||||
|
||||
rc = r_blob? _keybox_new_blob (r_blob, image, imagelen, off) : 0;
|
||||
|
@ -95,8 +97,6 @@ _keybox_write_blob (KEYBOXBLOB blob, FILE *fp)
|
|||
|
||||
image = _keybox_get_blob_image (blob, &length);
|
||||
if (fwrite (image, length, 1, fp) != 1)
|
||||
{
|
||||
return KEYBOX_Write_Error;
|
||||
}
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ int
|
|||
keybox_set_ephemeral (KEYBOX_HANDLE hd, int yes)
|
||||
{
|
||||
if (!hd)
|
||||
return KEYBOX_Invalid_Handle;
|
||||
return gpg_error (GPG_ERR_INV_HANDLE);
|
||||
hd->ephemeral = yes;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* keybox-search.c - Search operations
|
||||
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -23,6 +23,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../jnlib/stringhelp.h" /* ascii_xxxx() */
|
||||
#include "keybox-defs.h"
|
||||
|
@ -481,7 +482,7 @@ int
|
|||
keybox_search_reset (KEYBOX_HANDLE hd)
|
||||
{
|
||||
if (!hd)
|
||||
return KEYBOX_Invalid_Value;
|
||||
return gpg_error (GPG_ERR_INV_VALUE);
|
||||
|
||||
if (hd->found.blob)
|
||||
{
|
||||
|
@ -512,7 +513,7 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
|
|||
struct sn_array_s *sn_array = NULL;
|
||||
|
||||
if (!hd)
|
||||
return KEYBOX_Invalid_Value;
|
||||
return gpg_error (GPG_ERR_INV_VALUE);
|
||||
|
||||
/* clear last found result */
|
||||
if (hd->found.blob)
|
||||
|
@ -548,7 +549,7 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
|
|||
{
|
||||
sn_array = xtrycalloc (ndesc, sizeof *sn_array);
|
||||
if (!sn_array)
|
||||
return (hd->error = KEYBOX_Out_Of_Core);
|
||||
return (hd->error = gpg_error (gpg_err_code_from_errno (errno)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,8 +558,9 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
|
|||
hd->fp = fopen (hd->kb->fname, "rb");
|
||||
if (!hd->fp)
|
||||
{
|
||||
hd->error = gpg_error (gpg_err_code_from_errno (errno));
|
||||
xfree (sn_array);
|
||||
return (hd->error = KEYBOX_File_Open_Error);
|
||||
return hd->error;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -588,8 +590,9 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
|
|||
sn_array[n].sn = xtrymalloc (snlen);
|
||||
if (!sn_array[n].sn)
|
||||
{
|
||||
hd->error = gpg_error (gpg_err_code_from_errno (errno));
|
||||
release_sn_array (sn_array, n);
|
||||
return (hd->error = KEYBOX_Out_Of_Core);
|
||||
return hd->error;
|
||||
}
|
||||
sn_array[n].snlen = snlen;
|
||||
sn = sn_array[n].sn;
|
||||
|
@ -611,8 +614,9 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
|
|||
sn_array[n].sn = xtrymalloc (snlen);
|
||||
if (!sn_array[n].sn)
|
||||
{
|
||||
hd->error = gpg_error (gpg_err_code_from_errno (errno));
|
||||
release_sn_array (sn_array, n);
|
||||
return (hd->error = KEYBOX_Out_Of_Core);
|
||||
return hd->error;
|
||||
}
|
||||
sn_array[n].snlen = snlen;
|
||||
memcpy (sn_array[n].sn, sn, snlen);
|
||||
|
@ -700,7 +704,7 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
|
|||
goto found;
|
||||
break;
|
||||
default:
|
||||
rc = KEYBOX_Invalid_Value;
|
||||
rc = gpg_error (GPG_ERR_INV_VALUE);
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
|
@ -759,37 +763,37 @@ keybox_get_cert (KEYBOX_HANDLE hd, KsbaCert *r_cert)
|
|||
int rc;
|
||||
|
||||
if (!hd)
|
||||
return KEYBOX_Invalid_Value;
|
||||
return gpg_error (GPG_ERR_INV_VALUE);
|
||||
if (!hd->found.blob)
|
||||
return KEYBOX_Nothing_Found;
|
||||
return gpg_error (GPG_ERR_NOTHING_FOUND);
|
||||
|
||||
if (blob_get_type (hd->found.blob) != BLOBTYPE_X509)
|
||||
return KEYBOX_Wrong_Blob_Type;
|
||||
return gpg_error (GPG_ERR_WRONG_BLOB_TYPE);
|
||||
|
||||
buffer = _keybox_get_blob_image (hd->found.blob, &length);
|
||||
if (length < 40)
|
||||
return KEYBOX_Blob_Too_Short;
|
||||
return gpg_error (GPG_ERR_TOO_SHORT);
|
||||
cert_off = get32 (buffer+8);
|
||||
cert_len = get32 (buffer+12);
|
||||
if (cert_off+cert_len > length)
|
||||
return KEYBOX_Blob_Too_Short;
|
||||
return gpg_error (GPG_ERR_TOO_SHORT);
|
||||
|
||||
reader = ksba_reader_new ();
|
||||
if (!reader)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (GPG_ERR_ENOMEM);
|
||||
rc = ksba_reader_set_mem (reader, buffer+cert_off, cert_len);
|
||||
if (rc)
|
||||
{
|
||||
ksba_reader_release (reader);
|
||||
/* fixme: need to map the error codes */
|
||||
return KEYBOX_General_Error;
|
||||
return gpg_error (GPG_ERR_GENERAL);
|
||||
}
|
||||
|
||||
cert = ksba_cert_new ();
|
||||
if (!cert)
|
||||
{
|
||||
ksba_reader_release (reader);
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (GPG_ERR_ENOMEM);
|
||||
}
|
||||
|
||||
rc = ksba_cert_read_der (cert, reader);
|
||||
|
@ -798,7 +802,7 @@ keybox_get_cert (KEYBOX_HANDLE hd, KsbaCert *r_cert)
|
|||
ksba_cert_release (cert);
|
||||
ksba_reader_release (reader);
|
||||
/* fixme: need to map the error codes */
|
||||
return KEYBOX_General_Error;
|
||||
return gpg_error (GPG_ERR_GENERAL);
|
||||
}
|
||||
|
||||
*r_cert = cert;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* keybox-update.c - keybox update operations
|
||||
* Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -50,15 +50,16 @@ create_tmp_file (const char *template,
|
|||
{
|
||||
bakfname = xtrymalloc (strlen (template) + 1);
|
||||
if (!bakfname)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
strcpy (bakfname, template);
|
||||
strcpy (bakfname+strlen(template)-4, EXTSEP_S "bak");
|
||||
|
||||
tmpfname = xtrymalloc (strlen (template) + 1);
|
||||
if (!tmpfname)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
xfree (bakfname);
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return tmperr;
|
||||
}
|
||||
strcpy (tmpfname,template);
|
||||
strcpy (tmpfname + strlen (template)-4, EXTSEP_S "tmp");
|
||||
|
@ -67,28 +68,30 @@ create_tmp_file (const char *template,
|
|||
{ /* file does not end with kbx; hmmm */
|
||||
bakfname = xtrymalloc ( strlen (template) + 5);
|
||||
if (!bakfname)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
strcpy (stpcpy (bakfname, template), EXTSEP_S "bak");
|
||||
|
||||
tmpfname = xtrymalloc ( strlen (template) + 5);
|
||||
if (!tmpfname)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
xfree (bakfname);
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return tmperr;
|
||||
}
|
||||
strcpy (stpcpy (tmpfname, template), EXTSEP_S "tmp");
|
||||
}
|
||||
# else /* Posix file names */
|
||||
bakfname = xtrymalloc (strlen (template) + 2);
|
||||
if (!bakfname)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
strcpy (stpcpy (bakfname,template),"~");
|
||||
|
||||
tmpfname = xtrymalloc ( strlen (template) + 5);
|
||||
if (!tmpfname)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
xfree (bakfname);
|
||||
return KEYBOX_Out_Of_Core;
|
||||
return tmperr;
|
||||
}
|
||||
strcpy (stpcpy (tmpfname,template), EXTSEP_S "tmp");
|
||||
# endif /* Posix filename */
|
||||
|
@ -96,9 +99,10 @@ create_tmp_file (const char *template,
|
|||
*r_fp = fopen (tmpfname, "wb");
|
||||
if (!*r_fp)
|
||||
{
|
||||
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
|
||||
xfree (tmpfname);
|
||||
xfree (bakfname);
|
||||
return KEYBOX_File_Create_Error;
|
||||
return tmperr;
|
||||
}
|
||||
|
||||
*r_bakfname = bakfname;
|
||||
|
@ -139,7 +143,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
|
|||
#endif
|
||||
if (rename (fname, bakfname) )
|
||||
{
|
||||
return KEYBOX_File_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +153,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
|
|||
#endif
|
||||
if (rename (tmpfname, fname) )
|
||||
{
|
||||
rc = KEYBOX_File_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
if (secret)
|
||||
{
|
||||
/* log_info ("WARNING: 2 files with confidential" */
|
||||
|
@ -185,7 +189,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
/* Open the source file. Because we do a rename, we have to check the
|
||||
permissions of the file */
|
||||
if (access (fname, W_OK))
|
||||
return KEYBOX_Write_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
|
||||
fp = fopen (fname, "rb");
|
||||
if (mode == 1 && !fp && errno == ENOENT)
|
||||
|
@ -193,7 +197,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
newfp = fopen (fname, "wb");
|
||||
if (!newfp )
|
||||
{
|
||||
return KEYBOX_File_Create_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
}
|
||||
|
||||
rc = _keybox_write_blob (blob, newfp);
|
||||
|
@ -203,7 +207,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
}
|
||||
if ( fclose (newfp) )
|
||||
{
|
||||
return KEYBOX_File_Create_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
}
|
||||
|
||||
/* if (chmod( fname, S_IRUSR | S_IWUSR )) */
|
||||
|
@ -216,7 +220,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
|
||||
if (!fp)
|
||||
{
|
||||
rc = KEYBOX_File_Open_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
|
||||
|
@ -236,13 +240,13 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
{
|
||||
if (fwrite (buffer, nread, 1, newfp) != 1)
|
||||
{
|
||||
rc = KEYBOX_Write_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
if (ferror (fp))
|
||||
{
|
||||
rc = KEYBOX_Read_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
|
@ -265,14 +269,14 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
|
||||
if (fwrite (buffer, nread, 1, newfp) != 1)
|
||||
{
|
||||
rc = KEYBOX_Write_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
if (ferror (fp))
|
||||
{
|
||||
rc = KEYBOX_Read_Error;
|
||||
goto leave;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* skip this blob */
|
||||
|
@ -296,13 +300,13 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
{
|
||||
if (fwrite (buffer, nread, 1, newfp) != 1)
|
||||
{
|
||||
rc = KEYBOX_Write_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
if (ferror (fp))
|
||||
{
|
||||
rc = KEYBOX_Read_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
|
@ -310,13 +314,13 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
|||
/* close both files */
|
||||
if (fclose(fp))
|
||||
{
|
||||
rc = KEYBOX_File_Close_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
fclose (newfp);
|
||||
goto leave;
|
||||
}
|
||||
if (fclose(newfp))
|
||||
{
|
||||
rc = KEYBOX_File_Close_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
goto leave;
|
||||
}
|
||||
|
||||
|
@ -341,12 +345,12 @@ keybox_insert_cert (KEYBOX_HANDLE hd, KsbaCert cert,
|
|||
KEYBOXBLOB blob;
|
||||
|
||||
if (!hd)
|
||||
return KEYBOX_Invalid_Handle;
|
||||
return gpg_error (GPG_ERR_INV_HANDLE);
|
||||
if (!hd->kb)
|
||||
return KEYBOX_Invalid_Handle;
|
||||
return gpg_error (GPG_ERR_INV_HANDLE);
|
||||
fname = hd->kb->fname;
|
||||
if (!fname)
|
||||
return KEYBOX_Invalid_Handle;
|
||||
return gpg_error (GPG_ERR_INV_HANDLE);
|
||||
|
||||
/* close this one otherwise we will mess up the position for a next
|
||||
search. Fixme: it would be better to adjust the position after
|
||||
|
@ -390,18 +394,18 @@ keybox_delete (KEYBOX_HANDLE hd)
|
|||
int rc;
|
||||
|
||||
if (!hd)
|
||||
return KEYBOX_Invalid_Value;
|
||||
return gpg_error (GPG_ERR_INV_VALUE);
|
||||
if (!hd->found.blob)
|
||||
return KEYBOX_Nothing_Found;
|
||||
return gpg_error (GPG_ERR_NOTHING_FOUND);
|
||||
if (!hd->kb)
|
||||
return KEYBOX_Invalid_Handle;
|
||||
return gpg_error (GPG_ERR_INV_HANDLE);
|
||||
fname = hd->kb->fname;
|
||||
if (!fname)
|
||||
return KEYBOX_Invalid_Handle;
|
||||
return gpg_error (GPG_ERR_INV_HANDLE);
|
||||
|
||||
off = _keybox_get_blob_fileoffset (hd->found.blob);
|
||||
if (off == (off_t)-1)
|
||||
return KEYBOX_General_Error;
|
||||
return gpg_error (GPG_ERR_GENERAL);
|
||||
off += 4;
|
||||
|
||||
if (hd->fp)
|
||||
|
@ -412,19 +416,19 @@ keybox_delete (KEYBOX_HANDLE hd)
|
|||
|
||||
fp = fopen (hd->kb->fname, "r+b");
|
||||
if (!fp)
|
||||
return KEYBOX_File_Open_Error;
|
||||
return gpg_error (gpg_err_code_from_errno (errno));
|
||||
|
||||
if (fseeko (fp, off, SEEK_SET))
|
||||
rc = KEYBOX_Write_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
else if (putc (0, fp) == EOF)
|
||||
rc = KEYBOX_Write_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
else
|
||||
rc = 0;
|
||||
|
||||
if (fclose (fp))
|
||||
{
|
||||
if (!rc)
|
||||
rc = KEYBOX_File_Close_Error;
|
||||
rc = gpg_error (gpg_err_code_from_errno (errno));
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
|
26
kbx/keybox.h
26
kbx/keybox.h
|
@ -1,5 +1,5 @@
|
|||
/* keybox.h - Keybox operations
|
||||
* Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -43,27 +43,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
KEYBOX_No_Error = 0,
|
||||
KEYBOX_General_Error = 1,
|
||||
KEYBOX_Out_Of_Core = 2,
|
||||
KEYBOX_Invalid_Value = 3,
|
||||
KEYBOX_Timeout = 4,
|
||||
KEYBOX_Read_Error = 5,
|
||||
KEYBOX_Write_Error = 6,
|
||||
KEYBOX_File_Error = 7,
|
||||
KEYBOX_Blob_Too_Short = 8,
|
||||
KEYBOX_Blob_Too_Large = 9,
|
||||
KEYBOX_Invalid_Handle = 10,
|
||||
KEYBOX_File_Create_Error = 11,
|
||||
KEYBOX_File_Open_Error = 12,
|
||||
KEYBOX_File_Close_Error = 13,
|
||||
KEYBOX_Nothing_Found = 14,
|
||||
KEYBOX_Wrong_Blob_Type = 15,
|
||||
KEYBOX_Missing_Value = 16,
|
||||
} KeyboxError;
|
||||
|
||||
|
||||
|
||||
typedef struct keybox_handle *KEYBOX_HANDLE;
|
||||
|
||||
|
@ -115,9 +94,6 @@ void keybox_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
|
|||
void *(*new_realloc_func)(void *p, size_t n),
|
||||
void (*new_free_func)(void*) );
|
||||
|
||||
/*-- keybox-errors.c (built) --*/
|
||||
const char *keybox_strerror (KeyboxError err);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue