~ubuntu-branches/ubuntu/precise/gnupg2/precise-updates

« back to all changes in this revision

Viewing changes to agent/call-scd.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2011-02-13 16:06:41 UTC
  • mfrom: (1.2.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: james.westby@ubuntu.com-20110213160641-364ll4kdkhft0wq3
Tags: 2.0.17-1
* New upstream release. (Closes: #584316, #603985, #603983, #603984)
* debian/patches/02-encode-s2k.diff,
  debian/patches/03-gpgsm-realloc.diff, debian/patches/series: Drop now
  unneeded security patches.
* debian/rules, debian/patches/01-gnupg2-rename.diff,
  debian/gnupg2.info, debian/gnupg2.install: No need to rename the info
  file anymore.
* debian/patches/01-gnupg2-rename.diff: Rename the autoconf package for
  better renaming of pkg directories. (Closes: #579006)
* debian/control, debian/compat: Upgrade to debhelper level 8.
* debian/control:
  - Upgrade Standards-Version to 3.9.1.
  - Update Build-Depends versions for the latest release.
* debian/gnupg2.install: Add the applygnupgdefaults command. (Closes:
  #567537)
* debian/gnupg2.docs: doc/faq.html no longer exists.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#define MAX_OPEN_FDS 20
43
43
#endif
44
44
 
 
45
/* This Assuan flag is only available since libassuan 2.0.2.  Because
 
46
   comments lines are comments anyway we can use a replacement which
 
47
   might not do anything.  assuan_{g,s}et_flag don't return an error
 
48
   thus there won't be any ABI problem.  */
 
49
#ifndef ASSUAN_CONVEY_COMMENTS
 
50
#define ASSUAN_CONVEY_COMMENTS 4
 
51
#endif
 
52
 
 
53
 
45
54
/* Definition of module local data of the CTRL structure.  */
46
55
struct scd_local_s
47
56
{
108
117
 
109
118
 
110
119
/* Local prototypes.  */
111
 
static assuan_error_t membuf_data_cb (void *opaque,
112
 
                                      const void *buffer, size_t length);
 
120
static gpg_error_t membuf_data_cb (void *opaque,
 
121
                                   const void *buffer, size_t length);
113
122
 
114
123
 
115
124
 
176
185
static int 
177
186
unlock_scd (ctrl_t ctrl, int rc)
178
187
{
 
188
  if (gpg_err_code (rc) == GPG_ERR_NOT_OPERATIONAL
 
189
      && gpg_err_source (rc) == GPG_ERR_SOURCE_SCD)
 
190
    {
 
191
      /* If the SCdaemon returned this error, it detected a major
 
192
         problem, like no reader connected.  To finish this we need to
 
193
         stop the connection.  This simulates an explicit killing of
 
194
         the SCdaemon.  */
 
195
      assuan_transact (primary_scd_ctx, "BYE",
 
196
                       NULL, NULL, NULL, NULL, NULL, NULL);
 
197
    }
 
198
      
179
199
  if (ctrl->scd_local->locked != 1)
180
200
    {
181
201
      log_error ("unlock_scd: invalid lock count (%d)\n",
209
229
{
210
230
  gpg_error_t err = 0;
211
231
  const char *pgmname;
212
 
  assuan_context_t ctx;
 
232
  assuan_context_t ctx = NULL;
213
233
  const char *argv[3];
214
234
  int no_close_list[3];
215
235
  int i;
268
288
      goto leave;
269
289
    }
270
290
 
 
291
  rc = assuan_new (&ctx);
 
292
  if (rc)
 
293
    {
 
294
      log_error ("can't allocate assuan context: %s\n", gpg_strerror (rc));
 
295
      err = rc;
 
296
      goto leave;
 
297
    }
 
298
 
271
299
  if (socket_name)
272
300
    {
273
 
      rc = assuan_socket_connect (&ctx, socket_name, 0);
 
301
      rc = assuan_socket_connect (ctx, socket_name, 0, 0);
274
302
      if (rc)
275
303
        {
276
304
          log_error ("can't connect to socket `%s': %s\n",
325
353
  if (!opt.running_detached)
326
354
    {
327
355
      if (log_get_fd () != -1)
328
 
        no_close_list[i++] = log_get_fd ();
329
 
      no_close_list[i++] = fileno (stderr);
 
356
        no_close_list[i++] = assuan_fd_from_posix_fd (log_get_fd ());
 
357
      no_close_list[i++] = assuan_fd_from_posix_fd (fileno (stderr));
330
358
    }
331
359
  no_close_list[i] = -1;
332
360
 
333
361
  /* Connect to the pinentry and perform initial handshaking.  Use
334
362
     detached flag (128) so that under W32 SCDAEMON does not show up a
335
363
     new window.  */
336
 
  rc = assuan_pipe_connect_ext (&ctx, opt.scdaemon_program, argv,
337
 
                                no_close_list, atfork_cb, NULL, 128);
 
364
  rc = assuan_pipe_connect (ctx, opt.scdaemon_program, argv,
 
365
                            no_close_list, atfork_cb, NULL, 128);
338
366
  if (rc)
339
367
    {
340
368
      log_error ("can't connect to the SCdaemon: %s\n",
380
408
  }
381
409
 
382
410
  /* Tell the scdaemon we want him to send us an event signal. */
383
 
  {
384
 
    char buf[100];
385
 
 
 
411
  if (opt.sigusr2_enabled)
 
412
    {
 
413
      char buf[100];
 
414
      
386
415
#ifdef HAVE_W32_SYSTEM
387
 
    snprintf (buf, sizeof buf, "OPTION event-signal=%lx", 
388
 
              (unsigned long)get_agent_scd_notify_event ());
 
416
      snprintf (buf, sizeof buf, "OPTION event-signal=%lx", 
 
417
                (unsigned long)get_agent_scd_notify_event ());
389
418
#else
390
 
    snprintf (buf, sizeof buf, "OPTION event-signal=%d", SIGUSR2);
 
419
      snprintf (buf, sizeof buf, "OPTION event-signal=%d", SIGUSR2);
391
420
#endif
392
 
    assuan_transact (ctx, buf, NULL, NULL, NULL, NULL, NULL, NULL);
393
 
  }
 
421
      assuan_transact (ctx, buf, NULL, NULL, NULL, NULL, NULL, NULL);
 
422
    }
394
423
 
395
424
  primary_scd_ctx = ctx;
396
425
  primary_scd_ctx_reusable = 0;
399
428
  if (err)
400
429
    {
401
430
      unlock_scd (ctrl, err);
 
431
      if (ctx)
 
432
        assuan_release (ctx);
402
433
    } 
403
434
  else
404
435
    {
477
508
          struct scd_local_s *sl;
478
509
 
479
510
          assuan_set_flag (primary_scd_ctx, ASSUAN_NO_WAITPID, 1);
480
 
          assuan_disconnect (primary_scd_ctx);
 
511
          assuan_release (primary_scd_ctx);
481
512
 
482
513
          for (sl=scd_local_list; sl; sl = sl->next_local)
483
514
            {
484
515
              if (sl->ctx)
485
516
                {
486
517
                  if (sl->ctx != primary_scd_ctx)
487
 
                    assuan_disconnect (sl->ctx);
 
518
                    assuan_release (sl->ctx);
488
519
                  sl->ctx = NULL;
489
520
                }
490
521
            }
534
565
              primary_scd_ctx_reusable = 1;
535
566
            }
536
567
          else
537
 
            assuan_disconnect (ctrl->scd_local->ctx);
 
568
            assuan_release (ctrl->scd_local->ctx);
538
569
          ctrl->scd_local->ctx = NULL;
539
570
        }
540
571
      
563
594
 
564
595
 
565
596
 
566
 
static int
 
597
static gpg_error_t
567
598
learn_status_cb (void *opaque, const char *line)
568
599
{
569
600
  struct learn_parm_s *parm = opaque;
626
657
 
627
658
 
628
659
 
629
 
static int
 
660
static gpg_error_t
630
661
get_serialno_cb (void *opaque, const char *line)
631
662
{
632
663
  char **serialno = opaque;
684
715
 
685
716
 
686
717
 
687
 
static assuan_error_t
 
718
static gpg_error_t
688
719
membuf_data_cb (void *opaque, const void *buffer, size_t length)
689
720
{
690
721
  membuf_t *data = opaque;
695
726
}
696
727
  
697
728
/* Handle the NEEDPIN inquiry. */
698
 
static int
 
729
static gpg_error_t
699
730
inq_needpin (void *opaque, const char *line)
700
731
{
701
732
  struct inq_needpin_s *parm = opaque;
991
1022
};
992
1023
 
993
1024
/* Callback function for agent_card_getattr.  */
994
 
static assuan_error_t
 
1025
static gpg_error_t
995
1026
card_getattr_cb (void *opaque, const char *line)
996
1027
{
997
1028
  struct card_getattr_parm_s *parm = opaque;
1067
1098
 
1068
1099
 
1069
1100
 
1070
 
static int
 
1101
static gpg_error_t
1071
1102
pass_status_thru (void *opaque, const char *line)
1072
1103
{
1073
1104
  assuan_context_t ctx = opaque;
1087
1118
  return 0;
1088
1119
}
1089
1120
 
1090
 
static int
 
1121
static gpg_error_t
1091
1122
pass_data_thru (void *opaque, const void *buffer, size_t length)
1092
1123
{
1093
1124
  assuan_context_t ctx = opaque;
1108
1139
{
1109
1140
  int rc;
1110
1141
  struct inq_needpin_s inqparm;
 
1142
  int saveflag;
1111
1143
 
1112
1144
  rc = start_scd (ctrl);
1113
1145
  if (rc)
1117
1149
  inqparm.getpin_cb = getpin_cb;
1118
1150
  inqparm.getpin_cb_arg = getpin_cb_arg;
1119
1151
  inqparm.passthru = assuan_context;
 
1152
  saveflag = assuan_get_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS);
 
1153
  assuan_set_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS, 1);
1120
1154
  rc = assuan_transact (ctrl->scd_local->ctx, cmdline,
1121
1155
                        pass_data_thru, assuan_context,
1122
1156
                        inq_needpin, &inqparm,
1123
1157
                        pass_status_thru, assuan_context);
 
1158
  assuan_set_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS, saveflag);
1124
1159
  if (rc)
1125
1160
    {
1126
1161
      return unlock_scd (ctrl, rc);