chiark / gitweb /
gpg agent lockup fix: Interrupt main loop when active_connections_value==0
[gnupg2.git] / g10 / options.h
1 /* options.h
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3  *               2007, 2010, 2011 Free Software Foundation, Inc.
4  * Copyright (C) 2015 g10 Code GmbH
5  *
6  * This file is part of GnuPG.
7  *
8  * GnuPG is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * GnuPG is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <https://www.gnu.org/licenses/>.
20  */
21 #ifndef G10_OPTIONS_H
22 #define G10_OPTIONS_H
23
24 #include <sys/types.h>
25 #include <types.h>
26 #include <stdint.h>
27 #include "main.h"
28 #include "packet.h"
29 #include "tofu.h"
30 #include "../common/session-env.h"
31
32 #ifndef EXTERN_UNLESS_MAIN_MODULE
33 /* Norcraft can't cope with common symbols */
34 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
35 #define EXTERN_UNLESS_MAIN_MODULE extern
36 #else
37 #define EXTERN_UNLESS_MAIN_MODULE
38 #endif
39 #endif
40
41 /* Declaration of a keyserver spec type.  The definition is found in
42    ../common/keyserver.h.  */
43 struct keyserver_spec;
44 typedef struct keyserver_spec *keyserver_spec_t;
45
46
47 /* Global options for GPG.  */
48 EXTERN_UNLESS_MAIN_MODULE
49 struct
50 {
51   int verbose;
52   int quiet;
53   unsigned debug;
54   int armor;
55   char *outfile;
56   estream_t outfp;  /* Hack, sometimes used in place of outfile.  */
57   off_t max_output;
58
59   /* If > 0 a hint with the expected number of input data bytes.  This
60    * is not necessary an exact number but intended to be used for
61    * progress info and to decide on how to allocate buffers.  */
62   uint64_t input_size_hint;
63
64   int dry_run;
65   int autostart;
66   int list_only;
67   int mimemode;
68   int textmode;
69   int expert;
70   const char *def_sig_expire;
71   int ask_sig_expire;
72   const char *def_cert_expire;
73   int ask_cert_expire;
74   int batch;        /* run in batch mode */
75   int answer_yes; /* answer yes on most questions */
76   int answer_no;  /* answer no on most questions */
77   int check_sigs; /* check key signatures */
78   int with_colons;
79   int with_key_data;
80   int with_icao_spelling; /* Print ICAO spelling with fingerprints.  */
81   int with_fingerprint; /* Option --with-fingerprint active.  */
82   int with_subkey_fingerprint; /* Option --with-subkey-fingerprint active.  */
83   int with_keygrip;     /* Option --with-keygrip active.  */
84   int with_tofu_info;   /* Option --with-tofu_info active.  */
85   int with_secret;      /* Option --with-secret active.  */
86   int with_wkd_hash;    /* Option --with-wkd-hash.  */
87   int fingerprint; /* list fingerprints */
88   int list_sigs;   /* list signatures */
89   int no_armor;
90   int list_packets; /* Option --list-packets active.  */
91   int def_cipher_algo;
92   int force_mdc;
93   int disable_mdc;
94   int def_digest_algo;
95   int cert_digest_algo;
96   int compress_algo;
97   int compress_level;
98   int bz2_compress_level;
99   int bz2_decompress_lowmem;
100   strlist_t def_secret_key;
101   char *def_recipient;
102   int def_recipient_self;
103   strlist_t secret_keys_to_try;
104
105   /* A list of mail addresses (addr-spec) provided by the user with
106    * the option --sender.  */
107   strlist_t sender_list;
108
109   int def_cert_level;
110   int min_cert_level;
111   int ask_cert_level;
112   int emit_version;       /* 0 = none,
113                              1 = major only,
114                              2 = major and minor,
115                              3 = full version,
116                              4 = full version plus OS string. */
117   int marginals_needed;
118   int completes_needed;
119   int max_cert_depth;
120   const char *agent_program;
121   const char *dirmngr_program;
122
123   const char *def_new_key_algo;
124
125   /* Options to be passed to the gpg-agent */
126   session_env_t session_env;
127   char *lc_ctype;
128   char *lc_messages;
129
130   int skip_verify;
131   int skip_hidden_recipients;
132
133   /* TM_CLASSIC must be zero to accommodate trustdbsg generated before
134      we started storing the trust model inside the trustdb. */
135   enum
136     {
137       TM_CLASSIC=0, TM_PGP=1, TM_EXTERNAL=2,
138       TM_ALWAYS, TM_DIRECT, TM_AUTO, TM_TOFU, TM_TOFU_PGP
139     } trust_model;
140   enum tofu_policy tofu_default_policy;
141   int force_ownertrust;
142   enum
143     {
144       CO_GNUPG, CO_RFC4880, CO_RFC2440,
145       CO_PGP6, CO_PGP7, CO_PGP8, CO_DE_VS
146     } compliance;
147   enum
148     {
149       KF_DEFAULT, KF_NONE, KF_SHORT, KF_LONG, KF_0xSHORT, KF_0xLONG
150     } keyid_format;
151   int shm_coprocess;
152   const char *set_filename;
153   strlist_t comments;
154   int throw_keyids;
155   const char *photo_viewer;
156   int s2k_mode;
157   int s2k_digest_algo;
158   int s2k_cipher_algo;
159   unsigned char s2k_count; /* This is the encoded form, not the raw
160                               count */
161   int not_dash_escaped;
162   int escape_from;
163   int lock_once;
164   keyserver_spec_t keyserver;  /* The list of configured keyservers.  */
165   struct
166   {
167     unsigned int options;
168     unsigned int import_options;
169     unsigned int export_options;
170     char *http_proxy;
171   } keyserver_options;
172   int exec_disable;
173   int exec_path_set;
174   unsigned int import_options;
175   unsigned int export_options;
176   unsigned int list_options;
177   unsigned int verify_options;
178   const char *def_preference_list;
179   const char *def_keyserver_url;
180   prefitem_t *personal_cipher_prefs;
181   prefitem_t *personal_digest_prefs;
182   prefitem_t *personal_compress_prefs;
183   struct weakhash *weak_digests;
184   int no_perm_warn;
185   int no_mdc_warn;
186   char *temp_dir;
187   int no_encrypt_to;
188   int encrypt_to_default_key;
189   int interactive;
190   struct notation *sig_notations;
191   struct notation *cert_notations;
192   strlist_t sig_policy_url;
193   strlist_t cert_policy_url;
194   strlist_t sig_keyserver_url;
195   strlist_t cert_subpackets;
196   strlist_t sig_subpackets;
197   int allow_non_selfsigned_uid;
198   int allow_freeform_uid;
199   int no_literal;
200   ulong set_filesize;
201   int fast_list_mode;
202   int legacy_list_mode;
203   int ignore_time_conflict;
204   int ignore_valid_from;
205   int ignore_crc_error;
206   int ignore_mdc_error;
207   int command_fd;
208   const char *override_session_key;
209   int show_session_key;
210
211   const char *gpg_agent_info;
212   int try_all_secrets;
213   int no_expensive_trust_checks;
214   int no_sig_cache;
215   int no_auto_check_trustdb;
216   int preserve_permissions;
217   int no_homedir_creation;
218   struct groupitem *grouplist;
219   int mangle_dos_filenames;
220   int enable_progress_filter;
221   unsigned int screen_columns;
222   unsigned int screen_lines;
223   byte *show_subpackets;
224   int rfc2440_text;
225
226   /* If true, let write failures on the status-fd exit the process. */
227   int exit_on_status_write_error;
228
229   /* If > 0, limit the number of card insertion prompts to this
230      value. */
231   int limit_card_insert_tries;
232
233   struct
234   {
235     /* If set, require an 0x19 backsig to be present on signatures
236        made by signing subkeys.  If not set, a missing backsig is not
237        an error (but an invalid backsig still is). */
238     unsigned int require_cross_cert:1;
239
240     unsigned int use_embedded_filename:1;
241     unsigned int utf8_filename:1;
242     unsigned int dsa2:1;
243     unsigned int allow_multiple_messages:1;
244     unsigned int allow_weak_digest_algos:1;
245     unsigned int large_rsa:1;
246     unsigned int disable_signer_uid:1;
247     /* Flag to enbale experimental features from RFC4880bis.  */
248     unsigned int rfc4880bis:1;
249   } flags;
250
251   /* Linked list of ways to find a key if the key isn't on the local
252      keyring. */
253   struct akl
254   {
255     enum {
256       AKL_NODEFAULT,
257       AKL_LOCAL,
258       AKL_CERT,
259       AKL_PKA,
260       AKL_DANE,
261       AKL_WKD,
262       AKL_LDAP,
263       AKL_KEYSERVER,
264       AKL_SPEC
265     } type;
266     keyserver_spec_t spec;
267     struct akl *next;
268   } *auto_key_locate;
269
270   int passphrase_repeat;
271   int pinentry_mode;
272
273   int unwrap_encryption;
274   int only_sign_text_ids;
275 } opt;
276
277 /* CTRL is used to keep some global variables we currently can't
278    avoid.  Future concurrent versions of gpg will put it into a per
279    request structure CTRL. */
280 EXTERN_UNLESS_MAIN_MODULE
281 struct {
282   int in_auto_key_retrieve; /* True if we are doing an
283                                auto_key_retrieve. */
284   /* Hack to store the last error.  We currently need it because the
285      proc_packet machinery is not able to reliabale return error
286      codes.  Thus for the --server purposes we store some of the error
287      codes here.  FIXME! */
288   gpg_error_t lasterr;
289 } glo_ctrl;
290
291 #define DBG_PACKET_VALUE  1     /* debug packet reading/writing */
292 #define DBG_MPI_VALUE     2     /* debug mpi details */
293 #define DBG_CRYPTO_VALUE  4     /* debug crypto handling */
294                                 /* (may reveal sensitive data) */
295 #define DBG_FILTER_VALUE  8     /* debug internal filter handling */
296 #define DBG_IOBUF_VALUE   16    /* debug iobuf stuff */
297 #define DBG_MEMORY_VALUE  32    /* debug memory allocation stuff */
298 #define DBG_CACHE_VALUE   64    /* debug the caching */
299 #define DBG_MEMSTAT_VALUE 128   /* show memory statistics */
300 #define DBG_TRUST_VALUE   256   /* debug the trustdb */
301 #define DBG_HASHING_VALUE 512   /* debug hashing operations */
302 #define DBG_IPC_VALUE     1024  /* debug assuan communication */
303 #define DBG_CLOCK_VALUE   4096
304 #define DBG_LOOKUP_VALUE  8192  /* debug the key lookup */
305 #define DBG_EXTPROG_VALUE 16384 /* debug external program calls */
306
307 /* Tests for the debugging flags.  */
308 #define DBG_PACKET (opt.debug & DBG_PACKET_VALUE)
309 #define DBG_MPI    (opt.debug & DBG_MPI_VALUE)
310 #define DBG_CRYPTO (opt.debug & DBG_CRYPTO_VALUE)
311 #define DBG_FILTER (opt.debug & DBG_FILTER_VALUE)
312 #define DBG_CACHE  (opt.debug & DBG_CACHE_VALUE)
313 #define DBG_TRUST  (opt.debug & DBG_TRUST_VALUE)
314 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
315 #define DBG_IPC     (opt.debug & DBG_IPC_VALUE)
316 #define DBG_IPC     (opt.debug & DBG_IPC_VALUE)
317 #define DBG_CLOCK   (opt.debug & DBG_CLOCK_VALUE)
318 #define DBG_LOOKUP  (opt.debug & DBG_LOOKUP_VALUE)
319 #define DBG_EXTPROG (opt.debug & DBG_EXTPROG_VALUE)
320
321 /* FIXME: We need to check why we did not put this into opt. */
322 #define DBG_MEMORY    memory_debug_mode
323 #define DBG_MEMSTAT   memory_stat_debug_mode
324
325 EXTERN_UNLESS_MAIN_MODULE int memory_debug_mode;
326 EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode;
327
328
329 /* Compatibility flags.  */
330 #define GNUPG   (opt.compliance==CO_GNUPG || opt.compliance==CO_DE_VS)
331 #define RFC2440 (opt.compliance==CO_RFC2440)
332 #define RFC4880 (opt.compliance==CO_RFC4880)
333 #define PGP6    (opt.compliance==CO_PGP6)
334 #define PGP7    (opt.compliance==CO_PGP7)
335 #define PGP8    (opt.compliance==CO_PGP8)
336 #define PGPX    (PGP6 || PGP7 || PGP8)
337
338 /* Various option flags.  Note that there should be no common string
339    names between the IMPORT_ and EXPORT_ flags as they can be mixed in
340    the keyserver-options option. */
341
342 #define IMPORT_LOCAL_SIGS                (1<<0)
343 #define IMPORT_REPAIR_PKS_SUBKEY_BUG     (1<<1)
344 #define IMPORT_FAST                      (1<<2)
345 #define IMPORT_SHOW                      (1<<3)
346 #define IMPORT_MERGE_ONLY                (1<<4)
347 #define IMPORT_MINIMAL                   (1<<5)
348 #define IMPORT_CLEAN                     (1<<6)
349 #define IMPORT_NO_SECKEY                 (1<<7)
350 #define IMPORT_KEEP_OWNERTTRUST          (1<<8)
351 #define IMPORT_EXPORT                    (1<<9)
352
353 #define EXPORT_LOCAL_SIGS                (1<<0)
354 #define EXPORT_ATTRIBUTES                (1<<1)
355 #define EXPORT_SENSITIVE_REVKEYS         (1<<2)
356 #define EXPORT_RESET_SUBKEY_PASSWD       (1<<3)
357 #define EXPORT_MINIMAL                   (1<<4)
358 #define EXPORT_CLEAN                     (1<<5)
359 #define EXPORT_PKA_FORMAT                (1<<6)
360 #define EXPORT_DANE_FORMAT               (1<<7)
361
362 #define LIST_SHOW_PHOTOS                 (1<<0)
363 #define LIST_SHOW_POLICY_URLS            (1<<1)
364 #define LIST_SHOW_STD_NOTATIONS          (1<<2)
365 #define LIST_SHOW_USER_NOTATIONS         (1<<3)
366 #define LIST_SHOW_NOTATIONS (LIST_SHOW_STD_NOTATIONS|LIST_SHOW_USER_NOTATIONS)
367 #define LIST_SHOW_KEYSERVER_URLS         (1<<4)
368 #define LIST_SHOW_UID_VALIDITY           (1<<5)
369 #define LIST_SHOW_UNUSABLE_UIDS          (1<<6)
370 #define LIST_SHOW_UNUSABLE_SUBKEYS       (1<<7)
371 #define LIST_SHOW_KEYRING                (1<<8)
372 #define LIST_SHOW_SIG_EXPIRE             (1<<9)
373 #define LIST_SHOW_SIG_SUBPACKETS         (1<<10)
374 #define LIST_SHOW_USAGE                  (1<<11)
375
376 #define VERIFY_SHOW_PHOTOS               (1<<0)
377 #define VERIFY_SHOW_POLICY_URLS          (1<<1)
378 #define VERIFY_SHOW_STD_NOTATIONS        (1<<2)
379 #define VERIFY_SHOW_USER_NOTATIONS       (1<<3)
380 #define VERIFY_SHOW_NOTATIONS (VERIFY_SHOW_STD_NOTATIONS|VERIFY_SHOW_USER_NOTATIONS)
381 #define VERIFY_SHOW_KEYSERVER_URLS       (1<<4)
382 #define VERIFY_SHOW_UID_VALIDITY         (1<<5)
383 #define VERIFY_SHOW_UNUSABLE_UIDS        (1<<6)
384 #define VERIFY_PKA_LOOKUPS               (1<<7)
385 #define VERIFY_PKA_TRUST_INCREASE        (1<<8)
386 #define VERIFY_SHOW_PRIMARY_UID_ONLY     (1<<9)
387
388 #define KEYSERVER_HTTP_PROXY             (1<<0)
389 #define KEYSERVER_TIMEOUT                (1<<1)
390 #define KEYSERVER_ADD_FAKE_V3            (1<<2)
391 #define KEYSERVER_AUTO_KEY_RETRIEVE      (1<<3)
392 #define KEYSERVER_HONOR_KEYSERVER_URL    (1<<4)
393 #define KEYSERVER_HONOR_PKA_RECORD       (1<<5)
394
395
396 #endif /*G10_OPTIONS_H*/