[ADD/UNTESTED] Finalise step 5.2 of auth rules.
Some checks are pending
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Waiting to run

Next up is the invite membership(5.3).
This commit is contained in:
lda 2024-05-15 09:02:09 +02:00
parent 50759a3298
commit aec71d8d32

View file

@ -220,6 +220,26 @@ RoomStateGetID(Room * room, char *event_id)
JsonFree(name); \
} \
return ret
static bool
RoomIsJoinRule(Room * room, char *e_id, char *jr)
{
HashMap *state_point;
HashMap *joinrule = NULL;
char *id_joinrule = NULL;
bool ret = false;
if (!room || !e_id || !jr)
{
return false;
}
PrepareState(room, e_id, "m.room.join_rules", "", joinrule);
ret = StrEquals(
JsonValueAsString(JsonGet(joinrule, 1, "join_rule")),
jr);
finish:
FinishState(joinrule);
}
/* Verifies if user has a specific membership before [e_id] in the room. */
static bool
RoomUserHasMembership(Room * room, char *e_id, char *user, char *mbr)
@ -577,6 +597,14 @@ AuthoriseAliasV1(PduV1 pdu)
return true;
}
static bool
AuthorizeInviteMembershipV1(Room * room, PduV1 pdu)
{
/* TODO */
(void) room;
(void) pdu;
return false;
}
static bool
AuthorizeJoinMembershipV1(Room * room, PduV1 pdu)
{
/* Step 5.2.1: If the only previous event is an m.room.create and the
@ -609,10 +637,24 @@ AuthorizeJoinMembershipV1(Room * room, PduV1 pdu)
return false;
}
/* Step 5.2.3: If the sender is banned, reject. */
/* TODO */
if (RoomUserHasMembership(room, pdu.event_id, pdu.sender, "ban"))
{
return false;
}
/* Step 5.2.4: If the join_rule is invite then allow if membership
* state is invite or join. */
if (RoomIsJoinRule(room, pdu.event_id, "invite") &&
(RoomUserHasMembership(room, pdu.event_id, pdu.sender, "invite") ||
RoomUserHasMembership(room, pdu.event_id, pdu.sender, "join")))
{
return true;
}
/* Step 5.2.5: If the join_rule is public, allow. */
if (RoomIsJoinRule(room, pdu.event_id, "public"))
{
return true;
}
/* Step 5.2.6: Otherwise, reject. */
return false;
}
@ -644,9 +686,12 @@ AuthoriseMemberV1(Room * room, PduV1 pdu)
/* Step 5.2: If membership is join. */
JumpIfMembership("join", AuthorizeJoinMembershipV1);
/* Step 5.3: If membership is invite. */
JumpIfMembership("invite", AuthorizeInviteMembershipV1);
/* Step 4.3: Otherwise, allow. */
return true;
/* Step 5.6: Otherwise, the membership is unknown. Reject. */
return false;
#undef JumpIfMembership
}
static bool