1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-08 10:03:13 +02:00

Use generic numeric 531 (ERR_CANTSENDTOUSER) for all such cases and use hook

CAN_SEND_TO_USER rather than HOOKTYPE_PRE_USERMSG (which is now removed).

As for the numeric change: this makes it much easier for client devs.
You rarely need to differentiate in the client code between the various
causes. One only cares about detecting that the message was not sent and
that the user needs to be informed.
This replaces various NOTICEs, ERR_NOCTCP, ERR_NONONREG etc. with just the
new numeric 531, which is taken from InspIRCd. The syntax is:
:server 531 yourname targetname :reason for the block
This makes it similar to numeric 404 (ERR_CANNOTSENDTOCHAN) that is used to
indicate that a channel message was blocked.

For module devs, the new hook CAN_SEND_TO_USER prototype is:
int hooktype_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice);
You can replace the text via this, by setting *text in your function.
You can block the message, by returning HOOK_DENY. If doing so, then
you must also set *errmsg to an appropriate value.
Do not send any error message to the user! UnrealIRCd will take care of
sending the error message for you, if you set *errmsg.
Only if you need something special you could violate this rule, but
preferably not!

As you can see, CAN_SEND_TO_USER works just like CAN_SEND_TO_CHANNEL.
This commit is contained in:
Bram Matthys
2019-10-05 12:27:49 +02:00
parent 4a59e66af2
commit 2eecf4f2da
16 changed files with 297 additions and 244 deletions
+10 -17
View File
@@ -36,13 +36,13 @@ ModuleHeader MOD_HEADER
long UMODE_SECUREONLYMSG = 0L;
/* Forward declarations */
char *secureonlymsg_pre_usermsg(Client *client, Client *target, char *text, int notice);
int secureonlymsg_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice);
MOD_INIT()
{
UmodeAdd(modinfo->handle, 'Z', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_SECUREONLYMSG);
HookAddPChar(modinfo->handle, HOOKTYPE_PRE_USERMSG, 0, secureonlymsg_pre_usermsg);
HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, secureonlymsg_can_send_to_user);
MARK_AS_OFFICIAL_MODULE(modinfo);
return MOD_SUCCESS;
@@ -58,36 +58,29 @@ MOD_UNLOAD()
return MOD_SUCCESS;
}
char *secureonlymsg_pre_usermsg(Client *client, Client *target, char *text, int notice)
int secureonlymsg_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice)
{
if (IsSecureOnlyMsg(target) && !IsServer(client) && !IsULine(client) && !IsSecureConnect(client))
{
if (ValidatePermissionsForPath("client:override:message:secureonlymsg",client,target,NULL,text))
return text; /* TODO: this is actually an override */
return HOOK_CONTINUE; /* bypass this restriction */
/* A numeric is preferred to indicate the user cannot message.
* 492 is ERR_NOCTCP but apparently is also used by some other ircd(s) as a
* general "cannot send message" numeric (similar to the generic
* ERR_CANNOTSENDTOCHAN for channel messaging).
*/
sendto_one(client, NULL, ":%s 492 %s :Cannot send to user %s (You must be connected via SSL/TLS to message this user)",
me.name, client->name, target->name);
return NULL; /* Block the message */
*errmsg = "You must be connected via SSL/TLS to message this user";
return HOOK_DENY;
} else
if (IsSecureOnlyMsg(client) && !IsSecureConnect(target) && !IsULine(target))
{
if (ValidatePermissionsForPath("client:override:message:secureonlymsg",client,target,NULL,text))
return text; /* TODO: this is actually an override */
return HOOK_CONTINUE; /* bypass this restriction */
/* Similar to above but in this case we are +Z and are trying to message
* an SSL user (who does not have +Z set, note the 'else'). This does not
* make sense since they could never message back to us. Better block the
* message than leave the user confused.
*/
sendto_one(client, NULL, ":%s 492 %s :Cannot send to user %s (You have user mode +Z set but are not connected via SSL/TLS)",
me.name, client->name, target->name);
*errmsg = "Recipient is not connected via SSL/TLS and you are +Z";
return HOOK_DENY;
}
return text;
return HOOK_CONTINUE;
}