[MOD] Be stringent about OIDs, use fmemopen

This commit is contained in:
LDA 2024-08-29 15:31:11 +02:00
commit 3366fcb759
8 changed files with 76 additions and 122 deletions

View file

@ -186,6 +186,10 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
jid = ParseeLookupJID(from);
from_matrix = ParseeGetBridgedUser(args, stanza);
Log(LOG_DEBUG,
"Setting the avatar of '%s' to %s",
from_matrix, mxc
);
ASSetAvatar(args->config, from_matrix, mxc);
Free(mxc);
@ -224,12 +228,13 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
/* Get the base64, decode it, and shove it in a nicely put
* MXC address */
base64 = data->data;
base64 = TrimBase64(data->data);
b64len = base64 ? strlen(base64) : 0;
length = Base64DecodedSize(base64, b64len);
bdata = Base64Decode(base64, b64len);
datastream = StrStreamReaderN(bdata, length);
Log(LOG_DEBUG, "(%dB @ %p) = %p (%d)", b64len, base64, bdata, length);
mxc = ASUpload(
args->config,
datastream,
@ -237,6 +242,7 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
tdata ? tdata->data : NULL
);
Free(bdata);
Free(base64);
StreamClose(datastream);
room = ParseeGetBridgedRoom(args, stanza);
@ -247,8 +253,27 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
/* TODO: More reliable system for telling the difference appart */
if (jid && !StrEquals(from, resource))
{
from_matrix = ParseeGetBridgedUserI(args, stanza, jid);
char *oid = ParseeLookupOID(jid);
char *hsh = ParseeSHA256(oid);
bool scrambled =
oid && StrEquals(jid, HashMapGet(stanza->attrs, "from"));
from_matrix = scrambled
? ScrambleOID(args, oid)
: ParseeGetBridgedUser(args, stanza);
Log(LOG_DEBUG,
"Setting the vCard of '%s'(%s) to %s (%d B)",
from_matrix, jid, mxc,
length
);
Log(LOG_DEBUG,
"OID=%s[%s]",
oid, hsh
);
ASSetAvatar(args->config, from_matrix, mxc);
Free(oid);
Free(hsh);
}
else if (room)
{

View file

@ -88,14 +88,33 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
from = NULL;
decode_from = NULL;
from_matrix = NULL;
Log(LOG_DEBUG, "<message> usage=%d", MemoryAllocated());
from = HashMapGet(stanza->attrs, "from");
if (ParseeManageBan(args, from, NULL))
{
XMLFreeElement(stanza);
Log(LOG_DEBUG, "<message/> usage=%d (%s:%d)", MemoryAllocated(), __FILE__, __LINE__);
return false;
}
if (ServerHasXEP421(args, from))
{
XMLElement *occupant = XMLookForTKV(
stanza, "occupant-id",
"xmlns", "urn:xmpp:occupant-id:0"
);
char *occ_id = occupant ? HashMapGet(occupant->attrs, "id") : NULL;
if (occ_id)
{
Log(LOG_DEBUG,
"'%s' has support for XEP-421, fetching OID=%s",
from, occ_id
);
ParseePushOIDTable(from, occ_id);
}
}
if (StrEquals(type, "error"))
{
char *type, *text, *user, *parsee;
@ -132,6 +151,7 @@ end_error:
Free(parsee);
Free(room);
Free(user);
Log(LOG_DEBUG, "<message/> usage=%d (%s:%d)", MemoryAllocated(), __FILE__, __LINE__);
return false;
}
@ -402,6 +422,7 @@ end:
Free(decode_from);
Free(room);
Free(to);
Log(LOG_DEBUG, "<message/> usage=%d (%s:%d)", MemoryAllocated(), __FILE__, __LINE__);
return true;
}

View file

@ -63,8 +63,26 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
XMLElement *user_info;
XMLElement *vc = XMLookForTKV(stanza, "x", "xmlns", "vcard-temp:x:update");
XMLElement *status = XMLookForUnique(stanza, "status");
char *oid = HashMapGet(stanza->attrs, "from");
if (ServerHasXEP421(args, oid))
{
XMLElement *occupant = XMLookForTKV(
stanza, "occupant-id",
"xmlns", "urn:xmpp:occupant-id:0"
);
char *occ_id = occupant ? HashMapGet(occupant->attrs, "id") : NULL;
if (occ_id)
{
Log(LOG_DEBUG,
"'%s' has support for XEP-421, fetching OID=%s",
oid, occ_id
);
ParseePushOIDTable(oid, occ_id);
}
}
if ((user_info = XMLookForTKV(stanza, "x", "xmlns", MUC_USER_NS)))
{
XMLElement *item = XMLookForUnique(user_info, "item");
@ -259,7 +277,7 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
{
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
{
Log(LOG_DEBUG,
Log(LOG_WARNING,
"VCard: %s is already cached for %s", avatar_id, oid
);
}
@ -267,10 +285,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
return;
}
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
{
Log(LOG_DEBUG, "VCard: %s for %s", p_dat->data, oid);
}
JsonValueFree(JsonSet(
json, JsonValueString(p_dat->data),
1, oid)
@ -279,6 +293,9 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
from = ParseeJID(args);
Log(LOG_DEBUG,
"Sending a vCard avatar request for %s(=%s)", oid, p_dat->data
);
vcard_request = CreateVCardRequest(
from, HashMapGet(stanza->attrs, "from")
);