Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Commit bfa03e2

Browse files
committed
facilities.c: add override_unaff setting
1 parent dc11be3 commit bfa03e2

File tree

2 files changed

+55
-18
lines changed

2 files changed

+55
-18
lines changed

facilities.c

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ typedef struct
8585
int throttle[2];
8686

8787
facility_cloak_type cloaking;
88+
int cloak_override;
8889

8990
mowgli_list_t blacklist;
9091

@@ -157,11 +158,15 @@ void load_facilities()
157158
char *blocked = strtok(NULL, " ");
158159
char *throttle0 = strtok(NULL, " ");
159160
char *throttle1 = strtok(NULL, " ");
161+
162+
char *cloak_override = strtok(NULL, " ");
163+
160164
strncpy(curr_facility->hostpart, hostpart, HOSTLEN);
161165
curr_facility->cloaking = cloak_type_from_string(cloaking);
162166
curr_facility->blocked = atoi(blocked);
163167
curr_facility->throttle[0] = atoi(throttle0);
164168
curr_facility->throttle[1] = atoi(throttle1);
169+
curr_facility->cloak_override = cloak_override ? atoi(cloak_override) : 0;
165170

166171
mowgli_patricia_add(facilities, curr_facility->hostpart, curr_facility);
167172
continue;
@@ -219,8 +224,8 @@ void save_facilities()
219224
facility_t *f;
220225
MOWGLI_PATRICIA_FOREACH(f, &state, facilities)
221226
{
222-
fprintf(db, "F %s %s %d %d %d\n", f->hostpart, string_from_cloak_type(f->cloaking),
223-
f->blocked, f->throttle[0], f->throttle[1]);
227+
fprintf(db, "F %s %s %d %d %d %d\n", f->hostpart, string_from_cloak_type(f->cloaking),
228+
f->blocked, f->throttle[0], f->throttle[1], f->cloak_override);
224229
if (f->blockmessage)
225230
fprintf(db, "BM %s\n", f->blockmessage);
226231
if (f->throttlemessage)
@@ -288,20 +293,23 @@ static void mod_deinit(module_unload_intent_t intent)
288293
hook_del_hook("incoming_host_change", on_host_change);
289294
}
290295

291-
static void facility_set_cloak(user_t *u, const char * cloak)
296+
static void facility_set_cloak(user_t *u, const char * cloak, int cloak_override)
292297
{
293298
metadata_add(u, "syn:facility-cloak", cloak);
294299

295-
// Check whether they've already been cloaked. If vhost contains /, vhost != host, and
296-
// vhost isn't unaffiliated/*, then they have a project cloak that we shouldn't override.
297-
char *slash = strchr(u->vhost, '/');
298-
if (slash != NULL && 0 != strncmp(u->vhost, "unaffiliated", slash - u->vhost) &&
299-
0 != strncmp(u->vhost, u->host, HOSTLEN))
300-
return;
300+
if (cloak_override > 0)
301+
{
302+
metadata_add(u, "syn:facility-cloak-override", "1");
303+
// Check whether they've already been cloaked. If vhost != host and
304+
// vhost isn't unaffiliated/*, then they have a project cloak that we shouldn't override.
305+
if (strncmp(u->vhost, "unaffiliated/", 13) &&
306+
strncmp(u->vhost, u->host, HOSTLEN))
307+
return;
301308

302-
// Don't send out a no-op cloak change either
303-
if (strcmp(u->vhost, cloak))
304-
user_sethost(syn->me, u, cloak);
309+
// Don't send out a no-op cloak change either
310+
if (strcmp(u->vhost, cloak))
311+
user_sethost(syn->me, u, cloak);
312+
}
305313
}
306314

307315
void facility_newuser(hook_user_nick_t *data)
@@ -314,7 +322,7 @@ void facility_newuser(hook_user_nick_t *data)
314322
if (!u)
315323
return;
316324

317-
int blocked = 0, throttled = 0, blacklisted = 0;
325+
int blocked = 0, throttled = 0, blacklisted = 0, cloak_override = 0;
318326
char *blockmessage = NULL, *throttlemessage = NULL;
319327
facility_cloak_type cloak = facility_cloak_none;
320328
facility_t *blocking_facility = NULL, *throttling_facility = NULL;
@@ -360,6 +368,9 @@ void facility_newuser(hook_user_nick_t *data)
360368
if (f->cloaking != facility_cloak_undefined)
361369
cloak = f->cloaking;
362370

371+
if (f->cloak_override)
372+
cloak_override = f->cloak_override;
373+
363374
char nuh[NICKLEN+USERLEN+HOSTLEN+GECOSLEN];
364375
snprintf(nuh, sizeof(nuh), "%s!%s@%s %s", u->nick, u->user, u->host, u->gecos);
365376

@@ -433,7 +444,7 @@ void facility_newuser(hook_user_nick_t *data)
433444

434445
case facility_cloak_account:
435446
{
436-
facility_set_cloak(u, u->host);
447+
facility_set_cloak(u, u->host, cloak_override);
437448
break;
438449
}
439450

