ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/account.C
Revision: 1.6
Committed: Wed Sep 5 11:23:15 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +6 -6 lines
Log Message:
removed GPLed code and put license back to BSD

File Contents

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