1 |
pippijn |
1.1 |
/** |
2 |
|
|
* account.C: Account management |
3 |
pippijn |
1.8 |
* |
4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
|
|
* Rights to this code are as documented in COPYING. |
6 |
|
|
* |
7 |
|
|
* |
8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
9 |
pippijn |
1.2 |
* Rights to this code are documented in doc/pod/license.pod. |
10 |
pippijn |
1.4 |
* Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
11 |
pippijn |
1.1 |
*/ |
12 |
|
|
|
13 |
pippijn |
1.8 |
static char const rcsid[] = "$Id: account.C,v 1.7 2007-09-09 20:05:52 pippijn Exp $"; |
14 |
pippijn |
1.4 |
|
15 |
|
|
#include <boost/foreach.hpp> |
16 |
pippijn |
1.1 |
|
17 |
|
|
#include "atheme.h" |
18 |
|
|
#include <account/myuser.h> |
19 |
|
|
#include <account/mynick.h> |
20 |
|
|
#include <account/mychan.h> |
21 |
|
|
#include <account/chanacs.h> |
22 |
|
|
#include "uplink.h" /* XXX, for sendq_flush(curr_uplink->conn); */ |
23 |
|
|
#include "datastream.h" |
24 |
|
|
#include "privs.h" |
25 |
|
|
|
26 |
|
|
/* |
27 |
|
|
* init_accounts() |
28 |
|
|
* |
29 |
|
|
* Initializes the accounts DTree. |
30 |
|
|
* |
31 |
|
|
* Inputs: |
32 |
|
|
* - none |
33 |
|
|
* |
34 |
|
|
* Outputs: |
35 |
|
|
* - none |
36 |
|
|
* |
37 |
|
|
* Side Effects: |
38 |
|
|
* - if the DTree initialization fails, services will abort. |
39 |
|
|
*/ |
40 |
|
|
void |
41 |
|
|
init_accounts (void) |
42 |
|
|
{ |
43 |
|
|
#if 0 |
44 |
|
|
myuser_heap = BlockHeapCreate (sizeof (myuser_t), HEAP_USER); |
45 |
|
|
mynick_heap = BlockHeapCreate (sizeof (myuser_t), HEAP_USER); |
46 |
|
|
mychan_heap = BlockHeapCreate (sizeof (mychan_t), HEAP_CHANNEL); |
47 |
|
|
chanacs_heap = BlockHeapCreate (sizeof (chanacs_t), HEAP_CHANUSER); |
48 |
|
|
metadata_heap = BlockHeapCreate (sizeof (metadata_t), HEAP_CHANUSER); |
49 |
|
|
#endif |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
static int |
53 |
pippijn |
1.6 |
expire_myuser_cb (myuser_t::pair_type &mup) |
54 |
pippijn |
1.1 |
{ |
55 |
pippijn |
1.4 |
myuser_t *mu = mup.second; |
56 |
pippijn |
1.1 |
|
57 |
|
|
/* If they're logged in, update lastlogin time. |
58 |
|
|
* To decrease db traffic, may want to only do |
59 |
|
|
* this if the account would otherwise be |
60 |
|
|
* deleted. -- jilles |
61 |
|
|
*/ |
62 |
|
|
if (!mu->logins.empty ()) |
63 |
|
|
{ |
64 |
|
|
mu->lastlogin = NOW; |
65 |
|
|
return 0; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
if (MU_HOLD & mu->flags) |
69 |
|
|
return 0; |
70 |
|
|
|
71 |
|
|
if (((NOW - mu->lastlogin) >= nicksvs.expiry) || ((mu->flags & MU_WAITAUTH) && (NOW - mu->registered >= 86400))) |
72 |
|
|
{ |
73 |
|
|
/* Don't expire accounts with privs on them in atheme.conf, |
74 |
|
|
* otherwise someone can reregister |
75 |
|
|
* them and take the privs -- jilles */ |
76 |
|
|
if (is_conf_soper (mu)) |
77 |
|
|
return 0; |
78 |
|
|
|
79 |
|
|
snoop (_("EXPIRE: \2%s\2 from \2%s\2 "), mu->name, mu->email); |
80 |
|
|
slog (LG_REGISTER, "expire_check(): expiring account %s (unused %ds, email %s, nicks %d, chanacs %d)", mu->name, (int) (NOW - mu->lastlogin), mu->email, LIST_LENGTH (&mu->nicks), LIST_LENGTH (&mu->chanacs)); |
81 |
|
|
mu->refcnt_dec (); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
return 0; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
void |
88 |
|
|
expire_check (void *arg) |
89 |
|
|
{ |
90 |
|
|
mynick_t *mn; |
91 |
|
|
mychan_t *mc; |
92 |
|
|
user_t *u; |
93 |
|
|
|
94 |
|
|
/* Let them know about this and the likely subsequent db_save() |
95 |
|
|
* right away -- jilles */ |
96 |
|
|
sendq_flush (curr_uplink->conn); |
97 |
|
|
|
98 |
|
|
if (nicksvs.expiry != 0) |
99 |
|
|
{ |
100 |
pippijn |
1.6 |
std::for_each (myuser_t::map.begin (), myuser_t::map.end (), expire_myuser_cb); |
101 |
pippijn |
1.1 |
|
102 |
pippijn |
1.6 |
foreach (mynick_t::pair_type &mnp, mynick_t::map) |
103 |
pippijn |
1.4 |
{ |
104 |
|
|
mn = mnp.second; |
105 |
|
|
if ((NOW - mn->lastseen) >= nicksvs.expiry) |
106 |
|
|
{ |
107 |
|
|
if (MU_HOLD & mn->owner->flags) |
108 |
|
|
continue; |
109 |
|
|
|
110 |
|
|
/* do not drop main nick like this */ |
111 |
|
|
if (!irccasecmp (mn->nick, mn->owner->name)) |
112 |
|
|
continue; |
113 |
|
|
|
114 |
|
|
u = user_find_named (mn->nick); |
115 |
|
|
if (u != NULL && u->myuser == mn->owner) |
116 |
|
|
{ |
117 |
|
|
/* still logged in, bleh */ |
118 |
|
|
mn->lastseen = NOW; |
119 |
|
|
mn->owner->lastlogin = NOW; |
120 |
|
|
continue; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
snoop (_("EXPIRE: \2%s\2 from \2%s\2"), mn->nick, mn->owner->name); |
124 |
|
|
slog (LG_REGISTER, "expire_check(): expiring nick %s (unused %ds, account %s)", mn->nick, NOW - mn->lastseen, mn->owner->name); |
125 |
pippijn |
1.7 |
mn->refcnt_dec (); |
126 |
pippijn |
1.4 |
} |
127 |
|
|
} |
128 |
pippijn |
1.1 |
} |
129 |
pippijn |
1.4 |
|
130 |
pippijn |
1.1 |
if (chansvs.expiry != 0) |
131 |
|
|
{ |
132 |
pippijn |
1.7 |
foreach (mychan_t::pair_type &mp, mychan_t::map) |
133 |
pippijn |
1.5 |
{ |
134 |
|
|
mc = mp.second; |
135 |
|
|
if ((NOW - mc->used) >= 86400 - 3660) |
136 |
|
|
{ |
137 |
|
|
/* keep last used time accurate to |
138 |
|
|
* within a day, making sure an active |
139 |
|
|
* channel will never get "Last used" |
140 |
|
|
* in /cs info -- jilles */ |
141 |
|
|
if (mc->isused ()) |
142 |
|
|
{ |
143 |
|
|
mc->used = NOW; |
144 |
|
|
slog (LG_DEBUG, "expire_check(): updating last used time on %s because it appears to be still in use", mc->name); |
145 |
|
|
continue; |
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
if ((NOW - mc->used) >= chansvs.expiry) |
150 |
|
|
{ |
151 |
|
|
if (MC_HOLD & mc->flags) |
152 |
|
|
continue; |
153 |
|
|
|
154 |
|
|
snoop (_("EXPIRE: \2%s\2 from \2%s\2"), mc->name, mc->founder_names ()); |
155 |
|
|
slog (LG_REGISTER, "expire_check(): expiring channel %s (unused %ds, founder %s, chanacs %d)", |
156 |
|
|
mc->name, |
157 |
|
|
NOW - mc->used, |
158 |
|
|
mc->founder_names (), |
159 |
|
|
LIST_LENGTH (&mc->chanacs)); |
160 |
|
|
|
161 |
|
|
mc->callback.drop (mc); |
162 |
|
|
if ((config_options.chan && irccasecmp (mc->name, config_options.chan)) || !config_options.chan) |
163 |
|
|
part (mc->name, chansvs.nick); |
164 |
|
|
|
165 |
|
|
mc->refcnt_dec (); |
166 |
|
|
} |
167 |
|
|
} |
168 |
pippijn |
1.1 |
} |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
static int |
172 |
pippijn |
1.6 |
check_myuser_cb (myuser_t::pair_type &mup) |
173 |
pippijn |
1.1 |
{ |
174 |
pippijn |
1.4 |
myuser_t *mu = mup.second; |
175 |
pippijn |
1.1 |
mynick_t *mn; |
176 |
|
|
|
177 |
|
|
if (MU_OLD_ALIAS & mu->flags) |
178 |
|
|
{ |
179 |
|
|
slog (LG_REGISTER, "db_check(): converting previously linked nick %s to a standalone nick", mu->name); |
180 |
|
|
mu->flags &= ~MU_OLD_ALIAS; |
181 |
|
|
mu->del_metadata ("private:alias:parent"); |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
if (!nicksvs.no_nick_ownership) |
185 |
|
|
{ |
186 |
pippijn |
1.7 |
mn = mynick_t::find (mu->name); |
187 |
pippijn |
1.1 |
if (mn == NULL) |
188 |
|
|
{ |
189 |
|
|
slog (LG_REGISTER, "db_check(): adding missing nick %s", mu->name); |
190 |
pippijn |
1.7 |
mn = mynick_t::create (mu, mu->name); |
191 |
pippijn |
1.1 |
mn->registered = mu->registered; |
192 |
|
|
mn->lastseen = mu->lastlogin; |
193 |
|
|
} |
194 |
|
|
else if (mn->owner != mu) |
195 |
|
|
{ |
196 |
|
|
slog (LG_REGISTER, "db_check(): replacing nick %s owned by %s with %s", mn->nick, mn->owner->name, mu->name); |
197 |
pippijn |
1.7 |
mn->refcnt_dec (); |
198 |
|
|
mn = mynick_t::create (mu, mu->name); |
199 |
pippijn |
1.1 |
mn->registered = mu->registered; |
200 |
|
|
mn->lastseen = mu->lastlogin; |
201 |
|
|
} |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
return 0; |
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
void |
208 |
|
|
db_check () |
209 |
|
|
{ |
210 |
pippijn |
1.6 |
std::for_each (myuser_t::map.begin (), myuser_t::map.end (), check_myuser_cb); |
211 |
pippijn |
1.1 |
} |