]> jfr.im git - irc/quakenet/newserv.git/blame - helpmod2/haccount.c
GLINES: fix null pointer deref in trustgline / trustungline
[irc/quakenet/newserv.git] / helpmod2 / haccount.c
CommitLineData
c86edd1d
Q
1
2#include <string.h>
3#include <stdlib.h>
4#include <time.h>
5
6#include "../lib/sstring.h"
7#include "../lib/irc_string.h"
8
9#include "haccount.h"
10#include "helpmod.h"
11#include "huser.h"
12#include "hgen.h"
13
14haccount *haccount_get_by_name(const char *name)
15{
16 haccount *tmp;
17
18 if (name == NULL)
19 return NULL;
20
21 if (*name == '#')
22 name++;
23
24 tmp = haccounts;
25 for (;tmp;tmp = tmp->next)
26 if (!ircd_strcmp(tmp->name->content, name))
27 return tmp;
28
29 return NULL;
30}
31
32haccount *haccount_add(const char *name, hlevel lvl)
33{
2fd779e3 34 haccount *tmp;
c86edd1d 35
e908ecfa 36 if (haccount_get_by_name(name))
37 {
38 Error("helpmod", ERR_ERROR, "Attempt to add a duplicate account: %s", name);
39 return haccount_get_by_name(name);
40 }
41
c86edd1d
Q
42 if (*name == '#')
43 name++;
44
2fd779e3 45 tmp = (haccount*)malloc(sizeof (haccount));
c86edd1d
Q
46 tmp->name = getsstring(name, strlen(name));
47 tmp->level = lvl;
48 tmp->flags = H_ACCFLAGS_DEFAULT;
49 tmp->last_activity = time(NULL);
50 tmp->stats = NULL;
51
52 tmp->next = haccounts;
53 haccounts = tmp;
54
55 return tmp;
56}
57
58int haccount_del(haccount *hack)
59{
60 huser *h_ptr = husers;
61 haccount **ptr = &haccounts;
62
63 for (;h_ptr;h_ptr = h_ptr->next)
64 if (h_ptr->account == hack)
65 h_ptr->account = NULL;
66
67 for (;*ptr;ptr = &(*ptr)->next)
68 if (*ptr == hack)
69 {
70 hstat_account *tmp_stat;
71 haccount *tmp = (*ptr)->next;
72
73 while ((*ptr)->stats)
74 {
75 tmp_stat = (*ptr)->stats->next;
76 free((*ptr)->stats);
77 (*ptr)->stats = tmp_stat;
78 }
79
80 freesstring((*ptr)->name);
81 free(*ptr);
82
83 *ptr = tmp;
84 return 0;
85 }
86
87 return 0;
88}
89
90void haccount_clear_inactives(void)
91{
92 haccount **ptr = &haccounts;
93 while (*ptr)
726c8264 94 if ((time(NULL) - (*ptr)->last_activity > HELPMOD_ACCOUNT_EXPIRATION[(*ptr)->level]) && !((*ptr)->flags & H_NO_EXPIRE))
9af95c3d 95 haccount_del(*ptr);
96 else
c86edd1d
Q
97 ptr = &(*ptr)->next;
98}
99
100void haccount_set_level(haccount *hack, hlevel lvl)
101{
102 if (hack == NULL)
103 return;
104 hack->level = lvl;
105}
106
107const char *haccount_get_state(haccount* hacc, int mask)
108{
109 if (hacc->flags & mask)
3a839281 110 return "Yes";
c86edd1d 111 else
3a839281 112 return "No";
c86edd1d
Q
113}
114
115int haccount_count(hlevel lvl)
116{
117 haccount *hacc = haccounts;
118 int count = 0;
119 for (;hacc;hacc = hacc->next)
120 if (lvl == H_ANY)
121 count++;
122 else if (hacc->level == lvl)
123 count++;
124 return count;
125}
126
127const char *haccount_get_sname(int index)
128{
129 switch (index)
130 {
131 case 0:
132 return "Send replies as private messages";
133 case 1:
134 return "Send replies as notices";
135 case 2:
136 return "Do not send verbose messages";
137 case 3:
138 return "Auto-op on join";
139 case 4:
140 return "Auto-voice on join";
04f3fbba 141 case 5:
142 return "Suppress unknown command error";
c86edd1d 143 default:
3a839281 144 return "Error. Please contact strutsi";
c86edd1d
Q
145 }
146}