login-proxy.c revision e59faf65ce864fe95dc00f5d52b8323cdbd0608a
/* Copyright (c) 2004-2010 Dovecot authors, see the included COPYING file */
#include "login-common.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "llist.h"
#include "str-sanitize.h"
#include "time-util.h"
#include "master-service.h"
#include "client-common.h"
#include "ssl-proxy.h"
#include "login-proxy-state.h"
#include "login-proxy.h"
#define MAX_PROXY_INPUT_SIZE 4096
#define OUTBUF_THRESHOLD 1024
#define LOGIN_PROXY_DIE_IDLE_SECS 2
struct login_proxy {
struct istream *server_input;
struct ssl_proxy *ssl_server_proxy;
struct login_proxy_record *state_rec;
unsigned int port;
void *context;
unsigned int destroying:1;
unsigned int disconnecting:1;
};
static struct login_proxy_state *proxy_state;
{
unsigned char buf[OUTBUF_THRESHOLD];
/* client's output buffer is already quite full.
don't send more until we're below threshold. */
return;
}
}
{
unsigned char buf[OUTBUF_THRESHOLD];
/* proxy's output buffer is already quite full.
don't send more until we're below threshold. */
return;
}
}
{
return 1;
}
/* there's again space in proxy's output buffer, so we can
read more from client. */
}
return 1;
}
{
return 1;
}
/* there's again space in client's output buffer, so we can
read more from proxy. */
}
return 1;
}
{
}
{
FALSE);
}
{
/* there was a successful connection done since we started
connecting. perhaps this is just a temporary one-off
failure. */
} else {
}
}
{
int err;
if (err != 0) {
i_error("proxy: connect(%s, %u) failed: %s",
return;
}
if (login_proxy_starttls(proxy) < 0) {
return;
}
} else {
}
}
{
}
struct login_proxy *
{
struct login_proxy *proxy;
struct login_proxy_record *rec;
int fd;
return NULL;
}
i_error("proxy(%s): %s is not a valid IP",
return NULL;
}
rec->num_waiting_connections != 0) {
/* the server is down. fail immediately */
return NULL;
}
if (fd < 0) {
i_error("proxy(%s): connect(%s, %u) failed: %m",
return NULL;
}
if (set->connect_timeout_msecs != 0) {
}
return proxy;
}
{
const char *ipstr;
if (proxy->destroying)
return;
/* detached proxy */
i_info("proxy(%s): disconnecting %s",
} else {
}
}
{
return FALSE;
return FALSE;
return FALSE;
}
{
}
{
return proxy->server_output;
}
{
}
{
}
{
}
{
const unsigned char *data;
/* send all pending client input to proxy and get rid of the stream */
if (size != 0)
/* from now on, just do dummy proxying */
}
static int login_proxy_ssl_handshaked(void *context)
{
return 0;
"proxy: SSL certificate not received from %s:%u",
} else {
"proxy: Received invalid SSL certificate from %s:%u",
}
return -1;
}
{
int fd;
if (fd < 0) {
"proxy: SSL handshake failed to %s:%u",
return -1;
}
return 0;
}
{
}
void login_proxy_kill_idle(void)
{
unsigned int stop_msecs;
else {
}
}
}
void login_proxy_init(void)
{
}
void login_proxy_deinit(void)
{
struct login_proxy *proxy;
while (login_proxies != NULL) {
}
}