2001-12-10 09:27:30 +00:00
|
|
|
|
/* query.c - fork of the pinentry to query stuff from the user
|
|
|
|
|
* Copyright (C) 2001 Free Software Foundation, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/stat.h>
|
2002-05-23 09:07:45 +00:00
|
|
|
|
#ifdef USE_GNU_PTH
|
|
|
|
|
# include <pth.h>
|
|
|
|
|
#endif
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
#include "agent.h"
|
2002-08-21 11:11:04 +00:00
|
|
|
|
#include "i18n.h"
|
2001-12-10 09:27:30 +00:00
|
|
|
|
#include "../assuan/assuan.h"
|
|
|
|
|
|
|
|
|
|
#ifdef _POSIX_OPEN_MAX
|
|
|
|
|
#define MAX_OPEN_FDS _POSIX_OPEN_MAX
|
|
|
|
|
#else
|
|
|
|
|
#define MAX_OPEN_FDS 20
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static ASSUAN_CONTEXT entry_ctx = NULL;
|
2002-05-23 09:07:45 +00:00
|
|
|
|
#ifdef USE_GNU_PTH
|
|
|
|
|
static pth_mutex_t entry_lock = PTH_MUTEX_INIT;
|
|
|
|
|
#endif
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
/* data to be passed to our callbacks */
|
|
|
|
|
struct entry_parm_s {
|
|
|
|
|
int lines;
|
|
|
|
|
size_t size;
|
|
|
|
|
char *buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-05-23 09:07:45 +00:00
|
|
|
|
static int
|
|
|
|
|
unlock_pinentry (int rc)
|
|
|
|
|
{
|
|
|
|
|
#ifdef USE_GNU_PTH
|
|
|
|
|
if (!pth_mutex_release (&entry_lock))
|
|
|
|
|
{
|
|
|
|
|
log_error ("failed to release the entry lock\n");
|
|
|
|
|
if (!rc)
|
|
|
|
|
rc = GNUPG_Internal_Error;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fork off the pin entry if this has not already been done. Note,
|
|
|
|
|
that this function must always be used to aquire the lock for the
|
|
|
|
|
pinentry - we will serialize _all_ pinentry calls.
|
|
|
|
|
*/
|
2001-12-10 09:27:30 +00:00
|
|
|
|
static int
|
|
|
|
|
start_pinentry (void)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
const char *pgmname;
|
|
|
|
|
ASSUAN_CONTEXT ctx;
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
const char *argv[5];
|
2002-06-27 07:29:29 +00:00
|
|
|
|
int no_close_list[3];
|
|
|
|
|
int i;
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
2002-05-23 09:07:45 +00:00
|
|
|
|
#ifdef USE_GNU_PTH
|
|
|
|
|
if (!pth_mutex_acquire (&entry_lock, 0, NULL))
|
|
|
|
|
{
|
|
|
|
|
log_error ("failed to acquire the entry lock\n");
|
|
|
|
|
return GNUPG_Internal_Error;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if (entry_ctx)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return 0;
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
2002-04-27 13:49:40 +00:00
|
|
|
|
if (opt.verbose)
|
|
|
|
|
log_info ("no running PIN Entry - starting it\n");
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
if (fflush (NULL))
|
|
|
|
|
{
|
|
|
|
|
log_error ("error flushing pending output: %s\n", strerror (errno));
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (seterr (Write_Error));
|
2001-12-10 09:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!opt.pinentry_program || !*opt.pinentry_program)
|
2002-06-29 14:01:35 +00:00
|
|
|
|
opt.pinentry_program = GNUPG_DEFAULT_PINENTRY;
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if ( !(pgmname = strrchr (opt.pinentry_program, '/')))
|
|
|
|
|
pgmname = opt.pinentry_program;
|
|
|
|
|
else
|
|
|
|
|
pgmname++;
|
|
|
|
|
|
2002-05-23 09:07:45 +00:00
|
|
|
|
/* FIXME: We must do this thread specific */
|
2001-12-10 09:27:30 +00:00
|
|
|
|
argv[0] = pgmname;
|
2002-09-26 07:10:56 +00:00
|
|
|
|
if (opt.display && !opt.keep_display)
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
{
|
|
|
|
|
argv[1] = "--display";
|
|
|
|
|
argv[2] = opt.display;
|
|
|
|
|
argv[3] = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
argv[1] = NULL;
|
2002-06-27 07:29:29 +00:00
|
|
|
|
|
|
|
|
|
i=0;
|
|
|
|
|
if (!opt.running_detached)
|
|
|
|
|
{
|
|
|
|
|
if (log_get_fd () != -1)
|
|
|
|
|
no_close_list[i++] = log_get_fd ();
|
|
|
|
|
no_close_list[i++] = fileno (stderr);
|
|
|
|
|
}
|
|
|
|
|
no_close_list[i] = -1;
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
/* connect to the pinentry and perform initial handshaking */
|
2002-06-27 07:29:29 +00:00
|
|
|
|
rc = assuan_pipe_connect (&ctx, opt.pinentry_program, (char**)argv,
|
|
|
|
|
no_close_list);
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("can't connect to the PIN entry module: %s\n",
|
|
|
|
|
assuan_strerror (rc));
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (seterr (No_PIN_Entry));
|
2001-12-10 09:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
entry_ctx = ctx;
|
2002-04-27 13:49:40 +00:00
|
|
|
|
|
|
|
|
|
if (DBG_ASSUAN)
|
|
|
|
|
log_debug ("connection to PIN entry established\n");
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
2002-01-20 16:49:10 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx,
|
|
|
|
|
opt.no_grab? "OPTION no-grab":"OPTION grab",
|
2002-02-28 11:07:59 +00:00
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-01-20 16:49:10 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-09-26 07:10:56 +00:00
|
|
|
|
if (opt.ttyname && !opt.keep_tty)
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
{
|
|
|
|
|
char *optstr;
|
|
|
|
|
if (asprintf (&optstr, "OPTION ttyname=%s", opt.ttyname) < 0 )
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (GNUPG_Out_Of_Core);
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
free (optstr);
|
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
}
|
2002-09-26 07:10:56 +00:00
|
|
|
|
if (opt.ttytype && !opt.keep_tty)
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
{
|
|
|
|
|
char *optstr;
|
|
|
|
|
if (asprintf (&optstr, "OPTION ttytype=%s", opt.ttytype) < 0 )
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (GNUPG_Out_Of_Core);
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
}
|
|
|
|
|
if (opt.lc_ctype)
|
|
|
|
|
{
|
|
|
|
|
char *optstr;
|
|
|
|
|
if (asprintf (&optstr, "OPTION lc-ctype=%s", opt.lc_ctype) < 0 )
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (GNUPG_Out_Of_Core);
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
}
|
|
|
|
|
if (opt.lc_messages)
|
|
|
|
|
{
|
|
|
|
|
char *optstr;
|
|
|
|
|
if (asprintf (&optstr, "OPTION lc-messages=%s", opt.lc_messages) < 0 )
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (GNUPG_Out_Of_Core);
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for locale.h.
agent/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* agent.h (struct opt): Add members display, ttyname, ttytype,
lc_ctype, and lc_messages.
* gpg-agent.c (enum cmd_and_opt_values): Add oDisplay, oTTYname,
oTTYtype, oLCctype, and LCmessages.
(main): Handle these options.
* command.c (option_handler): New function.
(register_commands): Register option handler.
* query.c (start_pinentry): Pass the various display and tty
options to the pinentry.
sm/
2002-04-24 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.h (struct opt): New members display, ttyname, ttytype,
lc_ctype, lc_messages.
* gpgsm.c (enum cmd_and_opt_values): New members oDisplay,
oTTYname, oTTYtype, oLCctype, oLCmessages.
(opts): New entries for these options.
(main): Handle these new options.
* call-agent.c (start_agent): Set the various display and tty
parameter after resetting.
2002-04-24 21:52:47 +00:00
|
|
|
|
}
|
2001-12-10 09:27:30 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static AssuanError
|
|
|
|
|
getpin_cb (void *opaque, const void *buffer, size_t length)
|
|
|
|
|
{
|
|
|
|
|
struct entry_parm_s *parm = opaque;
|
|
|
|
|
|
2002-03-06 14:16:37 +00:00
|
|
|
|
if (!buffer)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2001-12-10 09:27:30 +00:00
|
|
|
|
/* we expect the pin to fit on one line */
|
|
|
|
|
if (parm->lines || length >= parm->size)
|
|
|
|
|
return ASSUAN_Too_Much_Data;
|
|
|
|
|
|
|
|
|
|
/* fixme: we should make sure that the assuan buffer is allocated in
|
|
|
|
|
secure memory or read the response byte by byte */
|
|
|
|
|
memcpy (parm->buffer, buffer, length);
|
|
|
|
|
parm->buffer[length] = 0;
|
|
|
|
|
parm->lines++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
all_digitsp( const char *s)
|
|
|
|
|
{
|
|
|
|
|
for (; *s && *s >= '0' && *s <= '9'; s++)
|
|
|
|
|
;
|
|
|
|
|
return !*s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-12-14 15:39:44 +00:00
|
|
|
|
/* Call the Entry and ask for the PIN. We do check for a valid PIN
|
2001-12-10 09:27:30 +00:00
|
|
|
|
number here and repeat it as long as we have invalid formed
|
|
|
|
|
numbers. */
|
|
|
|
|
int
|
2002-06-17 10:11:34 +00:00
|
|
|
|
agent_askpin (const char *desc_text, struct pin_entry_info_s *pininfo)
|
2001-12-10 09:27:30 +00:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
2001-12-13 23:20:02 +00:00
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2001-12-10 09:27:30 +00:00
|
|
|
|
struct entry_parm_s parm;
|
2002-06-17 10:11:34 +00:00
|
|
|
|
const char *errtext = NULL;
|
2002-08-22 09:47:39 +00:00
|
|
|
|
int is_pin = 0;
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
2001-12-14 15:39:44 +00:00
|
|
|
|
if (opt.batch)
|
|
|
|
|
return 0; /* fixme: we should return BAD PIN */
|
|
|
|
|
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if (!pininfo || pininfo->max_length < 1)
|
|
|
|
|
return seterr (Invalid_Value);
|
2002-08-22 09:47:39 +00:00
|
|
|
|
if (!desc_text && pininfo->min_digits)
|
|
|
|
|
desc_text = _("Please enter your PIN, so that the secret key "
|
|
|
|
|
"can be unlocked for this session");
|
|
|
|
|
else if (!desc_text)
|
|
|
|
|
desc_text = _("Please enter your passphrase, so that the secret key "
|
2002-08-21 11:11:04 +00:00
|
|
|
|
"can be unlocked for this session");
|
|
|
|
|
|
|
|
|
|
is_pin = desc_text && strstr (desc_text, "PIN");
|
|
|
|
|
|
2001-12-10 09:27:30 +00:00
|
|
|
|
rc = start_pinentry ();
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
snprintf (line, DIM(line)-1, "SETDESC %s", desc_text);
|
|
|
|
|
line[DIM(line)-1] = 0;
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
rc = assuan_transact (entry_ctx,
|
2002-08-21 11:11:04 +00:00
|
|
|
|
is_pin? "SETPROMPT PIN:"
|
|
|
|
|
: "SETPROMPT Passphrase:",
|
2002-02-28 11:07:59 +00:00
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
for (;pininfo->failed_tries < pininfo->max_tries; pininfo->failed_tries++)
|
|
|
|
|
{
|
|
|
|
|
memset (&parm, 0, sizeof parm);
|
|
|
|
|
parm.size = pininfo->max_length;
|
|
|
|
|
parm.buffer = pininfo->pin;
|
|
|
|
|
|
|
|
|
|
if (errtext)
|
|
|
|
|
{
|
|
|
|
|
/* fixme: should we show the try count? It must be translated */
|
2002-06-17 10:11:34 +00:00
|
|
|
|
snprintf (line, DIM(line)-1, "SETERROR %s (try %d of %d)",
|
|
|
|
|
errtext, pininfo->failed_tries+1, pininfo->max_tries);
|
2001-12-10 09:27:30 +00:00
|
|
|
|
line[DIM(line)-1] = 0;
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2001-12-10 09:27:30 +00:00
|
|
|
|
errtext = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-17 10:11:34 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, &parm,
|
|
|
|
|
NULL, NULL, NULL, NULL);
|
2001-12-10 09:27:30 +00:00
|
|
|
|
if (rc == ASSUAN_Too_Much_Data)
|
2002-08-21 11:11:04 +00:00
|
|
|
|
errtext = is_pin? _("PIN too long")
|
|
|
|
|
: _("Passphrase too long");
|
2001-12-10 09:27:30 +00:00
|
|
|
|
else if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-06-17 10:11:34 +00:00
|
|
|
|
|
2002-08-22 09:47:39 +00:00
|
|
|
|
if (!errtext && pininfo->min_digits)
|
2002-06-17 10:11:34 +00:00
|
|
|
|
{
|
|
|
|
|
/* do some basic checks on the entered PIN. */
|
|
|
|
|
if (!all_digitsp (pininfo->pin))
|
2002-08-21 11:11:04 +00:00
|
|
|
|
errtext = _("Invalid characters in PIN");
|
2002-06-17 10:11:34 +00:00
|
|
|
|
else if (pininfo->max_digits
|
|
|
|
|
&& strlen (pininfo->pin) > pininfo->max_digits)
|
2002-08-21 11:11:04 +00:00
|
|
|
|
errtext = _("PIN too long");
|
2002-06-17 10:11:34 +00:00
|
|
|
|
else if (strlen (pininfo->pin) < pininfo->min_digits)
|
2002-08-21 11:11:04 +00:00
|
|
|
|
errtext = _("PIN too short");
|
2002-06-17 10:11:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!errtext && pininfo->check_cb)
|
|
|
|
|
{
|
|
|
|
|
/* More checks by utilizing the optional callback. */
|
|
|
|
|
pininfo->cb_errtext = NULL;
|
|
|
|
|
rc = pininfo->check_cb (pininfo);
|
|
|
|
|
if (rc == -1 && pininfo->cb_errtext)
|
|
|
|
|
errtext = pininfo->cb_errtext;
|
|
|
|
|
else if (rc == GNUPG_Bad_Passphrase || rc == GNUPG_Bad_PIN)
|
2002-08-21 11:11:04 +00:00
|
|
|
|
errtext = (is_pin? _("Bad PIN")
|
|
|
|
|
: _("Bad Passphrase"));
|
2002-06-17 10:11:34 +00:00
|
|
|
|
else if (rc)
|
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
|
|
|
|
}
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
if (!errtext)
|
2002-06-17 10:11:34 +00:00
|
|
|
|
return unlock_pinentry (0); /* okay, got a PIN or passphrase */
|
2001-12-10 09:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (pininfo->min_digits? GNUPG_Bad_PIN
|
|
|
|
|
: GNUPG_Bad_Passphrase);
|
2001-12-10 09:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-01-10 19:45:32 +00:00
|
|
|
|
|
|
|
|
|
/* Ask for the passphrase using the supplied arguments. The
|
|
|
|
|
passphrase is returned in RETPASS as an hex encoded string to be
|
|
|
|
|
freed by the caller */
|
|
|
|
|
int
|
|
|
|
|
agent_get_passphrase (char **retpass, const char *desc, const char *prompt,
|
|
|
|
|
const char *errtext)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
struct entry_parm_s parm;
|
|
|
|
|
unsigned char *p, *hexstring;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
*retpass = NULL;
|
|
|
|
|
if (opt.batch)
|
|
|
|
|
return GNUPG_Bad_Passphrase;
|
|
|
|
|
|
|
|
|
|
rc = start_pinentry ();
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
2002-08-21 11:11:04 +00:00
|
|
|
|
if (!prompt)
|
|
|
|
|
prompt = desc && strstr (desc, "PIN")? "PIN": _("Passphrase");
|
|
|
|
|
|
|
|
|
|
|
2002-01-10 19:45:32 +00:00
|
|
|
|
if (desc)
|
|
|
|
|
snprintf (line, DIM(line)-1, "SETDESC %s", desc);
|
|
|
|
|
else
|
|
|
|
|
snprintf (line, DIM(line)-1, "RESET");
|
|
|
|
|
line[DIM(line)-1] = 0;
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-01-10 19:45:32 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-01-10 19:45:32 +00:00
|
|
|
|
|
2002-08-21 11:11:04 +00:00
|
|
|
|
snprintf (line, DIM(line)-1, "SETPROMPT %s", prompt);
|
2002-01-10 19:45:32 +00:00
|
|
|
|
line[DIM(line)-1] = 0;
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-01-10 19:45:32 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-01-10 19:45:32 +00:00
|
|
|
|
|
|
|
|
|
if (errtext)
|
|
|
|
|
{
|
|
|
|
|
snprintf (line, DIM(line)-1, "SETERROR %s", errtext);
|
|
|
|
|
line[DIM(line)-1] = 0;
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-01-10 19:45:32 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-01-10 19:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset (&parm, 0, sizeof parm);
|
|
|
|
|
parm.size = ASSUAN_LINELENGTH/2 - 5;
|
|
|
|
|
parm.buffer = gcry_malloc_secure (parm.size+10);
|
|
|
|
|
if (!parm.buffer)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (seterr (Out_Of_Core));
|
2002-01-10 19:45:32 +00:00
|
|
|
|
|
2002-01-19 18:19:47 +00:00
|
|
|
|
assuan_begin_confidential (entry_ctx);
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, &parm, NULL, NULL, NULL, NULL);
|
2002-01-10 19:45:32 +00:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (parm.buffer);
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-01-10 19:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hexstring = gcry_malloc_secure (strlen (parm.buffer)*2+1);
|
|
|
|
|
if (!hexstring)
|
|
|
|
|
{
|
|
|
|
|
xfree (parm.buffer);
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (seterr (Out_Of_Core));
|
2002-01-10 19:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0, p=parm.buffer; *p; p++, i += 2)
|
|
|
|
|
sprintf (hexstring+i, "%02X", *p);
|
|
|
|
|
|
|
|
|
|
xfree (parm.buffer);
|
|
|
|
|
*retpass = hexstring;
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (0);
|
2002-01-10 19:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-18 20:44:48 +00:00
|
|
|
|
|
|
|
|
|
/* Pop up the PIN-entry, display the text and the prompt and ask the
|
|
|
|
|
user to confirm this. We return 0 for success, ie. the used
|
|
|
|
|
confirmed it, GNUPG_Not_Confirmed for what the text says or an
|
|
|
|
|
other error. */
|
|
|
|
|
int
|
2002-04-24 23:18:53 +00:00
|
|
|
|
agent_get_confirmation (const char *desc, const char *ok, const char *cancel)
|
2002-02-18 20:44:48 +00:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
|
|
|
|
|
rc = start_pinentry ();
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
|
snprintf (line, DIM(line)-1, "SETDESC %s", desc);
|
|
|
|
|
else
|
|
|
|
|
snprintf (line, DIM(line)-1, "RESET");
|
|
|
|
|
line[DIM(line)-1] = 0;
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-02-18 20:44:48 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-02-18 20:44:48 +00:00
|
|
|
|
|
2002-04-24 23:18:53 +00:00
|
|
|
|
if (ok)
|
2002-02-18 20:44:48 +00:00
|
|
|
|
{
|
2002-04-24 23:18:53 +00:00
|
|
|
|
snprintf (line, DIM(line)-1, "SETOK %s", ok);
|
|
|
|
|
line[DIM(line)-1] = 0;
|
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-04-24 23:18:53 +00:00
|
|
|
|
}
|
|
|
|
|
if (cancel)
|
|
|
|
|
{
|
|
|
|
|
snprintf (line, DIM(line)-1, "SETCANCEL %s", cancel);
|
2002-02-18 20:44:48 +00:00
|
|
|
|
line[DIM(line)-1] = 0;
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-02-18 20:44:48 +00:00
|
|
|
|
if (rc)
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-02-18 20:44:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-28 11:07:59 +00:00
|
|
|
|
rc = assuan_transact (entry_ctx, "CONFIRM", NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-05-23 09:07:45 +00:00
|
|
|
|
return unlock_pinentry (map_assuan_err (rc));
|
2002-02-18 20:44:48 +00:00
|
|
|
|
}
|
2001-12-10 09:27:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|