mail-crypt-acl-plugin.c revision c1ab825edf003f5cfc6c31730442f36a17209101
/* Copyright (c) 2015-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop-private.h"
#include "str.h"
#include "sha2.h"
#include "module-dir.h"
#include "var-expand.h"
#include "hex-binary.h"
#include "mail-namespace.h"
#include "mail-storage-hooks.h"
#include "mail-storage-service.h"
#include "acl-plugin.h"
#include "acl-api-private.h"
#include "mail-crypt-common.h"
#include "mail-crypt-key.h"
#include "mail-crypt-plugin.h"
#define MAIL_CRYPT_ACL_LIST_CONTEXT(obj) \
struct mail_crypt_acl_mailbox_list {
struct acl_backend_vfuncs acl_vprev;
};
void mail_crypt_acl_plugin_deinit(void);
static int
const char *username,
const char **error_r)
{
struct acl_object_list_iter *iter;
struct acl_rights rights;
int ret = 0;
break;
}
}
if (acl_object_list_deinit(&iter) < 0) {
*error_r = "Failed to iterate ACL objects";
return -1;
}
return ret;
}
const char **error_r)
{
struct acl_object_list_iter *iter;
struct acl_rights rights;
int ret = 0;
ret = 1;
break;
}
}
if (acl_object_list_deinit(&iter) < 0) {
*error_r = "Failed to iterate ACL objects";
return -1;
}
return ret;
}
static int
const char *dest_user,
enum mail_attribute_type type,
const char **error_r)
{
const char *error;
int ret = 1;
if (mailbox_open(src_box) < 0) {
"mailbox_open(%s) failed: %s",
return -1;
}
"Failed to lookup public key digests: %s",
error);
return -1;
}
struct mailbox_transaction_context *t;
t = mailbox_transaction_begin(src_box, 0);
const char *const *hash;
const char *ptr;
/* if the id contains username part, skip to key public id */
ptr++;
else
error_r)) < 0) {
ret = -1;
break;
}
}
if (ret < 0) {
} else if (mailbox_transaction_commit(&t) < 0) {
"mailbox_transaction_commit(%s) failed: %s",
return -1;
}
return 0;
}
static int
struct mail_user **dest_user_r,
struct mail_storage_service_user **dest_service_user_r,
const char **error_r)
{
const struct mail_storage_service_input *old_input;
struct mail_storage_service_input input;
struct mail_storage_service_ctx *service_ctx;
struct ioloop_context *cur_ioloop_ctx;
int ret;
return ret;
}
static int
bool disallow_insecure,
const char **error_r)
{
struct dcrypt_private_key **keyp;
int ret = 0;
if (!set) {
error_r);
}
/* get public key from target user */
if (ret == 0 && disallow_insecure) {
return -1;
} else if (ret < 0) {
return -1;
} else if (ret == 0) {
/* perform insecure sharing */
}
}
}
struct mailbox_transaction_context *t =
/* get private keys from box */
ret = -1;
if (ret >= 0) {
}
}
if (mailbox_transaction_commit(&t) < 0) {
ret = -1;
}
return ret;
}
const struct acl_rights_update *update)
{
const char *error;
struct mail_crypt_acl_mailbox_list *mlist =
const char *username;
struct ioloop_context *cur_ioloop_ctx;
bool have_rights;
int ret = 0;
return -1;
bool disallow_insecure =
case ACL_ID_USER:
/* setting rights for specific user: we can encrypt the
mailbox key for the user. */
if (ret < 0) {
i_error("mail-crypt-acl-plugin: "
"mail_crypt_acl_has_user_read_right(%s) failed: %s",
error);
break;
}
have_rights = ret > 0;
&dest_service_user, &error);
/* to make sure we get correct logging context */
if (ret > 0)
);
if (ret <= 0) {
i_error("mail-crypt-acl-plugin: "
"Cannot initialize destination user %s: %s",
break;
} else {
i_error("mail-crypt-acl-plugin: "
"mailbox_open(%s) failed: %s",
&error)) < 0) {
i_error("mail-crypt-acl-plugin: "
"acl_update_private_key(%s, %s) failed: %s",
error);
}
}
/* logging context swap again */
);
);
break;
case ACL_ID_OWNER:
/* we should be the one doing this? ignore */
break;
case ACL_ID_ANYONE:
case ACL_ID_AUTHENTICATED:
case ACL_ID_GROUP:
case ACL_ID_GROUP_OVERRIDE:
if (disallow_insecure) {
i_error("mail-crypt-acl-plugin: "
"Secure key sharing is enabled -"
"Remove or set plugin { %s = no }",
ret = -1;
break;
}
/* the mailbox key needs to be stored unencrypted. for groups
we could in theory use per-group encrypted keys, which the
users belonging to the group would able to decrypt with
their private key, but that becomes quite complicated. */
i_error("mail-crypt-acl-plugin: "
"mailbox_open(%s) failed: %s",
NULL,
TRUE,
&error)) < 0) {
i_error("mail-crypt-acl-plugin: "
"acl_update_private_key(%s, %s) failed: %s",
"",
error);
}
break;
case ACL_ID_TYPE_COUNT:
i_unreached();
}
mailbox_free(&box);
return ret;
}
static void
{
struct mail_crypt_acl_mailbox_list *mlist =
struct acl_backend *backend;
return;
/* FIXME: this method works only if there's a single plugin doing it.
if there are ever multiple plugins hooking into ACL commands the
ACL core code would need some changing to make it work correctly. */
}
{
struct mail_crypt_acl_mailbox_list *mlist =
}
{
struct mail_crypt_acl_mailbox_list *mlist;
}
static struct mail_storage_hooks mail_crypt_acl_mail_storage_hooks = {
};
{
}
void mail_crypt_acl_plugin_deinit(void)
{
}