2003-06-05 09:14:21 +02:00
|
|
|
/* keybox-defs.h - interal Keybox defintions
|
2004-04-20 16:16:55 +02:00
|
|
|
* Copyright (C) 2001, 2004 Free Software Foundation, Inc.
|
2003-06-05 09:14:21 +02:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-05 09:14:21 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-04 21:49:40 +02:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2003-06-05 09:14:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEYBOX_DEFS_H
|
|
|
|
#define KEYBOX_DEFS_H 1
|
|
|
|
|
|
|
|
#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>
|
2004-12-18 11:22:10 +01:00
|
|
|
#define map_assuan_err(a) \
|
|
|
|
map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
|
|
|
|
|
2003-11-12 16:17:44 +01:00
|
|
|
#include <sys/types.h> /* off_t */
|
|
|
|
|
2004-04-20 16:16:55 +02:00
|
|
|
/* We include the type defintions from jnlib instead of defining our
|
|
|
|
owns here. This will not allow us build KBX in a standalone way
|
2004-12-02 08:48:09 +01:00
|
|
|
but there is currently no need for it anyway. Same goes for
|
|
|
|
stringhelp.h which for example provides a replacement for stpcpy -
|
2010-03-10 13:24:58 +01:00
|
|
|
fixme: Better use the LIBOBJ mechnism. */
|
|
|
|
#include "../common/types.h"
|
|
|
|
#include "../common/stringhelp.h"
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2004-04-20 16:16:55 +02:00
|
|
|
#include "keybox.h"
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BLOBTYPE_EMPTY = 0,
|
|
|
|
BLOBTYPE_HEADER = 1,
|
|
|
|
BLOBTYPE_PGP = 2,
|
|
|
|
BLOBTYPE_X509 = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct keyboxblob *KEYBOXBLOB;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct keybox_name *KB_NAME;
|
2008-04-01 17:08:57 +02:00
|
|
|
typedef struct keybox_name const *CONST_KB_NAME;
|
2011-02-04 12:57:53 +01:00
|
|
|
struct keybox_name
|
2008-04-01 17:08:57 +02:00
|
|
|
{
|
|
|
|
/* Link to the next resources, so that we can walk all
|
|
|
|
resources. */
|
|
|
|
KB_NAME next;
|
|
|
|
|
|
|
|
/* True if this is a keybox with secret keys. */
|
2003-06-05 09:14:21 +02:00
|
|
|
int secret;
|
2008-04-01 17:08:57 +02:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
/*DOTLOCK lockhd;*/
|
2008-04-01 17:08:57 +02:00
|
|
|
|
|
|
|
/* A table with all the handles accessing this resources.
|
|
|
|
HANDLE_TABLE_SIZE gives the allocated length of this table unused
|
|
|
|
entrues are set to NULL. HANDLE_TABLE may be NULL. */
|
|
|
|
KEYBOX_HANDLE *handle_table;
|
|
|
|
size_t handle_table_size;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2008-04-01 17:08:57 +02:00
|
|
|
/* Not yet used. */
|
2003-06-05 09:14:21 +02:00
|
|
|
int is_locked;
|
2008-04-01 17:08:57 +02:00
|
|
|
|
|
|
|
/* Not yet used. */
|
2003-06-05 09:14:21 +02:00
|
|
|
int did_full_scan;
|
2008-04-01 17:08:57 +02:00
|
|
|
|
|
|
|
/* The name of the resource file. */
|
2003-06-05 09:14:21 +02:00
|
|
|
char fname[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct keybox_handle {
|
|
|
|
CONST_KB_NAME kb;
|
|
|
|
int secret; /* this is for a secret keybox */
|
|
|
|
FILE *fp;
|
|
|
|
int eof;
|
|
|
|
int error;
|
2011-02-04 12:57:53 +01:00
|
|
|
int ephemeral;
|
2003-06-05 09:14:21 +02:00
|
|
|
struct {
|
|
|
|
KEYBOXBLOB blob;
|
|
|
|
off_t offset;
|
|
|
|
size_t pk_no;
|
|
|
|
size_t uid_no;
|
|
|
|
unsigned int n_packets; /*used for delete and update*/
|
|
|
|
} found;
|
|
|
|
struct {
|
|
|
|
char *name;
|
|
|
|
char *pattern;
|
|
|
|
} word_match;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-08-24 21:55:47 +02:00
|
|
|
/* Openpgp helper structures. */
|
|
|
|
struct _keybox_openpgp_key_info
|
|
|
|
{
|
|
|
|
struct _keybox_openpgp_key_info *next;
|
|
|
|
unsigned char keyid[8];
|
|
|
|
int fprlen; /* Either 16 or 20 */
|
|
|
|
unsigned char fpr[20];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _keybox_openpgp_uid_info
|
|
|
|
{
|
|
|
|
struct _keybox_openpgp_uid_info *next;
|
|
|
|
size_t off;
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _keybox_openpgp_info
|
|
|
|
{
|
|
|
|
int is_secret; /* True if this is a secret key. */
|
|
|
|
unsigned int nsubkeys;/* Total number of subkeys. */
|
|
|
|
unsigned int nuids; /* Total number of user IDs in the keyblock. */
|
|
|
|
unsigned int nsigs; /* Total number of signatures in the keyblock. */
|
|
|
|
|
|
|
|
/* Note, we use 2 structs here to better cope with the most common
|
|
|
|
use of having one primary and one subkey - this allows us to
|
|
|
|
statically allocate this structure and only malloc stuff for more
|
|
|
|
than one subkey. */
|
|
|
|
struct _keybox_openpgp_key_info primary;
|
|
|
|
struct _keybox_openpgp_key_info subkeys;
|
|
|
|
struct _keybox_openpgp_uid_info uids;
|
|
|
|
};
|
|
|
|
typedef struct _keybox_openpgp_info *keybox_openpgp_info_t;
|
|
|
|
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
/* Don't know whether this is needed: */
|
|
|
|
/* static struct { */
|
|
|
|
/* const char *homedir; */
|
|
|
|
/* int dry_run; */
|
|
|
|
/* int quiet; */
|
|
|
|
/* int verbose; */
|
|
|
|
/* int preserve_permissions; */
|
|
|
|
/* } keybox_opt; */
|
|
|
|
|
2008-04-01 17:08:57 +02:00
|
|
|
/*-- keybox-init.c --*/
|
|
|
|
void _keybox_close_file (KEYBOX_HANDLE hd);
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
/*-- keybox-blob.c --*/
|
|
|
|
#ifdef KEYBOX_WITH_OPENPGP
|
|
|
|
/* fixme */
|
|
|
|
#endif /*KEYBOX_WITH_OPENPGP*/
|
|
|
|
#ifdef KEYBOX_WITH_X509
|
2003-12-17 13:27:21 +01:00
|
|
|
int _keybox_create_x509_blob (KEYBOXBLOB *r_blob, ksba_cert_t cert,
|
2003-06-05 09:14:21 +02:00
|
|
|
unsigned char *sha1_digest, int as_ephemeral);
|
|
|
|
#endif /*KEYBOX_WITH_X509*/
|
|
|
|
|
2005-06-16 10:12:03 +02:00
|
|
|
int _keybox_new_blob (KEYBOXBLOB *r_blob,
|
|
|
|
unsigned char *image, size_t imagelen,
|
2003-06-05 09:14:21 +02:00
|
|
|
off_t off);
|
|
|
|
void _keybox_release_blob (KEYBOXBLOB blob);
|
2005-06-16 10:12:03 +02:00
|
|
|
const unsigned char *_keybox_get_blob_image (KEYBOXBLOB blob, size_t *n);
|
2003-06-05 09:14:21 +02:00
|
|
|
off_t _keybox_get_blob_fileoffset (KEYBOXBLOB blob);
|
2004-04-26 10:09:25 +02:00
|
|
|
void _keybox_update_header_blob (KEYBOXBLOB blob);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2004-08-24 21:55:47 +02:00
|
|
|
/*-- keybox-openpgp.c --*/
|
|
|
|
gpg_error_t _keybox_parse_openpgp (const unsigned char *image, size_t imagelen,
|
|
|
|
size_t *nparsed,
|
|
|
|
keybox_openpgp_info_t info);
|
|
|
|
void _keybox_destroy_openpgp_info (keybox_openpgp_info_t info);
|
|
|
|
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
/*-- keybox-file.c --*/
|
|
|
|
int _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp);
|
2004-04-26 10:09:25 +02:00
|
|
|
int _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted);
|
2003-06-05 09:14:21 +02:00
|
|
|
int _keybox_write_blob (KEYBOXBLOB blob, FILE *fp);
|
2004-04-26 10:09:25 +02:00
|
|
|
int _keybox_write_header_blob (FILE *fp);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2004-02-02 18:09:35 +01:00
|
|
|
/*-- keybox-search.c --*/
|
|
|
|
gpg_err_code_t _keybox_get_flag_location (const unsigned char *buffer,
|
|
|
|
size_t length,
|
|
|
|
int what,
|
|
|
|
size_t *flag_off, size_t *flag_size);
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
/*-- keybox-dump.c --*/
|
|
|
|
int _keybox_dump_blob (KEYBOXBLOB blob, FILE *fp);
|
2004-06-18 11:53:56 +02:00
|
|
|
int _keybox_dump_file (const char *filename, int stats_only, FILE *outfp);
|
2007-08-23 19:41:22 +02:00
|
|
|
int _keybox_dump_find_dups (const char *filename, int print_them, FILE *outfp);
|
|
|
|
int _keybox_dump_cut_records (const char *filename, unsigned long from,
|
|
|
|
unsigned long to, FILE *outfp);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*-- keybox-util.c --*/
|
|
|
|
void *_keybox_malloc (size_t n);
|
|
|
|
void *_keybox_calloc (size_t n, size_t m);
|
|
|
|
void *_keybox_realloc (void *p, size_t n);
|
|
|
|
void _keybox_free (void *p);
|
|
|
|
|
|
|
|
#define xtrymalloc(a) _keybox_malloc ((a))
|
|
|
|
#define xtrycalloc(a,b) _keybox_calloc ((a),(b))
|
|
|
|
#define xtryrealloc(a,b) _keybox_realloc((a),(b))
|
|
|
|
#define xfree(a) _keybox_free ((a))
|
|
|
|
|
|
|
|
|
|
|
|
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
|
|
|
#define DIMof(type,member) DIM(((type *)0)->member)
|
|
|
|
#ifndef STR
|
2007-08-23 19:41:22 +02:00
|
|
|
# define STR(v) #v
|
2003-06-05 09:14:21 +02:00
|
|
|
#endif
|
|
|
|
#define STR2(v) STR(v)
|
|
|
|
|
|
|
|
/*
|
2011-02-04 12:57:53 +01:00
|
|
|
a couple of handy macros
|
2003-06-05 09:14:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define return_if_fail(expr) do { \
|
|
|
|
if (!(expr)) { \
|
|
|
|
fprintf (stderr, "%s:%d: assertion `%s' failed\n", \
|
|
|
|
__FILE__, __LINE__, #expr ); \
|
|
|
|
return; \
|
|
|
|
} } while (0)
|
|
|
|
#define return_null_if_fail(expr) do { \
|
|
|
|
if (!(expr)) { \
|
|
|
|
fprintf (stderr, "%s:%d: assertion `%s' failed\n", \
|
|
|
|
__FILE__, __LINE__, #expr ); \
|
|
|
|
return NULL; \
|
|
|
|
} } while (0)
|
|
|
|
#define return_val_if_fail(expr,val) do { \
|
|
|
|
if (!(expr)) { \
|
|
|
|
fprintf (stderr, "%s:%d: assertion `%s' failed\n", \
|
|
|
|
__FILE__, __LINE__, #expr ); \
|
|
|
|
return (val); \
|
|
|
|
} } while (0)
|
|
|
|
#define never_reached() do { \
|
|
|
|
fprintf (stderr, "%s:%d: oops; should never get here\n", \
|
|
|
|
__FILE__, __LINE__ ); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
/* some macros to replace ctype ones and avoid locale problems */
|
|
|
|
#define digitp(p) (*(p) >= '0' && *(p) <= '9')
|
|
|
|
#define hexdigitp(a) (digitp (a) \
|
|
|
|
|| (*(a) >= 'A' && *(a) <= 'F') \
|
|
|
|
|| (*(a) >= 'a' && *(a) <= 'f'))
|
|
|
|
/* the atoi macros assume that the buffer has only valid digits */
|
|
|
|
#define atoi_1(p) (*(p) - '0' )
|
|
|
|
#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
|
|
|
|
#define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2))
|
|
|
|
#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
|
|
|
|
*(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
|
|
|
|
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
|
|
|
|
|
|
|
|
|
|
|
|
#endif /*KEYBOX_DEFS_H*/
|