Coverage Report

Created: 2026-01-10 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gnupg/kbx/keybox-defs.h
Line
Count
Source
1
/* keybox-defs.h - internal Keybox definitions
2
 *  Copyright (C) 2001, 2004 Free Software Foundation, Inc.
3
 *
4
 * This file is part of GnuPG.
5
 *
6
 * GnuPG is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GnuPG is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
#ifndef KEYBOX_DEFS_H
21
#define KEYBOX_DEFS_H 1
22
23
#ifndef GPG_ERR_SOURCE_DEFAULT
24
#define GPG_ERR_SOURCE_DEFAULT  GPG_ERR_SOURCE_KEYBOX
25
#endif
26
#include <gpg-error.h>
27
#define map_assuan_err(a) \
28
        map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
29
30
#include <sys/types.h> /* off_t */
31
32
#include "../common/util.h"
33
#include "keybox.h"
34
35
36
typedef struct keyboxblob *KEYBOXBLOB;
37
38
39
typedef struct keybox_name *KB_NAME;
40
struct keybox_name
41
{
42
  /* Link to the next resources, so that we can walk all
43
     resources.  */
44
  KB_NAME next;
45
46
  /* True if this is a keybox with secret keys.  */
47
  int secret;
48
49
  /* A table with all the handles accessing this resources.
50
     HANDLE_TABLE_SIZE gives the allocated length of this table unused
51
     entrues are set to NULL.  HANDLE_TABLE may be NULL. */
52
  KEYBOX_HANDLE *handle_table;
53
  size_t handle_table_size;
54
55
  /* The lock handle or NULL it not yet initialized.  */
56
  dotlock_t lockhd;
57
58
  /* Not yet used.  */
59
  int is_locked;
60
61
  /* Not yet used.  */
62
  int did_full_scan;
63
64
  /* The name of the resource file. */
65
  char fname[1];
66
};
67
68
69
struct keybox_found_s
70
{
71
  KEYBOXBLOB blob;
72
  size_t pk_no;
73
  size_t uid_no;
74
};
75
76
struct keybox_handle {
77
  KB_NAME kb;
78
  int secret;             /* this is for a secret keybox */
79
  estream_t fp;
80
  int eof;
81
  int error;
82
  int ephemeral;
83
  int for_openpgp;        /* Used by gpg.  */
84
  struct keybox_found_s found;
85
  struct keybox_found_s saved_found;
86
  struct {
87
    char *name;
88
    char *pattern;
89
  } word_match;
90
};
91
92
93
/* OpenPGP helper structures.  */
94
struct _keybox_openpgp_key_info
95
{
96
  struct _keybox_openpgp_key_info *next;
97
  int algo;
98
  int version;
99
  unsigned char grip[20];
100
  unsigned char keyid[8];
101
  int fprlen;  /* Either 16, 20 or 32 */
102
  unsigned char fpr[32];
103
};
104
105
struct _keybox_openpgp_uid_info
106
{
107
  struct _keybox_openpgp_uid_info *next;
108
  size_t off;
109
  size_t len;
110
};
111
112
struct _keybox_openpgp_info
113
{
114
  int is_secret;        /* True if this is a secret key. */
115
  unsigned int nsubkeys;/* Total number of subkeys.  */
116
  unsigned int nuids;   /* Total number of user IDs in the keyblock. */
117
  unsigned int nsigs;   /* Total number of signatures in the keyblock. */
118
119
  /* Note, we use 2 structs here to better cope with the most common
120
     use of having one primary and one subkey - this allows us to
121
     statically allocate this structure and only malloc stuff for more
122
     than one subkey. */
123
  struct _keybox_openpgp_key_info primary;
124
  struct _keybox_openpgp_key_info subkeys;
125
  struct _keybox_openpgp_uid_info uids;
126
};
127
typedef struct _keybox_openpgp_info *keybox_openpgp_info_t;
128
129
130
/* Don't know whether this is needed: */
131
/*  static struct { */
132
/*    int dry_run; */
133
/*    int quiet; */
134
/*    int verbose; */
135
/*    int preserve_permissions; */
136
/*  } keybox_opt; */
137
138
/*-- keybox-init.c --*/
139
140
#define KEYBOX_LL_OPEN_READ    0
141
14.8k
#define KEYBOX_LL_OPEN_UPDATE  1
142
20.7k
#define KEYBOX_LL_OPEN_CREATE  2
143
gpg_error_t _keybox_ll_open (estream_t *rfp, const char *fname,
144
                             unsigned int mode);
