bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#define FS_CLASS_CRYPT fs_class_mail_crypt
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#include "fs-crypt-common.c"
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomistatic
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint fs_crypt_load_keys(struct crypt_fs *fs, const char **error_r)
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi{
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct mailbox_list *list = mailbox_list_fs_get_list(&fs->fs);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *error;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi if (fs->keys_loaded)
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi return 0;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi if (fs->public_key_path != NULL || fs->private_key_path != NULL) {
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi /* overrides using settings */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi if (fs_crypt_load_keys_from_path(fs, error_r) < 0)
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi return -1;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs->keys_loaded = TRUE;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi return 0;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi }
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi if (list == NULL) {
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi *error_r = "fs-mail-crypt can be used only via lib-storage";
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi return -1;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi }
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi if (mail_crypt_global_keys_load(mailbox_list_get_namespace(list)->user,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs->set_prefix, &fs->keys, FALSE,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi &error) < 0) {
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi *error_r = t_strdup_printf("%s: %s", fs->set_prefix, error);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi return -1;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi }
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs->keys_loaded = TRUE;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi return 0;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi}
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiconst struct fs fs_class_mail_crypt = {
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi .name = "mail-crypt",
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi .v = {
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_alloc,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_init,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_deinit,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_get_properties,
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainen fs_crypt_file_alloc,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_file_init,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_file_deinit,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_file_close,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_file_get_path,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_set_async_callback,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_wait_async,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_set_metadata,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_get_metadata,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_prefetch,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_read_via_stream,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_read_stream,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_write_via_stream,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_write_stream,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_crypt_write_stream_finish,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_lock,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_unlock,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_exists,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_stat,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_copy,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_rename,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_delete,
4d71d712b42285afbd2a997f3408142ef0d5f899Timo Sirainen fs_wrapper_iter_alloc,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_iter_init,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_iter_next,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_iter_deinit,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi NULL,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi fs_wrapper_get_nlinks,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi }
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi};