#include "var-expand.h"
#include "auth-request.h"
#include "auth-cache.h"
+#include "auth-common.h"
#include <time.h>
struct auth_cache {
HASH_TABLE(char *, struct auth_cache_node *) hash;
struct auth_cache_node *head, *tail;
+ struct event *event;
size_t max_size, size_left;
unsigned int ttl_secs, neg_ttl_secs;
{
struct auth_cache *cache = context;
- i_info("SIGHUP received, %u cache entries flushed",
+ e_info(cache->event, "SIGHUP received, %u cache entries flushed",
auth_cache_clear(cache));
}
size_t cache_used;
total_count = cache->hit_count + cache->miss_count;
- i_info("Authentication cache hits %u/%u (%u%%)",
+ e_info(cache->event, "Authentication cache hits %u/%u (%u%%)",
cache->hit_count, total_count,
total_count == 0 ? 100 : (cache->hit_count * 100 / total_count));
- i_info("Authentication cache inserts: "
+ e_info(cache->event, "Authentication cache inserts: "
"positive: %u entries %llu bytes, "
"negative: %u entries %llu bytes",
cache->pos_entries, cache->pos_size,
cache->neg_entries, cache->neg_size);
cache_used = cache->max_size - cache->size_left;
- i_info("Authentication cache current size: "
+ e_info(cache->event, "Authentication cache current size: "
"%zu bytes used of %zu bytes (%u%%)",
cache_used, cache->max_size,
(unsigned int)(cache_used * 100ULL / cache->max_size));
cache->size_left = max_size;
cache->ttl_secs = ttl_secs;
cache->neg_ttl_secs = neg_ttl_secs;
+ cache->event = event_create(auth_event);
lib_signals_set_handler(SIGHUP, LIBSIG_FLAGS_SAFE,
sig_auth_cache_clear, cache);
auth_cache_clear(cache);
hash_table_destroy(&cache->hash);
+ event_unref(&cache->event);
i_free(cache);
}
auth_policy_json_template = i_strdup(str_c(template));
if (global_auth_settings->policy_log_only)
- i_warning("auth-policy: Currently in log-only mode. Ignoring "
+ e_warning(auth_event,
+ "auth-policy: Currently in log-only mode. Ignoring "
"tarpit and disconnect instructions from policy server");
}
fd = open(path, O_RDONLY);
if (fd == -1) {
if (errno != ENOENT)
- i_error("open(%s) failed: %m", path);
+ e_error(auth_event, "open(%s) failed: %m", path);
return -1;
}
if (fstat(fd, &st) < 0) {
- i_error("fstat(%s) failed: %m", path);
+ e_error(auth_event, "fstat(%s) failed: %m", path);
i_close_fd(&fd);
return -1;
}
/* check secret len and file type */
if (st.st_size != AUTH_TOKEN_SECRET_LEN || !S_ISREG(st.st_mode)) {
- i_error("Corrupted token secret file: %s", path);
+ e_error(auth_event, "Corrupted token secret file: %s", path);
i_close_fd(&fd);
i_unlink(path);
return -1;
/* verify that we're not dealing with a symbolic link */
if (lstat(path, &lst) < 0) {
- i_error("lstat(%s) failed: %m", path);
+ e_error(auth_event, "lstat(%s) failed: %m", path);
i_close_fd(&fd);
return -1;
}
st.st_uid != geteuid() || st.st_nlink > 1 ||
!S_ISREG(lst.st_mode) || st.st_ino != lst.st_ino ||
!CMP_DEV_T(st.st_dev, lst.st_dev)) {
- i_error("Compromised token secret file: %s", path);
+ e_error(auth_event, "Compromised token secret file: %s", path);
i_close_fd(&fd);
i_unlink(path);
return -1;
ret = read_full(fd, secret_r, AUTH_TOKEN_SECRET_LEN);
if (ret < 0)
- i_error("read(%s) failed: %m", path);
+ e_error(auth_event, "read(%s) failed: %m", path);
else if (ret == 0) {
- i_error("Token secret file unexpectedly shrank: %s", path);
+ e_error(auth_event, "Token secret file unexpectedly shrank: %s", path);
ret = -1;
}
if (close(fd) < 0)
- i_error("close(%s) failed: %m", path);
+ e_error(auth_event, "close(%s) failed: %m", path);
e_debug(auth_event, "Read auth token secret from %s", path);
return ret;
umask(old_mask);
if (fd == -1) {
- i_error("open(%s) failed: %m", temp_path);
+ e_error(auth_event, "open(%s) failed: %m", temp_path);
return -1;
}
ret = write_full(fd, secret, AUTH_TOKEN_SECRET_LEN);
if (ret < 0)
- i_error("write(%s) failed: %m", temp_path);
+ e_error(auth_event, "write(%s) failed: %m", temp_path);
if (close(fd) < 0) {
- i_error("close(%s) failed: %m", temp_path);
+ e_error(auth_event, "close(%s) failed: %m", temp_path);
ret = -1;
}
}
if (rename(temp_path, path) < 0) {
- i_error("rename(%s, %s) failed: %m", temp_path, path);
+ e_error(auth_event, "rename(%s, %s) failed: %m", temp_path, path);
i_unlink(temp_path);
return -1;
}
random_fill(auth_token_secret, sizeof(auth_token_secret));
if (auth_token_write_secret(secret_path, auth_token_secret) < 0) {
- i_error("Failed to write auth token secret file; "
+ e_error(auth_event,
+ "Failed to write auth token secret file; "
"returned tokens will be invalid once auth restarts");
}
}
#include "settings.h"
#include "auth-request.h"
#include "auth-worker-server.h"
+#include "auth-common.h"
#include "db-sql.h"
#include <stddef.h>
if (strcmp(conn->set.user_query,
default_db_sql_settings.user_query) != 0) {
- i_warning("sql: Ignoring changed user_query in %s, "
+ e_warning(auth_event,
+ "sql: Ignoring changed user_query in %s, "
"because userdb sql not used. "
"(If this is intentional, set userdb_warning_disable=yes)",
conn->config_path);
} else if (strcmp(conn->set.iterate_query,
default_db_sql_settings.iterate_query) != 0) {
- i_warning("sql: Ignoring changed iterate_query in %s, "
+ e_warning(auth_event,
+ "sql: Ignoring changed iterate_query in %s, "
"because userdb sql not used. "
"(If this is intentional, set userdb_warning_disable=yes)",
conn->config_path);
static void worker_connected(struct master_service_connection *conn)
{
if (auth_worker_has_connections()) {
- i_error("Auth workers can handle only a single client");
+ e_error(auth_event,
+ "Auth workers can handle only a single client");
return;
}
{ '\0', NULL, NULL }
};
+struct event *auth_event;
+
struct var_expand_table *
auth_request_get_var_expand_table_full(const struct auth_request *auth_request ATTR_UNUSED,
const char *username ATTR_UNUSED,
int main(void)
{
+ lib_init();
+ auth_event = event_create(NULL);
static void (*const test_functions[])(void) = {
test_auth_cache_parse_key,
NULL
};
- return test_run(test_functions);
+ int ret = test_run(test_functions);
+ event_unref(&auth_event);
+ return ret;
}