]> jfr.im git - irc/quakenet/newserv.git/blob - trusts/data.c
No longer allow db reloading on the fly.
[irc/quakenet/newserv.git] / trusts / data.c
1 #include <stdlib.h>
2
3 #include "../lib/sstring.h"
4 #include "trusts.h"
5
6 trustgroup *tglist;
7
8 void trusts_freeall(void) {
9 trustgroup *tg, *ntg;
10 trusthost *th, *nth;
11
12 for(tg=tglist;tg;tg=ntg) {
13 ntg = tg->next;
14 for(th=tg->hosts;th;th=nth) {
15 nth = th->next;
16
17 th_free(th);
18 }
19
20 tg_free(tg);
21 }
22
23 tglist = NULL;
24 }
25
26 trustgroup *tg_getbyid(unsigned int id) {
27 trustgroup *tg;
28
29 for(tg=tglist;tg;tg=tg->next)
30 if(tg->id == id)
31 return tg;
32
33 return NULL;
34 }
35
36 void th_free(trusthost *th) {
37 free(th);
38 }
39
40 int th_add(trustgroup *tg, char *host, unsigned int maxseen, time_t lastseen) {
41 u_int32_t ip, mask;
42 trusthost *th;
43
44 if(!trusts_str2cidr(host, &ip, &mask))
45 return 0;
46
47 th = malloc(sizeof(trusthost));
48 if(!th)
49 return 0;
50
51 th->maxseen = maxseen;
52 th->lastseen = lastseen;
53 th->ip = ip;
54 th->mask = mask;
55
56 th->users = NULL;
57 th->group = tg;
58 th->count = 0;
59
60 th->next = tg->hosts;
61 tg->hosts = th;
62
63 return 1;
64 }
65
66 void tg_free(trustgroup *tg) {
67 freesstring(tg->name);
68 freesstring(tg->createdby);
69 freesstring(tg->contact);
70 freesstring(tg->comment);
71 free(tg);
72 }
73
74 int tg_add(unsigned int id, char *name, unsigned int trustedfor, int mode, unsigned int maxperident, unsigned int maxseen, time_t expires, time_t lastseen, time_t lastmaxuserreset, char *createdby, char *contact, char *comment) {
75 trustgroup *tg = malloc(sizeof(trustgroup));
76 if(!tg)
77 return 0;
78
79 tg->name = getsstring(name, TRUSTNAMELEN);
80 tg->createdby = getsstring(createdby, NICKLEN);
81 tg->contact = getsstring(contact, CONTACTLEN);
82 tg->comment = getsstring(comment, COMMENTLEN);
83 if(!tg->name || !tg->createdby || !tg->contact || !tg->comment) {
84 tg_free(tg);
85 return 0;
86 }
87
88 tg->id = id;
89 tg->trustedfor = trustedfor;
90 tg->mode = mode;
91 tg->maxperident = maxperident;
92 tg->maxseen = maxseen;
93 tg->expires = expires;
94 tg->lastseen = lastseen;
95 tg->lastmaxuserreset = lastmaxuserreset;
96 tg->hosts = NULL;
97
98 tg->count = 0;
99
100 tg->next = tglist;
101 tglist = tg;
102
103 return 1;
104 }
105
106 trusthost *th_getbyhost(uint32_t host) {
107 trustgroup *tg;
108 trusthost *th;
109
110 for(tg=tglist;tg;tg=tg->next)
111 for(th=tg->hosts;th;th=th->next)
112 if((host & th->mask) == th->ip)
113 return th;
114
115 return NULL;
116 }