th_free(th);
}
- tg_free(tg);
+ tg_free(tg, 1);
}
tglist = NULL;
}
void th_free(trusthost *th) {
+ triggerhook(HOOK_TRUSTS_LOSTHOST, th);
+
nsfree(POOL_TRUSTS, th);
}
return th;
}
-void tg_free(trustgroup *tg) {
- triggerhook(HOOK_TRUSTS_LOSTGROUP, tg);
+void tg_free(trustgroup *tg, int created) {
+ if(created)
+ triggerhook(HOOK_TRUSTS_LOSTGROUP, tg);
freesstring(tg->name);
freesstring(tg->createdby);
memcpy(tg, itg, sizeof(trustgroup));
tg->name = getsstring(tg->name->content, TRUSTNAMELEN);
- tg->createdby = getsstring(tg->createdby->content, NICKLEN);
+ tg->createdby = getsstring(tg->createdby->content, CREATEDBYLEN);
tg->contact = getsstring(tg->contact->content, CONTACTLEN);
tg->comment = getsstring(tg->comment->content, COMMENTLEN);
if(!tg->name || !tg->createdby || !tg->contact || !tg->comment) {
- tg_free(tg);
+ tg_free(tg, 0);
return NULL;
}
return thmarker;
}
-trustgroup *tg_inttotg(unsigned int id) {
+trusthost *th_getbyid(unsigned int id) {
trustgroup *tg;
+ trusthost *th;
for(tg=tglist;tg;tg=tg->next)
- if(tg->id == id)
- return tg;
+ for(th=tg->hosts;th;th=th->next)
+ if(th->id == id)
+ return th;
return NULL;
}
+int tg_modify(trustgroup *oldtg, trustgroup *newtg) {
+ trustgroup vnewtg;
+
+ memcpy(&vnewtg, oldtg, sizeof(trustgroup));
+
+ /* unfortunately we can't just memcpy the new one over */
+
+ vnewtg.name = getsstring(newtg->name->content, TRUSTNAMELEN);
+ vnewtg.createdby = getsstring(newtg->createdby->content, CREATEDBYLEN);
+ vnewtg.contact = getsstring(newtg->contact->content, CONTACTLEN);
+ vnewtg.comment = getsstring(newtg->comment->content, COMMENTLEN);
+ if(!vnewtg.name || !vnewtg.createdby || !vnewtg.contact || !vnewtg.comment) {
+ freesstring(vnewtg.name);
+ freesstring(vnewtg.createdby);
+ freesstring(vnewtg.contact);
+ freesstring(vnewtg.comment);
+ return 0;
+ }
+
+ /* id remains the same, count/hosts/marker/next/exts are ignored */
+ vnewtg.trustedfor = newtg->trustedfor;
+ vnewtg.mode = newtg->mode;
+ vnewtg.maxperident = newtg->maxperident;
+ vnewtg.maxusage = newtg->maxusage;
+ vnewtg.expires = newtg->expires;
+ vnewtg.lastseen = newtg->lastseen;
+ vnewtg.lastmaxusereset = newtg->lastmaxusereset;
+
+ memcpy(oldtg, &vnewtg, sizeof(trustgroup));
+
+ return 1;
+}