Skip to content

Commit

Permalink
Add granular userfile sharing flags
Browse files Browse the repository at this point in the history
Patch by: Cizzle
Closes: #1
Closes: #7 

One-line summary: Introduces new bot flags bcejnu to allow a passive bot (slave) of sharing changes to bans, channels, exempts, invites, ignores and users respectively with an aggressive bot (hub). Also introduces bot flag d for when you don't want to share anything, as bot flag s will still allow anything to be shared.

The caution, however - this allows linked bots, sharing userfiles, to become desynchronized. If I add the leafbot on the hub with a bottattr of +n and then try and do a .+user user1 on the leafbot, the leafbot still adds that user to the local userfile. I guess linked bots that don't share userfiles are already going to be in the exact situation so it's not crazy to see this state, but that user would be over-written on the next userfile download from the hub, which doesn't happen on non-sharing linked bots.

And hey, how cool is it to close #1 ?!?!
  • Loading branch information
Cizzle committed Jan 2, 2021
1 parent 3d8c255 commit 8ec1948
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 85 deletions.
53 changes: 42 additions & 11 deletions doc/BOTNET
Expand Up @@ -115,17 +115,48 @@ Flags can be either global (such as +s) or channel specific (such as |+s

The following is a list of valid bot flags:

---------------- --------------------------------------------------------------------------------------------------------------------------------------------------
s share aggressively (SEND userfile to a passive bot)
p share passively (ACCEPT userfile from an aggressive bot)
g global share (share all channels)
h hub (automatically link to this bot)
a alternate (automatically link to this bot if the hub bot can't be linked)
l leaf (bot is not allowed to link in other bots)
r reject (bot will not be allowed to link)
i isolate (isolate the party line across a bot link)
0-9 user defined flags
---------------- --------------------------------------------------------------------------------------------------------------------------------------------------
------- ----------------------------------------------------------------
a alternate (automatically link to this bot if the hub bot can't
be linked)

b ban sharing (passive bot is allowed to share bans with
aggressive bot)

c channel sharing (passive bot is allowed to share channel
changes with aggressive bot)

d share aggressively (SEND userfile to a passive bot),
limited sharing (passive bot is NOT allowed to share anything)

e exempt sharing (passive bot is allowed to share exempts with
aggressive bot)

g global share (share all channels)

h hub (automatically link to this bot)

i isolate (isolate the party line across a bot link)

j invite sharing (passive bot is allowed to share invites with
aggressive bot)

l leaf (bot is not allowed to link in other bots)

n ignore sharing (passive bot is allowed to share ignores with
aggressive bot)

p share passively (ACCEPT userfile from an aggressive bot)

r reject (bot will not be allowed to link)

s share aggressively (SEND userfile to a passive bot),
unlimited sharing (passive bot is allowed to share anything)

u user sharing (passive bot is allowed to share user changes
with aggressive bot)

0-9 user defined flags
------- ----------------------------------------------------------------


ADDING AND LINKING BOTS
Expand Down
32 changes: 27 additions & 5 deletions doc/sphinx_source/mainDocs/botnet.rst
Expand Up @@ -92,22 +92,44 @@ Flags can be either global (such as +s) or channel specific (such as
The following is a list of valid bot flags:

+------+---------------------------------------------------------------+
| s | share aggressively (SEND userfile to a passive bot) |
| a | alternate (automatically link to this bot if the hub bot can't|
| | be linked) |
+------+---------------------------------------------------------------+
| p | share passively (ACCEPT userfile from an aggressive bot) |
| b | ban sharing (passive bot is allowed to share bans with |
| | aggressive bot) |
+------+---------------------------------------------------------------+
| c | channel sharing (passive bot is allowed to share channel |
| | changes with aggressive bot) |
+------+---------------------------------------------------------------+
| d | share aggressively (SEND userfile to a passive bot), |
| | limited sharing (passive bot is NOT allowed to share anything)|
+------+---------------------------------------------------------------+
| e | exempt sharing (passive bot is allowed to share exempts with |
| | aggressive bot) |
+------+---------------------------------------------------------------+
| g | global share (share all channels) |
+------+---------------------------------------------------------------+
| h | hub (automatically link to this bot) |
+------+---------------------------------------------------------------+
| a | alternate (automatically link to this bot if the hub bot can't|
| | be linked) |
| i | isolate (isolate the party line across a bot link) |
+------+---------------------------------------------------------------+
| j | invite sharing (passive bot is allowed to share invites with |
| | aggressive bot) |
+------+---------------------------------------------------------------+
| l | leaf (bot is not allowed to link in other bots) |
+------+---------------------------------------------------------------+
| n | ignore sharing (passive bot is allowed to share ignores with |
| | aggressive bot) |
+------+---------------------------------------------------------------+
| p | share passively (ACCEPT userfile from an aggressive bot) |
+------+---------------------------------------------------------------+
| r | reject (bot will not be allowed to link) |
+------+---------------------------------------------------------------+
| i | isolate (isolate the party line across a bot link) |
| s | share aggressively (SEND userfile to a passive bot), |
| | unlimited sharing (passive bot is allowed to share anything) |
+------+---------------------------------------------------------------+
| u | user sharing (passive bot is allowed to share user changes |
| | with aggressive bot) |
+------+---------------------------------------------------------------+
| 0-9 | user defined flags |
+------+---------------------------------------------------------------+
Expand Down
15 changes: 11 additions & 4 deletions help/cmds2.help
Expand Up @@ -414,14 +414,21 @@ See also: whom

For bots, there are additional flags seen under the "BOTATTR:" section.
Valid botflags include:
%bs%b - share aggressively (SEND userfile to a passive bot)
%bp%b - share passively (ACCEPT userfile from an aggressive bot)
%ba%b - alternate (bot is autolinked if no hub bots can be linked)
%bb%b - ban sharing (pasv bot can share bans with aggr bot)
%bc%b - channel sharing (pasv bot can share chan changes with aggr bot)
%bd%b - share aggressively (SEND userfile to a passive bot), none sharing (pasv bot to aggr bot)
%be%b - exempt sharing (pasv bot can share exempts with aggr bot)
%bg%b - global share (bot is sharing all channels)
%bh%b - hub (bot is autolinked at highest priority)
%ba%b - alternate (bot is autolinked if no hub bots can be linked)
%bi%b - isolate (isolate the party line across a botlink)
%bj%b - invite sharing (pasv bot can share invites with aggr bot)
%bl%b - leaf (bot is not allowed to link other bots onto the botnet)
%bn%b - ignore sharing (pasv bot can share ignores with aggr bot)
%bp%b - share passively (ACCEPT userfile from an aggressive bot)
%br%b - reject (bot will not be allowed to link to the botnet)
%bi%b - isolate (isolate the party line across a botlink)
%bs%b - share aggressively (SEND userfile to a passive bot), all sharing (pasv bot to aggr bot)
%bu%b - user sharing (pasv bot can share user changes with aggr bot)

There are also 10 user-defined bot flags (0-9). Bots may also have +s
(share) settings for individual channels.
Expand Down
2 changes: 1 addition & 1 deletion src/cmds.c
Expand Up @@ -1999,7 +1999,7 @@ static void cmd_botattr(struct userrec *u, int idx, char *par)
user.match = FR_BOT | (chan ? FR_CHAN : 0);
get_user_flagrec(u2, &user, par);
user.bot = (user.bot | pls.bot) & ~mns.bot;
if ((user.bot & BOT_SHARE) == BOT_SHARE)
if ((user.bot & BOT_PASSIVE) && (user.bot & (BOT_AGGRESSIVE|BOT_SHPERMS)))
user.bot &= ~BOT_SHARE;
if (chan)
user.chan = (user.chan | pls.chan) & ~mns.chan;
Expand Down
6 changes: 6 additions & 0 deletions src/cmdt.h
Expand Up @@ -36,4 +36,10 @@ typedef struct {
IntFunc func;
} botcmd_t;

typedef struct {
char *name;
char *flags;
IntFunc func;
} botscmd_t;

#endif /* _EGG_CMDT_H */
2 changes: 2 additions & 0 deletions src/flags.c
Expand Up @@ -788,6 +788,8 @@ static int botfl_set(struct userrec *u, struct user_entry *e, void *buf)

if ((atr & BOT_HUB) && (atr & BOT_ALT))
atr &= ~BOT_ALT;
if ((atr & BOT_AGGRESSIVE) && (atr & BOT_SHPERMS))
atr &= ~BOT_SHPERMS;
if (atr & BOT_REJECT) {
if (atr & BOT_SHARE)
atr &= ~(BOT_SHARE | BOT_REJECT);
Expand Down
30 changes: 16 additions & 14 deletions src/flags.h
Expand Up @@ -46,17 +46,17 @@ struct flag_record {
* unused letters: is
*
* botflags:
* a?????ghi??l???p?rs??0123456789
* unused letters: bcdefjkmnoqtu
* abcde?ghij?l?n?p?rs?u0123456789
* unused letters: fkmoqt
* unusable letters: vwxyz
*
* chanflags:
* a??defg???klmno?qrs??vw?yz + user defined A-Z
* unused letters: bchijptuw (s from bot flags)
* unused letters: bchijptux (s from bot flags)
*/
#define USER_VALID 0x003fbfeff /* Sum of all valid USER_ flags */
#define CHAN_VALID 0x003677c79 /* Sum of all valid CHAN_ flags */
#define BOT_VALID 0x07fe689c1 /* Sum of all valid BOT_ flags */
#define BOT_VALID 0x07ff6abdf /* Sum of all valid BOT_ flags */


#define USER_AUTOOP 0x00000001 /* a auto-op */
Expand Down Expand Up @@ -89,26 +89,26 @@ struct flag_record {

/* Flags specifically for bots */
#define BOT_ALT 0x00000001 /* a auto-link here if all hubs fail */
#define BOT_B 0x00000002 /* b unused */
#define BOT_C 0x00000004 /* c unused */
#define BOT_D 0x00000008 /* d unused */
#define BOT_E 0x00000010 /* e unused */
#define BOT_SHBAN 0x00000002 /* b can share bans */
#define BOT_SHCHAN 0x00000004 /* c can share channel changes */
#define BOT_SHLIMITED 0x00000008 /* d shares userfiles but can't share anything */
#define BOT_SHEXEMPT 0x00000010 /* e can share exempts */
#define BOT_F 0x00000020 /* f unused */
#define BOT_GLOBAL 0x00000040 /* g all channel are shared */
#define BOT_HUB 0x00000080 /* h auto-link to ONE of these bots */
#define BOT_ISOLATE 0x00000100 /* i isolate party line from botnet */
#define BOT_J 0x00000200 /* j unused */
#define BOT_SHINV 0x00000200 /* j can share invites */
#define BOT_K 0x00000400 /* k unused */
#define BOT_LEAF 0x00000800 /* l may not link other bots */
#define BOT_M 0x00001000 /* m unused */
#define BOT_N 0x00002000 /* n unused */
#define BOT_SHIGN 0x00002000 /* n can share ignores */
#define BOT_O 0x00004000 /* o unused */
#define BOT_PASSIVE 0x00008000 /* p share passively with this bot */
#define BOT_Q 0x00010000 /* q unused */
#define BOT_REJECT 0x00020000 /* r automatically reject anywhere */
#define BOT_AGGRESSIVE 0x00040000 /* s bot shares user files */
#define BOT_AGGRESSIVE 0x00040000 /* s shares userfiles and can share all */
#define BOT_T 0x00080000 /* t unused */
#define BOT_U 0x00100000 /* u unused */
#define BOT_SHUSER 0x00100000 /* u can share user changes */
/* BOT_V to BOT_Z not usable as they're bitflags 32-36 */
#define BOT_FLAG0 0x00200000 /* 0 user-defined flag #0 */
#define BOT_FLAG1 0x00400000 /* 1 user-defined flag #1 */
Expand All @@ -120,8 +120,10 @@ struct flag_record {
#define BOT_FLAG7 0x10000000 /* 7 user-defined flag #7 */
#define BOT_FLAG8 0x20000000 /* 8 user-defined flag #8 */
#define BOT_FLAG9 0x40000000 /* 9 user-defined flag #9 */
#define BOT_SHARE (BOT_AGGRESSIVE|BOT_PASSIVE)

/* BOT_S still shares everything for backward compat, but if removed to share more precisely,
we need those detailed flags to still indicate the bot shares */
#define BOT_SHPERMS (BOT_SHBAN|BOT_SHCHAN|BOT_SHEXEMPT|BOT_SHIGN|BOT_SHINV|BOT_SHUSER|BOT_SHLIMITED)
#define BOT_SHARE (BOT_AGGRESSIVE|BOT_PASSIVE|BOT_SHPERMS)

/* Flag checking macros */
#define chan_op(x) ((x).chan & USER_OP)
Expand Down
111 changes: 62 additions & 49 deletions src/mod/share.mod/share.c
Expand Up @@ -1130,7 +1130,7 @@ static void share_userfileq(int idx, char *par)
int ok = 1, i, bfl = bot_flags(dcc[idx].user);

flush_tbuf(dcc[idx].nick);
if (bfl & BOT_AGGRESSIVE)
if (bfl & (BOT_AGGRESSIVE|BOT_SHPERMS))
dprintf(idx, "s un I have you marked for Aggressive sharing.\n");
else if (!(bfl & BOT_PASSIVE))
dprintf(idx, "s un You are not marked for sharing with me.\n");
Expand Down Expand Up @@ -1274,7 +1274,7 @@ static void share_version(int idx, char *par)
STAT_OFFERED | STAT_AGGRESSIVE);
dcc[idx].u.bot->uff_flags = 0;
if ((dcc[idx].u.bot->numver >= min_share) &&
(bot_flags(dcc[idx].user) & BOT_AGGRESSIVE)) {
(bot_flags(dcc[idx].user) & (BOT_AGGRESSIVE|BOT_SHPERMS))) {
if (can_resync(dcc[idx].nick))
dprintf(idx, "s r?\n");
else
Expand Down Expand Up @@ -1322,49 +1322,52 @@ static void share_feats(int idx, char *par)
}


/* Note: these MUST be sorted. */
static botcmd_t C_share[] = {
{"!", (IntFunc) share_endstartup},
{"+b", (IntFunc) share_pls_ban},
{"+bc", (IntFunc) share_pls_banchan},
{"+bh", (IntFunc) share_pls_bothost},
{"+cr", (IntFunc) share_pls_chrec},
{"+e", (IntFunc) share_pls_exempt},
{"+ec", (IntFunc) share_pls_exemptchan},
{"+h", (IntFunc) share_pls_host},
{"+i", (IntFunc) share_pls_ignore},
{"+inv", (IntFunc) share_pls_invite},
{"+invc", (IntFunc) share_pls_invitechan},
{"-b", (IntFunc) share_mns_ban},
{"-bc", (IntFunc) share_mns_banchan},
{"-cr", (IntFunc) share_mns_chrec},
{"-e", (IntFunc) share_mns_exempt},
{"-ec", (IntFunc) share_mns_exemptchan},
{"-h", (IntFunc) share_mns_host},
{"-i", (IntFunc) share_mns_ignore},
{"-inv", (IntFunc) share_mns_invite},
{"-invc", (IntFunc) share_mns_invitechan},
{"a", (IntFunc) share_chattr},
{"c", (IntFunc) share_change},
{"chchinfo", (IntFunc) share_chchinfo},
{"e", (IntFunc) share_end},
{"feats", (IntFunc) share_feats},
{"h", (IntFunc) share_chhand},
{"k", (IntFunc) share_killuser},
{"n", (IntFunc) share_newuser},
{"nc", (IntFunc) share_newchan},
{"r!", (IntFunc) share_resync},
{"r?", (IntFunc) share_resyncq},
{"rn", (IntFunc) share_resync_no},
{"s", (IntFunc) share_stick_ban},
{"se", (IntFunc) share_stick_exempt},
{"sInv", (IntFunc) share_stick_invite},
{"u?", (IntFunc) share_userfileq},
{"un", (IntFunc) share_ufno},
{"us", (IntFunc) share_ufsend},
{"uy", (IntFunc) share_ufyes},
{"v", (IntFunc) share_version},
{NULL, NULL}
/* Note: these MUST be sorted.
* Flags (second arg) are compared with OR,
* here in particular this means +p can execute all
*/
static botscmd_t C_share[] = {
{"!", "", (IntFunc) share_endstartup},
{"+b", "psb", (IntFunc) share_pls_ban},
{"+bc", "psb", (IntFunc) share_pls_banchan},
{"+bh", "psu", (IntFunc) share_pls_bothost},
{"+cr", "psc", (IntFunc) share_pls_chrec},
{"+e", "pse", (IntFunc) share_pls_exempt},
{"+ec", "pse", (IntFunc) share_pls_exemptchan},
{"+h", "psu", (IntFunc) share_pls_host},
{"+i", "psn", (IntFunc) share_pls_ignore},
{"+inv", "psj", (IntFunc) share_pls_invite},
{"+invc", "psj", (IntFunc) share_pls_invitechan},
{"-b", "psb", (IntFunc) share_mns_ban},
{"-bc", "psb", (IntFunc) share_mns_banchan},
{"-cr", "psc", (IntFunc) share_mns_chrec},
{"-e", "pse", (IntFunc) share_mns_exempt},
{"-ec", "pse", (IntFunc) share_mns_exemptchan},
{"-h", "psu", (IntFunc) share_mns_host},
{"-i", "psn", (IntFunc) share_mns_ignore},
{"-inv", "psj", (IntFunc) share_mns_invite},
{"-invc", "psj", (IntFunc) share_mns_invitechan},
{"a", "psu", (IntFunc) share_chattr},
{"c", "psu", (IntFunc) share_change},
{"chchinfo", "psu", (IntFunc) share_chchinfo},
{"e", "", (IntFunc) share_end},
{"feats", "", (IntFunc) share_feats},
{"h", "psu", (IntFunc) share_chhand},
{"k", "psu", (IntFunc) share_killuser},
{"n", "psu", (IntFunc) share_newuser},
{"nc", "psc", (IntFunc) share_newchan},
{"r!", "", (IntFunc) share_resync},
{"r?", "", (IntFunc) share_resyncq},
{"rn", "", (IntFunc) share_resync_no},
{"s", "psb", (IntFunc) share_stick_ban},
{"se", "pse", (IntFunc) share_stick_exempt},
{"sInv", "psj", (IntFunc) share_stick_invite},
{"u?", "", (IntFunc) share_userfileq},
{"un", "", (IntFunc) share_ufno},
{"us", "", (IntFunc) share_ufsend},
{"uy", "", (IntFunc) share_ufyes},
{"v", "", (IntFunc) share_version},
{NULL, NULL, NULL}
};


Expand All @@ -1377,9 +1380,19 @@ static void sharein_mod(int idx, char *msg)
for (f = 0, i = 0; C_share[i].name && !f; i++) {
int y = strcasecmp(code, C_share[i].name);

if (!y)
if (!y) {
/* Found a match */
(C_share[i].func) (idx, msg);
struct flag_record fr = { FR_BOT , 0, 0, 0, 0, 0 };
struct flag_record req = { FR_BOT | FR_OR, 0, 0, 0, 0, 0 };

break_down_flags(C_share[i].flags, &req, NULL);
get_user_flagrec(dcc[idx].user, &fr, NULL);
if (flagrec_eq(&req, &fr)) {
(C_share[i].func) (idx, msg);
} else {
putlog(LOG_DEBUG, "*", "Userfile modification from %s rejected: incorrect bot flag permissions for \"%s %s\"", dcc[idx].nick, code, msg);
}
}
if (y <= 0)
f = 1;
}
Expand Down Expand Up @@ -1529,13 +1542,13 @@ static void check_expired_tbufs()
if (dcc[i].type->flags & DCT_BOT) {
if (dcc[i].status & STAT_OFFERED) {
if ((now - dcc[i].timeval > 120) && (dcc[i].user &&
(bot_flags(dcc[i].user) & BOT_AGGRESSIVE)))
(bot_flags(dcc[i].user) & (BOT_AGGRESSIVE|BOT_SHPERMS))))
dprintf(i, "s u?\n");
/* ^ send it again in case they missed it */
/* If it's a share bot that hasnt been sharing, ask again */
} else if (!(dcc[i].status & STAT_SHARE)) {
/* Patched from original source by giusc@gbss.it <20040207> */
if (dcc[i].user && (bot_flags(dcc[i].user) & BOT_AGGRESSIVE)) {
if (dcc[i].user && (bot_flags(dcc[i].user) & (BOT_AGGRESSIVE|BOT_SHPERMS))) {
dprintf(i, "s u?\n");
dcc[i].status |= STAT_OFFERED;
}
Expand Down
2 changes: 1 addition & 1 deletion src/users.c
Expand Up @@ -1005,7 +1005,7 @@ int readuserfile(char *file, struct userrec **ret)
}

/* New methodology - cycle through list 3 times
* 1st time scan for +sh bots and link if none connected
* 1st time scan for +(sbcdejnu)h bots and link if none connected
* 2nd time scan for +h bots
* 3rd time scan for +a/+h bots */
void autolink_cycle(char *start)
Expand Down

0 comments on commit 8ec1948

Please sign in to comment.