1998-07-09 15:37:17 +02:00
|
|
|
/* tdbio.h - Trust database I/O functions
|
|
|
|
* Copyright (C) 1998 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef G10_TDBIO_H
|
|
|
|
#define G10_TDBIO_H
|
|
|
|
|
|
|
|
|
|
|
|
#define TRUST_RECORD_LEN 40
|
|
|
|
#define SIGS_PER_RECORD ((TRUST_RECORD_LEN-10)/5)
|
|
|
|
#define ITEMS_PER_HTBL_RECORD ((TRUST_RECORD_LEN-2)/4)
|
|
|
|
#define ITEMS_PER_HLST_RECORD ((TRUST_RECORD_LEN-6)/5)
|
1998-08-05 18:51:59 +02:00
|
|
|
#define ITEMS_PER_PREF_RECORD (TRUST_RECORD_LEN-10)
|
|
|
|
#if ITEMS_PER_PREF_RECORD % 2
|
|
|
|
#error ITEMS_PER_PREF_RECORD must be even
|
|
|
|
#endif
|
1998-07-09 15:37:17 +02:00
|
|
|
#define MAX_LIST_SIGS_DEPTH 20
|
|
|
|
|
|
|
|
|
|
|
|
#define RECTYPE_VER 1
|
|
|
|
#define RECTYPE_DIR 2
|
|
|
|
#define RECTYPE_KEY 3
|
1998-07-14 19:10:28 +02:00
|
|
|
#define RECTYPE_UID 4
|
|
|
|
#define RECTYPE_PREF 5
|
|
|
|
#define RECTYPE_SIG 6
|
|
|
|
#define RECTYPE_CACH 9
|
|
|
|
#define RECTYPE_HTBL 10
|
|
|
|
#define RECTYPE_HLST 11
|
1998-07-09 15:37:17 +02:00
|
|
|
|
|
|
|
|
1998-07-21 14:53:38 +02:00
|
|
|
#define DIRF_CHECKED 1 /* everything has been checked, the other bits are
|
|
|
|
valid */
|
|
|
|
#define DIRF_MISKEY 2 /* some keys are missing, so they could not be checked*/
|
|
|
|
#define DIRF_ERROR 4 /* severe errors: the key is not valid for some reasons
|
|
|
|
but we mark it to avoid duplicate checks */
|
|
|
|
#define DIRF_REVOKED 8 /* the complete key has been revoked */
|
|
|
|
|
|
|
|
#define KEYF_REVOKED DIRF_REVOKED /* this key has been revoked
|
|
|
|
(only useful on subkeys)*/
|
|
|
|
#define UIDF_REVOKED DIRF_REVOKED /* this user id has been revoked */
|
|
|
|
|
|
|
|
|
1998-07-09 15:37:17 +02:00
|
|
|
struct trust_record {
|
|
|
|
int rectype;
|
1998-07-15 20:05:01 +02:00
|
|
|
struct trust_record *next; /* help pointer to build lists in memory */
|
|
|
|
struct trust_record *help_pref;
|
|
|
|
int mark;
|
|
|
|
ulong recnum;
|
1998-07-09 15:37:17 +02:00
|
|
|
union {
|
1998-07-29 21:35:05 +02:00
|
|
|
struct { /* version record: */
|
|
|
|
byte version; /* should be 2 */
|
1998-07-09 15:37:17 +02:00
|
|
|
ulong created; /* timestamp of trustdb creation */
|
|
|
|
ulong modified; /* timestamp of last modification */
|
|
|
|
ulong validated; /* timestamp of last validation */
|
1998-07-29 21:35:05 +02:00
|
|
|
ulong keyhashtbl;
|
1998-07-09 15:37:17 +02:00
|
|
|
} ver;
|
|
|
|
struct { /* directory record */
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong lid;
|
|
|
|
ulong keylist; /* List of keys (the first is the primary key)*/
|
|
|
|
ulong uidlist; /* list of uid records */
|
|
|
|
ulong cacherec; /* the cache record */
|
|
|
|
byte ownertrust;
|
1998-07-21 14:53:38 +02:00
|
|
|
byte dirflags;
|
1998-07-09 15:37:17 +02:00
|
|
|
} dir;
|
|
|
|
struct { /* primary public key record */
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong lid;
|
|
|
|
ulong next; /* next key */
|
1998-07-21 14:53:38 +02:00
|
|
|
byte keyflags;
|
1998-07-09 15:37:17 +02:00
|
|
|
byte pubkey_algo;
|
|
|
|
byte fingerprint_len;
|
|
|
|
byte fingerprint[20];
|
|
|
|
} key;
|
|
|
|
struct { /* user id reord */
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong lid; /* point back to the directory record */
|
|
|
|
ulong next; /* points to next user id record */
|
1998-07-15 20:05:01 +02:00
|
|
|
ulong prefrec; /* recno of preference record */
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong siglist; /* list of valid signatures (w/o self-sig)*/
|
1998-07-21 14:53:38 +02:00
|
|
|
byte uidflags;
|
1998-07-14 19:10:28 +02:00
|
|
|
byte namehash[20]; /* ripemd hash of the username */
|
1998-07-09 15:37:17 +02:00
|
|
|
} uid;
|
1998-08-05 18:51:59 +02:00
|
|
|
struct { /* preference record */
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong lid; /* point back to the directory record */
|
|
|
|
/* or 0 for a glocal pref record */
|
|
|
|
ulong next; /* points to next pref record */
|
1998-08-05 18:51:59 +02:00
|
|
|
byte data[ITEMS_PER_PREF_RECORD];
|
1998-07-14 19:10:28 +02:00
|
|
|
} pref;
|
1998-07-09 15:37:17 +02:00
|
|
|
struct { /* signature record */
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong lid;
|
|
|
|
ulong next; /* recnno of next record or NULL for last one */
|
1998-07-09 15:37:17 +02:00
|
|
|
struct {
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong lid; /* of pubkey record of signator (0=unused) */
|
1998-07-21 14:53:38 +02:00
|
|
|
byte flag; /* SIGRF_xxxxx */
|
1998-07-09 15:37:17 +02:00
|
|
|
} sig[SIGS_PER_RECORD];
|
|
|
|
} sig;
|
1998-07-14 19:10:28 +02:00
|
|
|
struct { /* cache record */
|
|
|
|
ulong lid;
|
|
|
|
byte blockhash[20];
|
|
|
|
byte trustlevel; /* calculated trustlevel */
|
|
|
|
} cache;
|
1998-07-09 15:37:17 +02:00
|
|
|
struct {
|
|
|
|
ulong item[ITEMS_PER_HTBL_RECORD];
|
|
|
|
} htbl;
|
|
|
|
struct {
|
1998-07-14 19:10:28 +02:00
|
|
|
ulong next;
|
1998-07-29 21:35:05 +02:00
|
|
|
ulong rnum[ITEMS_PER_HLST_RECORD]; /* of a key record */
|
1998-07-09 15:37:17 +02:00
|
|
|
} hlst;
|
|
|
|
} r;
|
|
|
|
};
|
|
|
|
typedef struct trust_record TRUSTREC;
|
|
|
|
|
|
|
|
typedef struct {
|
1998-07-21 14:53:38 +02:00
|
|
|
ulong lid; /* localid */
|
1998-07-09 15:37:17 +02:00
|
|
|
ulong sigrec;
|
1998-07-21 14:53:38 +02:00
|
|
|
ulong sig_lid; /* returned signatures LID */
|
1998-07-09 15:37:17 +02:00
|
|
|
unsigned sig_flag; /* returned signature record flag */
|
|
|
|
struct { /* internal data */
|
|
|
|
int init_done;
|
|
|
|
int eof;
|
|
|
|
TRUSTREC rec;
|
1998-07-21 14:53:38 +02:00
|
|
|
ulong nextuid;
|
1998-07-09 15:37:17 +02:00
|
|
|
int index;
|
|
|
|
} ctl;
|
|
|
|
} SIGREC_CONTEXT;
|
|
|
|
|
|
|
|
|
|
|
|
/*-- tdbio.c --*/
|
|
|
|
int tdbio_set_dbname( const char *new_dbname, int create );
|
|
|
|
const char *tdbio_get_dbname(void);
|
1998-07-21 14:53:38 +02:00
|
|
|
void tdbio_dump_record( TRUSTREC *rec, FILE *fp );
|
1998-07-09 15:37:17 +02:00
|
|
|
int tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected );
|
1998-07-15 20:05:01 +02:00
|
|
|
int tdbio_write_record( TRUSTREC *rec );
|
1998-07-21 14:53:38 +02:00
|
|
|
int tdbio_delete_record( ulong recnum );
|
1998-07-09 15:37:17 +02:00
|
|
|
ulong tdbio_new_recnum(void);
|
1998-07-30 19:37:03 +02:00
|
|
|
int tdbio_search_dir_bypk( PKT_public_key *pk, TRUSTREC *rec );
|
|
|
|
int tdbio_search_dir_byfpr( const byte *fingerprint, size_t fingerlen,
|
|
|
|
int pubkey_algo, TRUSTREC *rec );
|
1998-07-21 14:53:38 +02:00
|
|
|
int tdbio_delete_uidrec( ulong dirlid, ulong uidlid );
|
1998-07-09 15:37:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
#define buftoulong( p ) ((*(byte*)(p) << 24) | (*((byte*)(p)+1)<< 16) | \
|
|
|
|
(*((byte*)(p)+2) << 8) | (*((byte*)(p)+3)))
|
|
|
|
#define buftoushort( p ) ((*((byte*)(p)) << 8) | (*((byte*)(p)+1)))
|
|
|
|
#define ulongtobuf( p, a ) do { \
|
|
|
|
((byte*)p)[0] = a >> 24; \
|
|
|
|
((byte*)p)[1] = a >> 16; \
|
|
|
|
((byte*)p)[2] = a >> 8; \
|
|
|
|
((byte*)p)[3] = a ; \
|
|
|
|
} while(0)
|
|
|
|
#define ushorttobuf( p, a ) do { \
|
|
|
|
((byte*)p)[0] = a >> 8; \
|
|
|
|
((byte*)p)[1] = a ; \
|
|
|
|
} while(0)
|
|
|
|
#define buftou32( p) buftoulong( (p) )
|
|
|
|
#define u32tobuf( p, a) ulongtobuf( (p), (a) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /*G10_TDBIO_H*/
|