~ubuntu-branches/ubuntu/quantal/gnupg2/quantal-proposed

« back to all changes in this revision

Viewing changes to agent/call-pinentry.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-05-25 14:27:35 UTC
  • mfrom: (1.1.15 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110525142735-jccyw0fopnyv728q
Tags: 2.0.17-2ubuntu1
* Merge from debian unstable. Remaining changes:
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
    . debian/gnupg2.dev: udev rules to set ACLs on SCM smartcard readers.
    . debian/rules: Call dh_installudev.
  - debian/control: Rename Vcs-* to XS-Debian-Vcs-*.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
3
4
 *
4
5
 * This file is part of GnuPG.
5
6
 *
32
33
# include <signal.h>
33
34
#endif
34
35
#include <pth.h>
 
36
 
 
37
#include "agent.h"
35
38
#include <assuan.h>
36
 
 
37
 
#include "agent.h"
38
39
#include "setenv.h"
39
40
#include "i18n.h"
40
41
 
158
159
      if (!rc)
159
160
        rc = gpg_error (GPG_ERR_INTERNAL);
160
161
    }
161
 
  assuan_disconnect (ctx);
 
162
  assuan_release (ctx);
162
163
  return rc;
163
164
}
164
165
 
196
197
}
197
198
 
198
199
 
199
 
static int
 
200
static gpg_error_t
200
201
getinfo_pid_cb (void *opaque, const void *buffer, size_t length)
201
202
{
202
203
  unsigned long *pid = opaque;
304
305
  if (!opt.running_detached)
305
306
    {
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));
309
310
    }
310
311
  no_close_list[i] = -1;
311
312
 
 
313
  rc = assuan_new (&ctx);
 
314
  if (rc)
 
315
    {
 
316
      log_error ("can't allocate assuan context: %s\n", gpg_strerror (rc));
 
317
      return rc;
 
318
    }
 
319
 
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);
318
327
  if (rc)
319
328
    {
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));
323
333
    }
324
334
  entry_ctx = ctx;
352
362
        return unlock_pinentry (out_of_core ());
353
363
      rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
354
364
                            NULL);
 
365
      xfree (optstr);
355
366
      if (rc)
356
367
        return unlock_pinentry (rc);
357
368
    }
362
373
        return unlock_pinentry (out_of_core ());
363
374
      rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
364
375
                            NULL);
 
376
      xfree (optstr);
365
377
      if (rc)
366
378
        return unlock_pinentry (rc);
367
379
    }
372
384
        return unlock_pinentry (out_of_core ());
373
385
      rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
374
386
                            NULL);
 
387
      xfree (optstr);
375
388
      if (rc)
376
389
        return unlock_pinentry (rc);
377
390
    }
378
391
 
 
392
  {
 
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:") },
 
404
      { NULL, NULL}
 
405
    };
 
406
    char *optstr;
 
407
    int idx;
 
408
    const char *s, *s2;
 
409
 
 
410
    for (idx=0; tbl[idx].key; idx++)
 
411
      {
 
412
        s = _(tbl[idx].value);
 
413
        if (*s == '|' && (s2=strchr (s+1,'|')))
 
414
          s = s2+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,
 
418
                         NULL);
 
419
        xfree (optstr);
 
420
      }
 
421
  }
 
422
 
379
423
  
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
463
507
}
464
508
 
465
509
 
466
 
static int
 
510
static gpg_error_t
467
511
getpin_cb (void *opaque, const void *buffer, size_t length)
468
512
{
469
513
  struct entry_parm_s *parm = opaque;
553
597
 
554
598
 
555
599
/* Handle the QUALITY inquiry. */
556
 
static int
 
600
static gpg_error_t
557
601
inq_quality (void *opaque, const char *line)
558
602
{
559
603
  assuan_context_t ctx = opaque;
661
705
  struct entry_parm_s parm;
662
706
  const char *errtext = NULL;
663
707
  int is_pin = 0;
 
708
  int saveflag;
664
709
 
665
710
  if (opt.batch)
666
711
    return 0; /* fixme: we should return BAD PIN */
738
783
          errtext = NULL;
739
784
        }
740
785
      
 
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. */
801
849
  int rc;
802
850
  char line[ASSUAN_LINELENGTH];
803
851
  struct entry_parm_s parm;
 
852
  int saveflag;
804
853
 
805
854
  *retpass = NULL;
806
855
  if (opt.batch)
851
900
  if (!parm.buffer)
852
901
    return unlock_pinentry (out_of_core ());
853
902
 
 
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. */
914
965
  if (notok)
915
966
    {
916
967
      /* Try to use the newer NOTOK feature if a cancel button is
917
 
         requested.  If no cacnel button is requested we keep on using
 
968
         requested.  If no cancel button is requested we keep on using
918
969
         the standard cancel.  */
919
970
      if (with_cancel)
920
971
        {