1
1
/* call-agent.c - divert operations to the agent
2
* Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
2
* Copyright (C) 2001, 2002, 2003, 2006, 2007 Free Software Foundation, Inc.
4
4
* This file is part of GnuPG.
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.
11
11
* GnuPG is distributed in the hope that it will be useful,
14
14
* GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
22
#if 0 /* let Emacs display a red warning */
23
#error fixme: this shares a lot of code with the file in ../sm
26
20
#include <config.h>
28
22
#include <stdlib.h>
87
return 0; /* fixme: We need a context for each thread or serialize
76
return 0; /* Fixme: We need a context for each thread or serialize
88
77
the access to the agent. */
90
infostr = force_pipe_server? NULL : getenv ("GPG_AGENT_INFO");
91
if (!infostr || !*infostr)
99
log_info (_("no running gpg-agent - starting one\n"));
103
gpg_error_t tmperr = gpg_error_from_syserror ();
104
log_error ("error flushing pending output: %s\n", strerror (errno));
108
if (!opt.agent_program || !*opt.agent_program)
109
opt.agent_program = GNUPG_DEFAULT_AGENT;
110
if ( !(pgmname = strrchr (opt.agent_program, '/')))
111
pgmname = opt.agent_program;
116
argv[1] = "--server";
120
if (log_get_fd () != -1)
121
no_close_list[i++] = log_get_fd ();
122
no_close_list[i++] = fileno (stderr);
123
no_close_list[i] = -1;
125
/* connect to the agent and perform initial handshaking */
126
rc = assuan_pipe_connect (&ctx, opt.agent_program, argv,
134
infostr = xstrdup (infostr);
135
if ( !(p = strchr (infostr, ':')) || p == infostr)
137
log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
139
force_pipe_server = 1;
140
return start_agent ();
144
while (*p && *p != ':')
146
prot = *p? atoi (p+1) : 0;
149
log_error (_("gpg-agent protocol version %d is not supported\n"),
152
force_pipe_server = 1;
153
return start_agent ();
156
rc = assuan_socket_connect (&ctx, infostr, pid);
158
if (gpg_err_code (rc) == GPG_ERR_ASS_CONNECT_FAILED)
160
log_info (_("can't connect to the agent - trying fall back\n"));
161
force_pipe_server = 1;
162
return start_agent ();
168
log_error ("can't connect to the agent: %s\n", gpg_strerror (rc));
169
return gpg_error (GPG_ERR_NO_AGENT);
174
log_debug ("connection to agent established\n");
176
rc = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL,NULL);
180
return send_pinentry_environment (agent_ctx, GPG_ERR_SOURCE_DEFAULT,
181
opt.display, opt.ttyname, opt.ttytype,
182
opt.lc_ctype, opt.lc_messages);
79
return start_new_gpg_agent (&agent_ctx,
80
GPG_ERR_SOURCE_DEFAULT,
83
opt.display, opt.ttyname, opt.ttytype,
84
opt.lc_ctype, opt.lc_messages,
85
opt.verbose, DBG_ASSUAN,
596
500
/* Send a GENKEY command to the SCdaemon. SERIALNO is not used in
597
this implementation. */
501
this implementation. If CREATEDATE has been given, it will be
502
passed to SCDAEMON so that the key can be created with this
503
timestamp; note the user needs to use the returned timestamp as old
504
versions of scddaemon don't support this option. */
599
506
agent_scd_genkey (struct agent_card_genkey_s *info, int keyno, int force,
600
const char *serialno)
507
const char *serialno, u32 createtime)
603
510
char line[ASSUAN_LINELENGTH];
511
gnupg_isotime_t tbuf;
605
513
rc = start_agent ();
518
epoch2isotime (tbuf, createtime);
609
522
memset (info, 0, sizeof *info);
610
snprintf (line, DIM(line)-1, "SCD GENKEY %s%d",
611
force? "--force ":"", keyno);
523
snprintf (line, DIM(line)-1, "SCD GENKEY %s%s %s %d",
524
*tbuf? "--timestamp=":"", tbuf,
612
527
line[DIM(line)-1] = 0;
614
529
memset (info, 0, sizeof *info);