master-login.c revision f096367f0f7b0e481f8abe0969afdf2d8250057e
/* Copyright (c) 2009-2010 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "ostream.h"
#include "fdpass.h"
#include "fd-close-on-exec.h"
#include "llist.h"
#include "str.h"
#include "strescape.h"
#include "master-service-private.h"
#include "master-login.h"
#include "master-login-auth.h"
#include <unistd.h>
struct master_login_connection {
struct master_login *login;
int refcount;
int fd;
};
struct master_login_postlogin {
struct master_login_client *client;
int fd;
};
struct master_login {
struct master_service *service;
struct master_login_connection *conns;
struct master_login_auth *auth;
char *postlogin_socket_path;
unsigned int stopping:1;
};
struct master_login *
const char *postlogin_socket_path,
{
struct master_login *login;
return login;
}
{
}
}
static int
struct master_auth_request *req_r,
unsigned char data[MASTER_AUTH_MAX_DATA_SIZE],
int *client_fd_r)
{
*client_fd_r = -1;
if (ret == 0) {
/* disconnected */
} else if (ret > 0) {
/* request wasn't fully read */
i_error("fd_read() partial input (%d/%d)",
} else {
return 0;
i_error("fd_read() failed: %m");
}
return -1;
}
i_error("Too large auth data_size sent");
return -1;
}
/* @UNSAFE */
if (ret == 0) {
/* disconnected */
} else if (ret > 0) {
/* request wasn't fully read */
i_error("Data read partially %d/%u",
} else {
i_error("read(data) failed: %m");
}
return -1;
}
}
if (*client_fd_r == -1) {
i_error("Auth request missing a file descriptor");
return -1;
}
i_error("fstat(fd_read client) failed: %m");
return -1;
}
i_error("Auth request inode mismatch: %s != %s",
return -1;
}
return 1;
}
{
i_error("close(fd_read client) failed: %m");
}
}
const char *const *auth_args)
{
bool close_sockets;
if (close_sockets) {
/* we're dying as soon as this connection closes. */
/* try stopping again */
}
}
{
i_error("close(postlogin) failed: %m");
}
{
char buf[1024];
const char **auth_args, **p;
unsigned int len;
int fd = -1;
if (fd != -1) {
/* post-login script replaced fd */
i_error("close(client) failed: %m");
}
}
/* finished reading the input */
} else {
if (ret < 0) {
return;
i_error("fd_read(%s) failed: %m",
} else {
i_error("fd_read(%s) failed: disconnected",
}
return;
}
*p = str_tabunescape(t_strdup_noconst(*p));
}
{
i_error("%s: Timeout waiting for post-login script to finish, aborting",
}
const char *const *auth_args)
{
struct master_login_postlogin *pl;
unsigned int i;
int fd;
if (fd == -1) {
i_error("net_connect_unix(%s) failed: %m",
return -1;
}
}
if (ret < 0) {
i_error("write(%s) failed: %m",
} else {
i_error("write(%s) failed: partial write",
}
return -1;
}
return 0;
}
static void
{
struct master_auth_reply reply;
i_error("login client: Username missing from auth reply");
return;
}
else {
/* execute post-login scripts before finishing auth */
}
}
}
{
struct master_auth_request req;
struct master_login_client *client;
unsigned char data[MASTER_AUTH_MAX_DATA_SIZE];
if (ret <= 0) {
if (ret < 0)
if (client_fd != -1) {
i_error("close(fd_read client) failed: %m");
}
return;
}
/* @UNSAFE: we have a request. do userdb lookup for it. */
}
{
struct master_login_connection *conn;
/* FIXME: currently there's a separate connection for each request.
and currently we don't try to accept more connections until this
request's authentication is finished, because updating
available_count gets tricky. */
}
{
/* already deinitialized */
return;
}
i_error("close(master login) failed: %m");
}
{
}
}
{
}
}