Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::{Server, cache::invalidate::CacheInvalidationBuilder, ipc::CacheInvalidation};
|
||||
use types::acl::{AclGrant, ArchivedAclGrant};
|
||||
|
||||
impl Server {
|
||||
pub async fn refresh_acls(
|
||||
&self,
|
||||
acl_changes: &[AclGrant],
|
||||
current: Option<&[AclGrant]>,
|
||||
) -> trc::Result<()> {
|
||||
let mut changed_principals = CacheInvalidationBuilder::default();
|
||||
if let Some(acl_current) = current {
|
||||
for current_item in acl_current {
|
||||
let mut invalidate = true;
|
||||
for change_item in acl_changes {
|
||||
if change_item.account_id == current_item.account_id {
|
||||
invalidate = change_item.grants != current_item.grants;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if invalidate {
|
||||
changed_principals
|
||||
.invalidate(CacheInvalidation::AccessToken(current_item.account_id));
|
||||
}
|
||||
}
|
||||
|
||||
for change_item in acl_changes {
|
||||
let mut invalidate = true;
|
||||
for current_item in acl_current {
|
||||
if change_item.account_id == current_item.account_id {
|
||||
invalidate = change_item.grants != current_item.grants;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if invalidate {
|
||||
changed_principals
|
||||
.invalidate(CacheInvalidation::AccessToken(change_item.account_id));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for value in acl_changes {
|
||||
changed_principals.invalidate(CacheInvalidation::AccessToken(value.account_id));
|
||||
}
|
||||
}
|
||||
|
||||
self.invalidate_caches(changed_principals).await
|
||||
}
|
||||
|
||||
pub async fn refresh_archived_acls(
|
||||
&self,
|
||||
acl_changes: &[AclGrant],
|
||||
acl_current: &[ArchivedAclGrant],
|
||||
) -> trc::Result<()> {
|
||||
let mut changed_principals = CacheInvalidationBuilder::default();
|
||||
|
||||
for current_item in acl_current.iter() {
|
||||
let mut invalidate = true;
|
||||
for change_item in acl_changes {
|
||||
if change_item.account_id == current_item.account_id {
|
||||
invalidate = change_item.grants != current_item.grants;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if invalidate {
|
||||
changed_principals.invalidate(CacheInvalidation::AccessToken(
|
||||
current_item.account_id.to_native(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
for change_item in acl_changes {
|
||||
let mut invalidate = true;
|
||||
for current_item in acl_current.iter() {
|
||||
if change_item.account_id == current_item.account_id {
|
||||
invalidate = change_item.grants != current_item.grants;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if invalidate {
|
||||
changed_principals
|
||||
.invalidate(CacheInvalidation::AccessToken(change_item.account_id));
|
||||
}
|
||||
}
|
||||
|
||||
self.invalidate_caches(changed_principals).await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::auth::AccessToken;
|
||||
use rkyv::vec::ArchivedVec;
|
||||
use types::acl::{Acl, AclGrant, ArchivedAclGrant};
|
||||
use utils::map::bitmap::Bitmap;
|
||||
|
||||
pub mod acl;
|
||||
pub mod notification;
|
||||
pub mod resources;
|
||||
|
||||
pub trait EffectiveAcl {
|
||||
fn effective_acl(&self, access_token: &AccessToken) -> Bitmap<Acl>;
|
||||
}
|
||||
|
||||
impl EffectiveAcl for Vec<AclGrant> {
|
||||
fn effective_acl(&self, access_token: &AccessToken) -> Bitmap<Acl> {
|
||||
self.as_slice().effective_acl(access_token)
|
||||
}
|
||||
}
|
||||
|
||||
impl EffectiveAcl for &[AclGrant] {
|
||||
fn effective_acl(&self, access_token: &AccessToken) -> Bitmap<Acl> {
|
||||
let mut acl = Bitmap::<Acl>::new();
|
||||
for item in self.iter() {
|
||||
if access_token.is_member(item.account_id) {
|
||||
acl.union(&item.grants);
|
||||
}
|
||||
}
|
||||
|
||||
acl
|
||||
}
|
||||
}
|
||||
|
||||
impl EffectiveAcl for ArchivedVec<ArchivedAclGrant> {
|
||||
fn effective_acl(&self, access_token: &AccessToken) -> Bitmap<Acl> {
|
||||
let mut acl = Bitmap::<Acl>::new();
|
||||
for item in self.iter() {
|
||||
if access_token.is_member(item.account_id.into()) {
|
||||
acl.union_raw(item.grants.bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
acl
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use store::{Deserialize, SerializeInfallible, U32_LEN, U64_LEN, write::key::KeySerializer};
|
||||
use types::{acl::Acl, collection::Collection};
|
||||
use utils::map::bitmap::Bitmap;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct ShareNotification {
|
||||
pub object_account_id: u32,
|
||||
pub object_id: u32,
|
||||
pub object_type: Collection,
|
||||
pub changed_by: u32,
|
||||
pub old_rights: Bitmap<Acl>,
|
||||
pub new_rights: Bitmap<Acl>,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl SerializeInfallible for ShareNotification {
|
||||
fn serialize(&self) -> Vec<u8> {
|
||||
KeySerializer::new(U64_LEN * 2 + U32_LEN * 3 + 1 + self.name.len())
|
||||
.write(self.object_account_id)
|
||||
.write(self.object_id)
|
||||
.write(self.object_type as u8)
|
||||
.write(self.changed_by)
|
||||
.write(self.old_rights.bitmap)
|
||||
.write(self.new_rights.bitmap)
|
||||
.write(self.name.as_bytes())
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for ShareNotification {
|
||||
fn deserialize(bytes: &[u8]) -> trc::Result<Self> {
|
||||
Self::deserialize_from_slice(bytes)
|
||||
.ok_or(trc::StoreEvent::DataCorruption.caused_by(trc::location!()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ShareNotification {
|
||||
fn deserialize_from_slice(bytes: &[u8]) -> Option<Self> {
|
||||
Some(Self {
|
||||
object_account_id: bytes
|
||||
.get(..U32_LEN)
|
||||
.and_then(|b| b.try_into().ok())
|
||||
.map(u32::from_be_bytes)?,
|
||||
object_id: bytes
|
||||
.get(U32_LEN..U32_LEN * 2)
|
||||
.and_then(|b| b.try_into().ok())
|
||||
.map(u32::from_be_bytes)?,
|
||||
object_type: bytes.get(U32_LEN * 2).copied().map(Collection::from)?,
|
||||
changed_by: bytes
|
||||
.get(U32_LEN * 2 + 1..U32_LEN * 3 + 1)
|
||||
.and_then(|b| b.try_into().ok())
|
||||
.map(u32::from_be_bytes)?,
|
||||
old_rights: bytes
|
||||
.get(U32_LEN * 3 + 1..U32_LEN * 3 + U64_LEN + 1)
|
||||
.and_then(|b| b.try_into().ok())
|
||||
.map(u64::from_be_bytes)
|
||||
.map(Bitmap::from)?,
|
||||
new_rights: bytes
|
||||
.get(U32_LEN * 3 + U64_LEN + 1..U32_LEN * 3 + U64_LEN * 2 + 1)
|
||||
.and_then(|b| b.try_into().ok())
|
||||
.map(u64::from_be_bytes)
|
||||
.map(Bitmap::from)?,
|
||||
name: bytes
|
||||
.get(U32_LEN * 3 + U64_LEN * 2 + 1..)
|
||||
.and_then(|b| String::from_utf8(b.to_vec()).ok())
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::{DavResources, auth::AccessToken};
|
||||
use store::roaring::RoaringBitmap;
|
||||
use types::acl::Acl;
|
||||
use utils::map::bitmap::Bitmap;
|
||||
|
||||
impl DavResources {
|
||||
pub fn shared_containers(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
check_acls: impl IntoIterator<Item = Acl>,
|
||||
match_any: bool,
|
||||
) -> RoaringBitmap {
|
||||
let check_acls = Bitmap::<Acl>::from_iter(check_acls);
|
||||
let mut document_ids = RoaringBitmap::new();
|
||||
|
||||
for resource in &self.resources {
|
||||
if let Some(acls) = resource.acls() {
|
||||
for acl in acls {
|
||||
if access_token.is_member(acl.account_id) {
|
||||
let mut grants = acl.grants;
|
||||
grants.intersection(&check_acls);
|
||||
if grants == check_acls || (match_any && !grants.is_empty()) {
|
||||
document_ids.insert(resource.document_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document_ids
|
||||
}
|
||||
|
||||
pub fn shared_items(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
check_acls: impl IntoIterator<Item = Acl>,
|
||||
match_any: bool,
|
||||
) -> RoaringBitmap {
|
||||
let shared_containers = self.shared_containers(access_token, check_acls, match_any);
|
||||
|
||||
if !shared_containers.is_empty() {
|
||||
let mut document_ids = RoaringBitmap::new();
|
||||
|
||||
for resource in &self.resources {
|
||||
if !resource.is_container() && shared_containers.contains(resource.document_id) {
|
||||
document_ids.insert(resource.document_id);
|
||||
}
|
||||
}
|
||||
|
||||
for path in &self.paths {
|
||||
if let Some(parent_id) = path.parent_id
|
||||
&& shared_containers.contains(parent_id)
|
||||
{
|
||||
document_ids.insert(self.resources[path.resource_idx].document_id);
|
||||
}
|
||||
}
|
||||
|
||||
document_ids
|
||||
} else {
|
||||
shared_containers
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shared_documents(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
check_acls: impl IntoIterator<Item = Acl>,
|
||||
match_any: bool,
|
||||
) -> RoaringBitmap {
|
||||
let shared_containers = self.shared_containers(access_token, check_acls, match_any);
|
||||
let mut document_ids = shared_containers.clone();
|
||||
|
||||
if !shared_containers.is_empty() {
|
||||
for path in &self.paths {
|
||||
if let Some(parent_id) = path.parent_id
|
||||
&& shared_containers.contains(parent_id)
|
||||
{
|
||||
document_ids.insert(self.resources[path.resource_idx].document_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document_ids
|
||||
}
|
||||
|
||||
pub fn has_access_to_container(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
document_id: u32,
|
||||
check_acls: impl Into<Bitmap<Acl>>,
|
||||
) -> bool {
|
||||
let check_acls = check_acls.into();
|
||||
|
||||
for resource in &self.resources {
|
||||
if resource.document_id == document_id
|
||||
&& let Some(acls) = resource.acls()
|
||||
{
|
||||
for acl in acls {
|
||||
if access_token.is_member(acl.account_id) {
|
||||
let mut grants = acl.grants;
|
||||
grants.intersection(&check_acls);
|
||||
return !grants.is_empty();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn container_acl(&self, access_token: &AccessToken, document_id: u32) -> Bitmap<Acl> {
|
||||
let mut account_acls = Bitmap::<Acl>::new();
|
||||
|
||||
for resource in &self.resources {
|
||||
if resource.document_id == document_id
|
||||
&& let Some(acls) = resource.acls()
|
||||
{
|
||||
for acl in acls {
|
||||
if access_token.is_member(acl.account_id) {
|
||||
account_acls.union(&acl.grants);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
account_acls
|
||||
}
|
||||
|
||||
pub fn document_ids(&self, is_container: bool) -> impl Iterator<Item = u32> {
|
||||
self.resources.iter().filter_map(move |resource| {
|
||||
if resource.is_container() == is_container {
|
||||
Some(resource.document_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn has_container_id(&self, id: &u32) -> bool {
|
||||
self.resources
|
||||
.iter()
|
||||
.any(|r| r.document_id == *id && r.is_container())
|
||||
}
|
||||
|
||||
pub fn has_item_id(&self, id: &u32) -> bool {
|
||||
self.resources
|
||||
.iter()
|
||||
.any(|r| r.document_id == *id && !r.is_container())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user