1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* soup-queue.c: Asyncronous Callback-based HTTP Request Queue.
*
* Authors:
* Alex Graveley (alex@ximian.com)
*
* Copyright (C) 2001-2002, Ximian, Inc.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include "soup-ssl.h"
#include "soup-nss.h"
#include "soup-misc.h"
#ifdef HAVE_NSS
GIOChannel *
soup_ssl_get_iochannel (GIOChannel *sock, SoupSSLType type)
{
g_return_val_if_fail (sock != NULL, NULL);
return soup_nss_get_iochannel (sock, type);
}
#else /* HAVE_NSS */
static gboolean
soup_ssl_hup_waitpid (GIOChannel *source, GIOCondition condition, gpointer ppid)
{
waitpid (GPOINTER_TO_INT (ppid), NULL, 0);
return FALSE;
}
GIOChannel *
soup_ssl_get_iochannel (GIOChannel *sock, SoupSSLType type)
{
GIOChannel *new_chan;
int sock_fd;
int pid;
int pair[2], flags;
const char *cert_file, *key_file;
g_return_val_if_fail (sock != NULL, NULL);
g_io_channel_ref (sock);
if (!(sock_fd = g_io_channel_unix_get_fd (sock))) goto ERROR_ARGS;
flags = fcntl(sock_fd, F_GETFD, 0);
fcntl (sock_fd, F_SETFD, flags & ~FD_CLOEXEC);
if (socketpair (PF_UNIX, SOCK_STREAM, 0, pair) != 0) goto ERROR_ARGS;
fflush (stdin);
fflush (stdout);
pid = fork ();
switch (pid) {
case -1:
goto ERROR;
case 0:
close (pair [1]);
dup2 (pair [0], STDIN_FILENO);
dup2 (pair [0], STDOUT_FILENO);
close (pair [0]);
putenv (g_strdup_printf ("SOCKFD=%d", sock_fd));
if (type == SOUP_SSL_TYPE_SERVER)
putenv ("IS_SERVER=1");
if (soup_get_ssl_ca_file ()) {
putenv (g_strdup_printf ("HTTPS_CA_FILE=%s",
soup_get_ssl_ca_file ()));
}
if (soup_get_ssl_ca_dir ()) {
putenv (g_strdup_printf ("HTTPS_CA_DIR=%s",
soup_get_ssl_ca_dir ()));
}
soup_get_ssl_cert_files (&cert_file, &key_file);
if (cert_file) {
putenv (g_strdup_printf ("HTTPS_CERT_FILE=%s",
cert_file));
}
if (key_file) {
putenv (g_strdup_printf ("HTTPS_KEY_FILE=%s",
key_file));
}
execl (LIBEXECDIR G_DIR_SEPARATOR_S SSL_PROXY_NAME,
LIBEXECDIR G_DIR_SEPARATOR_S SSL_PROXY_NAME,
NULL);
execlp (SSL_PROXY_NAME, SSL_PROXY_NAME, NULL);
g_error ("Error executing SSL Proxy\n");
}
close (pair [0]);
flags = fcntl(pair [1], F_GETFL, 0);
fcntl (pair [1], F_SETFL, flags | O_NONBLOCK);
new_chan = g_io_channel_unix_new (pair [1]);
g_io_add_watch (new_chan, G_IO_HUP | G_IO_ERR | G_IO_NVAL,
soup_ssl_hup_waitpid, GINT_TO_POINTER (pid));
return new_chan;
ERROR:
close (pair [0]);
close (pair [1]);
ERROR_ARGS:
g_io_channel_unref (sock);
return NULL;
}
#endif /* HAVE_NSS */
|