# automatically created and destroyed as needed.
#auth_worker_max_count = 30
-# Number of auth requests to handle before destroying the process. This may
-# be useful if PAM plugins leak memory.
-#auth_worker_max_request_count = 0
-
# Host name to use in GSSAPI principal names. The default is to use the
# name returned by gethostname(). Use "$ALL" to allow all keytab entries.
#auth_gssapi_hostname =
# REMEMBER: You'll need /etc/pam.d/dovecot file created for PAM
# authentication to actually work. <doc/wiki/PasswordDatabase.PAM.txt>
passdb pam {
- # [session=yes] [setcred=yes] [failure_show_msg=yes]
+ # [session=yes] [setcred=yes] [failure_show_msg=yes] [max_requests=<n>]
# [cache_key=<key>] [<service name>]
#
# session=yes makes Dovecot open and immediately close PAM session. Some
# need that. They aren't ever deleted though, so this isn't enabled by
# default.
#
+ # max_requests specifies how many PAM lookups to do in one process before
+ # recreating the process. The default is 100, because many PAM plugins
+ # leak memory.
+ #
# cache_key can be used to enable authentication caching for PAM
# (auth_cache_size also needs to be set). It isn't enabled by default
# because PAM modules can do all kinds of checks besides checking password,
}
}
+static void auth_worker_send_reply(struct auth_worker_client *client,
+ string_t *str)
+{
+ if (shutdown_request)
+ o_stream_send_str(client->output, "SHUTDOWN\n");
+ o_stream_send(client->output, str_data(str), str_len(str));
+}
+
static void verify_plain_callback(enum passdb_result result,
struct auth_request *request)
{
}
str = auth_stream_reply_get_str(reply);
str_append_c(str, '\n');
- o_stream_send(client->output, str_data(str), str_len(str));
+ auth_worker_send_reply(client, str);
auth_request_unref(&request);
auth_worker_client_check_throttle(client);
}
str = auth_stream_reply_get_str(reply);
str_append_c(str, '\n');
- o_stream_send(client->output, str_data(str), str_len(str));
+ auth_worker_send_reply(client, str);
auth_request_unref(&request);
auth_worker_client_check_throttle(client);
str = t_str_new(64);
str_printfa(str, "%u\t%s\n", request->id, success ? "OK" : "FAIL");
- o_stream_send(client->output, str_data(str), str_len(str));
+ auth_worker_send_reply(client, str);
auth_request_unref(&request);
auth_worker_client_check_throttle(client);
}
str_append_c(str, '\n');
- o_stream_send(client->output, str_data(str), str_len(str));
+ auth_worker_send_reply(client, str);
auth_request_unref(&auth_request);
auth_worker_client_check_throttle(client);
struct ostream *output;
struct timeout *to;
+ struct auth_worker_request *request;
unsigned int id_counter;
- struct auth_worker_request *request;
- unsigned int requests_left;
+ unsigned int shutdown:1;
};
static ARRAY_DEFINE(connections, struct auth_worker_connection *) = ARRAY_INIT;
static unsigned int idle_count;
static unsigned int auth_workers_max;
-static unsigned int auth_workers_max_request_count;
static ARRAY_DEFINE(worker_request_array, struct auth_worker_request *);
static struct aqueue *worker_request_queue;
{
struct const_iovec iov[3];
- i_assert(conn->requests_left > 0);
-
if (ioloop_time - request->created > AUTH_WORKER_DELAY_WARN_SECS &&
ioloop_time - auth_worker_last_warn >
AUTH_WORKER_DELAY_WARN_MIN_INTERVAL_SECS) {
o_stream_sendv(conn->output, iov, 3);
conn->request = request;
- conn->requests_left--;
timeout_remove(&conn->to);
conn->to = timeout_add(AUTH_WORKER_LOOKUP_TIMEOUT_SECS * 1000,
FALSE);
conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
conn->io = io_add(fd, IO_READ, worker_input, conn);
- conn->requests_left = auth_workers_max_request_count;
conn->to = timeout_add(AUTH_WORKER_MAX_IDLE_SECS * 1000,
auth_worker_idle_timeout, conn);
}
while ((line = i_stream_next_line(conn->input)) != NULL) {
+ if (strcmp(line, "SHUTDOWN") == 0) {
+ conn->shutdown = TRUE;
+ continue;
+ }
id_str = line;
line = strchr(line, '\t');
if (line == NULL)
}
}
- if (conn->requests_left == 0)
+ if (conn->shutdown && conn->request == NULL)
auth_worker_destroy(&conn, "Max requests limit", TRUE);
else
auth_worker_request_send_next(conn);
i_fatal("AUTH_WORKER_MAX_COUNT environment not set");
auth_workers_max = atoi(env);
- env = getenv("AUTH_WORKER_MAX_REQUEST_COUNT");
- if (env == NULL)
- i_fatal("AUTH_WORKER_MAX_REQUEST_COUNT environment not set");
- auth_workers_max_request_count = atoi(env);
- if (auth_workers_max_request_count == 0)
- auth_workers_max_request_count = (unsigned int)-1;
-
i_array_init(&worker_request_array, 128);
worker_request_queue = aqueue_init(&worker_request_array.arr);
#define WORKER_SERVER_FD 4
extern struct ioloop *ioloop;
-extern bool standalone, worker;
+extern bool standalone, worker, shutdown_request;
extern time_t process_start_time;
#endif
#include <sys/stat.h>
struct ioloop *ioloop;
-bool standalone = FALSE, worker = FALSE;
+bool standalone = FALSE, worker = FALSE, shutdown_request = FALSE;
time_t process_start_time;
static struct module *modules = NULL;
#endif
typedef linux_const void *pam_item_t;
+#define PASSDB_PAM_DEFAULT_MAX_REQUESTS 100
+
struct pam_passdb_module {
struct passdb_module module;
const char *service_name, *pam_cache_key;
+ unsigned int requests_left;
unsigned int pam_setcred:1;
unsigned int pam_session:1;
string_t *expanded_service;
const char *service;
+ if (module->requests_left > 0) {
+ if (--module->requests_left == 0)
+ shutdown_request = TRUE;
+ }
+
expanded_service = t_str_new(64);
var_expand(expanded_service, module->service_name,
auth_request_get_var_expand_table(request, NULL));
given by the auth mechanism */
module->module.default_pass_scheme = "PLAIN";
module->module.blocking = TRUE;
+ module->requests_left = PASSDB_PAM_DEFAULT_MAX_REQUESTS;
t_args = t_strsplit_spaces(args, " ");
for(i = 0; t_args[i] != NULL; i++) {
} else if (strcmp(t_args[i], "*") == 0) {
/* for backwards compatibility */
module->service_name = "%Ls";
+ } else if (strncmp(t_args[i], "max_requests=", 13) == 0) {
+ module->requests_left = atoi(t_args[i] + 13);
} else if (t_args[i+1] == NULL) {
module->service_name =
p_strdup(auth_passdb->auth->pool, t_args[i]);
dec2str(getpid())));
env_put(t_strdup_printf("AUTH_WORKER_MAX_COUNT=%u",
group->set->worker_max_count));
- env_put(t_strdup_printf("AUTH_WORKER_MAX_REQUEST_COUNT=%u",
- group->set->worker_max_request_count));
/* make sure we don't leak syslog fd, but do it last so that
any errors above will be logged */
DEF_INT(count),
DEF_INT(worker_max_count),
- DEF_INT(worker_max_request_count),
DEF_INT(process_size),
{ 0, NULL, 0 }
MEMBER(count) 1,
MEMBER(worker_max_count) 30,
- MEMBER(worker_max_request_count) 0,
MEMBER(process_size) 256,
/* .. */
unsigned int count;
unsigned int worker_max_count;
- unsigned int worker_max_request_count;
unsigned int process_size;
/* .. */