Debian Codegraph @

src/assuan/assuan-pipe-server.c

raw symbols SCIP
1 /* assuan-pipe-server.c - Assuan server working over a pipe
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, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <config.h>cxx . . $ `<file>/config.h`/
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #ifdef HAVE_W32_SYSTEM
27 #include <windows.h>
28 #include <fcntl.h>
29 #endif
30
31 #include "assuan-defs.h"cxx . . $ `<file>/src/assuan/assuan-defs.h`/
32
33
34 static void
35 deinit_pipe_servercxx . . $ deinit_pipe_server(746ddb6f27ff0333). (assuan_context_tcxx . . $ assuan_context_t# ctx)
36 {
37 /* nothing to do for this simple server */
38 }
39
40 static int
41 accept_connectioncxx . . $ accept_connection(29493cd997091d1). (assuan_context_tcxx . . $ assuan_context_t# ctx)
42 {
43 /* This is a NOP for a pipe server */
44 return 0;
45 }
46
47 static int
48 finish_connectioncxx . . $ finish_connection(29493cd997091d1). (assuan_context_tcxx . . $ assuan_context_t# ctx)
49 {
50 /* This is a NOP for a pipe server */
51 return 0;
52 }
53
54 /* Create a new context. Note that the handlers are set up for a pipe
55 server/client - this way we don't need extra dummy functions */
56 int
57 _assuan_new_contextcxx . . $ `src/assuan/assuan.h:173:9`! (assuan_context_tcxx . . $ assuan_context_t# *r_ctx)
58 {
59 static struct assuan_iocxx . . $ assuan_io# io = { _assuan_simple_readcxx . . $ `src/assuan/assuan.h:168:9`!,
60 _assuan_simple_writecxx . . $ `src/assuan/assuan.h:169:9`!,
61 0, 0 };
62
63 assuan_context_tcxx . . $ assuan_context_t# ctx;
64 int rc;
65
66 *r_ctx = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
67 ctx = xtrycalloccxx . . $ `src/assuan/assuan-defs.h:262:9`! (1, sizeof *ctx);
68 if (!ctx)
69 return _assuan_errorcxx . . $ `src/assuan/assuan.h:189:9`! (ASSUAN_Out_Of_Corecxx . . $ `src/assuan/assuan.h:239:10`!);
70 ctx->input_fdcxx . . $ assuan_context_s#input_fd. = ASSUAN_INVALID_FDcxx . . $ `src/assuan/assuan.h:395:9`!;
71 ctx->output_fdcxx . . $ assuan_context_s#output_fd. = ASSUAN_INVALID_FDcxx . . $ `src/assuan/assuan.h:395:9`!;
72
73 ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_1#fd. = ASSUAN_INVALID_FDcxx . . $ `src/assuan/assuan.h:395:9`!;
74 ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_3#fd. = ASSUAN_INVALID_FDcxx . . $ `src/assuan/assuan.h:395:9`!;
75 ctx->iocxx . . $ assuan_context_s#io. = &io;
76
77 ctx->listen_fdcxx . . $ assuan_context_s#listen_fd. = ASSUAN_INVALID_FDcxx . . $ `src/assuan/assuan.h:395:9`!;
78 /* Use the pipe server handler as a default. */
79 ctx->deinit_handlercxx . . $ assuan_context_s#deinit_handler. = deinit_pipe_servercxx . . $ deinit_pipe_server(746ddb6f27ff0333).;
80 ctx->accept_handlercxx . . $ assuan_context_s#accept_handler. = accept_connectioncxx . . $ accept_connection(29493cd997091d1).;
81 ctx->finish_handlercxx . . $ assuan_context_s#finish_handler. = finish_connectioncxx . . $ finish_connection(29493cd997091d1).;
82
83 rc = _assuan_register_std_commandscxx . . $ `src/assuan/assuan.h:166:9`! (ctx);
84 if (rc)
85 xfreecxx . . $ `src/assuan/assuan-defs.h:264:9`! (ctx);
86 else
87 *r_ctx = ctx;
88 return rc;
89 }
90
91
92 /* Returns true if atoi(S) denotes a valid socket. */
93 #ifndef HAVE_W32_SYSTEM
94 static int
95 is_valid_socketcxx . . $ is_valid_socket(5c4306d8553b3696). (const char *s)
96 {
97 struct statcxx . . $ stat# buf;
98
99 if ( fstatcxx . . $ fstat(a43660ce2f600cb5). (atoicxx . . $ atoi(5c4306d8553b3696). (s), &buf ) )
100 return 0;
101 return S_ISSOCKcxx . . $ `<external>/531885356569766532/stat.h:142:10`! (buf.st_mode);
102 }
103 #endif /*!HAVE_W32_SYSTEM*/
104
105
106 int
107 assuan_init_pipe_servercxx . . $ `src/assuan/assuan.h:106:9`! (assuan_context_tcxx . . $ assuan_context_t# *r_ctx, int filedes[2])
108 {
109 int rc;
110
111 rc = _assuan_new_contextcxx . . $ `src/assuan/assuan.h:173:9`! (r_ctx);
112 if (!rc)
113 {
114 assuan_context_tcxx . . $ assuan_context_t# ctx = *r_ctx;
115 const char *s;
116 unsigned long ul;
117
118 ctx->is_servercxx . . $ assuan_context_s#is_server. = 1;
119 #ifdef HAVE_W32_SYSTEM
120 /* MS Windows has so many different types of handle that one
121 needs to tranlsate them at many place forth and back. Also
122 make sure that the file descriptors are in binary mode. */
123 setmode (filedes[0], O_BINARY);
124 setmode (filedes[1], O_BINARY);
125 ctx->inbound.fd = (void*)_get_osfhandle (filedes[0]);
126 ctx->outbound.fd = (void*)_get_osfhandle (filedes[1]);
127 #else
128 s = getenvcxx . . $ getenv(a8b8e32347182212). ("_assuan_connection_fd");
129 if (s && *s && is_valid_socketcxx . . $ is_valid_socket(5c4306d8553b3696). (s) )
130 {
131 /* Well, we are called with an bi-directional file
132 descriptor. Prepare for using sendmsg/recvmsg. In this
133 case we ignore the passed file descriptors. */
134 ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_1#fd. = ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_3#fd. = atoicxx . . $ atoi(5c4306d8553b3696). (s);
135 _assuan_init_uds_iocxx . . $ `src/assuan/assuan.h:191:9`! (ctx);
136 ctx->deinit_handlercxx . . $ assuan_context_s#deinit_handler. = _assuan_uds_deinitcxx . . $ `src/assuan/assuan.h:193:9`!;
137 }
138 else if (filedes && filedes[0] != ASSUAN_INVALID_FDcxx . . $ `src/assuan/assuan.h:395:9`!
139 && filedes[1] != ASSUAN_INVALID_FDcxx . . $ `src/assuan/assuan.h:395:9`! )
140 {
141 /* Standard pipe server. */
142 ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_1#fd. = filedes[0];
143 ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_3#fd. = filedes[1];
144 }
145 else
146 {
147 _assuan_release_contextcxx . . $ `src/assuan/assuan.h:174:9`! (*r_ctx);
148 *r_ctx = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
149 return ASSUAN_Problem_Starting_Servercxx . . $ `src/assuan/assuan.h:246:10`!;
150 }
151 #endif
152 ctx->pipe_modecxx . . $ assuan_context_s#pipe_mode. = 1;
153
154 s = getenvcxx . . $ getenv(a8b8e32347182212). ("_assuan_pipe_connect_pid");
155 if (s && (ul=strtoulcxx . . $ strtoul(31746e8d6ec49860). (s, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 10)) && ul)
156 ctx->pidcxx . . $ assuan_context_s#pid. = (pid_tcxx . . $ pid_t#)ul;
157 else
158 ctx->pidcxx . . $ assuan_context_s#pid. = (pid_tcxx . . $ pid_t#)-1;
159
160 }
161 return rc;
162 }
163
164
165 void
166 _assuan_release_contextcxx . . $ `src/assuan/assuan.h:174:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx)
167 {
168 if (ctx)
169 {
170 _assuan_inquire_releasecxx . . $ _assuan_inquire_release(746ddb6f27ff0333). (ctx);
171 xfreecxx . . $ `src/assuan/assuan-defs.h:264:9`! (ctx->hello_line);
172 xfreecxx . . $ `src/assuan/assuan-defs.h:264:9`! (ctx->okay_line);
173 xfreecxx . . $ `src/assuan/assuan-defs.h:264:9`! (ctx->cmdtbl);
174 xfreecxx . . $ `src/assuan/assuan-defs.h:264:9`! (ctx);
175 }
176 }
177
178 void
179 assuan_deinit_servercxx . . $ `src/assuan/assuan.h:107:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx)
180 {
181 if (ctx)
182 {
183 /* We use this function pointer to avoid linking other server
184 when not needed but still allow for a generic deinit function. */
185 ctx->deinit_handlercxx . . $ assuan_context_s#deinit_handler. (ctx);
186 ctx->deinit_handlercxx . . $ assuan_context_s#deinit_handler. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
187 _assuan_release_contextcxx . . $ `src/assuan/assuan.h:174:9`! (ctx);
188 }
189 }