Skip to content

Commit

Permalink
nets: Fix MSP IRC username and hostmask.
Browse files Browse the repository at this point in the history
Prefix "MSP/" to usernames for MSP-injected
messages to IRC, to clearly differentiate the
source of these messages. Also, use the IP
address directly for the hostname part of
the hostmask.
  • Loading branch information
InterLinked1 committed Nov 27, 2023
1 parent a6b7512 commit f306e82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions nets/net_irc.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,12 @@ int _irc_relay_send(const char *channel, enum channel_user_modes modes, const ch

/* If something specific specified, use the override, otherwise use the same thing.
* This allows relay modules to customize the hostmask if they want. */
hostsender = S_OR(hostsender, sender);
snprintf(hostname, sizeof(hostname), "%s/%s", relayname, hostsender);
if (!strlen_zero(hostsender)) {
/* We were provided a hostname/IP address directly for this part that we can use. */
safe_strncpy(hostname, hostsender, sizeof(hostname));
} else {
snprintf(hostname, sizeof(hostname), "%s/%s", relayname, sender);
}

/* It's not our job to filter messages, clients can do that. For example, decimal 1 is legitimate for CTCP commands. */

Expand Down
5 changes: 3 additions & 2 deletions nets/net_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ static int strnsep(const char **restrict var, char **restrict buf, size_t *restr
if (!*len) {
*buf = NULL; /* There is nothing more to read, that's the end of the buffer */
}
bbs_debug(4, "Parsed token '%s'\n", *var);
return 0;
}
if (!*len) {
Expand Down Expand Up @@ -280,9 +279,11 @@ static int handle_msp(struct msp *restrict msp, const char *ip)
} else {
/* Directed to a particular user (or channel). */
if (!isalpha(*msp->recip)) {
char nativenick[64];
/* Begins with a non-numeric character.
* Assume it's the name of an IRC channel. */
res = irc_relay_send(msp->recip, CHANNEL_USER_MODE_NONE, "MSP", msp->sender, NULL, msp->message, NULL);
snprintf(nativenick, sizeof(nativenick), "%s/%s", "MSP", msp->sender);
res = irc_relay_send(msp->recip, CHANNEL_USER_MODE_NONE, "MSP", nativenick, ip, msp->message, NULL);
if (res) {
MSP_ERROR(msp, "Channel does not exist");
return -1;
Expand Down

0 comments on commit f306e82

Please sign in to comment.