1
1
/* simple-pwquery.c - A simple password query client for gpg-agent
2
* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
2
* Copyright (C) 2002, 2004, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
21
20
/* This module is intended as a standalone client implementation to
156
break; /* at least one full line available - that's enough.
160
break; /* At least one full line available - that's enough.
157
161
This function is just a simple implementation, so
158
it is okay to forget about pending bytes */
162
it is okay to forget about pending bytes. */
203
207
char *dft_display = NULL;
204
208
char *dft_ttyname = NULL;
205
209
char *dft_ttytype = NULL;
210
char *dft_xauthority = NULL;
211
char *dft_pinentry_user_data = NULL;
208
214
dft_display = getenv ("DISPLAY");
282
288
#endif /*HAVE_SETLOCALE*/
290
/* Send the XAUTHORITY variable. */
291
dft_xauthority = getenv ("XAUTHORITY");
294
/* We ignore errors here because older gpg-agents don't support
296
agent_send_option (fd, "xauthority", dft_xauthority);
299
/* Send the PINENTRY_USER_DATA variable. */
300
dft_pinentry_user_data = getenv ("PINENTRY_USER_DATA");
301
if (dft_pinentry_user_data)
303
/* We ignore errors here because older gpg-agents don't support
305
agent_send_option (fd, "pinentry-user-data", dft_pinentry_user_data);
305
329
infostr = getenv ( "GPG_AGENT_INFO" );
306
330
if ( !infostr || !*infostr )
331
infostr = default_gpg_agent_info;
332
if ( !infostr || !*infostr )
308
334
#ifdef SPWQ_USE_LOGGING
309
335
log_error (_("gpg-agent is not available in this session\n"));
453
/* Set the name of the default socket to NAME. */
455
simple_pw_set_socket (const char *name)
457
spwq_free (default_gpg_agent_info);
460
default_gpg_agent_info = spwq_malloc (strlen (name) + 4 + 1);
461
if (!default_gpg_agent_info)
462
return SPWQ_OUT_OF_CORE;
463
/* We don't know the PID thus we use 0. */
464
strcpy (stpcpy (default_gpg_agent_info, name),
465
PATHSEP_S "0" PATHSEP_S "1");
468
default_gpg_agent_info = NULL;
427
474
/* Ask the gpg-agent for a passphrase and present the user with a
428
DESCRIPTION, a PROMPT and optiaonlly with a TRYAGAIN extra text.
475
DESCRIPTION, a PROMPT and optionally with a TRYAGAIN extra text.
429
476
If a CACHEID is not NULL it is used to locate the passphrase in in
430
the cache and store it under this ID. If ERRORCODE is not NULL it
431
should point a variable receiving an errorcode; thsi errocode might
432
be 0 if the user canceled the operation. The function returns NULL
433
to indicate an error. */
477
the cache and store it under this ID. If OPT_CHECK is true
478
gpg-agent is asked to apply some checks on the passphrase security.
479
If ERRORCODE is not NULL it should point a variable receiving an
480
errorcode; this error code might be 0 if the user canceled the
481
operation. The function returns NULL to indicate an error. */
435
483
simple_pwquery (const char *cacheid,
436
484
const char *tryagain,
437
485
const char *prompt,
438
486
const char *description,
476
525
strcpy (line, "GET_PASSPHRASE ");
528
p = stpcpy (p, "--check ");
478
529
p = copy_and_escape (p, cacheid);
480
531
p = copy_and_escape (p, tryagain);
525
576
#ifdef SPWQ_USE_LOGGING
526
577
log_info (_("canceled by user\n") );
528
*errorcode = 0; /* canceled */
579
*errorcode = 0; /* Special error code to indicate Cancel. */
581
else if (nread > 4 && !memcmp (pw, "ERR ", 4))
583
switch ( (strtoul (pw+4, NULL, 0) & 0xffff) )
585
case 85: rc = SPWQ_NO_PIN_ENTRY; break;
586
default: rc = SPWQ_GENERAL_ERROR; break;