~ubuntu-branches/ubuntu/feisty/gnupg2/feisty

« back to all changes in this revision

Viewing changes to agent/command-ssh.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-11-24 18:48:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061124184823-17ir9m46tl09n9k4
Tags: 2.0.0-4ubuntu1
* Synchronize to Debian, reapply remaining Ubuntu changes to pristine Debian
  version:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).

Show diffs side-by-side

added added

removed removed

Lines of Context:
268
268
  s = xtrymalloc (data_n + 1);
269
269
  if (s)
270
270
    {
271
 
      strncpy (s, data, data_n);
 
271
      memcpy (s, data, data_n);
272
272
      s[data_n] = 0;
273
273
    }
274
274
 
294
294
  if (ret == EOF)
295
295
    {
296
296
      if (es_ferror (stream))
297
 
        err = gpg_error_from_errno (errno);
 
297
        err = gpg_error_from_syserror ();
298
298
      else
299
299
        err = gpg_error (GPG_ERR_EOF);
300
300
      *b = 0;
317
317
 
318
318
  ret = es_fputc (b, stream);
319
319
  if (ret == EOF)
320
 
    err = gpg_error_from_errno (errno);
 
320
    err = gpg_error_from_syserror ();
321
321
  else
322
322
    err = 0;
323
323
 
335
335
 
336
336
  ret = es_read (stream, buffer, sizeof (buffer), &bytes_read);
337
337
  if (ret)
338
 
    err = gpg_error_from_errno (errno);
 
338
    err = gpg_error_from_syserror ();
339
339
  else
340
340
    {
341
341
      if (bytes_read != sizeof (buffer))
368
368
 
369
369
  ret = es_write (stream, buffer, sizeof (buffer), NULL);
370
370
  if (ret)
371
 
    err = gpg_error_from_errno (errno);
 
371
    err = gpg_error_from_syserror ();
372
372
  else
373
373
    err = 0;
374
374
 
385
385
 
386
386
  ret = es_read (stream, buffer, size, &bytes_read);
387
387
  if (ret)
388
 
    err = gpg_error_from_errno (errno);
 
388
    err = gpg_error_from_syserror ();
389
389
  else
390
390
    {
391
391
      if (bytes_read != size)
406
406
 
407
407
  ret = es_write (stream, buffer, size, NULL);
408
408
  if (ret)
409
 
    err = gpg_error_from_errno (errno);
 
409
    err = gpg_error_from_syserror ();
410
410
  else
411
411
    err = 0;
412
412
 
438
438
    buffer = xtrymalloc (length + 1);
439
439
  if (! buffer)
440
440
    {
441
 
      err = gpg_error_from_errno (errno);
 
441
      err = gpg_error_from_syserror ();
442
442
      goto out;
443
443
    }
444
444
 
526
526
  if (err)
527
527
    goto out;
528
528
 
 
529
  /* To avoid excessive use of secure memory we check that an MPI is
 
530
     not too large. */
 
531
  if (mpi_data_size > 520)
 
532
    {
 
533
      log_error (_("ssh keys greater than %d bits are not supported\n"), 4096);
 
534
      err = GPG_ERR_TOO_LARGE;
 
535
      goto out;
 
536
    }
 
537
 
529
538
  err = gcry_mpi_scan (&mpi, GCRYMPI_FMT_STD, mpi_data, mpi_data_size, NULL);
530
539
  if (err)
531
540
    goto out;
578
587
      if (ret || (! bytes_read))
579
588
        {
580
589
          if (ret)
581
 
            err = gpg_error_from_errno (errno);
 
590
            err = gpg_error_from_syserror ();
582
591
          break;
583
592
        }
584
593
      ret = es_write (dst, buffer, bytes_read, NULL);
585
594
      if (ret)
586
595
        {
587
 
          err = gpg_error_from_errno (errno);
 
596
          err = gpg_error_from_syserror ();
588
597
          break;
589
598
        }
590
599
    }
614
623
  stream = es_fopen (filename, "r");
615
624
  if (! stream)
616
625
    {
617
 
      err = gpg_error_from_errno (errno);
 
626
      err = gpg_error_from_syserror ();
618
627
      goto out;
619
628
    }
620
629
 
621
630
  ret = fstat (es_fileno (stream), &statbuf);
622
631
  if (ret)
623
632
    {
624
 
      err = gpg_error_from_errno (errno);
 
633
      err = gpg_error_from_syserror ();
625
634
      goto out;
626
635
    }
627
636
 
628
637
  buffer_new = xtrymalloc (statbuf.st_size);
629
638
  if (! buffer_new)
630
639
    {
631
 
      err = gpg_error_from_errno (errno);
 
640
      err = gpg_error_from_syserror ();
632
641
      goto out;
633
642
    }
634
643
 
853
862
  elems_public = key_spec.elems_key_public;
854
863
  elems_public_n = strlen (elems_public);
855
864
 
856
 
  mpis = xtrymalloc (sizeof (*mpis) * (elems_n + 1));
857
 
  if (! mpis)
 
865
  mpis = xtrycalloc (elems_n + 1, sizeof *mpis );
 
866
  if (!mpis)
858
867
    {
859
 
      err = gpg_error_from_errno (errno);
 
868
      err = gpg_error_from_syserror ();
860
869
      goto out;
861
870
    }
862
 
  
863
 
  memset (mpis, 0, sizeof (*mpis) * (elems_n + 1));
864
871
 
865
872
  elem_is_secret = 0;
866
873
  for (i = 0; i < elems_n; i++)
1033
1040
  sexp_template = xtrymalloc (sexp_template_n);
1034
1041
  if (! sexp_template)
1035
1042
    {
1036
 
      err = gpg_error_from_errno (errno);
 
1043
      err = gpg_error_from_syserror ();
1037
1044
      goto out;
1038
1045
    }
1039
1046
 
1041
1048
  arg_list = xtrymalloc (sizeof (*arg_list) * (2 + elems_n + 1));
1042
1049
  if (! arg_list)
1043
1050
    {
1044
 
      err = gpg_error_from_errno (errno);
 
1051
      err = gpg_error_from_syserror ();
1045
1052
      goto out;
1046
1053
    }
1047
1054
 
1143
1150
    }
1144
1151
 
1145
1152
  elems_n = strlen (elems);
1146
 
  mpis_new = xtrymalloc (sizeof (*mpis_new) * (elems_n + 1));
1147
 
  if (! mpis_new)
 
1153
  mpis_new = xtrycalloc (elems_n + 1, sizeof *mpis_new );
 
1154
  if (!mpis_new)
1148
1155
    {
1149
 
      err = gpg_error_from_errno (errno);
 
1156
      err = gpg_error_from_syserror ();
1150
1157
      goto out;
1151
1158
    }
1152
 
  memset (mpis_new, 0, sizeof (*mpis_new) * (elems_n + 1));
1153
1159
 
1154
1160
  value_list = gcry_sexp_find_token (sexp, key_spec.identifier, 0);
1155
1161
  if (! value_list)
1198
1204
  comment_new = make_cstring (data, data_n);
1199
1205
  if (! comment_new)
1200
1206
    {
1201
 
      err = gpg_error_from_errno (errno);
 
1207
      err = gpg_error_from_syserror ();
1202
1208
      goto out;
1203
1209
    }
1204
1210
 
1395
1401
  stream = es_mopen (NULL, 0, 0, 1, NULL, NULL, "r+");
1396
1402
  if (! stream)
1397
1403
    {
1398
 
      err = gpg_error_from_errno (errno);
 
1404
      err = gpg_error_from_syserror ();
1399
1405
      goto out;
1400
1406
    }
1401
1407
 
1411
1417
  blob_size_new = es_ftell (stream);
1412
1418
  if (blob_size_new == -1)
1413
1419
    {
1414
 
      err = gpg_error_from_errno (errno);
 
1420
      err = gpg_error_from_syserror ();
1415
1421
      goto out;
1416
1422
    }
1417
1423
  
1422
1428
  blob_new = xtrymalloc (blob_size_new);
1423
1429
  if (! blob_new)
1424
1430
    {
1425
 
      err = gpg_error_from_errno (errno);
 
1431
      err = gpg_error_from_syserror ();
1426
1432
      goto out;
1427
1433
    }
1428
1434
 
1514
1520
  blob_stream = es_mopen (NULL, 0, 0, 1, NULL, NULL, "r+");
1515
1521
  if (! blob_stream)
1516
1522
    {
1517
 
      err = gpg_error_from_errno (errno);
 
1523
      err = gpg_error_from_syserror ();
1518
1524
      goto out;
1519
1525
    }
1520
1526
 
1678
1684
      shadow_info = make_shadow_info (serialno, authkeyid);
1679
1685
      if (!shadow_info)
1680
1686
        {
1681
 
          err = gpg_error_from_errno (errno);
 
1687
          err = gpg_error_from_syserror ();
1682
1688
          xfree (pkbuf);
1683
1689
          gcry_sexp_release (s_pk);
1684
1690
          xfree (serialno);
1728
1734
        *cardsn = xtryasprintf ("cardno:%s", serialno);
1729
1735
      if (!*cardsn)
1730
1736
        {
1731
 
          err = gpg_error_from_errno (errno);
 
1737
          err = gpg_error_from_syserror ();
1732
1738
          xfree (pkbuf);
1733
1739
          gcry_sexp_release (s_pk);
1734
1740
          xfree (serialno);
1795
1801
  key_blobs = es_mopen (NULL, 0, 0, 1, NULL, NULL, "r+");
1796
1802
  if (! key_blobs)
1797
1803
    {
1798
 
      err = gpg_error_from_errno (errno);
 
1804
      err = gpg_error_from_syserror ();
1799
1805
      goto out;
1800
1806
    }
1801
1807
 
1919
1925
  ret = es_fseek (key_blobs, 0, SEEK_SET);
1920
1926
  if (ret)
1921
1927
    {
1922
 
      err = gpg_error_from_errno (errno);
 
1928
      err = gpg_error_from_syserror ();
1923
1929
      goto out;
1924
1930
    }
1925
1931
 
2026
2032
  stream = es_mopen (NULL, 0, 0, 1, NULL, NULL, "r+");
2027
2033
  if (! stream)
2028
2034
    {
2029
 
      err = gpg_error_from_errno (errno);
 
2035
      err = gpg_error_from_syserror ();
2030
2036
      goto out;
2031
2037
    }
2032
2038
 
2040
2046
  identifier = make_cstring (identifier_raw, identifier_n);
2041
2047
  if (! identifier)
2042
2048
    {
2043
 
      err = gpg_error_from_errno (errno);
 
2049
      err = gpg_error_from_syserror ();
2044
2050
      goto out;
2045
2051
    }
2046
2052
 
2055
2061
  elems = spec.elems_signature;
2056
2062
  elems_n = strlen (elems);
2057
2063
 
2058
 
  mpis = xtrymalloc (sizeof (*mpis) * (elems_n + 1));
2059
 
  if (! mpis)
 
2064
  mpis = xtrycalloc (elems_n + 1, sizeof *mpis);
 
2065
  if (!mpis)
2060
2066
    {
2061
 
      err = gpg_error_from_errno (errno);
 
2067
      err = gpg_error_from_syserror ();
2062
2068
      goto out;
2063
2069
    }
2064
 
  memset (mpis, 0, sizeof (*mpis) * (elems_n + 1));
2065
2070
 
2066
2071
  for (i = 0; i < elems_n; i++)
2067
2072
    {
2093
2098
  sig_blob_n = es_ftell (stream);
2094
2099
  if (sig_blob_n == -1)
2095
2100
    {
2096
 
      err = gpg_error_from_errno (errno);
 
2101
      err = gpg_error_from_syserror ();
2097
2102
      goto out;
2098
2103
    }
2099
2104
 
2100
2105
  sig_blob = xtrymalloc (sig_blob_n);
2101
2106
  if (! sig_blob)
2102
2107
    {
2103
 
      err = gpg_error_from_errno (errno);
 
2108
      err = gpg_error_from_syserror ();
2104
2109
      goto out;
2105
2110
    }
2106
2111
 
2107
2112
  ret = es_fseek (stream, 0, SEEK_SET);
2108
2113
  if (ret)
2109
2114
    {
2110
 
      err = gpg_error_from_errno (errno);
 
2115
      err = gpg_error_from_syserror ();
2111
2116
      goto out;
2112
2117
    }    
2113
2118
 
2264
2269
  comment_new = make_cstring (data, data_n);
2265
2270
  if (! comment_new)
2266
2271
    {
2267
 
      err = gpg_error_from_errno (errno);
 
2272
      err = gpg_error_from_syserror ();
2268
2273
      goto out;
2269
2274
    }
2270
2275
 
2294
2299
  buffer_new = xtrymalloc_secure (buffer_new_n);
2295
2300
  if (! buffer_new)
2296
2301
    {
2297
 
      err = gpg_error_from_errno (errno);
 
2302
      err = gpg_error_from_syserror ();
2298
2303
      goto out;
2299
2304
    }
2300
2305
  
2351
2356
                   "within gpg-agent's key storage"),
2352
2357
                 comment ? comment : "?") < 0)
2353
2358
    {
2354
 
      err = gpg_error_from_errno (errno);
 
2359
      err = gpg_error_from_syserror ();
2355
2360
      goto out;
2356
2361
    }
2357
2362
 
2359
2364
  pi = gcry_calloc_secure (1, sizeof (*pi) + 100 + 1);
2360
2365
  if (!pi)
2361
2366
    {
2362
 
      err = gpg_error_from_errno (errno);
 
2367
      err = gpg_error_from_syserror ();
2363
2368
      goto out;
2364
2369
    }
2365
2370
  pi->max_length = 100;
2715
2720
    request = es_mopen (NULL, 0, 0, 1, gcry_realloc, gcry_free, "r+");
2716
2721
  if (! request)
2717
2722
    {
2718
 
      err = gpg_error_from_errno (errno);
 
2723
      err = gpg_error_from_syserror ();
2719
2724
      goto out;
2720
2725
    }
2721
2726
  ret = es_setvbuf (request, NULL, _IONBF, 0);
2722
2727
  if (ret)
2723
2728
    {
2724
 
      err = gpg_error_from_errno (errno);
 
2729
      err = gpg_error_from_syserror ();
2725
2730
      goto out;
2726
2731
    }
2727
2732
  err = stream_write_data (request, request_data + 1, request_data_size - 1);
2732
2737
  response = es_mopen (NULL, 0, 0, 1, NULL, NULL, "r+");
2733
2738
  if (! response)
2734
2739
    {
2735
 
      err = gpg_error_from_errno (errno);
 
2740
      err = gpg_error_from_syserror ();
2736
2741
      goto out;
2737
2742
    }
2738
2743
 
2848
2853
  stream_sock = es_fdopen (sock_client, "r+");
2849
2854
  if (!stream_sock)
2850
2855
    {
2851
 
      err = gpg_error_from_errno (errno);
 
2856
      err = gpg_error_from_syserror ();
2852
2857
      log_error (_("failed to create stream from socket: %s\n"),
2853
2858
                 gpg_strerror (err));
2854
2859
      goto out;
2858
2863
  ret = es_setvbuf (stream_sock, NULL, _IONBF, 0);
2859
2864
  if (ret)
2860
2865
    {
2861
 
      err = gpg_error_from_errno (errno);
2862
 
      log_error (_("failed to disable buffering "
2863
 
                   "on socket stream: %s\n"), gpg_strerror (err));
 
2866
      err = gpg_error_from_syserror ();
 
2867
      log_error ("failed to disable buffering "
 
2868
                 "on socket stream: %s\n", gpg_strerror (err));
2864
2869
      goto out;
2865
2870
    }
2866
2871