Debian Codegraph @

modules/nickserv/info.c

raw
1 /*
2 * Copyright (c) 2005-2006 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the NickServ INFO functions.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "nickserv/info", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void ns_cmd_info(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t ns_info = { "INFO", N_("Displays information on registrations."), AC_NONE, 2, ns_cmd_info, { .path = "nickserv/info" } };
21
22 void _modinit(module_t *m)
23 {
24 service_named_bind_command("nickserv", &ns_info);
25 }
26
27 void _moddeinit(module_unload_intent_t intent)
28 {
29 service_named_unbind_command("nickserv", &ns_info);
30 }
31
32 static void ns_cmd_info(sourceinfo_t *si, int parc, char *parv[])
33 {
34 myuser_t *mu;
35 mynick_t *mn = NULL;
36 myuser_name_t *mun;
37 user_t *u = NULL;
38 bool recognized = false;
39 const char *name = parv[0];
40 char buf[BUFSIZE], strfbuf[BUFSIZE], lastlogin[BUFSIZE], *p;
41 size_t buflen;
42 time_t registered;
43 struct tm tm, tm2;
44 metadata_t *md;
45 mowgli_node_t *n;
46 mowgli_patricia_iteration_state_t state;
47 const char *vhost;
48 const char *vhost_timestring;
49 const char *vhost_assigner;
50 time_t vhost_time;
51 bool has_user_auspex;
52 bool hide_info;
53 hook_user_req_t req;
54 hook_info_noexist_req_t noexist_req;
55
56 /* On IRC, default the name to something.
57 * Not currently documented.
58 */
59 if (!name && si->su)
60 {
61 if (!nicksvs.no_nick_ownership)
62 name = si->su->nick;
63 else if (si->smu)
64 name = entity(si->smu)->name;
65 }
66
67 if (!name)
68 {
69 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO");
70 command_fail(si, fault_needmoreparams, _("Syntax: INFO <nickname>"));
71 return;
72 }
73
74 noexist_req.si = si;
75 noexist_req.nick = name;
76
77 has_user_auspex = has_priv(si, PRIV_USER_AUSPEX);
78
79 if (!(mu = myuser_find_ext(name)))
80 {
81 if (has_user_auspex && (mun = myuser_name_find(name)) != NULL)
82 {
83 const char *setter;
84 const char *reason;
85 time_t ts;
86
87 md = metadata_find(mun, "private:mark:setter");
88 setter = md != NULL ? md->value : "unknown";
89 md = metadata_find(mun, "private:mark:reason");
90 reason = md != NULL ? md->value : "unknown";
91 md = metadata_find(mun, "private:mark:timestamp");
92 ts = md != NULL ? atoi(md->value) : 0;
93
94 tm = *localtime(&ts);
95 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
96
97 command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered anymore, but was marked by %s on %s (%s)."), mun->name, setter, strfbuf, reason);
98 hook_call_user_info_noexist(&noexist_req);
99 }
100 else {
101 hook_call_user_info_noexist(&noexist_req);
102 command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), name);
103 }
104 return;
105 }
106
107 hide_info = use_account_private && mu->flags & MU_PRIVATE &&
108 mu != si->smu && !has_user_auspex;
109
110 if (!nicksvs.no_nick_ownership)
111 {
112 mn = mynick_find(*name == '=' ? name + 1 : name);
113 if (mn != NULL && mn->owner != mu)
114 mn = NULL;
115 if (mn == NULL)
116 mn = mynick_find(entity(mu)->name);
117 u = user_find_named(mn->nick);
118 if (u != NULL && u->myuser != mu)
119 {
120 if (myuser_access_verify(u, mu))
121 recognized = true;
122 u = NULL;
123 }
124 }
125
126 if (mn != NULL)
127 command_success_nodata(si, _("Information on \2%s\2 (account \2%s\2):"), mn->nick, entity(mu)->name);
128 else
129 command_success_nodata(si, _("Information on \2%s\2:"), entity(mu)->name);
130
131 registered = mn != NULL ? mn->registered : mu->registered;
132 tm = *localtime(&registered);
133 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
134 command_success_nodata(si, _("Registered : %s (%s ago)"), strfbuf, time_ago(registered));
135 /* show account's time if it's different from nick's time */
136 if (mu->registered != registered)
137 {
138 tm = *localtime(&mu->registered);
139 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
140 command_success_nodata(si, _("User reg. : %s (%s ago)"), strfbuf, time_ago(mu->registered));
141 }
142
143 if (config_options.show_entity_id || has_user_auspex)
144 command_success_nodata(si, _("Entity ID : %s"), entity(mu)->id);
145
146 md = metadata_find(mu, "private:usercloak");
147 vhost = md ? md->value : NULL;
148
149 md = metadata_find(mu, "private:usercloak-timestamp");
150 vhost_timestring = md ? md->value : NULL;
151
152 md = metadata_find(mu, "private:usercloak-assigner");
153 vhost_assigner = md ? md->value : NULL;
154
155 if (!hide_info && (md = metadata_find(mu, "private:host:vhost")))
156 {
157 mowgli_strlcpy(buf, md->value, sizeof buf);
158 if (vhost != NULL)
159 {
160 p = strchr(buf, '@');
161 if (p == NULL)
162 p = buf;
163 else
164 p++;
165 mowgli_strlcpy(p, vhost, sizeof buf - (p - buf));
166 }
167 command_success_nodata(si, _("Last addr : %s"), buf);
168 }
169
170 if ((vhost || vhost_timestring || vhost_assigner) && (si->smu == mu || has_user_auspex))
171 {
172 buf[0] = '\0';
173 buflen = 0;
174
175 if (vhost_timestring && (vhost || has_user_auspex))
176 {
177 vhost_time = atoi(vhost_timestring);
178 tm2 = *localtime(&vhost_time);
179 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm2);
180 buflen += snprintf(buf + buflen, BUFSIZE - buflen, _(" on %s (%s ago)"), strfbuf, time_ago(vhost_time));
181 }
182
183 if (has_user_auspex && vhost_assigner)
184 buflen += snprintf(buf + buflen, BUFSIZE - buflen, _(" by %s"), vhost_assigner);
185
186 if (vhost && !buf[0])
187 command_success_nodata(si, _("vHost : %s"), vhost);
188 else if (vhost && buf[0])
189 command_success_nodata(si, _("vHost : %s (assigned%s)"), vhost, buf);
190 else if (!vhost && buf[0])
191 command_success_nodata(si, _("vHost : unassigned%s"), buf);
192 }
193
194 if (has_user_auspex)
195 {
196 if ((md = metadata_find(mu, "private:host:actual")))
197 command_success_nodata(si, _("Real addr : %s"), md->value);
198 }
199
200 if (recognized)
201 command_success_nodata(si, _("Recognized : now (matches access list)"));
202 /* show nick's lastseen/online, if we have a nick */
203 if (u != NULL)
204 command_success_nodata(si, _("Last seen : now"));
205 else if (mn != NULL)
206 {
207 tm2 = *localtime(&mn->lastseen);
208 strftime(lastlogin, sizeof lastlogin, TIME_FORMAT, &tm2);
209 if (hide_info)
210 command_success_nodata(si, _("Last seen : (about %d weeks ago)"), (int)((CURRTIME - mn->lastseen) / 604800));
211 else
212 command_success_nodata(si, _("Last seen : %s (%s ago)"), lastlogin, time_ago(mn->lastseen));
213 }
214
215 /* if noone is logged in to this account, show account's lastseen,
216 * unless we have a nick and it quit at the same time as the account
217 */
218 if (MOWGLI_LIST_LENGTH(&mu->logins) == 0)
219 {
220 tm2 = *localtime(&mu->lastlogin);
221 strftime(lastlogin, sizeof lastlogin, TIME_FORMAT, &tm2);
222 if (mn == NULL)
223 {
224 if (hide_info)
225 command_success_nodata(si, _("Last seen : (about %d weeks ago)"), (int)((CURRTIME - mu->lastlogin) / 604800));
226 else
227 command_success_nodata(si, _("Last seen : %s (%s ago)"), lastlogin, time_ago(mu->lastlogin));
228 }
229 else if (mn->lastseen != mu->lastlogin)
230 {
231 if (hide_info)
232 command_success_nodata(si, _("User seen : (about %d weeks ago)"), (int)((CURRTIME - mu->lastlogin) / 604800));
233 else
234 command_success_nodata(si, _("User seen : %s (%s ago)"), lastlogin, time_ago(mu->lastlogin));
235 }
236 }
237 /* someone is logged in to this account
238 * if they're privileged, show them the sessions
239 */
240 else if (mu == si->smu || has_user_auspex)
241 {
242 buf[0] = '\0';
243 MOWGLI_ITER_FOREACH(n, mu->logins.head)
244 {
245 if (strlen(buf) > 80)
246 {
247 command_success_nodata(si, _("Logins from: %s"), buf);
248 buf[0] = '\0';
249 }
250 if (buf[0])
251 mowgli_strlcat(buf, " ", sizeof buf);
252 mowgli_strlcat(buf, ((user_t *)(n->data))->nick, sizeof buf);
253 }
254 if (buf[0])
255 command_success_nodata(si, _("Logins from: %s"), buf);
256 }
257 /* tell them this account is online, but not which nick
258 * unless we have already told them above
259 */
260 else if (u == NULL)
261 {
262 if (mn != NULL)
263 command_success_nodata(si, _("User seen : now"));
264 else
265 command_success_nodata(si, _("Last seen : now"));
266 }
267
268 if (!nicksvs.no_nick_ownership)
269 {
270 /* list registered nicks if privileged */
271 if (mu == si->smu || has_user_auspex)
272 {
273 buf[0] = '\0';
274 MOWGLI_ITER_FOREACH(n, mu->nicks.head)
275 {
276 if (strlen(buf) > 80)
277 {
278 command_success_nodata(si, _("Nicks : %s"), buf);
279 buf[0] = '\0';
280 }
281 if (buf[0])
282 mowgli_strlcat(buf, " ", sizeof buf);
283 mowgli_strlcat(buf, ((mynick_t *)(n->data))->nick, sizeof buf);
284 }
285 if (buf[0])
286 command_success_nodata(si, _("Nicks : %s"), buf);
287 }
288 }
289
290 if (!(mu->flags & MU_HIDEMAIL)
291 || (si->smu == mu || has_user_auspex))
292 command_success_nodata(si, _("Email : %s%s"), mu->email,
293 (mu->flags & MU_HIDEMAIL) ? " (hidden)": "");
294
295 MOWGLI_PATRICIA_FOREACH(md, &state, object(mu)->metadata)
296 {
297 if (!strncmp(md->name, "private:", 8))
298 continue;
299 command_success_nodata(si, _("Metadata : %s = %s"),
300 md->name, md->value);
301 }
302
303 *buf = '\0';
304
305 if (MU_HIDEMAIL & mu->flags)
306 strcat(buf, "HideMail");
307
308 if (MU_HOLD & mu->flags)
309 {
310 if (*buf)
311 strcat(buf, ", ");
312
313 strcat(buf, "Hold");
314 }
315 if (MU_NEVEROP & mu->flags)
316 {
317 if (*buf)
318 strcat(buf, ", ");
319
320 strcat(buf, "NeverOp");
321 }
322 if (MU_NOOP & mu->flags)
323 {
324 if (*buf)
325 strcat(buf, ", ");
326
327 strcat(buf, "NoOp");
328 }
329 if (MU_NOMEMO & mu->flags)
330 {
331 if (*buf)
332 strcat(buf, ", ");
333
334 strcat(buf, "NoMemo");
335 }
336 if (MU_EMAILMEMOS & mu->flags)
337 {
338 if (*buf)
339 strcat(buf, ", ");
340
341 strcat(buf, "EMailMemos");
342 }
343 if (MU_NEVERGROUP & mu->flags)
344 {
345 if (*buf)
346 strcat(buf, ", ");
347
348 strcat(buf, "NeverGroup");
349 }
350 if (use_account_private && MU_PRIVATE & mu->flags)
351 {
352 if (*buf)
353 strcat(buf, ", ");
354
355 strcat(buf, "Private");
356 }
357 if (MU_REGNOLIMIT & mu->flags)
358 {
359 if (*buf)
360 strcat(buf, ", ");
361
362 strcat(buf, "RegNoLimit");
363 }
364 if (MU_NOGREET & mu->flags)
365 {
366 if (*buf)
367 strcat(buf, ", ");
368
369 strcat(buf, "NoGreet");
370 }
371 if (MU_NOPASSWORD & mu->flags)
372 {
373 if (*buf)
374 strcat(buf, ", ");
375
376 strcat(buf, "NoPassword");
377 }
378
379 if (*buf)
380 command_success_nodata(si, _("Flags : %s"), buf);
381
382 #ifdef ENABLE_NLS
383 if (mu == si->smu || has_user_auspex)
384 command_success_nodata(si, _("Language : %s"),
385 language_get_name(mu->language));
386 #endif
387
388 if (mu->soper && (mu == si->smu || has_priv(si, PRIV_VIEWPRIVS)))
389 {
390 command_success_nodata(si, _("Oper class : %s"), mu->soper->operclass ? mu->soper->operclass->name : mu->soper->classname);
391 }
392
393 if (mu == si->smu || has_user_auspex || has_priv(si, PRIV_CHAN_AUSPEX))
394 {
395 chanacs_t *ca;
396 int founder = 0, other = 0;
397
398 MOWGLI_ITER_FOREACH(n, entity(mu)->chanacs.head)
399 {
400 ca = n->data;
401 if (ca->level & CA_FOUNDER)
402 founder++;
403 else if (ca->level != CA_AKICK)
404 other++;
405 }
406 command_success_nodata(si, _("Channels : %d founder, %d other"), founder, other);
407 }
408
409 if (has_user_auspex && (md = metadata_find(mu, "private:freeze:freezer")))
410 {
411 const char *setter = md->value;
412 const char *reason;
413 time_t ts;
414
415 md = metadata_find(mu, "private:freeze:reason");
416 reason = md != NULL ? md->value : "unknown";
417
418 md = metadata_find(mu, "private:freeze:timestamp");
419 ts = md != NULL ? atoi(md->value) : 0;
420
421 tm = *localtime(&ts);
422 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
423
424 command_success_nodata(si, _("%s was \2FROZEN\2 by %s on %s (%s)"), entity(mu)->name, setter, strfbuf, reason);
425 }
426 else if (metadata_find(mu, "private:freeze:freezer"))
427 command_success_nodata(si, _("%s has been frozen by the %s administration."), entity(mu)->name, me.netname);
428
429 if (has_user_auspex && (md = metadata_find(mu, "private:mark:setter")))
430 {
431 const char *setter = md->value;
432 const char *reason;
433 time_t ts;
434
435 md = metadata_find(mu, "private:mark:reason");
436 reason = md != NULL ? md->value : "unknown";
437
438 md = metadata_find(mu, "private:mark:timestamp");
439 ts = md != NULL ? atoi(md->value) : 0;
440
441 tm = *localtime(&ts);
442 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
443
444 command_success_nodata(si, _("%s was \2MARKED\2 by %s on %s (%s)"), entity(mu)->name, setter, strfbuf, reason);
445 }
446
447 if (MU_WAITAUTH & mu->flags)
448 command_success_nodata(si, _("%s has \2NOT COMPLETED\2 registration verification"), entity(mu)->name);
449
450 if ((mu == si->smu || has_user_auspex) &&
451 (md = metadata_find(mu, "private:verify:emailchg:newemail")))
452 {
453 const char *newemail = md->value;
454 time_t ts;
455
456 md = metadata_find(mu, "private:verify:emailchg:timestamp");
457 ts = md != NULL ? atoi(md->value) : 0;
458 tm = *localtime(&ts);
459 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
460
461 command_success_nodata(si, _("%s has requested an email address change to %s on %s"), entity(mu)->name, newemail, strfbuf);
462 }
463
464 req.si = si;
465 req.mu = mu;
466 req.mn = mn;
467 hook_call_user_info(&req);
468
469 command_success_nodata(si, _("*** \2End of Info\2 ***"));
470
471 logcommand(si, CMDLOG_GET, "INFO: \2%s\2", mn != NULL ? mn->nick : entity(mu)->name);
472 }
473
474 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
475 * vim:ts=8
476 * vim:sw=8
477 * vim:noexpandtab
478 */