~ubuntu-branches/ubuntu/hardy/gnupg2/hardy-proposed

« back to all changes in this revision

Viewing changes to tools/gpg-connect-agent.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-05-15 13:54:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070515135455-89qfyalmgjy6gcqw
Tags: 2.0.4-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
  - Build-depend on libcurl3-gnutls-dev
  - g10/call-agent.c: set DBG_ASSUAN to 0 to suppress a debug message
  - Include /doc files as done with gnupg
  - debian/rules: add doc/com-certs.pem to the docs for gpgsm
  - debian/copyright: update download url
  - debian/README.Debian: remove note the gnupg2 isn't released yet.
  - debian/control: Change Maintainer/XSBC-Original-Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* gpg-connect-agent.c - Tool to connect to the agent.
2
 
 *      Copyright (C) 2005 Free Software Foundation, Inc.
 
2
 *      Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
5
5
 *
46
46
    oNoVerbose  = 500,
47
47
    oHomedir,
48
48
    oHex,
 
49
    oDecode,
49
50
    oNoExtConnect
50
51
 
51
52
  };
59
60
    { oVerbose, "verbose",  0, N_("verbose") },
60
61
    { oQuiet, "quiet",      0, N_("quiet") },
61
62
    { oHex,   "hex",        0, N_("print data out hex encoded") },
 
63
    { oDecode,"decode",     0, N_("decode received data lines") },
62
64
    { oRawSocket, "raw-socket", 2, N_("|NAME|connect to Assuan socket NAME")},
63
65
    { oExec, "exec", 0, N_("run the Assuan server given on the command line")},
64
66
    { oNoExtConnect, "no-ext-connect",
78
80
  int quiet;            /* Be extra quiet.  */
79
81
  const char *homedir;  /* Configuration directory name */
80
82
  int hex;              /* Print data lines in hex format. */
 
83
  int decode;           /* Decode received data lines.  */
81
84
  const char *raw_socket; /* Name of socket to connect in raw mode. */
82
85
  int exec;             /* Run the pgm given on the command line. */
83
86
  unsigned int connect_flags;    /* Flags used for connecting. */
306
309
        case oNoVerbose: opt.verbose = 0; break;
307
310
        case oHomedir:   opt.homedir = pargs.r.ret_str; break;
308
311
        case oHex:       opt.hex = 1; break;
 
312
        case oDecode:    opt.decode = 1; break;
309
313
        case oRawSocket: opt.raw_socket = pargs.r.ret_str; break;
310
314
        case oExec:      opt.exec = 1; break;
311
315
        case oNoExtConnect: opt.connect_flags &= ~(1); break;
436
440
              do_recvfd (ctx, p);
437
441
              continue;
438
442
            }
 
443
          else if (!strcmp (cmd, "hex"))
 
444
            opt.hex = 1;
 
445
          else if (!strcmp (cmd, "nohex"))
 
446
            opt.hex = 0;
 
447
          else if (!strcmp (cmd, "decode"))
 
448
            opt.decode = 1;
 
449
          else if (!strcmp (cmd, "nodecode"))
 
450
            opt.decode = 0;
439
451
          else if (!strcmp (cmd, "help"))
440
452
            {
441
453
              puts (
451
463
"/cleardef              Delete all definitions.\n"
452
464
"/sendfd FILE MODE      Open FILE and pass descriptor to server.\n"
453
465
"/recvfd                Receive FD from server and print. \n"
454
 
                    "/help                  Print this help.");
 
466
"/[no]hex               Enable hex dumping of received data lines.\n"
 
467
"/[no]decode            Enable decoding of received data lines.\n"
 
468
"/help                  Print this help.");
455
469
            }
456
470
          else
457
471
            log_error (_("unknown command `%s'\n"), cmd );
577
591
  size_t linelen;
578
592
  assuan_error_t rc;
579
593
  int i, j;
 
594
  int need_lf = 0;
580
595
 
581
596
  for (;;)
582
597
    {
628
643
                  putchar ('\n');
629
644
                }
630
645
            }
631
 
          else
632
 
            {
633
 
              fwrite (line, linelen, 1, stdout);
634
 
              putchar ('\n');
635
 
            }
636
 
        }
637
 
      else if (linelen >= 1
638
 
               && line[0] == 'S' 
639
 
               && (line[1] == '\0' || line[1] == ' '))
640
 
        {
641
 
          fwrite (line, linelen, 1, stdout);
642
 
          putchar ('\n');
643
 
        }  
644
 
      else if (linelen >= 2
645
 
               && line[0] == 'O' && line[1] == 'K'
646
 
               && (line[2] == '\0' || line[2] == ' '))
647
 
        {
648
 
          fwrite (line, linelen, 1, stdout);
649
 
          putchar ('\n');
650
 
          return 0;
651
 
        }
