server-connection.c revision 98bdd7c244be24484c98f6927fc5108173bd9694
/* Copyright (c) 2010-2013 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "base64.h"
#include "ioloop.h"
#include "net.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
#include "strescape.h"
#include "iostream-ssl.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "settings-parser.h"
#include "doveadm-print.h"
#include "doveadm-util.h"
#include "doveadm-server.h"
#include "doveadm-settings.h"
#include "server-connection.h"
#include <sysexits.h>
#include <unistd.h>
enum server_reply_state {
};
struct server_connection {
struct doveadm_server *server;
struct doveadm_settings *set;
int fd;
struct ssl_iostream *ssl_iostream;
const char *delayed_cmd;
void *context;
enum server_reply_state state;
unsigned int handshaked:1;
unsigned int authenticated:1;
unsigned int streaming:1;
};
static void print_connection_released(void)
{
struct server_connection *const *conns;
unsigned int i, count;
for (i = 0; i < count; i++) {
continue;
server_connection_input, conns[i]);
if (printing_conn != NULL)
break;
}
}
static void
{
}
{
const char *text;
str_truncate(str, 0);
}
{
if (size > 0)
doveadm_print_stream("", 0);
} else {
const char *text;
str_truncate(str, 0);
}
}
static void
{
if (printing_conn == conn) {
/* continue printing */
} else if (printing_conn == NULL) {
} else {
/* someone else is printing. don't continue until it
goes away */
return;
}
/* last character is an escape */
size--;
}
if (data[i] == '\n') {
if (i != start) {
i_error("doveadm server sent broken print input");
return;
}
return;
}
if (data[i] == '\t') {
start = i + 1;
}
}
}
}
{
}
}
static int
{
i_error("doveadm_password not set, "
"can't authenticate to remote server");
return -1;
}
return 0;
}
{
const char *error;
}
}
{
const unsigned char *data;
const char *line;
int exit_code;
if (!conn->handshaked) {
}
return;
}
if (server_connection_authenticate(conn) < 0) {
return;
}
return;
} else {
i_error("doveadm server sent invalid handshake: %s",
line);
return;
}
}
/* disconnected */
return;
}
if (!conn->authenticated) {
return;
else {
return;
}
}
if (size == 0)
return;
case SERVER_REPLY_STATE_DONE:
i_error("doveadm server sent unexpected input");
return;
case SERVER_REPLY_STATE_PRINT:
break;
/* fall through */
case SERVER_REPLY_STATE_RET:
return;
if (line[0] == '+')
else if (line[0] == '-') {
line++;
/* old doveadm-server */
}
} else {
i_error("doveadm server sent broken input "
"(expected cmd reply): %s", line);
break;
}
/* we're finished, close the connection */
}
break;
}
}
{
const struct setting_parser_info *set_roots[] = {
};
struct master_service_settings_input input;
struct master_service_settings_output output;
const char *error;
unsigned int port;
void *set;
return -1;
}
return 0;
}
{
const char *host, *p;
if (p != NULL)
return -1;
if (doveadm_debug)
return 0;
}
{
struct ssl_iostream_settings ssl_set;
const char *error;
return 0;
return -1;
}
conn);
i_error("SSL handshake failed: %s",
return -1;
}
return 0;
}
struct server_connection **conn_r)
{
#define DOVEADM_SERVER_HANDSHAKE "VERSION\tdoveadm-server\t1\t0\n"
struct server_connection *conn;
if (server_connection_read_settings(conn) < 0 ||
server_connection_init_ssl(conn) < 0) {
return -1;
}
return 0;
}
{
struct server_connection *const *conns;
const char *error;
unsigned int i, count;
for (i = 0; i < count; i++) {
break;
}
}
}
error);
}
if (printing_conn == conn)
i_error("close(server) failed: %m");
}
}
struct doveadm_server *
{
}
{
if (conn->authenticated)
else
}
{
}
struct ssl_iostream **ssl_iostream_r)
{
}