@@ -455,7 +466,7 @@ void facility_newuser(hook_user_nick_t *data)
455466
strncpy(ipstart, "ip.", new_vhost + HOSTLEN - ipstart);
456467
ipstart += 3;
457468
strncpy(ipstart, ip, new_vhost + HOSTLEN - ipstart);
458-
facility_set_cloak(u, new_vhost);
469+
facility_set_cloak(u, new_vhost, cloak_override);
459470
}
460471
else
461472
{
@@ -490,7 +501,7 @@ void facility_newuser(hook_user_nick_t *data)
490501
}
491502

492503
strncpy(identstart, suffix, new_vhost + HOSTLEN - identstart);
493-
facility_set_cloak(u, new_vhost);
504+
facility_set_cloak(u, new_vhost, cloak_override);
494505
break;
495506
}
496507
case facility_cloak_random:
@@ -502,7 +513,7 @@ void facility_newuser(hook_user_nick_t *data)
502513
break;
503514
}
504515
strncpy(randstart, get_random_host_part(u), new_vhost + HOSTLEN - randstart);
505-
facility_set_cloak(u, new_vhost);
516+
facility_set_cloak(u, new_vhost, cloak_override);
506517
break;
507518
}
508519
}
@@ -540,6 +551,7 @@ static void syn_facility_help(sourceinfo_t *si, const char *subcmd)
540551
command_success_nodata(si, " - The message to send to clients denied because of this");
541552
command_success_nodata(si, " facility's throttle.");
542553
command_success_nodata(si, " - The cloaking scheme applied to matching clients.");
554+
command_success_nodata(si, " - Whether facility cloaks will override unaffiliated cloaks.");
543555
command_success_nodata(si, " - A blacklist of regular expressions. If any of these match");
544556
command_success_nodata(si, " a client that matches this facility, it will be denied.");
545557
command_success_nodata(si, " ");
@@ -580,6 +592,10 @@ static void syn_facility_help(sourceinfo_t *si, const char *subcmd)
580592
command_success_nodata(si, "If no matching facility has a defined cloaking method, then");
581593
command_success_nodata(si, "the default is \2none\2.");
582594
command_success_nodata(si, " ");
595+
command_success_nodata(si, "As with the 'blocked' setting, the override_unaff setting");
596+
command_success_nodata(si, "may be set to 1 to disallow unaffiliated cloaks or -1");
597+
command_success_nodata(si, "to specifically allow them even though a more general");
598+
command_success_nodata(si, "facility would not allow them. The default is to allow them.");
583599
command_help(si, syn_facility_cmds);
584600
command_success_nodata(si, " ");
585601
command_success_nodata(si, _("For more information, use \2/msg %s HELP FACILITY \37command\37\2."), si->service->nick);
@@ -717,6 +733,21 @@ void syn_cmd_facility_set(sourceinfo_t *si, int parc, char **parv)
717733
return;
718734
}
719735

736+
if (0 == strcasecmp(parv[1], "override_unaff"))
737+
{
738+
if (parc < 3)
739+
f->cloak_override = 0;
740+
else
741+
f->cloak_override = atoi(parv[2]);
742+
743+
syn_report("\002FACILITY SET\002 override_unaff->%d for %s by %s",
744+
f->cloak_override, f->hostpart, get_oper_name(si));
745+
command_success_nodata(si, "Overriding unaffiliated cloaks for %s was set to %d", f->hostpart, f->cloak_override);
746+
747+
save_facilities();
748+
return;
749+
}
750+
720751
if (0 == strcasecmp(parv[1], "blocked"))
721752
{
722753
if (parc < 3)
@@ -891,6 +922,8 @@ void syn_cmd_facility_show(sourceinfo_t *si, int parc, char **parv)
891922

892923
command_success_nodata(si, "Facility %s:", f->hostpart);
893924
command_success_nodata(si, " cloaking method: %s", string_from_cloak_type(f->cloaking));
925+
command_success_nodata(si, " unaffiliated cloaks: %s",
926+
f->cloak_override > 0 ? "disallowed" : (f->cloak_override < 0 ? "allowed" : "(see parent facility)"));
894927
command_success_nodata(si, " %s, block message \"%s\"",
895928
f->blocked > 0 ? "blocked" : ( f->blocked < 0 ? "unblocked" : "not blocked"),
896929
f->blockmessage);
@@ -917,7 +950,10 @@ static void on_host_change(void *vdata)
917950
if (!md)
918951
return;
919952

920-
if ((0 == strncmp(data->user->vhost, "unaffiliated/", 13) && 0 != strncmp(data->oldvhost, "nat/", 4)) ||
953+
if (!metadata_find(data->user, "syn:facility-cloak-override"))
954+
return;
955+
956+
if (0 == strncmp(data->user->vhost, "unaffiliated/", 13) ||
921957
0 == strncmp(data->user->vhost, data->user->host, HOSTLEN))
922958
{
923959
// Override the host change -- a facility cloak is being replaced by unaffiliated, or a facility by

help/facility_set

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Possible settings are:
99
- throttle
1010
- blockmessage
1111
- throttlemessage
12+
- override_unaff
1213

1314
See /msg &nick& HELP FACILITY for the meaning of each
1415
setting.

0 commit comments

Comments
 (0)