~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to agent/agent.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#ifndef AGENT_H
32
31
 
33
32
#include <gcrypt.h>
34
33
#include "../common/util.h"
35
 
#include "../common/errors.h"
36
 
#include "membuf.h"
37
 
 
38
 
/* Convenience function to be used instead of returning the old
39
 
   GNUPG_Out_Of_Core. */
40
 
static inline gpg_error_t
41
 
out_of_core (void)
42
 
{
43
 
  return gpg_error (gpg_err_code_from_errno (errno));
44
 
}
45
 
 
46
 
#define MAX_DIGEST_LEN 24 
 
34
#include "../common/membuf.h"
 
35
#include "../common/sysutils.h" /* (gnupg_fd_t) */
 
36
 
 
37
/* To convey some special hash algorithms we use algorithm numbers
 
38
   reserved for application use. */
 
39
#ifndef GCRY_MD_USER
 
40
#define GCRY_MD_USER 1024
 
41
#endif
 
42
#define GCRY_MD_USER_TLS_MD5SHA1 (GCRY_MD_USER+1)
 
43
 
 
44
/* Maximum length of a digest.  */
 
45
#define MAX_DIGEST_LEN 36
47
46
 
48
47
/* A large struct name "opt" to keep global flags */
49
 
struct {
 
48
struct
 
49
{
50
50
  unsigned int debug;  /* Debug flags (DBG_foo_VALUE) */
51
51
  int verbose;         /* Verbosity level */
52
52
  int quiet;           /* Be as quiet as possible */
54
54
  int batch;           /* Batch mode */
55
55
  const char *homedir; /* Configuration directory name */
56
56
 
57
 
  /* Environment setting gathered at program start or hanged using the
 
57
  /* Environment setting gathered at program start or changed using the
58
58
     Assuan command UPDATESTARTUPTTY. */
59
59
  char *startup_display;
60
60
  char *startup_ttyname;
61
61
  char *startup_ttytype;
62
62
  char *startup_lc_ctype;
63
63
  char *startup_lc_messages;
 
64
  char *startup_xauthority;   
 
65
  char *startup_pinentry_user_data; 
64
66
 
65
67
 
66
68
  const char *pinentry_program; /* Filename of the program to start as
70
72
  int disable_scdaemon;         /* Never use the SCdaemon. */
71
73
  int no_grab;         /* Don't let the pinentry grab the keyboard */
72
74
 
 
75
  /* The name of the file pinentry shall tocuh before exiting.  If
 
76
     this is not set the filoe name of the standard socket is used. */
 
77
  const char *pinentry_touch_file;
 
78
 
73
79
  /* The default and maximum TTL of cache entries. */
74
80
  unsigned long def_cache_ttl;     /* Default. */
75
81
  unsigned long def_cache_ttl_ssh; /* for SSH. */
76
82
  unsigned long max_cache_ttl;     /* Default. */
77
83
  unsigned long max_cache_ttl_ssh; /* for SSH. */
78
84
 
 
85
  /* Flag disallowing bypassing of the warning.  */
 
86
  int enforce_passphrase_constraints;
 
87
  /* The require minmum length of a passphrase. */
 
88
  unsigned int min_passphrase_len;
 
89
  /* The minimum number of non-alpha characters in a passphrase.  */
 
90
  unsigned int min_passphrase_nonalpha;
 
91
  /* File name with a patternfile or NULL if not enabled.  */
 
92
  const char *check_passphrase_pattern;
 
93
  /* If not 0 the user is asked to change his passphrase after these
 
94
     number of days.  */
 
95
  unsigned int max_passphrase_days;
 
96
  /* If set, a passphrase history will be written and checked at each
 
97
     passphrase change.  */
 
98
  int enable_passhrase_history;
79
99
 
80
100
  int running_detached; /* We are running detached from the tty. */
81
101
 
110
130
/* Collection of data per session (aka connection). */
111
131
struct server_control_s 
112
132
{
 
133
  /* Private data used to fire up the connection thread.  We use this
 
134
     structure do avoid an extra allocation for just a few bytes. */
 
135
  struct {
 
136
    gnupg_fd_t fd;
 
137
  } thread_startup;
 
138
  
113
139
  /* Private data of the server (command.c). */
114
140
  struct server_local_s *server_local;
115
141
 
116
142
  /* Private data of the SCdaemon (call-scd.c). */
117
143
  struct scd_local_s *scd_local;
118
144
 
119
 
  int   connection_fd; /* -1 or an identifier for the current connection. */
120
 
 
121
145
  char *display;
122
146
  char *ttyname;
123
147
  char *ttytype;
124
148
  char *lc_ctype;
125
149
  char *lc_messages;
 
150
  char *xauthority;   
 
151
  char *pinentry_user_data; 
126
152
  struct {
127
153
    int algo;
128
154
    unsigned char value[MAX_DIGEST_LEN];
134
160
 
135
161
  int use_auth_call; /* Hack to send the PKAUTH command instead of the
136
162
                        PKSIGN command to the scdaemon.  */
 
163
  int in_passwd;     /* Hack to inhibit enforced passphrase change
 
164
                        during an explicit passwd command.  */
137
165
};
138
 
typedef struct server_control_s *CTRL;
139
 
typedef struct server_control_s *ctrl_t;
140
 
 
141
 
 
142
 
struct pin_entry_info_s {
 
166
 
 
167
 
 
168
struct pin_entry_info_s 
 
169
{
143
170
  int min_digits; /* min. number of digits required or 0 for freeform entry */
144
171
  int max_digits; /* max. number of allowed digits allowed*/
145
172
  int max_tries;
146
173
  int failed_tries;
 
174
  int with_qualitybar; /* Set if the quality bar should be displayed.  */
147
175
  int (*check_cb)(struct pin_entry_info_s *); /* CB used to check the PIN */
148
176
  void *check_cb_arg;  /* optional argument which might be of use in the CB */
149
177
  const char *cb_errtext; /* used by the cb to displaye a specific error */
164
192
/* Values for the cache_mode arguments. */
165
193
typedef enum 
166
194
  {
167
 
    CACHE_MODE_IGNORE = 0, /* Special mode to by pass the cache. */
 
195
    CACHE_MODE_IGNORE = 0, /* Special mode to bypass the cache. */
168
196
    CACHE_MODE_ANY,        /* Any mode except ignore matches. */
169
197
    CACHE_MODE_NORMAL,     /* Normal cache (gpg-agent). */
170
198
    CACHE_MODE_USER,       /* GET_PASSPHRASE related cache. */
175
203
 
176
204
/*-- gpg-agent.c --*/
177
205
void agent_exit (int rc) JNLIB_GCC_A_NR; /* Also implemented in other tools */
178
 
void agent_init_default_ctrl (struct server_control_s *ctrl);
 
206
const char *get_agent_socket_name (void);
 
207
const char *get_agent_ssh_socket_name (void);
 
208
#ifdef HAVE_W32_SYSTEM
 
209
void *get_agent_scd_notify_event (void);
 
210
#endif
 
211
void agent_sighup_action (void);
179
212
 
180
213
/*-- command.c --*/
181
 
void start_command_handler (int, int);
 
214
gpg_error_t agent_inq_pinentry_launched (ctrl_t ctrl, unsigned long pid);
 
215
gpg_error_t agent_write_status (ctrl_t ctrl, const char *keyword, ...);
 
216
void bump_key_eventcounter (void);
 
217
void bump_card_eventcounter (void);
 
218
void start_command_handler (ctrl_t, gnupg_fd_t, gnupg_fd_t);
182
219
 
183
220
/*-- command-ssh.c --*/
184
 
void start_command_handler_ssh (int);
 
221
void start_command_handler_ssh (ctrl_t, gnupg_fd_t);
185
222
 
186
223
/*-- findkey.c --*/
187
224
int agent_write_private_key (const unsigned char *grip,
197
234
                                        gcry_sexp_t *result);
198
235
int agent_key_available (const unsigned char *grip);
199
236
 
200
 
/*-- query.c --*/
201
 
void initialize_module_query (void);
 
237
/*-- call-pinentry.c --*/
 
238
void initialize_module_call_pinentry (void);
202
239
void agent_query_dump_state (void);
203
240
void agent_reset_query (ctrl_t ctrl);
 
241
int pinentry_active_p (ctrl_t ctrl, int waitseconds);
204
242
int agent_askpin (ctrl_t ctrl,
205
243
                  const char *desc_text, const char *prompt_text,
206
244
                  const char *inital_errtext,
210
248
                          const char *errtext);
211
249
int agent_get_confirmation (ctrl_t ctrl, const char *desc, const char *ok,
212
250
                            const char *cancel);
213
 
int agent_popup_message_start (ctrl_t ctrl, const char *desc,
214
 
                               const char *ok_btn, const char *cancel_btn);
 
251
int agent_show_message (ctrl_t ctrl, const char *desc, const char *ok_btn);
 
252
int agent_popup_message_start (ctrl_t ctrl,
 
253
                               const char *desc, const char *ok_btn);
215
254
void agent_popup_message_stop (ctrl_t ctrl);
216
255
 
217
256
 
237
276
                     membuf_t *outbuf);
238
277
 
239
278
/*-- genkey.c --*/
 
279
int check_passphrase_constraints (ctrl_t ctrl, const char *pw, int silent);
240
280
int agent_genkey (ctrl_t ctrl, 
241
281
                  const char *keyparam, size_t keyparmlen, membuf_t *outbuf);
242
282
int agent_protect_and_store (ctrl_t ctrl, gcry_sexp_t s_skey);
245
285
int agent_protect (const unsigned char *plainkey, const char *passphrase,
246
286
                   unsigned char **result, size_t *resultlen);
247
287
int agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
 
288
                     gnupg_isotime_t protected_at, 
248
289
                     unsigned char **result, size_t *resultlen);
249
290
int agent_private_key_type (const unsigned char *privatekey);
250
291
unsigned char *make_shadow_info (const char *serialno, const char *idstring);
256
297
 
257
298
 
258
299
/*-- trustlist.c --*/
259
 
int agent_istrusted (const char *fpr);
260
 
int agent_listtrusted (void *assuan_context);
261
 
int agent_marktrusted (ctrl_t ctrl, const char *name,
262
 
                       const char *fpr, int flag);
263
 
void agent_trustlist_housekeeping (void);
 
300
void initialize_module_trustlist (void);
 
301
gpg_error_t agent_istrusted (ctrl_t ctrl, const char *fpr);
 
302
gpg_error_t agent_listtrusted (void *assuan_context);
 
303
gpg_error_t agent_marktrusted (ctrl_t ctrl, const char *name,
 
304
                               const char *fpr, int flag);
264
305
void agent_reload_trustlist (void);
265
306
 
266
307