1
/* call-pinentry.c - fork of the pinentry to query stuff from the user
2
* Copyright (C) 2001, 2002, 2004, 2007, 2008 Free Software Foundation, Inc.
1
/* call-pinentry.c - Spawn the pinentry to query stuff from the user
2
* Copyright (C) 2001, 2002, 2004, 2007, 2008,
3
* 2010 Free Software Foundation, Inc.
4
5
* This file is part of GnuPG.
304
305
if (!opt.running_detached)
306
307
if (log_get_fd () != -1)
307
no_close_list[i++] = log_get_fd ();
308
no_close_list[i++] = fileno (stderr);
308
no_close_list[i++] = assuan_fd_from_posix_fd (log_get_fd ());
309
no_close_list[i++] = assuan_fd_from_posix_fd (fileno (stderr));
310
311
no_close_list[i] = -1;
313
rc = assuan_new (&ctx);
316
log_error ("can't allocate assuan context: %s\n", gpg_strerror (rc));
312
320
/* Connect to the pinentry and perform initial handshaking. Note
313
321
that atfork is used to change the environment for pinentry. We
314
322
start the server in detached mode to suppress the console window
315
323
under Windows. */
316
rc = assuan_pipe_connect_ext (&ctx, opt.pinentry_program, argv,
317
no_close_list, atfork_cb, ctrl, 128);
324
rc = assuan_pipe_connect (ctx, opt.pinentry_program, argv,
325
no_close_list, atfork_cb, ctrl,
326
ASSUAN_PIPE_CONNECT_DETACHED);
320
329
log_error ("can't connect to the PIN entry module: %s\n",
321
330
gpg_strerror (rc));
331
assuan_release (ctx);
322
332
return unlock_pinentry (gpg_error (GPG_ERR_NO_PIN_ENTRY));
352
362
return unlock_pinentry (out_of_core ());
353
363
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
356
367
return unlock_pinentry (rc);
362
373
return unlock_pinentry (out_of_core ());
363
374
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
366
378
return unlock_pinentry (rc);
372
384
return unlock_pinentry (out_of_core ());
373
385
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
376
389
return unlock_pinentry (rc);
393
/* Provide a few default strings for use by the pinentries. This
394
may help a pinentry to avoid implementing localization code. */
395
static struct { const char *key, *value; } tbl[] = {
396
/* TRANSLATORS: These are labels for buttons etc used in
397
Pinentries. An underscore indicates that the next letter
398
should be used as an accelerator. Double the underscore for
399
a literal one. The actual to be translated text starts after
400
the second vertical bar. */
401
{ "ok", N_("|pinentry-label|_OK") },
402
{ "cancel", N_("|pinentry-label|_Cancel") },
403
{ "prompt", N_("|pinentry-label|PIN:") },
410
for (idx=0; tbl[idx].key; idx++)
412
s = _(tbl[idx].value);
413
if (*s == '|' && (s2=strchr (s+1,'|')))
415
if (asprintf (&optstr, "OPTION default-%s=%s", tbl[idx].key, s) < 0 )
416
return unlock_pinentry (out_of_core ());
417
assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
380
424
/* Tell the pinentry the name of a file it shall touch after having
381
425
messed with the tty. This is optional and only supported by
786
saveflag = assuan_get_flag (entry_ctx, ASSUAN_CONFIDENTIAL);
787
assuan_begin_confidential (entry_ctx);
741
788
rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, &parm,
742
789
inq_quality, entry_ctx, NULL, NULL);
790
assuan_set_flag (entry_ctx, ASSUAN_CONFIDENTIAL, saveflag);
743
791
/* Most pinentries out in the wild return the old Assuan error code
744
792
for canceled which gets translated to an assuan Cancel error and
745
793
not to the code for a user cancel. Fix this here. */
851
900
if (!parm.buffer)
852
901
return unlock_pinentry (out_of_core ());
903
saveflag = assuan_get_flag (entry_ctx, ASSUAN_CONFIDENTIAL);
854
904
assuan_begin_confidential (entry_ctx);
855
905
rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, &parm,
856
906
inq_quality, entry_ctx, NULL, NULL);
907
assuan_set_flag (entry_ctx, ASSUAN_CONFIDENTIAL, saveflag);
857
908
/* Most pinentries out in the wild return the old Assuan error code
858
909
for canceled which gets translated to an assuan Cancel error and
859
910
not to the code for a user cancel. Fix this here. */