ssl-params.c revision 46b823ac3bce2c0f9f0fc73911e48d3a77b04fbe
/* Copyright (c) 2009-2015 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "buffer.h"
#include "file-lock.h"
#include "read-full.h"
#include "write-full.h"
#include "master-interface.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "iostream-ssl.h"
#include "ssl-params-settings.h"
#include "ssl-params.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef HAVE_SYS_TIME_H
#endif
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
#define SSL_PARAMS_PRIORITY 15
struct ssl_params {
char *path;
struct ssl_params_settings set;
};
static void
unsigned int ssl_dh_parameters_length ATTR_UNUSED)
{
#ifdef HAVE_SETPRIORITY
#endif
if (fd == -1)
/* If multiple dovecot instances are running, only one of them needs
to regenerate this file. */
if (ret < 0)
if (ret == 0) {
/* someone else is writing this */
i_fatal("Timeout while waiting for %s generation to complete",
path);
}
/* make sure the .tmp file is still the one we created */
}
/* nope. so someone else just generated the file. */
i_close_fd(&fd);
return;
}
/* check that the parameters file is still the same */
i_close_fd(&fd);
return;
}
/* ok, we really want to generate it. */
i_info("Generating SSL parameters");
&error) < 0) {
i_fatal("ssl_iostream_generate_params(%u) failed: %s",
}
i_info("SSL parameters regeneration completed");
}
static void ssl_params_close_listeners(void)
{
unsigned int i;
/* we have forked, but the fds are still shared. we can't go
io_remove()ing the fds from ioloop, because with many ioloops
(e.g. epoll) the fds get removed from the main process's ioloop
as well. so we'll just do the closing here manually. */
for (i = 0; i < master_service_get_socket_count(master_service); i++) {
int fd = MASTER_LISTEN_FD_FIRST + i;
}
}
{
switch (fork()) {
case -1:
i_fatal("fork() failed: %m");
case 0:
/* child - close listener fds so a long-running ssl-params
doesn't cause Dovecot restart to fail */
exit(0);
default:
/* parent */
break;
}
}
static bool
{
/* <bitsize><length><data>... */
if (bitsize == 0) {
if (found)
return TRUE;
i_warning("Regenerating %s for ssl_dh_parameters_length=%u",
return FALSE;
}
break;
break;
}
return FALSE;
}
{
unsigned char *buffer;
if (fd == -1) {
return -1;
}
i_close_fd(&fd);
return -1;
}
i_close_fd(&fd);
return -1;
}
if (ret < 0)
else if (ret == 0) {
ret = -1;
ret = -1;
} else {
}
return ret;
}
struct ssl_params *
const struct ssl_params_settings *set)
{
struct ssl_params *param;
return param;
}
{
if (ssl_params_read(param) < 0)
}
{
}