Skip to content

Commit

Permalink
net_irc: Add private namespace channels to prevent relay collisions.
Browse files Browse the repository at this point in the history
Add the ability for channels to exist in a "private"
per-user namespace, which allows a channel to be restricted
to a single user. This is mostly useful in conjunction
with private relays, to ensure that the channel is automatically
access restricted and also to prevent channel naming conflicts
between users/relays, since each such channel is unique by user,
thus avoiding naming collisions.

This extends the modeless channel prefix '+' for this purpose;
we still honor the modeless property of the channel, since modes
are not useful for private namespace channels.
  • Loading branch information
InterLinked1 committed Feb 4, 2024
1 parent 5d37a96 commit 731862c
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 51 deletions.
8 changes: 5 additions & 3 deletions configs/mod_slack.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ cookie_ds=
; If this user is on IRC but not in a relayed channel, the user will be automatically invited to channels with activity.
; Messages posted from IRC will not be tagged with your username, so they will appear to be coming from you
; (generally, it is appropriate to use a user token with this feature, as opposed to a bot token).
; Access to the channel itself is not inherently restricted, but other users cannot post over the relay (though they can to the IRC side),
; Access to the channel itself is not inherently restricted by default, but other users cannot post over the relay (though they can to the IRC side),
; and if other members are present in the channel when a message is posted, they will be kicked.
; If you need to totally restrict access to the IRC channel, you will need to use ChanServ or the appropriate channel modes.
; For example, the channel topic, if set on Slack, will be set as the IRC channel's topic, and is not private.
; Additionally, since personal relays don't generally make sense to share between IRC users, it is recommended that
; you use the local channel prefix (&) instead of the network channel prefix (#).
; you use the modeless channel prefix (+) instead of the network channel prefix (#). +-prefixed channels in LBBS are "private namespace channels".
; These are treated specially in that the IRC channel exists in a namespace private to the specified user, so access is automatically restricted.
; It also prevents naming conflicts since the channels exist in separate namespaces; the channel +test for two different users refers to two different channels.
; If you do not use the + channel prefix, you can manually restrict channel access by normal mechanisms, e.g. using ChanServ or the appropriate channel modes.
;preservethreading=no ; If the first word of a message relayed from IRC to Slack consists of a thread ID followed by a colon,
; then that message will be replied to "in thread" (without the thread ID prefixed). This allows transparently preserving Slack threading from IRC.
; Default is 'no'.
Expand Down
16 changes: 15 additions & 1 deletion include/net_irc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
#define PRIVATE_CHANNEL_PREFIX "*"
#define SECRET_CHANNEL_PREFIX "@"

/*! \brief RFC 2811 channel names namespace */
/*! \note There is no real support for &, +, and ! channels, as defined in the RFC; these are just defined here for completeness.
* Consequently, we hijack + (modeless channels) for private namespace channels (separate namespace per user),
* since we don't need modes for these anyways, and there's not much use for modeless channels otherwise.
* We can't use some other arbitrary prefix because IRC clients will just prefix # automatically
* if the channel name doesn't begin with one of the officially valid prefixes. */
/* "Standard" channels */
#define CHANNEL_NAME_PREFIX_NETWORK "#"
#define CHANNEL_NAME_PREFIX_LOCAL "&"
#define CHANNEL_NAME_PREFIX_MODELESS "+"
/* "Safe" channels */
#define CHANNEL_NAME_PREFIX_TIMESTAMPED "!"

#define PREFIX_FOUNDER "~"
#define PREFIX_ADMIN "&"
#define PREFIX_OP "@"
Expand Down Expand Up @@ -164,9 +177,10 @@ int _irc_relay_send(const char *channel, enum channel_user_modes modes, const ch
* \brief Set the channel topic (from a relay)
* \param channel Channel name
* \param topic Topic description
* \param ircuser Name of owner, for private namespace channels
* \retval 0 on success, -1 on failure
*/
int irc_relay_set_topic(const char *channel, const char *topic);
int irc_relay_set_topic(const char *channel, const char *topic, const char *ircuser);

#define irc_relay_raw_send(channel, msg) _irc_relay_raw_send(channel, msg, BBS_MODULE_SELF)

Expand Down
2 changes: 1 addition & 1 deletion modules/mod_auth_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static int make_user(const char *username, const char *password, const char *ful
}

/*! \note Sysop can always manually adjust the database if needed to override */
#define USERNAME_RESERVED(u) (!strcasecmp(u, "root") || !strcasecmp(u, "sysop") || !strcasecmp(u, "bbs") || !strcasecmp(u, "ChanServ") || !strcasecmp(u, "NickServ") || !strcasecmp(u, "services") || !strcasecmp(u, "postmaster"))
#define USERNAME_RESERVED(u) (!strcasecmp(u, "root") || !strcasecmp(u, "sysop") || !strcasecmp(u, "bbs") || !strcasecmp(u, "ChanServ") || !strcasecmp(u, "NickServ") || !strcasecmp(u, "MessageServ") || !strcasecmp(u, "services") || !strcasecmp(u, "postmaster") || !strcasecmp(u, "newsmaster") || !strcasecmp(u, "anonymous"))

static int username_reserved(const char *username)
{
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_slack.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ static int slack_send(struct irc_relay_message *rmsg)
if (!strlen_zero(cp->topic)) { /* The first time anybody joins, set the channel topic */
cp->used = 1; /* Only need to do this once */
/* XXX Note: Since anyone can join the channel, the channel topic may "leak" */
irc_relay_set_topic(channel, cp->topic);
irc_relay_set_topic(channel, cp->topic, relay->ircuser);
}
}
if (!relay->relaysystem) {
Expand Down
Loading

0 comments on commit 731862c

Please sign in to comment.