145
gpg_error_t _keybox_ll_close (estream_t fp);
146
147
void _keybox_close_file (KEYBOX_HANDLE hd);
148
149
150
/*-- keybox-blob.c --*/
151
gpg_error_t _keybox_create_openpgp_blob (KEYBOXBLOB *r_blob,
152
                                         keybox_openpgp_info_t info,
153
                                         const unsigned char *image,
154
                                         size_t imagelen,
155
                                         int as_ephemeral);
156
char *_keybox_x509_email_kludge (const char *name);
157
158
#ifdef KEYBOX_WITH_X509
159
int _keybox_create_x509_blob (KEYBOXBLOB *r_blob, ksba_cert_t cert,
160
                              unsigned char *sha1_digest, int as_ephemeral);
161
#endif /*KEYBOX_WITH_X509*/
162
163
int  _keybox_new_blob (KEYBOXBLOB *r_blob,
164
                       unsigned char *image, size_t imagelen,
165
                       off_t off);
166
void _keybox_release_blob (KEYBOXBLOB blob);
167
const unsigned char *_keybox_get_blob_image (KEYBOXBLOB blob, size_t *n);
168
off_t _keybox_get_blob_fileoffset (KEYBOXBLOB blob);
169
void _keybox_update_header_blob (KEYBOXBLOB blob, int for_openpgp);
170
171
/*-- keybox-openpgp.c --*/
172
gpg_error_t _keybox_parse_openpgp (const unsigned char *image, size_t imagelen,
173
                                   int only_primary, size_t *nparsed,
174
                                   keybox_openpgp_info_t info);
175
void _keybox_destroy_openpgp_info (keybox_openpgp_info_t info);
176
177
178
/*-- keybox-file.c --*/
179
int _keybox_read_blob (KEYBOXBLOB *r_blob, estream_t fp, int *skipped_deleted);
180
int _keybox_write_blob (KEYBOXBLOB blob, estream_t fp, FILE *outfp);
181
182
/*-- keybox-search.c --*/
183
gpg_err_code_t _keybox_get_flag_location (const unsigned char *buffer,
184
                                          size_t length,
185
                                          int what,
186
                                          size_t *flag_off, size_t *flag_size);
187
188
static inline int
189
blob_get_type (KEYBOXBLOB blob)
190
300k
{
191
300k
  const unsigned char *buffer;
192
300k
  size_t length;
193
194
300k
  buffer = _keybox_get_blob_image (blob, &length);
195
300k
  if (length < 32)
196
0
    return -1; /* blob too short */
197
198
300k
  return buffer[4];
199
300k
}
Unexecuted instantiation: keybox-util.c:blob_get_type
Unexecuted instantiation: keybox-init.c:blob_get_type
Unexecuted instantiation: keybox-blob.c:blob_get_type
Unexecuted instantiation: keybox-file.c:blob_get_type
keybox-search.c:blob_get_type
Line
Count
Source
190
297k
{
191
297k
  const unsigned char *buffer;
192
297k
  size_t length;
193
194
297k
  buffer = _keybox_get_blob_image (blob, &length);
195
297k
  if (length < 32)
196
0
    return -1; /* blob too short */
197
198
297k
  return buffer[4];
199
297k
}
keybox-update.c:blob_get_type
Line
Count
Source
190
2.89k
{
191
2.89k
  const unsigned char *buffer;
192
2.89k
  size_t length;
193
194
2.89k
  buffer = _keybox_get_blob_image (blob, &length);
195
2.89k
  if (length < 32)
196
0
    return -1; /* blob too short */
197
198
2.89k
  return buffer[4];
199
2.89k
}
Unexecuted instantiation: keybox-openpgp.c:blob_get_type
200
201
202
/*-- keybox-dump.c --*/
203
int _keybox_dump_blob (KEYBOXBLOB blob, FILE *fp);
204
int _keybox_dump_file (const char *filename, int stats_only, FILE *outfp);
205
int _keybox_dump_find_dups (const char *filename, int print_them, FILE *outfp);
206
int _keybox_dump_cut_records (const char *filename, unsigned long from,
207
                              unsigned long to, FILE *outfp);
208
209
210
/*-- keybox-util.c --*/
211
212
/*
213
 * A couple of handy macros
214
 */
215
216
217
#endif /*KEYBOX_DEFS_H*/