typedef int (*trustmodificationfn)(trustgroup *, char *arg);
struct trustmodification {
- char *name;
+ char name[50];
trustmodificationfn fn;
};
controlreply(sender, "Host added.");
triggerhook(HOOK_TRUSTS_ADDHOST, th);
- /* TODO: controlwall */
+ controlwall(NO_OPER, NL_TRUSTS, "%s TRUSTADD'ed host %s to group '%s'", controlid(sender), host, th->group->name->content);
return CMD_OK;
}
itg.mode = enforceident;
itg.maxperident = maxperident;
itg.expires = howlong + time(NULL);
- itg.createdby = getsstring(createdby, NICKLEN);
+ itg.createdby = getsstring(createdby, CREATEDBYLEN);
itg.contact = getsstring(contact, CONTACTLEN);
itg.comment = getsstring(comment, COMMENTLEN);
itg.name = getsstring(name, TRUSTNAMELEN);
controlreply(sender, "Group added.");
triggerhook(HOOK_TRUSTS_ADDGROUP, tg);
- /* TODO: controlwall */
+ controlwall(NO_OPER, NL_TRUSTS, "%s TRUSTGROUPADD'ed '%s'", controlid(sender), tg->name->content);
return CMD_OK;
}
return CMD_ERROR;
}
+ controlreply(sender, "TODO: NOT IMPLEMENTED");
+
+ controlwall(NO_OPER, NL_TRUSTS, "%s TRUSTGROUPDEL'ed '%s'.", controlid(sender), tg->name->content);
+
triggerhook(HOOK_TRUSTS_DELGROUP, tg);
tg_delete(tg);
controlreply(sender, "Group deleted.");
- /* TODO: controlwall */
return CMD_OK;
}
trusthost *th;
uint32_t ip, mask;
nick *sender = source;
+ char *host;
if(cargc < 2)
return CMD_USAGE;
return CMD_ERROR;
}
- if(!trusts_str2cidr(cargv[1], &ip, &mask)) {
+ host = cargv[1];
+ if(!trusts_str2cidr(host, &ip, &mask)) {
controlreply(sender, "Invalid IP/mask.");
return CMD_ERROR;
}
return CMD_ERROR;
}
+ controlreply(sender, "TODO: NOT IMPLEMENTED");
+
triggerhook(HOOK_TRUSTS_DELHOST, th);
th_delete(th);
controlreply(sender, "Host deleted.");
- /* TODO: controlwall */
- return CMD_OK;
-}
-
-static int modifyname(trustgroup *tg, char *name) {
- sstring *n = getsstring(name, TRUSTNAMELEN);
- if(!n)
- return 0;
-
- freesstring(tg->name);
- tg->name = n;
+ controlwall(NO_OPER, NL_TRUSTS, "%s TRUSTDEL'ed %s from group '%s'.", controlid(sender), host, tg->name->content);
- return 1;
+ return CMD_OK;
}
static int modifycomment(trustgroup *tg, char *comment) {
return 1;
}
-static int modifymaxperuser(trustgroup *tg, char *num) {
- unsigned int maxperuser = strtoul(num, NULL, 10);
+static int modifymaxperident(trustgroup *tg, char *num) {
+ unsigned int maxperident = strtoul(num, NULL, 10);
- if(maxperuser > MAXPERIDENT)
+ if(maxperident > MAXPERIDENT)
return 0;
- tg->maxperident = maxperuser;
+ tg->maxperident = maxperident;
return 1;
}
return 1;
}
-#define MS(x) (struct trustmodification){ .name = # x, .fn = modify ## x }
+static array trustmods_a;
+static struct trustmodification *trustmods;
static int trusts_cmdtrustgroupmodify(void *source, int cargc, char **cargv) {
trustgroup *tg;
nick *sender = source;
char *what, *to, validfields[512];
- struct trustmodification *mods = (struct trustmodification []){ MS(expires), MS(enforceident), MS(maxperuser), MS(name), MS(contact), MS(comment), MS(trustedfor) };
- int modcount = sizeof(mods) / sizeof(struct trustmodification);
int i;
StringBuf b;
-#undef MS
if(cargc < 3)
return CMD_USAGE;
to = cargv[2];
sbinit(&b, validfields, sizeof(validfields));
- for(i=0;i<modcount;i++) {
- if(!strcmp(what, mods[i].name)) {
- if(!(mods[i].fn)(tg, to)) {
+ for(i=0;i<trustmods_a.cursi;i++) {
+ if(!strcmp(what, trustmods[i].name)) {
+ if(!(trustmods[i].fn)(tg, to)) {
controlreply(sender, "An error occured changing that property, check the syntax.");
return CMD_ERROR;
}
if(i > 0)
sbaddstr(&b, ", ");
- sbaddstr(&b, mods[i].name);
+ sbaddstr(&b, trustmods[i].name);
}
- if(i == modcount) {
+ if(i == trustmods_a.cursi) {
sbterminate(&b);
controlreply(sender, "No such field, valid fields are: %s", validfields);
return CMD_ERROR;
tg_update(tg);
controlreply(sender, "Group modified.");
- /* TODO: controlwall */
+ controlwall(NO_OPER, NL_TRUSTS, "%s TRUSTMODIFIED'ed group '%s' (field: %s, value: %s)", controlid(sender), tg->name->content, what, to);
+
return CMD_OK;
}
static int loaded;
+#define _ms_(x) (struct trustmodification){ .name = # x, .fn = modify ## x }
+#define MS(x) { int slot = array_getfreeslot(&trustmods_a); trustmods = (struct trustmodification *)trustmods_a.content; memcpy(&trustmods[slot], &_ms_(x), sizeof(struct trustmodification)); }
+
+static void setupmods(void) {
+ MS(expires);
+ MS(enforceident);
+ MS(maxperident);
+ MS(contact);
+ MS(comment);
+ MS(trustedfor);
+}
+
void _init(void) {
sstring *m;
+ array_init(&trustmods_a, sizeof(struct trustmodification));
+ setupmods();
+
m = getconfigitem("trusts", "master");
if(!m || (atoi(m->content) != 1)) {
Error("trusts_management", ERR_ERROR, "Not a master server, not loaded.");
}
void _fini(void) {
+ array_free(&trustmods_a);
+
if(!loaded)
return;