script-login.c revision 3c296d819c54e21ce05c3d2eeeedc79be42ac593
/* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "env-util.h"
#include "execv-const.h"
#include "fdpass.h"
#include "restrict-access.h"
#include "str.h"
#include "strescape.h"
#include "settings-parser.h"
#include "mail-storage-service.h"
#include "master-interface.h"
#include "master-service.h"
#include "master-service-settings.h"
#include <stdlib.h>
#include <unistd.h>
#define SCRIPT_LOGIN_PROTOCOL_VERSION_MAJOR 1
#define SCRIPT_LOGIN_READ_TIMEOUT_SECS 10
#define ENV_USERDB_KEYS "USERDB_KEYS"
#define SCRIPT_COMM_FD 3
static const char **exec_args;
static bool drop_to_userdb_privileges = FALSE;
{
enum mail_storage_service_flags flags =
struct mail_storage_service_ctx *service_ctx;
struct mail_storage_service_input input;
struct mail_storage_service_user *user;
char buf[1024];
unsigned int i, socket_count;
int fd = -1;
while (ret > 0) {
break;
}
}
else
version_line = NULL;
if (version_line == NULL ||
i_fatal("Client not compatible with this binary "
"(connecting to wrong socket?)");
}
}
if (ret <= 0) {
if (ret < 0)
i_fatal("read() failed: %m");
else
i_fatal("read() failed: disconnected");
}
if (fd == -1)
i_fatal("client fd not received");
alarm(0);
/* put everything to environment */
env_clean();
i_fatal("Missing input fields");
i = 0;
for (; args[i] != '\0'; i++) {
}
}
if (drop_to_userdb_privileges) {
/* we can't exec anything in a chroot */
env_remove("RESTRICT_CHROOT");
}
i_fatal("dup2() failed: %m");
i_fatal("dup2() failed: %m");
i_fatal("close() failed: %m");
i_fatal("dup2() failed: %m");
i_fatal("close() failed: %m");
}
/* close all listener sockets */
for (i = 0; i < socket_count; i++) {
if (close(MASTER_LISTEN_FD_FIRST + i) < 0)
i_error("close(listener) failed: %m");
}
if (close(MASTER_STATUS_FD) < 0)
i_error("close(status) failed: %m");
}
static void script_execute_finish(void)
{
i_fatal("USER environment missing");
}
}
/* finish by sending the fd to the mail process */
/* success */
} else {
if (ret < 0)
i_error("fd_send() failed: %m");
else
i_error("fd_send() sent partial output");
/* exit with 0 even though we failed. non-0 exit just makes
master log an unnecessary error. */
}
}
{
enum master_service_flags flags = 0;
int i, c;
while ((c = master_getopt(master_service)) > 0) {
switch (c) {
case 'd':
break;
default:
return FATAL_DEFAULT;
}
}
if (!drop_to_userdb_privileges &&
(flags & MASTER_SERVICE_FLAG_STANDALONE) == 0) {
/* drop to privileges defined by service settings */
}
if ((flags & MASTER_SERVICE_FLAG_STANDALONE) != 0) {
/* The last post-login script is calling us to finish login */
} else {
i_fatal("Missing script path");
for (i = 0; i < argc; i++)
if (exec_args[0][0] != '/') {
}
}
return 0;
}