[ADD] MUC whitelists, part II

This commit is contained in:
LDA 2024-09-28 15:58:41 +02:00
commit 0b00a665bf
5 changed files with 48 additions and 3 deletions

View file

@ -30,7 +30,9 @@ and speeds up Parsee a tad bit.
- Start dealing with some basic PEP-based avatars.
- Allows MbedTLS through a specific Cytoplasm patch.
- Kicking/Banning Parsee from XMPP effectively unlinks it.
- Start adding documentation to Parsee;
- Start adding documentation to Parsee
- Add MUC whitelists for plumbing, alongside a `whitelist` tool
#### Bugfixes
- Adds more information to media events so that clients can
behave.

View file

@ -24,7 +24,8 @@ CommandHead(CmdPlumb, cmd, argp)
BotRequired(room);
/* Check MUC viability */
if (ParseeManageBan(args->data, muc, NULL))
if (ParseeManageBan(args->data, muc, NULL) ||
ParseeIsMUCWhitelisted(args->data, muc))
{
ReplySprintf("MUC '%s' is not allowed on this bridge.", muc);
goto end;

View file

@ -7,6 +7,7 @@
#include <Cytoplasm/Str.h>
#include <stdlib.h>
#include <string.h>
#include <Routes.h>
#include <AS.h>
@ -573,3 +574,37 @@ ParseeUnlinkRoom(ParseeData *data, char *chat_id)
Free(muc);
Free(room);
}
bool
ParseeIsMUCWhitelisted(ParseeData *data, char *muc)
{
char *server, *serv_start;
DbRef *ref;
bool ret;
if (!data || !muc)
{
return false;
}
if (!DbExists(data->db, 1, "whitelist"))
{
return true;
}
serv_start = strchr(muc, '@');
serv_start = serv_start ? serv_start : muc;
server = StrDuplicate(serv_start + 1);
if (strchr(server, '/'))
{
*(strchr(server, '/')) = '\0';
}
ref = DbLockIntent(data->db,
DB_HINT_READONLY,
1, "whitelist"
);
ret = HashMapGet(DbJson(ref), server);
DbUnlock(data->db, ref);
Free(server);
return ret;
}

View file

@ -67,7 +67,8 @@ RouteHead(RouteRoomAck, arr, argp)
}
muc = ParseeDecodeLocalMUC(args->data->config, room);
if (ParseeManageBan(args->data, muc, NULL))
if (ParseeManageBan(args->data, muc, NULL) ||
ParseeIsMUCWhitelisted(args->data, muc))
{
HttpResponseStatus(args->ctx, HTTP_METHOD_NOT_ALLOWED);
response = MatrixCreateError(

View file

@ -420,4 +420,10 @@ extern void ParseeBroadcastStanza(ParseeData *data, char *from, XMLElement *s);
* Returns: NOTHING */
extern void ParseeUnlinkRoom(ParseeData *data, char *chat_id);
/** Verifies if there is no whitelists OR that a MUC's server is whitelisted.
* ----------------------
* Returns: if a MUC is to be allowed
* Modifies: NOTHING */
extern bool ParseeIsMUCWhitelisted(ParseeData *data, char *muc);
#endif