652
 
      else if (linelen >= 3
653
 
               && line[0] == 'E' && line[1] == 'R' && line[2] == 'R'
654
 
               && (line[3] == '\0' || line[3] == ' '))
655
 
        {
656
 
          fwrite (line, linelen, 1, stdout);
657
 
          putchar ('\n');
658
 
          return 0;
659
 
        }  
660
 
      else if (linelen >= 7
661
 
               && line[0] == 'I' && line[1] == 'N' && line[2] == 'Q'
662
 
               && line[3] == 'U' && line[4] == 'I' && line[5] == 'R'
663
 
               && line[6] == 'E' 
664
 
               && (line[7] == '\0' || line[7] == ' '))
665
 
        {
666
 
          fwrite (line, linelen, 1, stdout);
667
 
          putchar ('\n');
668
 
          if (!handle_inquire (ctx, line))
669
 
            assuan_write_line (ctx, "CANCEL");
670
 
        }
671
 
      else if (linelen >= 3
672
 
               && line[0] == 'E' && line[1] == 'N' && line[2] == 'D'
673
 
               && (line[3] == '\0' || line[3] == ' '))
674
 
        {
675
 
          fwrite (line, linelen, 1, stdout);
676
 
          putchar ('\n');
677
 
          /* Received from server, thus more responses are expected.  */
678
 
        }
679
 
      else
680
 
        return gpg_error (GPG_ERR_ASS_INV_RESPONSE);
 
646
          else if (opt.decode)
 
647
            {
 
648
              const unsigned char *s;
 
649
              int need_d = 1;
 
650
              int c = 0;
 
651
 
 
652
              for (j=2, s=(unsigned char*)line+2; j < linelen; j++, s++ )
 
653
                {
 
654
                  if (need_d)
 
655
                    {
 
656
                      fputs ("D ", stdout);
 
657
                      need_d = 0;
 
658
                    }
 
659
                  if (*s == '%' && j+2 < linelen)
 
660
                    { 
 
661
                      s++; j++;
 
662
                      c = xtoi_2 ( s );
 
663
                      s++; j++;
 
664
                    }
 
665
                  else
 
666
                    c = *s;
 
667
                  if (c == '\n')
 
668
                    need_d = 1;
 
669
                  putchar (c);
 
670
                }
 
671
              need_lf = (c != '\n');
 
672
            }
 
673
          else
 
674
            {
 
675
              fwrite (line, linelen, 1, stdout);
 
676
              putchar ('\n');
 
677
            }
 
678
        }
 
679
      else 
 
680
        {
 
681
          if (need_lf)
 
682
            {
 
683
              putchar ('\n');
 
684
              need_lf = 0;
 
685
            }
 
686
 
 
687
          if (linelen >= 1
 
688
              && line[0] == 'S' 
 
689
              && (line[1] == '\0' || line[1] == ' '))
 
690
            {
 
691
              fwrite (line, linelen, 1, stdout);
 
692
              putchar ('\n');
 
693
            }  
 
694
          else if (linelen >= 2
 
695
                   && line[0] == 'O' && line[1] == 'K'
 
696
                   && (line[2] == '\0' || line[2] == ' '))
 
697
            {
 
698
              fwrite (line, linelen, 1, stdout);
 
699
              putchar ('\n');
 
700
              return 0;
 
701
            }
 
702
          else if (linelen >= 3
 
703
                   && line[0] == 'E' && line[1] == 'R' && line[2] == 'R'
 
704
                   && (line[3] == '\0' || line[3] == ' '))
 
705
            {
 
706
              fwrite (line, linelen, 1, stdout);
 
707
              putchar ('\n');
 
708
              return 0;
 
709
            }  
 
710
          else if (linelen >= 7
 
711
                   && line[0] == 'I' && line[1] == 'N' && line[2] == 'Q'
 
712
                   && line[3] == 'U' && line[4] == 'I' && line[5] == 'R'
 
713
                   && line[6] == 'E' 
 
714
                   && (line[7] == '\0' || line[7] == ' '))
 
715
            {
 
716
              fwrite (line, linelen, 1, stdout);
 
717
              putchar ('\n');
 
718
              if (!handle_inquire (ctx, line))
 
719
                assuan_write_line (ctx, "CANCEL");
 
720
            }
 
721
          else if (linelen >= 3
 
722
                   && line[0] == 'E' && line[1] == 'N' && line[2] == 'D'
 
723
                   && (line[3] == '\0' || line[3] == ' '))
 
724
            {
 
725
              fwrite (line, linelen, 1, stdout);
 
726
              putchar ('\n');
 
727
              /* Received from server, thus more responses are expected.  */
 
728
            }
 
729
          else
 
730
            return gpg_error (GPG_ERR_ASS_INV_RESPONSE);
 
731
        }
681
732
    }
682
733
}
683
734