]> jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/hticket.c
GLINES: fix null pointer deref in trustgline / trustungline
[irc/quakenet/newserv.git] / helpmod2 / hticket.c
1 #include <time.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "hchannel.h"
6 #include "hticket.h"
7 #include "hgen.h"
8
9 hticket *hticket_get(const char *authname, struct hchannel_struct *hchan)
10 {
11 hticket *tmp;
12 if (hchan == NULL)
13 return NULL;
14 for (tmp = hchan->htickets;tmp;tmp = tmp->next)
15 if (!ci_strcmp(authname, tmp->authname))
16 return tmp;
17 return NULL;
18 }
19
20 hticket *hticket_del(hticket *htick, struct hchannel_struct *hchan)
21 {
22 hticket **ptr;
23 for (ptr = &hchan->htickets;*ptr;ptr = &(*ptr)->next)
24 if (*ptr == htick)
25 {
26 hticket *tmp = (*ptr)->next;
27 if ((*ptr)->message)
28 freesstring((*ptr)->message);
29 free(*ptr);
30 *ptr = tmp;
31 return NULL;
32 }
33
34 return htick;
35 }
36
37 hticket *hticket_add(const char *authname, time_t expiration, struct hchannel_struct *hchan, const char *message)
38 {
39 hticket *tmp = hticket_get(authname, hchan), **ptr;
40
41 if (hchan == NULL)
42 return NULL;
43
44 if (tmp != NULL)
45 return tmp;
46
47 tmp = (hticket*)malloc(sizeof(struct hticket_struct));
48
49 strcpy(tmp->authname, authname);
50 tmp->time_expiration = expiration;
51
52 if (message == NULL)
53 tmp->message = NULL;
54 else
55 tmp->message = getsstring(message, strlen(message));
56
57 /* find the correct position */
58 for (ptr = &hchan->htickets;*ptr && (*ptr)->time_expiration >= expiration;ptr = &(*ptr)->next);
59
60 tmp->next = *ptr;
61 *ptr = tmp;
62
63 return tmp;
64 }
65
66 int hticket_count(void)
67 {
68 int count = 0;
69 hticket *htick;
70 hchannel *hchan;
71
72 for (hchan = hchannels;hchan;hchan = hchan->next)
73 for (htick = hchan->htickets;htick;htick = htick->next)
74 count++;
75
76 return count;
77 }
78
79 void hticket_remove_expired(void)
80 {
81 hchannel *hchan;
82 hticket **tmp;
83 for (hchan = hchannels;hchan;hchan = hchan->next)
84 {
85 tmp = &hchan->htickets;
86 while (*tmp)
87 if ((*tmp)->time_expiration < time(NULL))
88 hticket_del(*tmp, hchan);
89 else
90 tmp = &(*tmp)->next;
91 }
92 }