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

« back to all changes in this revision

Viewing changes to sm/server.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:
51
51
};
52
52
 
53
53
 
54
 
 
 
54
/* Cookie definition for assuan data line output.  */
 
55
static ssize_t data_line_cookie_write (void *cookie,
 
56
                                       const void *buffer, size_t size);
 
57
static int data_line_cookie_close (void *cookie);
 
58
static es_cookie_io_functions_t data_line_cookie_functions =
 
59
  {
 
60
    NULL,
 
61
    data_line_cookie_write,
 
62
    NULL,
 
63
    data_line_cookie_close
 
64
  };
 
65
 
 
66
 
 
67
 
 
68
 
55
69
/* Note that it is sufficient to allocate the target string D as
56
70
   long as the source string S, i.e.: strlen(s)+1; */
57
71
static void
106
120
}
107
121
 
108
122
 
 
123
/* A write handler used by es_fopencookie to write assuan data
 
124
   lines.  */
 
125
static ssize_t
 
126
data_line_cookie_write (void *cookie, const void *buffer, size_t size)
 
127
{
 
128
  assuan_context_t ctx = cookie;
 
129
 
 
130
  if (assuan_send_data (ctx, buffer, size))
 
131
    {
 
132
      errno = EIO;
 
133
      return -1;
 
134
    }
 
135
 
 
136
  return size;
 
137
}
 
138
 
 
139
static int
 
140
data_line_cookie_close (void *cookie)
 
141
{
 
142
  assuan_context_t ctx = cookie;
 
143
 
 
144
  if (assuan_send_data (ctx, NULL, 0))
 
145
    {
 
146
      errno = EIO;
 
147
      return -1;
 
148
    }
 
149
 
 
150
  return 0;
 
151
}
 
152
 
 
153
 
109
154
static void 
110
155
close_message_fd (ctrl_t ctrl)
111
156
{
556
601
cmd_export (assuan_context_t ctx, char *line)
557
602
{
558
603
  ctrl_t ctrl = assuan_get_pointer (ctx);
559
 
  int fd = assuan_get_output_fd (ctx);
560
 
  FILE *out_fp;
561
604
  char *p;
562
605
  strlist_t list, sl;
563
606
  int use_data;
598
641
 
599
642
  if (use_data)
600
643
    {
601
 
      out_fp = assuan_get_data_fp (ctx);
602
 
      if (!out_fp)
 
644
      estream_t stream;
 
645
 
 
646
      stream = es_fopencookie (ctx, "w", data_line_cookie_functions);
 
647
      if (!stream)
603
648
        {
604
649
          free_strlist (list);
605
 
          return set_error (GPG_ERR_ASS_GENERAL, "no data stream");
 
650
          return set_error (GPG_ERR_ASS_GENERAL, 
 
651
                            "error setting up a data stream");
606
652
        }
607
 
      gpgsm_export (ctrl, list, out_fp);
 
653
      gpgsm_export (ctrl, list, NULL, stream);
 
654
      es_fclose (stream);
608
655
    }
609
656
  else
610
657
    {
 
658
      int fd = assuan_get_output_fd (ctx);
 
659
      FILE *out_fp;
 
660
 
611
661
      if (fd == -1)
612
662
        {
613
663
          free_strlist (list);
620
670
          return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
621
671
        }
622
672
      
623
 
      gpgsm_export (ctrl, list, out_fp);
 
673
      gpgsm_export (ctrl, list, out_fp, NULL);
624
674
      fclose (out_fp);
625
675
    }
626
676
 
706
756
do_listkeys (assuan_context_t ctx, char *line, int mode)
707
757
{
708
758
  ctrl_t ctrl = assuan_get_pointer (ctx);
709
 
  FILE *fp;
 
759
  estream_t fp;
710
760
  char *p;
711
761
  strlist_t list, sl;
712
762
  unsigned int listmode;
737
787
 
738
788
  if (ctrl->server_local->list_to_output)
739
789
    {
740
 
      if ( assuan_get_output_fd (ctx) == -1 )
 
790
      int outfd = assuan_get_output_fd (ctx);
 
791
 
 
792
      if ( outfd == -1 )
741
793
        return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
742
 
      fp = fdopen (assuan_get_output_fd (ctx), "w");
 
794
      fp = es_fdopen ( dup (outfd), "w");
743
795
      if (!fp)
744
 
        return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
 
796
        return set_error (GPG_ERR_ASS_GENERAL, "es_fdopen() failed");
745
797
    }
746
798
  else
747
799
    {
748
 
      fp = assuan_get_data_fp (ctx);
 
800
      fp = es_fopencookie (ctx, "w", data_line_cookie_functions);
749
801
      if (!fp)
750
 
        return set_error (GPG_ERR_ASS_GENERAL, "no data stream");
 
802
        return set_error (GPG_ERR_ASS_GENERAL, 
 
803
                          "error setting up a data stream");
751
804
    }
752
805
  
753
806
  ctrl->with_colons = 1;
758
811
    listmode |= (1<<7);
759
812
  err = gpgsm_list_keys (assuan_get_pointer (ctx), list, fp, listmode);
760
813
  free_strlist (list);
 
814
  es_fclose (fp);
761
815
  if (ctrl->server_local->list_to_output)
762
 
    {
763
 
      fclose (fp);
764
 
      assuan_close_output_fd (ctx);
765
 
    }
 
816
    assuan_close_output_fd (ctx);
766
817
  return err;
767
818
}
768
819