summaryrefslogtreecommitdiffstats
path: root/src/plugins/mail-crypt/fs-crypt.c
blob: 0a81c696700516579c050b70b3906cced57d1aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
#define FS_CLASS_CRYPT fs_class_crypt
#include "fs-crypt-common.c"

static
int fs_crypt_load_keys(struct crypt_fs *fs, const char **error_r)
{
	const char *error;

	if (fs->keys_loaded)
		return 0;
	if (fs->public_key_path != NULL || fs->private_key_path != NULL) {
		/* overrides using settings */
		if (fs_crypt_load_keys_from_path(fs, error_r) < 0)
			return -1;
		fs->keys_loaded = TRUE;
		return 0;
	}
	if (mail_crypt_global_keys_load_pluginenv(fs->set_prefix, &fs->keys,
	    &error) < 0) {
		*error_r = t_strdup_printf("%s: %s", fs->set_prefix, error);
		return -1;
	}
	fs->keys_loaded = TRUE;
	return 0;
}

const struct fs fs_class_crypt = {
	.name = "crypt",
	.v = {
		fs_crypt_alloc,
		fs_crypt_init,
		NULL,
		fs_crypt_free,
		fs_wrapper_get_properties,
		fs_crypt_file_alloc,
		fs_crypt_file_init,
		fs_crypt_file_deinit,
		fs_crypt_file_close,
		fs_wrapper_file_get_path,
		fs_wrapper_set_async_callback,
		fs_wrapper_wait_async,
		fs_wrapper_set_metadata,
		fs_wrapper_get_metadata,
		fs_wrapper_prefetch,
		fs_read_via_stream,
		fs_crypt_read_stream,
		fs_write_via_stream,
		fs_crypt_write_stream,
		fs_crypt_write_stream_finish,
		fs_wrapper_lock,
		fs_wrapper_unlock,
		fs_wrapper_exists,
		fs_wrapper_stat,
		fs_wrapper_copy,
		fs_wrapper_rename,
		fs_wrapper_delete,
		fs_wrapper_iter_alloc,
		fs_wrapper_iter_init,
		fs_wrapper_iter_next,
		fs_wrapper_iter_deinit,
		NULL,
		fs_wrapper_get_nlinks,
	}
};