1998-07-09 15:37:17 +02:00
|
|
|
/* tdbio.h - Trust database I/O functions
|
2000-07-14 19:34:53 +02:00
|
|
|
* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
1998-07-09 15:37:17 +02:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* This file is part of GnuPG.
|
1998-07-09 15:37:17 +02:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1998-07-09 15:37:17 +02:00
|
|
|
* 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.
|
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1998-07-09 15:37:17 +02:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2000-01-27 17:50:45 +01:00
|
|
|
#ifndef GPG_TDBIO_H
|
|
|
|
#define GPG_TDBIO_H
|
1998-07-09 15:37:17 +02:00
|
|
|
|
1998-10-21 19:34:36 +02:00
|
|
|
#include "host2net.h"
|
1998-07-09 15:37:17 +02:00
|
|
|
|
|
|
|
#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
|
1998-10-12 22:16:38 +02:00
|
|
|
#define RECTYPE_SDIR 8
|
1998-07-14 19:10:28 +02:00
|
|
|
#define RECTYPE_CACH 9
|
|
|
|
#define RECTYPE_HTBL 10
|
|
|
|
#define RECTYPE_HLST 11
|
1998-10-07 15:30:43 +02:00
|
|
|
#define RECTYPE_FREE 254
|
1998-07-09 15:37:17 +02:00
|
|
|
|
|
|
|
|
1998-11-13 20:41:41 +01:00
|
|
|
#define DIRF_CHECKED 1 /* has been checked - bits 1,2,3 are valid */
|
1998-10-21 19:34:36 +02:00
|
|
|
#define DIRF_VALID 2 /* This key is valid: There is at least */
|
|
|
|
/* one uid with a selfsignature or an revocation */
|
|
|
|
#define DIRF_EXPIRED 4 /* the complete key has expired */
|
1998-07-21 14:53:38 +02:00
|
|
|
#define DIRF_REVOKED 8 /* the complete key has been revoked */
|
2000-07-14 19:34:53 +02:00
|
|
|
#define DIRF_NEWKEYS 128 /* new keys are available: we can check the sigs */
|
1998-07-21 14:53:38 +02:00
|
|
|
|
1998-10-21 19:34:36 +02:00
|
|
|
#define KEYF_CHECKED 1 /* This key has been checked */
|
|
|
|
#define KEYF_VALID 2 /* This is a valid (sub)key */
|
1998-10-18 17:21:22 +02:00
|
|
|
#define KEYF_EXPIRED 4 /* this key is expired */
|
|
|
|
#define KEYF_REVOKED 8 /* this key has been revoked */
|
1998-07-21 14:53:38 +02:00
|
|
|
|
1999-02-10 17:22:40 +01:00
|
|
|
#define UIDF_CHECKED 1 /* user id has been checked - other bits are valid */
|
|
|
|
#define UIDF_VALID 2 /* this is a valid user id */
|
|
|
|
#define UIDF_REVOKED 8 /* this user id has been revoked */
|
1998-10-12 22:16:38 +02:00
|
|
|
|
|
|
|
#define SIGF_CHECKED 1 /* signature has been checked - bits 0..6 are valid */
|
|
|
|
#define SIGF_VALID 2 /* the signature is valid */
|
1998-10-21 19:34:36 +02:00
|
|
|
#define SIGF_EXPIRED 4 /* the key of this signature has expired */
|
1998-10-12 22:16:38 +02:00
|
|
|
#define SIGF_REVOKED 8 /* this signature has been revoked */
|
1999-06-29 21:50:54 +02:00
|
|
|
#define SIGF_IGNORED 64 /* this signature is ignored by the system */
|
1998-10-12 22:16:38 +02:00
|
|
|
#define SIGF_NOPUBKEY 128 /* there is no pubkey for this sig */
|
1998-07-21 14:53:38 +02:00
|
|
|
|
1998-07-09 15:37:17 +02:00
|
|
|
struct trust_record {
|
|
|
|
int rectype;
|
1998-07-15 20:05:01 +02:00
|
|
|
int mark;
|
1998-10-12 22:16:38 +02:00
|
|
|
int dirty; /* for now only used internal by functions */
|
1998-10-07 15:30:43 +02:00
|
|
|
struct trust_record *next; /* help pointer to build lists in memory */
|
1998-07-15 20:05:01 +02:00
|
|
|
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-11-13 20:41:41 +01:00
|
|
|
byte marginals;
|
|
|
|
byte completes;
|
|
|
|
byte cert_depth;
|
1998-07-09 15:37:17 +02:00
|
|
|
ulong created; /* timestamp of trustdb creation */
|
1999-03-11 16:42:06 +01:00
|
|
|
ulong mod_down; /* timestamp of last modification downward */
|
|
|
|
ulong mod_up; /* timestamp of last modification upward */
|
1998-07-29 21:35:05 +02:00
|
|
|
ulong keyhashtbl;
|
1998-10-07 15:30:43 +02:00
|
|
|
ulong firstfree;
|
1998-10-12 22:16:38 +02:00
|
|
|
ulong sdirhashtbl;
|
1998-07-09 15:37:17 +02:00
|
|
|
} ver;
|
1998-10-07 15:30:43 +02:00
|
|
|
struct { /* free record */
|
|
|
|
ulong next;
|
|
|
|
} free;
|
1998-07-09 15:37:17 +02:00
|
|
|
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;
|
1999-06-29 21:50:54 +02:00
|
|
|
byte validity; /* calculated trustlevel over all uids */
|
|
|
|
ulong valcheck; /* timestamp of last validation check */
|
|
|
|
ulong checkat; /* Check key when this time has been reached*/
|
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;
|
1999-02-10 17:22:40 +01:00
|
|
|
byte validity; /* calculated trustlevel of this uid */
|
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 */
|
2000-07-14 19:34:53 +02:00
|
|
|
/* or 0 for a global pref record */
|
1998-07-14 19:10:28 +02:00
|
|
|
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-10-12 22:16:38 +02:00
|
|
|
byte flag; /* SIGF_xxxxx */
|
1998-07-09 15:37:17 +02:00
|
|
|
} sig[SIGS_PER_RECORD];
|
|
|
|
} sig;
|
1998-10-12 22:16:38 +02:00
|
|
|
struct {
|
|
|
|
ulong lid;
|
|
|
|
u32 keyid[2];
|
|
|
|
byte pubkey_algo;
|
|
|
|
u32 hintlist;
|
|
|
|
} sdir;
|
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-10-12 22:16:38 +02:00
|
|
|
ulong rnum[ITEMS_PER_HLST_RECORD]; /* of another 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-11-13 20:41:41 +01:00
|
|
|
int tdbio_db_matches_options(void);
|
1999-03-11 16:42:06 +01:00
|
|
|
ulong tdbio_read_modify_stamp( int modify_down );
|
1999-03-17 13:13:04 +01:00
|
|
|
void tdbio_write_modify_stamp( int up, int down );
|
1998-10-25 20:00:01 +01:00
|
|
|
int tdbio_is_dirty(void);
|
1998-10-16 18:00:17 +02:00
|
|
|
int tdbio_sync(void);
|
1998-10-25 20:00:01 +01:00
|
|
|
int tdbio_begin_transaction(void);
|
|
|
|
int tdbio_end_transaction(void);
|
|
|
|
int tdbio_cancel_transaction(void);
|
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 );
|
1999-06-29 21:50:54 +02:00
|
|
|
int tdbio_search_dir( u32 *keyid, int pubkey_algo, TRUSTREC *rec );
|
1998-10-12 22:16:38 +02:00
|
|
|
int tdbio_search_sdir( u32 *keyid, int pubkey_algo, TRUSTREC *rec );
|
1998-07-09 15:37:17 +02:00
|
|
|
|
1999-03-11 16:42:06 +01:00
|
|
|
void tdbio_invalid(void);
|
1998-07-09 15:37:17 +02:00
|
|
|
|
2000-01-27 17:50:45 +01:00
|
|
|
#endif /*GPG_TDBIO_H*/
|