fix and enable collapsible_if lint
Signed-off-by: June Strawberry <june@vern.cc>
This commit is contained in:
@@ -987,7 +987,6 @@ style = { level = "warn", priority = -1 }
|
||||
assertions_on_constants = { level = "allow", priority = 1 }
|
||||
module_inception = { level = "allow", priority = 1 }
|
||||
obfuscated_if_else = { level = "allow", priority = 1 }
|
||||
collapsible_if = { level = "allow", priority = 1 } # TODO stable v. nightly 05-21-25
|
||||
toplevel-ref-arg = { level = "allow", priority = 1 }
|
||||
|
||||
###################
|
||||
|
||||
@@ -35,10 +35,10 @@ async fn destinations_cache(&self, server_name: Option<OwnedServerName>) -> Resu
|
||||
.boxed();
|
||||
|
||||
while let Some((name, CachedDest { dest, host, expire })) = destinations.next().await {
|
||||
if let Some(server_name) = server_name.as_ref() {
|
||||
if name != server_name {
|
||||
continue;
|
||||
}
|
||||
if let Some(server_name) = server_name.as_ref()
|
||||
&& name != server_name
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let expire = time::format(expire, "%+");
|
||||
@@ -61,10 +61,10 @@ async fn overrides_cache(&self, server_name: Option<String>) -> Result {
|
||||
while let Some((name, CachedOverride { ips, port, expire, overriding })) =
|
||||
overrides.next().await
|
||||
{
|
||||
if let Some(server_name) = server_name.as_ref() {
|
||||
if name != server_name {
|
||||
continue;
|
||||
}
|
||||
if let Some(server_name) = server_name.as_ref()
|
||||
&& name != server_name
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let expire = time::format(expire, "%+");
|
||||
|
||||
@@ -50,10 +50,10 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
||||
|
||||
let admin_room_alias = &self.services.admin.admin_alias;
|
||||
|
||||
if let Ok(admin_room_id) = self.services.admin.get_admin_room().await {
|
||||
if room.to_string().eq(&admin_room_id) || room.to_string().eq(admin_room_alias) {
|
||||
return Err!("Not allowed to ban the admin room.");
|
||||
}
|
||||
if let Ok(admin_room_id) = self.services.admin.get_admin_room().await
|
||||
&& (room.to_string().eq(&admin_room_id) || room.to_string().eq(admin_room_alias))
|
||||
{
|
||||
return Err!("Not allowed to ban the admin room.");
|
||||
}
|
||||
|
||||
let room_id = if room.is_room_id() {
|
||||
@@ -217,12 +217,12 @@ async fn ban_list_of_rooms(&self) -> Result {
|
||||
for &room in &rooms_s {
|
||||
match <&RoomOrAliasId>::try_from(room) {
|
||||
| Ok(room_alias_or_id) => {
|
||||
if let Ok(admin_room_id) = self.services.admin.get_admin_room().await {
|
||||
if room.to_owned().eq(&admin_room_id) || room.to_owned().eq(admin_room_alias)
|
||||
{
|
||||
warn!("User specified admin room in bulk ban list, ignoring");
|
||||
continue;
|
||||
}
|
||||
if let Ok(admin_room_id) = self.services.admin.get_admin_room().await
|
||||
&& (room.to_owned().eq(&admin_room_id)
|
||||
|| room.to_owned().eq(admin_room_alias))
|
||||
{
|
||||
warn!("User specified admin room in bulk ban list, ignoring");
|
||||
continue;
|
||||
}
|
||||
|
||||
if room_alias_or_id.is_room_id() {
|
||||
|
||||
@@ -49,10 +49,10 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
|
||||
// Validate user id
|
||||
let user_id = parse_local_user_id(self.services, &username)?;
|
||||
|
||||
if let Err(e) = user_id.validate_strict() {
|
||||
if self.services.config.emergency_password.is_none() {
|
||||
return Err!("Username {user_id} contains disallowed characters or spaces: {e}");
|
||||
}
|
||||
if let Err(e) = user_id.validate_strict()
|
||||
&& self.services.config.emergency_password.is_none()
|
||||
{
|
||||
return Err!("Username {user_id} contains disallowed characters or spaces: {e}");
|
||||
}
|
||||
|
||||
if self.services.users.exists(&user_id).await {
|
||||
|
||||
@@ -301,30 +301,26 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(query) = search_room_id {
|
||||
if chunk.room_id.as_str().contains(query) {
|
||||
if let Some(query) = search_room_id
|
||||
&& chunk.room_id.as_str().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(query) = search_term.as_deref() {
|
||||
if let Some(name) = &chunk.name {
|
||||
if name.as_str().to_lowercase().contains(query) {
|
||||
if let Some(name) = &chunk.name
|
||||
&& name.as_str().to_lowercase().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(topic) = &chunk.topic {
|
||||
if topic.to_lowercase().contains(query) {
|
||||
if let Some(topic) = &chunk.topic
|
||||
&& topic.to_lowercase().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(canonical_alias) = &chunk.canonical_alias {
|
||||
if canonical_alias.as_str().to_lowercase().contains(query) {
|
||||
if let Some(canonical_alias) = &chunk.canonical_alias
|
||||
&& canonical_alias.as_str().to_lowercase().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -484,10 +484,10 @@ where
|
||||
{
|
||||
self_signing_keys.insert(user_id.to_owned(), self_signing_key);
|
||||
}
|
||||
if Some(user_id) == sender_user {
|
||||
if let Ok(user_signing_key) = services.users.get_user_signing_key(user_id).await {
|
||||
user_signing_keys.insert(user_id.to_owned(), user_signing_key);
|
||||
}
|
||||
if Some(user_id) == sender_user
|
||||
&& let Ok(user_signing_key) = services.users.get_user_signing_key(user_id).await
|
||||
{
|
||||
user_signing_keys.insert(user_id.to_owned(), user_signing_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,11 +49,9 @@ pub(crate) async fn invite_user_route(
|
||||
if let Ok(target_user_membership) = services
|
||||
.state_accessor
|
||||
.get_member(room_id, user_id)
|
||||
.await
|
||||
.await && target_user_membership.membership == MembershipState::Ban
|
||||
{
|
||||
if target_user_membership.membership == MembershipState::Ban {
|
||||
return Err!(Request(Forbidden("User is banned from this room.")));
|
||||
}
|
||||
return Err!(Request(Forbidden("User is banned from this room.")));
|
||||
}
|
||||
|
||||
if recipient_ignored_by_sender {
|
||||
|
||||
@@ -48,14 +48,13 @@ pub(crate) async fn get_presence_route(
|
||||
.user_sees_user(body.sender_user(), &body.user_id)
|
||||
.await;
|
||||
|
||||
if has_shared_rooms {
|
||||
if let Ok(presence) = services
|
||||
if has_shared_rooms
|
||||
&& let Ok(presence) = services
|
||||
.presence
|
||||
.get_presence(&body.user_id)
|
||||
.await
|
||||
{
|
||||
presence_event = Some(presence);
|
||||
}
|
||||
{
|
||||
presence_event = Some(presence);
|
||||
}
|
||||
|
||||
match presence_event {
|
||||
|
||||
@@ -93,10 +93,10 @@ pub(crate) async fn get_register_available_route(
|
||||
return Err!(Request(UserInUse("User ID is not available.")));
|
||||
}
|
||||
|
||||
if let Some(ref info) = body.appservice_info {
|
||||
if !info.is_user_match(&user_id) {
|
||||
return Err!(Request(Exclusive("Username is not in an appservice namespace.")));
|
||||
}
|
||||
if let Some(ref info) = body.appservice_info
|
||||
&& !info.is_user_match(&user_id)
|
||||
{
|
||||
return Err!(Request(Exclusive("Username is not in an appservice namespace.")));
|
||||
}
|
||||
|
||||
if services
|
||||
|
||||
@@ -446,10 +446,10 @@ async fn create_create_event(
|
||||
))))
|
||||
})?;
|
||||
|
||||
if !services.config.federate_created_rooms {
|
||||
if !services.config.allow_federation || !content.contains_key("m.federate") {
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
if !services.config.federate_created_rooms
|
||||
&& (!services.config.allow_federation || !content.contains_key("m.federate"))
|
||||
{
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
|
||||
content.insert(
|
||||
@@ -578,10 +578,10 @@ async fn create_create_event_legacy(
|
||||
},
|
||||
}
|
||||
|
||||
if !services.config.federate_created_rooms {
|
||||
if !services.config.allow_federation || !content.contains_key("m.federate") {
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
if !services.config.federate_created_rooms
|
||||
&& (!services.config.allow_federation || !content.contains_key("m.federate"))
|
||||
{
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
|
||||
content.insert(
|
||||
|
||||
@@ -646,8 +646,9 @@ async fn try_user_id(
|
||||
|
||||
fn parse_user_id(server_name: &ServerName, username: &str) -> Result<OwnedUserId> {
|
||||
match UserId::parse_with_server_name(username, server_name) {
|
||||
| Err(e) =>
|
||||
Err!(Request(InvalidUsername(debug_error!("Username {username} is not valid: {e}")))),
|
||||
| Err(e) => {
|
||||
Err!(Request(InvalidUsername(debug_error!("Username {username} is not valid: {e}"))))
|
||||
},
|
||||
| Ok(user_id) => match user_id.validate_strict() {
|
||||
| Ok(()) => Ok(user_id),
|
||||
| Err(e) => Err!(Request(InvalidUsername(debug_error!(
|
||||
|
||||
@@ -45,12 +45,12 @@ pub(crate) async fn get_hierarchy_route(
|
||||
.and_then(|s| PaginationToken::from_str(s).ok());
|
||||
|
||||
// Should prevent unexpected behaviour in (bad) clients
|
||||
if let Some(ref token) = key {
|
||||
if token.suggested_only != body.suggested_only || token.max_depth != max_depth {
|
||||
return Err!(Request(InvalidParam(
|
||||
"suggested_only and max_depth cannot change on paginated requests"
|
||||
)));
|
||||
}
|
||||
if let Some(ref token) = key
|
||||
&& (token.suggested_only != body.suggested_only || token.max_depth != max_depth)
|
||||
{
|
||||
return Err!(Request(InvalidParam(
|
||||
"suggested_only and max_depth cannot change on paginated requests"
|
||||
)));
|
||||
}
|
||||
|
||||
get_client_hierarchy(
|
||||
|
||||
@@ -276,21 +276,21 @@ async fn allowed_to_send_state_event(
|
||||
},
|
||||
| StateEventType::RoomJoinRules => {
|
||||
// admin room is a sensitive room, it should not ever be made public
|
||||
if let Ok(admin_room_id) = services.admin.get_admin_room().await {
|
||||
if admin_room_id == room_id {
|
||||
match json.deserialize_as_unchecked::<RoomJoinRulesEventContent>() {
|
||||
| Ok(join_rule) =>
|
||||
if join_rule.join_rule == JoinRule::Public {
|
||||
return Err!(Request(Forbidden(
|
||||
"Admin room is a sensitive room, it cannot be made public"
|
||||
)));
|
||||
},
|
||||
| Err(e) => {
|
||||
return Err!(Request(BadJson(debug_warn!(
|
||||
"Room join rules event is invalid: {e}"
|
||||
))));
|
||||
if let Ok(admin_room_id) = services.admin.get_admin_room().await
|
||||
&& admin_room_id == room_id
|
||||
{
|
||||
match json.deserialize_as_unchecked::<RoomJoinRulesEventContent>() {
|
||||
| Ok(join_rule) =>
|
||||
if join_rule.join_rule == JoinRule::Public {
|
||||
return Err!(Request(Forbidden(
|
||||
"Admin room is a sensitive room, it cannot be made public"
|
||||
)));
|
||||
},
|
||||
}
|
||||
| Err(e) => {
|
||||
return Err!(Request(BadJson(debug_warn!(
|
||||
"Room join rules event is invalid: {e}"
|
||||
))));
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,14 +51,13 @@ pub(crate) async fn create_invite_route(
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if services
|
||||
|
||||
@@ -54,16 +54,15 @@ pub(crate) async fn create_join_event_template_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
|
||||
let room_version_id = services
|
||||
|
||||
@@ -46,14 +46,13 @@ pub(crate) async fn create_knock_event_template_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
let room_version = services
|
||||
@@ -80,17 +79,15 @@ pub(crate) async fn create_knock_event_template_route(
|
||||
if let Ok(membership) = services
|
||||
.state_accessor
|
||||
.get_member(&body.room_id, &body.user_id)
|
||||
.await
|
||||
.await && membership.membership == MembershipState::Ban
|
||||
{
|
||||
if membership.membership == MembershipState::Ban {
|
||||
debug_warn!(
|
||||
"Remote user {} is banned from {} but attempted to knock",
|
||||
&body.user_id,
|
||||
&body.room_id
|
||||
);
|
||||
debug_warn!(
|
||||
"Remote user {} is banned from {} but attempted to knock",
|
||||
&body.user_id,
|
||||
&body.room_id
|
||||
);
|
||||
|
||||
return Err!(Request(Forbidden("You cannot knock on a room you are banned from.")));
|
||||
}
|
||||
return Err!(Request(Forbidden("You cannot knock on a room you are banned from.")));
|
||||
}
|
||||
|
||||
let pdu_json = services
|
||||
|
||||
@@ -115,10 +115,10 @@ pub(crate) async fn send_transaction_message_route(
|
||||
"Finished txn",
|
||||
);
|
||||
for (id, result) in &results {
|
||||
if let Err(e) = result {
|
||||
if matches!(e, Error::BadRequest(ErrorKind::NotFound, _)) {
|
||||
warn!("Incoming PDU failed {id}: {e:?}");
|
||||
}
|
||||
if let Err(e) = result
|
||||
&& matches!(e, Error::BadRequest(ErrorKind::NotFound, _))
|
||||
{
|
||||
warn!("Incoming PDU failed {id}: {e:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -285,23 +285,22 @@ pub(crate) async fn create_join_event_v1_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
|
||||
Ok(create_join_event::v1::Response {
|
||||
@@ -326,23 +325,22 @@ pub(crate) async fn create_join_event_v2_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
|
||||
let create_join_event::v1::RoomState { auth_chain, state, event } =
|
||||
|
||||
@@ -39,20 +39,19 @@ pub(crate) async fn create_knock_event_v1_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried knocking room ID {} which has a server name that is globally \
|
||||
forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried knocking room ID {} which has a server name that is globally \
|
||||
forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if !services.metadata.exists(&body.room_id).await {
|
||||
|
||||
@@ -269,13 +269,13 @@ pub fn check(config: &Config) -> Result {
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(Either::Right(_)) = config.url_preview_bound_interface.as_ref() {
|
||||
if !matches!(OS, "android" | "fuchsia" | "linux") {
|
||||
return Err!(Config(
|
||||
"url_preview_bound_interface",
|
||||
"Not a valid IP address. Interface names not supported on {OS}."
|
||||
));
|
||||
}
|
||||
if let Some(Either::Right(_)) = config.url_preview_bound_interface.as_ref()
|
||||
&& !matches!(OS, "android" | "fuchsia" | "linux")
|
||||
{
|
||||
return Err!(Config(
|
||||
"url_preview_bound_interface",
|
||||
"Not a valid IP address. Interface names not supported on {OS}."
|
||||
));
|
||||
}
|
||||
|
||||
if !Server::available_room_versions()
|
||||
|
||||
@@ -53,13 +53,13 @@ fn append_features(features: &mut Vec<&'static str>, flags: &[&'static str]) {
|
||||
for flag in flags {
|
||||
let is_cfg = *flag == "--cfg";
|
||||
let is_feature = flag.starts_with("feature=");
|
||||
if replace(&mut next_is_cfg, is_cfg) && is_feature {
|
||||
if let Some(feature) = flag
|
||||
if replace(&mut next_is_cfg, is_cfg)
|
||||
&& is_feature
|
||||
&& let Some(feature) = flag
|
||||
.split_once('=')
|
||||
.map(|(_, feature)| feature.trim_matches('"'))
|
||||
{
|
||||
features.push(feature);
|
||||
}
|
||||
{
|
||||
features.push(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ fn matches_user_id(user_id: &UserId, filter: &Filter) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(senders) = filter.senders.as_ref() {
|
||||
if !senders.iter().any(is_equal_to!(user_id)) {
|
||||
return false;
|
||||
}
|
||||
if let Some(senders) = filter.senders.as_ref()
|
||||
&& !senders.iter().any(is_equal_to!(user_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
@@ -79,10 +79,10 @@ fn matches_room_id(room_id: &RoomId, filter: &RoomFilter) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(rooms) = filter.rooms.as_ref() {
|
||||
if !rooms.iter().any(is_equal_to!(room_id)) {
|
||||
return false;
|
||||
}
|
||||
if let Some(rooms) = filter.rooms.as_ref()
|
||||
&& !rooms.iter().any(is_equal_to!(room_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
@@ -97,10 +97,10 @@ fn matches_room<E: Event>(event: &E, filter: &RoomEventFilter) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(rooms) = filter.rooms.as_ref() {
|
||||
if !rooms.iter().any(is_equal_to!(event.room_id())) {
|
||||
return false;
|
||||
}
|
||||
if let Some(rooms) = filter.rooms.as_ref()
|
||||
&& !rooms.iter().any(is_equal_to!(event.room_id()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
@@ -115,10 +115,10 @@ fn matches_sender<E: Event>(event: &E, filter: &RoomEventFilter) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(senders) = filter.senders.as_ref() {
|
||||
if !senders.iter().any(is_equal_to!(event.sender())) {
|
||||
return false;
|
||||
}
|
||||
if let Some(senders) = filter.senders.as_ref()
|
||||
&& !senders.iter().any(is_equal_to!(event.sender()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
@@ -131,10 +131,10 @@ fn matches_type<E: Event>(event: &E, filter: &RoomEventFilter) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(types) = filter.types.as_ref() {
|
||||
if !types.iter().any(is_equal_to!(&kind)) {
|
||||
return false;
|
||||
}
|
||||
if let Some(types) = filter.types.as_ref()
|
||||
&& !types.iter().any(is_equal_to!(&kind))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
|
||||
@@ -32,14 +32,12 @@ pub fn into_outgoing_federation(
|
||||
if !room_rules
|
||||
.event_format
|
||||
.require_room_create_room_id
|
||||
{
|
||||
if pdu_json
|
||||
&& pdu_json
|
||||
.get("type")
|
||||
.and_then(CanonicalJsonValue::as_str)
|
||||
.is_some_and(is_equal_to!("m.room.create"))
|
||||
{
|
||||
pdu_json.remove("room_id");
|
||||
}
|
||||
{
|
||||
pdu_json.remove("room_id");
|
||||
}
|
||||
|
||||
if matches!(room_rules.events_reference_format, EventsReferenceFormatVersion::V1) {
|
||||
|
||||
@@ -201,15 +201,14 @@ where
|
||||
let mut room_create_event = None;
|
||||
let mut room_power_levels_event = None;
|
||||
let event = fetch(event_id.to_owned()).await;
|
||||
if let Ok(event) = &event {
|
||||
if rules
|
||||
if let Ok(event) = &event
|
||||
&& rules
|
||||
.authorization
|
||||
.room_create_event_id_as_room_id
|
||||
{
|
||||
let create_id = event.room_id().as_event_id()?;
|
||||
let fetched = fetch(create_id).await?;
|
||||
room_create_event = Some(RoomCreateEvent::new(fetched));
|
||||
}
|
||||
{
|
||||
let create_id = event.room_id().as_event_id()?;
|
||||
let fetched = fetch(create_id).await?;
|
||||
room_create_event = Some(RoomCreateEvent::new(fetched));
|
||||
}
|
||||
|
||||
for auth_event_id in event
|
||||
|
||||
@@ -146,11 +146,11 @@ fn generate_example(input: &ItemStruct, args: &[Meta], write: bool) -> Result<To
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(file) = file.as_mut() {
|
||||
if let Some(footer) = settings.get("footer") {
|
||||
file.write_all(footer.as_bytes())
|
||||
.expect("written to config file");
|
||||
}
|
||||
if let Some(file) = file.as_mut()
|
||||
&& let Some(footer) = settings.get("footer")
|
||||
{
|
||||
file.write_all(footer.as_bytes())
|
||||
.expect("written to config file");
|
||||
}
|
||||
|
||||
let struct_name = &input.ident;
|
||||
|
||||
@@ -70,10 +70,10 @@ fn before_send(event: Event<'static>) -> Option<Event<'static>> {
|
||||
}
|
||||
|
||||
//NOTE: we can enable this to specify error!(sentry = true, ...)
|
||||
if let Some(Context::Other(context)) = event.contexts.get("Rust Tracing Fields") {
|
||||
if !context.contains_key("sentry") {
|
||||
//return None;
|
||||
}
|
||||
if let Some(Context::Other(context)) = event.contexts.get("Rust Tracing Fields")
|
||||
&& !context.contains_key("sentry")
|
||||
{
|
||||
//return None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,10 +132,10 @@ async fn handle_services_poll(
|
||||
) -> Result {
|
||||
debug!("Service manager finished: {result:?}");
|
||||
|
||||
if server.running() {
|
||||
if let Err(e) = server.shutdown() {
|
||||
error!("Failed to send shutdown signal: {e}");
|
||||
}
|
||||
if server.running()
|
||||
&& let Err(e) = server.shutdown()
|
||||
{
|
||||
error!("Failed to send shutdown signal: {e}");
|
||||
}
|
||||
|
||||
if let Err(e) = listener.await {
|
||||
|
||||
@@ -174,12 +174,12 @@ async fn fini(server: &Arc<Server>, listener: UnixListener, mut tasks: JoinSet<(
|
||||
debug!("Shutting down...");
|
||||
tasks.shutdown().await;
|
||||
|
||||
if let Ok(local) = local {
|
||||
if let Some(path) = local.as_pathname() {
|
||||
debug!(?path, "Removing unix socket file.");
|
||||
if let Err(e) = fs::remove_file(path).await {
|
||||
warn!(?path, "Failed to remove UNIX socket file: {e}");
|
||||
}
|
||||
if let Ok(local) = local
|
||||
&& let Some(path) = local.as_pathname()
|
||||
{
|
||||
debug!(?path, "Removing unix socket file.");
|
||||
if let Err(e) = fs::remove_file(path).await {
|
||||
warn!(?path, "Failed to remove UNIX socket file: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ pub(super) async fn startup_execute(&self) -> Result {
|
||||
sleep(Duration::from_millis(500)).await;
|
||||
|
||||
for (i, command) in commands.iter().enumerate() {
|
||||
if let Err(e) = self.execute_command(i, command.clone()).await {
|
||||
if !errors {
|
||||
return Err(e);
|
||||
}
|
||||
if let Err(e) = self.execute_command(i, command.clone()).await
|
||||
&& !errors
|
||||
{
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
tokio::task::yield_now().await;
|
||||
@@ -92,10 +92,10 @@ pub(super) async fn signal_execute(&self) -> Result {
|
||||
.admin_execute_errors_ignore;
|
||||
|
||||
for (i, command) in commands.iter().enumerate() {
|
||||
if let Err(e) = self.execute_command(i, command.clone()).await {
|
||||
if !ignore_errors {
|
||||
return Err(e);
|
||||
}
|
||||
if let Err(e) = self.execute_command(i, command.clone()).await
|
||||
&& !ignore_errors
|
||||
{
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
tokio::task::yield_now().await;
|
||||
|
||||
@@ -132,15 +132,14 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result {
|
||||
.admin_room_tag
|
||||
.as_str();
|
||||
|
||||
if !room_tag.is_empty() {
|
||||
if let Err(e) = self
|
||||
if !room_tag.is_empty()
|
||||
&& let Err(e) = self
|
||||
.services
|
||||
.account_data
|
||||
.set_room_tag(user_id, &room_id, room_tag.into(), None)
|
||||
.await
|
||||
{
|
||||
error!(?room_id, ?user_id, ?room_tag, "Failed to set tag for admin grant: {e}");
|
||||
}
|
||||
{
|
||||
error!(?room_id, ?user_id, ?room_tag, "Failed to set tag for admin grant: {e}");
|
||||
}
|
||||
|
||||
if self.services.server.config.admin_room_notices {
|
||||
|
||||
@@ -18,10 +18,10 @@ impl NamespaceRegex {
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(non_exclusive) = &self.non_exclusive {
|
||||
if non_exclusive.is_match(heystack) {
|
||||
return true;
|
||||
}
|
||||
if let Some(non_exclusive) = &self.non_exclusive
|
||||
&& non_exclusive.is_match(heystack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
@@ -30,10 +30,10 @@ impl NamespaceRegex {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn is_exclusive_match(&self, heystack: &str) -> bool {
|
||||
if let Some(exclusive) = &self.exclusive {
|
||||
if exclusive.is_match(heystack) {
|
||||
return true;
|
||||
}
|
||||
if let Some(exclusive) = &self.exclusive
|
||||
&& exclusive.is_match(heystack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
@@ -124,11 +124,11 @@ where
|
||||
|
||||
#[implement(super::Service)]
|
||||
fn validate_url(&self, url: &Url) -> Result {
|
||||
if let Some(url_host) = url.host_str() {
|
||||
if let Ok(ip) = IPAddress::parse(url_host) {
|
||||
trace!("Checking request URL IP {ip:?}");
|
||||
self.services.resolver.validate_ip(&ip)?;
|
||||
}
|
||||
if let Some(url_host) = url.host_str()
|
||||
&& let Ok(ip) = IPAddress::parse(url_host)
|
||||
{
|
||||
trace!("Checking request URL IP {ip:?}");
|
||||
self.services.resolver.validate_ip(&ip)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -337,10 +337,10 @@ impl Service {
|
||||
let file_rm = fs::remove_file(&path);
|
||||
let legacy_rm = fs::remove_file(&legacy);
|
||||
let (file_rm, legacy_rm) = tokio::join!(file_rm, legacy_rm);
|
||||
if let Err(e) = legacy_rm {
|
||||
if self.services.server.config.media_compat_file_link {
|
||||
debug_error!(?key, ?legacy, "Failed to remove legacy media symlink: {e}");
|
||||
}
|
||||
if let Err(e) = legacy_rm
|
||||
&& self.services.server.config.media_compat_file_link
|
||||
{
|
||||
debug_error!(?key, ?legacy, "Failed to remove legacy media symlink: {e}");
|
||||
}
|
||||
|
||||
Ok(file_rm?)
|
||||
|
||||
@@ -79,10 +79,10 @@ pub async fn get_url_preview(&self, url: &Url) -> Result<UrlPreviewData> {
|
||||
|
||||
#[implement(Service)]
|
||||
async fn request_url_preview(&self, url: &Url) -> Result<UrlPreviewData> {
|
||||
if let Ok(ip) = IPAddress::parse(url.host_str().expect("URL previously validated")) {
|
||||
if !self.services.client.valid_cidr_range(&ip) {
|
||||
return Err!(Request(Forbidden("Requesting from this address is forbidden")));
|
||||
}
|
||||
if let Ok(ip) = IPAddress::parse(url.host_str().expect("URL previously validated"))
|
||||
&& !self.services.client.valid_cidr_range(&ip)
|
||||
{
|
||||
return Err!(Request(Forbidden("Requesting from this address is forbidden")));
|
||||
}
|
||||
|
||||
let client = &self.services.client.url_preview;
|
||||
@@ -93,10 +93,10 @@ async fn request_url_preview(&self, url: &Url) -> Result<UrlPreviewData> {
|
||||
if let Some(remote_addr) = response.remote_addr() {
|
||||
debug!(?url, "URL preview response remote address: {:?}", remote_addr);
|
||||
|
||||
if let Ok(ip) = IPAddress::parse(remote_addr.ip().to_string()) {
|
||||
if !self.services.client.valid_cidr_range(&ip) {
|
||||
return Err!(Request(Forbidden("Requesting from this address is forbidden")));
|
||||
}
|
||||
if let Ok(ip) = IPAddress::parse(remote_addr.ip().to_string())
|
||||
&& !self.services.client.valid_cidr_range(&ip)
|
||||
{
|
||||
return Err!(Request(Forbidden("Requesting from this address is forbidden")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,12 +96,10 @@ pub async fn join(
|
||||
.services
|
||||
.state_accessor
|
||||
.get_member(room_id, sender_user)
|
||||
.await
|
||||
.await && membership.membership == MembershipState::Ban
|
||||
{
|
||||
if membership.membership == MembershipState::Ban {
|
||||
debug_warn!("{sender_user} is banned from {room_id} but attempted to join");
|
||||
return Err!(Request(Forbidden("You are banned from the room.")));
|
||||
}
|
||||
debug_warn!("{sender_user} is banned from {room_id} but attempted to join");
|
||||
return Err!(Request(Forbidden("You are banned from the room.")));
|
||||
}
|
||||
|
||||
let server_in_room = self
|
||||
@@ -249,57 +247,54 @@ pub async fn join_remote(
|
||||
);
|
||||
}
|
||||
|
||||
if join_authorized_via_users_server.is_some() {
|
||||
if let Some(signed_raw) = &response.event {
|
||||
debug_info!(
|
||||
"There is a signed event with join_authorized_via_users_server. This room is \
|
||||
probably using restricted joins. Adding signature to our event"
|
||||
);
|
||||
if join_authorized_via_users_server.is_some()
|
||||
&& let Some(signed_raw) = &response.event
|
||||
{
|
||||
debug_info!(
|
||||
"There is a signed event with join_authorized_via_users_server. This room is \
|
||||
probably using restricted joins. Adding signature to our event"
|
||||
);
|
||||
|
||||
let (signed_event_id, signed_value) =
|
||||
gen_event_id_canonical_json(signed_raw, &room_version_id).map_err(|e| {
|
||||
err!(Request(BadJson(warn!(
|
||||
"Could not convert event to canonical JSON: {e}"
|
||||
))))
|
||||
})?;
|
||||
let (signed_event_id, signed_value) =
|
||||
gen_event_id_canonical_json(signed_raw, &room_version_id).map_err(|e| {
|
||||
err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}"))))
|
||||
})?;
|
||||
|
||||
if signed_event_id != event_id {
|
||||
return Err!(Request(BadJson(warn!(
|
||||
%signed_event_id, %event_id,
|
||||
"Server {remote_server} sent event with wrong event ID"
|
||||
))));
|
||||
}
|
||||
if signed_event_id != event_id {
|
||||
return Err!(Request(BadJson(warn!(
|
||||
%signed_event_id, %event_id,
|
||||
"Server {remote_server} sent event with wrong event ID"
|
||||
))));
|
||||
}
|
||||
|
||||
match signed_value["signatures"]
|
||||
.as_object()
|
||||
.ok_or_else(|| {
|
||||
match signed_value["signatures"]
|
||||
.as_object()
|
||||
.ok_or_else(|| {
|
||||
err!(BadServerResponse(warn!(
|
||||
"Server {remote_server} sent invalid signatures type"
|
||||
)))
|
||||
})
|
||||
.and_then(|e| {
|
||||
e.get(remote_server.as_str()).ok_or_else(|| {
|
||||
err!(BadServerResponse(warn!(
|
||||
"Server {remote_server} sent invalid signatures type"
|
||||
"Server {remote_server} did not send its signature for a restricted room"
|
||||
)))
|
||||
})
|
||||
.and_then(|e| {
|
||||
e.get(remote_server.as_str()).ok_or_else(|| {
|
||||
err!(BadServerResponse(warn!(
|
||||
"Server {remote_server} did not send its signature for a restricted \
|
||||
room"
|
||||
)))
|
||||
})
|
||||
}) {
|
||||
| Ok(signature) => {
|
||||
join_event
|
||||
.get_mut("signatures")
|
||||
.expect("we created a valid pdu")
|
||||
.as_object_mut()
|
||||
.expect("we created a valid pdu")
|
||||
.insert(remote_server.as_str().into(), signature.clone());
|
||||
},
|
||||
| Err(e) => {
|
||||
warn!(
|
||||
"Server {remote_server} sent invalid signature in send_join signatures \
|
||||
for event {signed_value:?}: {e:?}",
|
||||
);
|
||||
},
|
||||
}
|
||||
}) {
|
||||
| Ok(signature) => {
|
||||
join_event
|
||||
.get_mut("signatures")
|
||||
.expect("we created a valid pdu")
|
||||
.as_object_mut()
|
||||
.expect("we created a valid pdu")
|
||||
.insert(remote_server.as_str().into(), signature.clone());
|
||||
},
|
||||
| Err(e) => {
|
||||
warn!(
|
||||
"Server {remote_server} sent invalid signature in send_join signatures for \
|
||||
event {signed_value:?}: {e:?}",
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,12 +83,10 @@ pub async fn knock(
|
||||
.services
|
||||
.state_accessor
|
||||
.get_member(room_id, sender_user)
|
||||
.await
|
||||
.await && membership.membership == MembershipState::Ban
|
||||
{
|
||||
if membership.membership == MembershipState::Ban {
|
||||
debug_warn!("{sender_user} is banned from {room_id} but attempted to knock");
|
||||
return Err!(Request(Forbidden("You cannot knock on a room you are banned from.")));
|
||||
}
|
||||
debug_warn!("{sender_user} is banned from {room_id} but attempted to knock");
|
||||
return Err!(Request(Forbidden("You cannot knock on a room you are banned from.")));
|
||||
}
|
||||
|
||||
let server_in_room = self
|
||||
|
||||
@@ -195,10 +195,10 @@ where
|
||||
.body(body);
|
||||
}
|
||||
|
||||
if let Some(session) = session {
|
||||
if let Some(access_token) = session.access_token.clone() {
|
||||
request = request.bearer_auth(access_token);
|
||||
}
|
||||
if let Some(session) = session
|
||||
&& let Some(access_token) = session.access_token.clone()
|
||||
{
|
||||
request = request.bearer_auth(access_token);
|
||||
}
|
||||
|
||||
let response: JsonValue = request
|
||||
|
||||
@@ -129,26 +129,22 @@ pub async fn delete(&self, sess_id: &str) {
|
||||
|
||||
// Check the user_id still points to this sess_id before deleting. If not, the
|
||||
// association was updated to a newer session.
|
||||
if let Some(user_id) = session.user_id.as_deref() {
|
||||
if let Ok(assoc_id) = self.get_sess_id_by_user(user_id).await {
|
||||
if assoc_id == sess_id {
|
||||
self.db.userid_oauthid.remove(user_id);
|
||||
}
|
||||
}
|
||||
if let Some(user_id) = session.user_id.as_deref()
|
||||
&& let Ok(assoc_id) = self.get_sess_id_by_user(user_id).await
|
||||
&& assoc_id == sess_id
|
||||
{
|
||||
self.db.userid_oauthid.remove(user_id);
|
||||
}
|
||||
|
||||
// Check the unique identity still points to this sess_id before deleting. If
|
||||
// not, the association was updated to a newer session.
|
||||
if let Some(idp_id) = session.idp_id.as_ref() {
|
||||
if let Ok(provider) = self.providers.get(idp_id).await {
|
||||
if let Ok(unique_id) = unique_id((&provider, &session)) {
|
||||
if let Ok(assoc_id) = self.get_sess_id_by_unique_id(&unique_id).await {
|
||||
if assoc_id == sess_id {
|
||||
self.db.oauthuniqid_oauthid.remove(&unique_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(idp_id) = session.idp_id.as_ref()
|
||||
&& let Ok(provider) = self.providers.get(idp_id).await
|
||||
&& let Ok(unique_id) = unique_id((&provider, &session))
|
||||
&& let Ok(assoc_id) = self.get_sess_id_by_unique_id(&unique_id).await
|
||||
&& assoc_id == sess_id
|
||||
{
|
||||
self.db.oauthuniqid_oauthid.remove(&unique_id);
|
||||
}
|
||||
|
||||
self.db.oauthid_session.remove(sess_id);
|
||||
@@ -166,14 +162,13 @@ pub async fn put(&self, sess_id: &str, session: &Session) {
|
||||
self.db.userid_oauthid.insert(user_id, sess_id);
|
||||
}
|
||||
|
||||
if let Some(idp_id) = session.idp_id.as_ref() {
|
||||
if let Ok(provider) = self.providers.get(idp_id).await {
|
||||
if let Ok(unique_id) = unique_id((&provider, session)) {
|
||||
self.db
|
||||
.oauthuniqid_oauthid
|
||||
.insert(&unique_id, sess_id);
|
||||
}
|
||||
}
|
||||
if let Some(idp_id) = session.idp_id.as_ref()
|
||||
&& let Ok(provider) = self.providers.get(idp_id).await
|
||||
&& let Ok(unique_id) = unique_id((&provider, session))
|
||||
{
|
||||
self.db
|
||||
.oauthuniqid_oauthid
|
||||
.insert(&unique_id, sess_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,17 +68,15 @@ pub(crate) async fn append_pdu(&self, pdu_id: RawPduId, pdu: &Pdu) -> Result {
|
||||
|
||||
let (mut push_target, power_levels) = join(push_target, power_levels).boxed().await;
|
||||
|
||||
if *pdu.kind() == TimelineEventType::RoomMember {
|
||||
if let Some(Ok(target_user_id)) = pdu.state_key().map(UserId::parse) {
|
||||
if self
|
||||
.services
|
||||
.users
|
||||
.is_active_local(target_user_id)
|
||||
.await
|
||||
{
|
||||
push_target.insert(target_user_id.to_owned());
|
||||
}
|
||||
}
|
||||
if *pdu.kind() == TimelineEventType::RoomMember
|
||||
&& let Some(Ok(target_user_id)) = pdu.state_key().map(UserId::parse)
|
||||
&& self
|
||||
.services
|
||||
.users
|
||||
.is_active_local(target_user_id)
|
||||
.await
|
||||
{
|
||||
push_target.insert(target_user_id.to_owned());
|
||||
}
|
||||
|
||||
let serialized = pdu.to_format();
|
||||
|
||||
@@ -110,12 +110,11 @@ pub async fn set_pusher(
|
||||
|
||||
if let Ok(ip) =
|
||||
IPAddress::parse(url.host_str().expect("URL previously validated"))
|
||||
&& !self.services.client.valid_cidr_range(&ip)
|
||||
{
|
||||
if !self.services.client.valid_cidr_range(&ip) {
|
||||
return Err!(Request(InvalidParam(
|
||||
warn!(%url, "HTTP pusher URL is a forbidden remote address")
|
||||
)));
|
||||
}
|
||||
return Err!(Request(InvalidParam(
|
||||
warn!(%url, "HTTP pusher URL is a forbidden remote address")
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ where
|
||||
let reqwest_request = reqwest::Request::try_from(http_request)?;
|
||||
if let Some(url_host) = reqwest_request.url().host_str() {
|
||||
trace!("Checking request URL for IP");
|
||||
if let Ok(ip) = IPAddress::parse(url_host) {
|
||||
if !self.services.client.valid_cidr_range(&ip) {
|
||||
return Err!(BadServerResponse("Not allowed to send requests to this IP"));
|
||||
}
|
||||
if let Ok(ip) = IPAddress::parse(url_host)
|
||||
&& !self.services.client.valid_cidr_range(&ip)
|
||||
{
|
||||
return Err!(BadServerResponse("Not allowed to send requests to this IP"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,14 +55,11 @@ where
|
||||
// reqwest::Response -> http::Response conversion
|
||||
|
||||
trace!("Checking response destination's IP");
|
||||
if let Some(remote_addr) = response.remote_addr() {
|
||||
if let Ok(ip) = IPAddress::parse(remote_addr.ip().to_string()) {
|
||||
if !self.services.client.valid_cidr_range(&ip) {
|
||||
return Err!(BadServerResponse(
|
||||
"Not allowed to send requests to this IP"
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(remote_addr) = response.remote_addr()
|
||||
&& let Ok(ip) = IPAddress::parse(remote_addr.ip().to_string())
|
||||
&& !self.services.client.valid_cidr_range(&ip)
|
||||
{
|
||||
return Err!(BadServerResponse("Not allowed to send requests to this IP"));
|
||||
}
|
||||
|
||||
let status = response.status();
|
||||
|
||||
@@ -104,12 +104,12 @@ async fn send_notice<Pdu: Event>(
|
||||
)));
|
||||
}
|
||||
|
||||
if let Ok(ip) = IPAddress::parse(url.host_str().expect("URL previously validated")) {
|
||||
if !self.services.client.valid_cidr_range(&ip) {
|
||||
return Err!(Request(InvalidParam(
|
||||
warn!(%url, "HTTP pusher URL is a forbidden remote address")
|
||||
)));
|
||||
}
|
||||
if let Ok(ip) = IPAddress::parse(url.host_str().expect("URL previously validated"))
|
||||
&& !self.services.client.valid_cidr_range(&ip)
|
||||
{
|
||||
return Err!(Request(InvalidParam(
|
||||
warn!(%url, "HTTP pusher URL is a forbidden remote address")
|
||||
)));
|
||||
}
|
||||
|
||||
// TODO (timo): can pusher/devices have conflicting formats
|
||||
|
||||
@@ -93,11 +93,11 @@ pub async fn witness_retain(&self, senders: Witness, ctx: &Context<'_>) -> Witne
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Status::Seen(seen) = status {
|
||||
if seen == 0 || ctx.token == Some(seen) {
|
||||
senders.insert(sender.into());
|
||||
continue;
|
||||
}
|
||||
if let Status::Seen(seen) = status
|
||||
&& (seen == 0 || ctx.token == Some(seen))
|
||||
{
|
||||
senders.insert(sender.into());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -500,10 +500,10 @@ fn get_space_child_events<'a>(
|
||||
.await
|
||||
})
|
||||
.ready_filter_map(|(state_key, pdu)| {
|
||||
if let Ok(content) = pdu.get_content::<SpaceChildEventContent>() {
|
||||
if content.via.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if let Ok(content) = pdu.get_content::<SpaceChildEventContent>()
|
||||
&& content.via.is_empty()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
if RoomId::parse(&state_key).is_err() {
|
||||
|
||||
@@ -113,34 +113,32 @@ where
|
||||
.services
|
||||
.state
|
||||
.pdu_shortstatehash(pdu.event_id())
|
||||
.await && let Ok(prev_state) = self
|
||||
.services
|
||||
.state_accessor
|
||||
.state_get(shortstatehash, &pdu.kind().to_string().into(), state_key)
|
||||
.await
|
||||
{
|
||||
if let Ok(prev_state) = self
|
||||
.services
|
||||
.state_accessor
|
||||
.state_get(shortstatehash, &pdu.kind().to_string().into(), state_key)
|
||||
.await
|
||||
{
|
||||
unsigned.insert(
|
||||
"prev_content".into(),
|
||||
CanonicalJsonValue::Object(
|
||||
utils::to_canonical_object(prev_state.get_content_as_value())
|
||||
.map_err(|e| {
|
||||
err!(Database(error!(
|
||||
"Failed to convert prev_state to canonical JSON: {e}",
|
||||
)))
|
||||
})?,
|
||||
),
|
||||
);
|
||||
unsigned.insert(
|
||||
"prev_sender".into(),
|
||||
CanonicalJsonValue::String(prev_state.sender().to_string()),
|
||||
);
|
||||
unsigned.insert(
|
||||
"replaces_state".into(),
|
||||
CanonicalJsonValue::String(prev_state.event_id().to_string()),
|
||||
);
|
||||
}
|
||||
unsigned.insert(
|
||||
"prev_content".into(),
|
||||
CanonicalJsonValue::Object(
|
||||
utils::to_canonical_object(prev_state.get_content_as_value()).map_err(
|
||||
|e| {
|
||||
err!(Database(error!(
|
||||
"Failed to convert prev_state to canonical JSON: {e}",
|
||||
)))
|
||||
},
|
||||
)?,
|
||||
),
|
||||
);
|
||||
unsigned.insert(
|
||||
"prev_sender".into(),
|
||||
CanonicalJsonValue::String(prev_state.sender().to_string()),
|
||||
);
|
||||
unsigned.insert(
|
||||
"replaces_state".into(),
|
||||
CanonicalJsonValue::String(prev_state.event_id().to_string()),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
error!("Invalid unsigned type in pdu.");
|
||||
@@ -222,30 +220,28 @@ async fn append_pdu_effects(
|
||||
|
||||
match room_version_id {
|
||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
|
||||
if let Some(redact_id) = pdu.redacts() {
|
||||
if self
|
||||
if let Some(redact_id) = pdu.redacts()
|
||||
&& self
|
||||
.services
|
||||
.state_accessor
|
||||
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
|
||||
.await?
|
||||
{
|
||||
self.redact_pdu(redact_id, pdu, shortroomid)
|
||||
.await?;
|
||||
}
|
||||
{
|
||||
self.redact_pdu(redact_id, pdu, shortroomid)
|
||||
.await?;
|
||||
}
|
||||
},
|
||||
| _ => {
|
||||
let content: RoomRedactionEventContent = pdu.get_content()?;
|
||||
if let Some(redact_id) = &content.redacts {
|
||||
if self
|
||||
if let Some(redact_id) = &content.redacts
|
||||
&& self
|
||||
.services
|
||||
.state_accessor
|
||||
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
|
||||
.await?
|
||||
{
|
||||
self.redact_pdu(redact_id, pdu, shortroomid)
|
||||
.await?;
|
||||
}
|
||||
{
|
||||
self.redact_pdu(redact_id, pdu, shortroomid)
|
||||
.await?;
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -317,15 +313,14 @@ async fn append_pdu_effects(
|
||||
| _ => {},
|
||||
}
|
||||
|
||||
if let Ok(content) = pdu.get_content::<ExtractRelatesToEventId>() {
|
||||
if let Ok(related_pducount) = self
|
||||
if let Ok(content) = pdu.get_content::<ExtractRelatesToEventId>()
|
||||
&& let Ok(related_pducount) = self
|
||||
.get_pdu_count(&content.relates_to.event_id)
|
||||
.await
|
||||
{
|
||||
self.services
|
||||
.pdu_metadata
|
||||
.add_relation(count, related_pducount);
|
||||
}
|
||||
{
|
||||
self.services
|
||||
.pdu_metadata
|
||||
.add_relation(count, related_pducount);
|
||||
}
|
||||
|
||||
if let Ok(content) = pdu.get_content::<ExtractRelatesTo>() {
|
||||
|
||||
@@ -70,28 +70,26 @@ pub async fn build_and_append_pdu(
|
||||
.await?
|
||||
{
|
||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
|
||||
if let Some(redact_id) = pdu.redacts() {
|
||||
if !self
|
||||
if let Some(redact_id) = pdu.redacts()
|
||||
&& !self
|
||||
.services
|
||||
.state_accessor
|
||||
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
|
||||
.await?
|
||||
{
|
||||
return Err!(Request(Forbidden("User cannot redact this event.")));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden("User cannot redact this event.")));
|
||||
}
|
||||
},
|
||||
| _ => {
|
||||
let content: RoomRedactionEventContent = pdu.get_content()?;
|
||||
if let Some(redact_id) = &content.redacts {
|
||||
if !self
|
||||
if let Some(redact_id) = &content.redacts
|
||||
&& !self
|
||||
.services
|
||||
.state_accessor
|
||||
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
|
||||
.await?
|
||||
{
|
||||
return Err!(Request(Forbidden("User cannot redact this event.")));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden("User cannot redact this event.")));
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -155,14 +153,13 @@ pub async fn build_and_append_pdu(
|
||||
|
||||
// In case we are kicking or banning a user, we need to inform their server of
|
||||
// the change
|
||||
if *pdu.kind() == TimelineEventType::RoomMember {
|
||||
if let Some(state_key_uid) = &pdu
|
||||
if *pdu.kind() == TimelineEventType::RoomMember
|
||||
&& let Some(state_key_uid) = &pdu
|
||||
.state_key
|
||||
.as_ref()
|
||||
.and_then(|state_key| UserId::parse(state_key.as_str()).ok())
|
||||
{
|
||||
servers.insert(state_key_uid.server_name().to_owned());
|
||||
}
|
||||
{
|
||||
servers.insert(state_key_uid.server_name().to_owned());
|
||||
}
|
||||
|
||||
// Remove our server from the server list since it will be added to it by
|
||||
|
||||
@@ -100,18 +100,16 @@ pub async fn create_hash_and_sign_event(
|
||||
.saturating_add(uint!(1));
|
||||
|
||||
let mut unsigned = unsigned.unwrap_or_default();
|
||||
if let Some(state_key) = &state_key {
|
||||
if let Ok(prev_pdu) = self
|
||||
if let Some(state_key) = &state_key
|
||||
&& let Ok(prev_pdu) = self
|
||||
.services
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &event_type.to_string().into(), state_key)
|
||||
.await
|
||||
{
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.get_content_as_value());
|
||||
unsigned.insert("prev_sender".to_owned(), serde_json::to_value(prev_pdu.sender())?);
|
||||
unsigned
|
||||
.insert("replaces_state".to_owned(), serde_json::to_value(prev_pdu.event_id())?);
|
||||
}
|
||||
{
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.get_content_as_value());
|
||||
unsigned.insert("prev_sender".to_owned(), serde_json::to_value(prev_pdu.sender())?);
|
||||
unsigned.insert("replaces_state".to_owned(), serde_json::to_value(prev_pdu.event_id())?);
|
||||
}
|
||||
|
||||
let unsigned = unsigned
|
||||
|
||||
@@ -31,12 +31,12 @@ pub async fn redact_pdu<Pdu: Event + Send + Sync>(
|
||||
err!(Database(error!(?pdu_id, ?event_id, ?e, "PDU ID points to invalid PDU.")))
|
||||
})?;
|
||||
|
||||
if let Ok(content) = pdu.get_content::<ExtractBody>() {
|
||||
if let Some(body) = content.body {
|
||||
self.services
|
||||
.search
|
||||
.deindex_pdu(shortroomid, &pdu_id, &body);
|
||||
}
|
||||
if let Ok(content) = pdu.get_content::<ExtractBody>()
|
||||
&& let Some(body) = content.body
|
||||
{
|
||||
self.services
|
||||
.search
|
||||
.deindex_pdu(shortroomid, &pdu_id, &body);
|
||||
}
|
||||
|
||||
let room_version_id = self
|
||||
|
||||
@@ -325,15 +325,15 @@ impl Service {
|
||||
}
|
||||
|
||||
// Add EDU's into the transaction
|
||||
if let Destination::Federation(server_name) = dest {
|
||||
if let Ok((select_edus, last_count)) = self.select_edus(server_name).await {
|
||||
debug_assert!(select_edus.len() <= EDU_LIMIT, "exceeded edus limit");
|
||||
let select_edus = select_edus.into_iter().map(SendingEvent::Edu);
|
||||
if let Destination::Federation(server_name) = dest
|
||||
&& let Ok((select_edus, last_count)) = self.select_edus(server_name).await
|
||||
{
|
||||
debug_assert!(select_edus.len() <= EDU_LIMIT, "exceeded edus limit");
|
||||
let select_edus = select_edus.into_iter().map(SendingEvent::Edu);
|
||||
|
||||
events.extend(select_edus);
|
||||
self.db
|
||||
.set_latest_educount(server_name, last_count);
|
||||
}
|
||||
events.extend(select_edus);
|
||||
self.db
|
||||
.set_latest_educount(server_name, last_count);
|
||||
}
|
||||
|
||||
Ok(Some(events))
|
||||
@@ -735,12 +735,11 @@ impl Service {
|
||||
}
|
||||
},
|
||||
| SendingEvent::Edu(edu) =>
|
||||
if appservice.receive_ephemeral {
|
||||
if let Ok(edu) =
|
||||
if appservice.receive_ephemeral
|
||||
&& let Ok(edu) =
|
||||
serde_json::from_slice(edu).and_then(|edu| Raw::new(&edu))
|
||||
{
|
||||
edu_jsons.push(edu);
|
||||
}
|
||||
{
|
||||
edu_jsons.push(edu);
|
||||
},
|
||||
| SendingEvent::Flush => {}, // flush only; no new content
|
||||
}
|
||||
|
||||
@@ -82,31 +82,28 @@ pub async fn get_verify_key(
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
if notary_first {
|
||||
if let Ok(result) = self
|
||||
if notary_first
|
||||
&& let Ok(result) = self
|
||||
.get_verify_key_from_notaries(origin, key_id)
|
||||
.await
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
if !notary_only {
|
||||
if let Ok(result) = self
|
||||
if !notary_only
|
||||
&& let Ok(result) = self
|
||||
.get_verify_key_from_origin(origin, key_id)
|
||||
.await
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
if !notary_first {
|
||||
if let Ok(result) = self
|
||||
if !notary_first
|
||||
&& let Ok(result) = self
|
||||
.get_verify_key_from_notaries(origin, key_id)
|
||||
.await
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
Err!(BadServerResponse(debug_error!(
|
||||
|
||||
@@ -141,16 +141,16 @@ pub async fn verify_key_exists(&self, origin: &ServerName, key_id: &ServerSignin
|
||||
return false;
|
||||
};
|
||||
|
||||
if let Ok(Some(verify_keys)) = keys.get_field::<KeysMap<'_>>("verify_keys") {
|
||||
if verify_keys.contains_key(key_id) {
|
||||
return true;
|
||||
}
|
||||
if let Ok(Some(verify_keys)) = keys.get_field::<KeysMap<'_>>("verify_keys")
|
||||
&& verify_keys.contains_key(key_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Ok(Some(old_verify_keys)) = keys.get_field::<KeysMap<'_>>("old_verify_keys") {
|
||||
if old_verify_keys.contains_key(key_id) {
|
||||
return true;
|
||||
}
|
||||
if let Ok(Some(old_verify_keys)) = keys.get_field::<KeysMap<'_>>("old_verify_keys")
|
||||
&& old_verify_keys.contains_key(key_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
|
||||
@@ -247,10 +247,10 @@ pub fn store(&self, service: &Service, key: &ConnectionKey) {
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub fn update_rooms_prologue(&mut self, retard_since: Option<u64>) {
|
||||
self.rooms.values_mut().for_each(|room| {
|
||||
if let Some(retard_since) = retard_since {
|
||||
if room.roomsince > retard_since {
|
||||
room.roomsince = retard_since;
|
||||
}
|
||||
if let Some(retard_since) = retard_since
|
||||
&& room.roomsince > retard_since
|
||||
{
|
||||
room.roomsince = retard_since;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,16 +117,16 @@ pub async fn try_auth(
|
||||
#[cfg(feature = "ldap")]
|
||||
if !password_verified && self.services.server.config.ldap.enable {
|
||||
// Search for user in LDAP to get their DN
|
||||
if let Ok(dns) = self.services.users.search_ldap(&user_id).await {
|
||||
if let Some((user_dn, _is_admin)) = dns.first() {
|
||||
// Try to authenticate with LDAP
|
||||
password_verified = self
|
||||
.services
|
||||
.users
|
||||
.auth_ldap(user_dn, password)
|
||||
.await
|
||||
.is_ok();
|
||||
}
|
||||
if let Ok(dns) = self.services.users.search_ldap(&user_id).await
|
||||
&& let Some((user_dn, _is_admin)) = dns.first()
|
||||
{
|
||||
// Try to authenticate with LDAP
|
||||
password_verified = self
|
||||
.services
|
||||
.users
|
||||
.auth_ldap(user_dn, password)
|
||||
.await
|
||||
.is_ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,10 +113,10 @@ pub(super) async fn remove_dehydrated_device(
|
||||
return Err!(Request(NotFound("No dehydrated device for this user.")));
|
||||
};
|
||||
|
||||
if let Some(maybe_device_id) = maybe_device_id {
|
||||
if maybe_device_id != device_id {
|
||||
return Err!(Request(NotFound("Not the user's dehydrated device.")));
|
||||
}
|
||||
if let Some(maybe_device_id) = maybe_device_id
|
||||
&& maybe_device_id != device_id
|
||||
{
|
||||
return Err!(Request(NotFound("Not the user's dehydrated device.")));
|
||||
}
|
||||
|
||||
self.db.userid_dehydrateddevice.remove(user_id);
|
||||
|
||||
Reference in New Issue
Block a user