auth-master.c revision 52d058e5234181fca90048d5904a151a1ccc8a6b
/* Copyright (c) 2005-2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "lib-signals.h"
#include "array.h"
#include "ioloop.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "auth-master.h"
#include <stdlib.h>
#include <unistd.h>
#define AUTH_PROTOCOL_MAJOR 1
#define AUTH_PROTOCOL_MINOR 0
#define AUTH_REQUEST_TIMEOUT_SECS 30
#define AUTH_MASTER_IDLE_SECS 60
#define MAX_INBUF_SIZE 8192
#define MAX_OUTBUF_SIZE 1024
struct auth_master_connection {
char *auth_socket_path;
int fd;
unsigned int request_counter;
const char *user;
struct auth_user_reply *user_reply;
int return_value;
unsigned int debug:1;
unsigned int sent_handshake:1;
unsigned int handshaked:1;
unsigned int aborted:1;
};
struct auth_master_connection *
{
struct auth_master_connection *conn;
return conn;
}
{
}
}
{
}
{
}
const char *const *args)
{
else {
}
}
}
{
i_error("userdb lookup(%s): "
"Auth protocol version mismatch "
return -1;
}
break;
}
}
return 0;
}
{
case 0:
return;
case -1:
/* disconnected */
i_error("userdb lookup(%s): Disconnected unexpectedly",
return;
case -2:
/* buffer full */
i_error("userdb lookup(%s): BUG: Received more than %d bytes",
return;
}
if (!conn->handshaked) {
if (auth_input_handshake(conn) < 0)
return;
}
return;
id = "";
else {
args++;
}
return;
}
conn->return_value = 0;
return;
}
i_error("userdb lookup(%s) failed: %s",
"Internal failure");
return;
}
}
i_error("userdb lookup(%s): %s is an auth client socket. "
"It should be a master socket.",
} else {
i_error("userdb lookup(%s): BUG: Unexpected input: %s",
}
}
{
/* max. 1 second wait here. */
break;
/* busy. wait for a while. */
}
if (fd == -1) {
i_error("userdb lookup: connect(%s) failed: %m",
return -1;
}
return 0;
}
{
if (!conn->handshaked)
else
}
{
}
{
}
struct ioloop *prev_ioloop)
{
}
static bool is_valid_string(const char *str)
{
const char *p;
/* make sure we're not sending any characters that have a special
meaning. */
for (p = str; *p != '\0'; p++) {
if (*p == '\t' || *p == '\n' || *p == '\r')
return FALSE;
}
return TRUE;
}
{
struct ioloop *prev_ioloop;
const char *str;
/* non-allowed characters, the user can't exist */
return 0;
}
if (auth_master_connect(conn) < 0)
return -1;
}
if (++conn->request_counter == 0) {
/* avoid zero */
conn->request_counter++;
}
if (!conn->sent_handshake) {
}
i_error("write(auth socket) failed: %m");
} else {
}
}
return conn->return_value;
}