/* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "str.h"
#include "strescape.h"
#include "home-expand.h"
#include "mkdir-parents.h"
#include "eacces-error.h"
#include "file-lock.h"
#include "file-dotlock.h"
#include "nfs-workarounds.h"
#include "istream.h"
#include "ostream.h"
#include "dict-transaction-memory.h"
#include "dict-private.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
struct file_dict {
char *path;
int fd;
bool refreshed;
};
struct file_dict_iterate_path {
const char *path;
};
struct file_dict_iterate_context {
const char *error;
};
.stale_timeout = 60,
};
static int
const struct dict_settings *set,
{
const char *p, *path;
if (p == NULL) {
/* no parameters */
} else {
if (strcmp(p, "lock=fcntl") == 0)
else if (strcmp(p, "lock=flock") == 0)
else {
return -1;
}
}
return 0;
}
{
}
{
/* Change nothing while there are iterators or they can crash
because the hash table content recreated. */
return FALSE;
}
return TRUE;
/* Disable NFS flushing for now since it can cause unnecessary
problems and there's no easy way for us to know here if
mail_nfs_storage=yes. In any case it's pretty much an unsupported
setting nowadays. */
/*nfs_flush_file_handle_cache(dict->path);*/
return FALSE;
}
return TRUE;
}
/* file changed */
return TRUE;
}
return FALSE;
}
{
int open_type;
if (!file_dict_need_refresh(dict))
return 0;
return 0;
else
return -1;
}
return 1;
}
{
return -1;
return 0;
/* strdup() before the second read */
break;
}
}
return 0;
}
{
return -1;
}
static struct dict_iterate_context *
enum dict_iterate_flags flags)
{
unsigned int i, path_count;
const char *error;
for (i = 0; i < path_count; i++) {
}
}
static const struct file_dict_iterate_path *
const char *key)
{
unsigned int i;
}
return NULL;
}
{
(struct file_dict_iterate_context *)_ctx;
continue;
/* match everything */
continue;
} else {
continue;
}
return TRUE;
}
return FALSE;
}
const char **error_r)
{
(struct file_dict_iterate_context *)_ctx;
return ret;
}
static struct dict_transaction_context *
{
}
bool *atomic_inc_not_found_r)
{
const char *tmp;
long long diff;
&orig_key, &orig_value)) {
} else {
}
case DICT_CHANGE_TYPE_INC:
break;
}
i_unreached();
else {
}
/* fall through */
case DICT_CHANGE_TYPE_SET:
}
break;
case DICT_CHANGE_TYPE_UNSET:
break;
}
}
}
static int
{
return -1;
}
/* group has different permissions from world.
preserve the group. */
i_error("fchown(%s, -1, %s) failed: %m",
return -1;
}
}
i_error("fchmod(%s, %o) failed: %m",
return -1;
}
}
return 0;
}
{
return -1;
}
}
static int
const char *dest_path)
{
const char *src_dir, *p;
if (p == NULL)
src_dir = ".";
else
return -1;
}
}
{
if (p == NULL)
return 0;
else
return -1;
}
/* preserve parent's permissions when it has setgid bit */
}
else
return -1;
}
return 0;
}
static int
const char **error_r)
{
int ret;
return -1;
/* quota file doesn't exist yet, we need to create it */
return -1;
}
else {
}
return -1;
}
}
do {
lock_r) <= 0) {
return -1;
}
/* check again if we need to reopen the file because it was
just replaced */
return ret < 0 ? -1 : 0;
}
static int
bool *atomic_inc_not_found_r, const char **error_r)
{
switch (dict->lock_method) {
case FILE_LOCK_METHOD_FCNTL:
case FILE_LOCK_METHOD_FLOCK:
return -1;
if (fd == -1) {
"dict-file: creat(%s) failed: %m", temp_path);
file_unlock(&lock);
return -1;
}
break;
case FILE_LOCK_METHOD_DOTLOCK:
&dotlock);
return -1;
}
if (fd == -1) {
"dict-file: file_dotlock_open(%s) failed: %m",
return -1;
}
break;
}
/* refresh once more now that we're locked */
else {
i_close_fd(&fd);
file_unlock(&lock);
}
return -1;
}
/* preserve the permissions */
} else {
/* get initial permissions from parent directory */
}
str_truncate(str, 0);
}
if (o_stream_finish(output) <= 0) {
i_close_fd(&fd);
return -1;
}
if (file_dotlock_replace(&dotlock,
i_close_fd(&fd);
return -1;
}
} else {
file_unlock(&lock);
i_close_fd(&fd);
return -1;
}
}
return 0;
}
static void
bool async ATTR_UNUSED,
void *context)
{
(struct dict_transaction_memory_context *)_ctx;
bool atomic_inc_not_found;
else if (atomic_inc_not_found)
else
}
.name = "file",
{
.init = file_dict_init,
}
};