~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to assuan/assuan-listen.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2006-01-24 04:31:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060124043142-pbg192or6qxv3yk2
Tags: 1.9.20-1
* New Upstream version. Closes:#306890,#344530
  * Closes:#320490: gpg-protect-tool fails to decrypt PKCS-12 files 
* Depend on libopensc2-dev, not -1-. Closes:#348106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* assuan-listen.c - Wait for a connection (server) 
 
2
 *      Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of Assuan.
 
5
 *
 
6
 * Assuan is free software; you can redistribute it and/or modify it
 
7
 * under the terms of the GNU Lesser General Public License as
 
8
 * published by the Free Software Foundation; either version 2.1 of
 
9
 * the License, or (at your option) any later version.
 
10
 *
 
11
 * Assuan is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
#include <stdlib.h>
 
23
#include <stdio.h>
 
24
#include <string.h>
 
25
#include <unistd.h>
 
26
 
 
27
#include "assuan-defs.h"
 
28
 
 
29
AssuanError
 
30
assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line)
 
31
{
 
32
  if (!ctx)
 
33
    return ASSUAN_Invalid_Value;
 
34
  if (!line)
 
35
    {
 
36
      xfree (ctx->hello_line);
 
37
      ctx->hello_line = NULL;
 
38
    }
 
39
  else
 
40
    {
 
41
      char *buf = xtrymalloc (3+strlen(line)+1);
 
42
      if (!buf)
 
43
        return ASSUAN_Out_Of_Core;
 
44
      strcpy (buf, "OK ");
 
45
      strcpy (buf+3, line);
 
46
      xfree (ctx->hello_line);
 
47
      ctx->hello_line = buf;
 
48
    }
 
49
  return 0;
 
50
}
 
51
 
 
52
 
 
53
/**
 
54
 * assuan_accept:
 
55
 * @ctx: context
 
56
 * 
 
57
 * Cancel any existing connectiion and wait for a connection from a
 
58
 * client.  The initial handshake is performed which may include an
 
59
 * initial authentication or encryption negotiation.
 
60
 * 
 
61
 * Return value: 0 on success or an error if the connection could for
 
62
 * some reason not be established.
 
63
 **/
 
64
AssuanError
 
65
assuan_accept (ASSUAN_CONTEXT ctx)
 
66
{
 
67
  int rc;
 
68
 
 
69
  if (!ctx)
 
70
    return ASSUAN_Invalid_Value;
 
71
 
 
72
  if (ctx->pipe_mode > 1)
 
73
    return -1; /* second invocation for pipemode -> terminate */
 
74
  ctx->finish_handler (ctx);
 
75
 
 
76
  rc = ctx->accept_handler (ctx);
 
77
  if (rc)
 
78
    return rc;
 
79
 
 
80
  /* send the hello */
 
81
  rc = assuan_write_line (ctx, ctx->hello_line? ctx->hello_line
 
82
                                              : "OK Your orders please");
 
83
  if (rc)
 
84
    return rc;
 
85
  
 
86
  if (ctx->pipe_mode)
 
87
    ctx->pipe_mode = 2;
 
88
  
 
89
  return 0;
 
90
}
 
91
 
 
92
 
 
93
 
 
94
int
 
95
assuan_get_input_fd (ASSUAN_CONTEXT ctx)
 
96
{
 
97
  return ctx? ctx->input_fd : -1;
 
98
}
 
99
 
 
100
 
 
101
int
 
102
assuan_get_output_fd (ASSUAN_CONTEXT ctx)
 
103
{
 
104
  return ctx? ctx->output_fd : -1;
 
105
}
 
106
 
 
107
 
 
108
/* Close the fd descriptor set by the command INPUT FD=n.  We handle
 
109
   this fd inside assuan so that we can do some initial checks */
 
110
AssuanError
 
111
assuan_close_input_fd (ASSUAN_CONTEXT ctx)
 
112
{
 
113
  if (!ctx || ctx->input_fd == -1)
 
114
    return ASSUAN_Invalid_Value;
 
115
  close (ctx->input_fd);
 
116
  ctx->input_fd = -1;
 
117
  return 0;
 
118
}
 
119
 
 
120
/* Close the fd descriptor set by the command OUTPUT FD=n.  We handle
 
121
   this fd inside assuan so that we can do some initial checks */
 
122
AssuanError
 
123
assuan_close_output_fd (ASSUAN_CONTEXT ctx)
 
124
{
 
125
  if (!ctx || ctx->output_fd == -1)
 
126
    return ASSUAN_Invalid_Value;
 
127
 
 
128
  close (ctx->output_fd);
 
129
  ctx->output_fd = -1;
 
130
  return 0;
 
131
}
 
132