1 /*
2 * Copyright (c) 2010 William Pitcock <nenolod@atheme.org>
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for blocking registrations of guest nicks.
6 * Particularly for use with webchat clients.
7 *
8 * To actually use this, add a something like the following to
9 * the nickserv {} block of your atheme.conf:
10 * guestnicks {
11 * "mib_";
12 * "WebUser";
13 * };
14 *
15 */
16
17 #include "atheme-compat.h"
18 #include "conf.h"
19
20 DECLARE_MODULE_V1
21 (
22 "contrib/ns_guestnoreg", false, _modinit, _moddeinit,
23 PACKAGE_STRING,
24 VENDOR_STRING
25 );
26
27 static mowgli_list_t guestnicks = { NULL, NULL, 0 };
28
guestnoreg_hook(hook_user_register_check_t * hdata)29 static void guestnoreg_hook(hook_user_register_check_t *hdata)
30 {
31 mowgli_node_t *n;
32
33 return_if_fail(hdata != NULL);
34 return_if_fail(hdata->si != NULL);
35
36 MOWGLI_ITER_FOREACH(n, guestnicks.head)
37 {
38 char *nick = n->data;
39 int nicklen = strlen(nick);
40
41 if (!strncasecmp(hdata->account, nick, nicklen))
42 {
43 command_fail(hdata->si, fault_badparams, _("Registering of guest nicknames is disallowed."));
44 hdata->approved++;
45 }
46 }
47
48 }
49
guestnoreg_config_handler(mowgli_config_file_entry_t * ce)50 static int guestnoreg_config_handler(mowgli_config_file_entry_t *ce)
51 {
52 mowgli_config_file_entry_t *cce;
53
54 MOWGLI_ITER_FOREACH(cce, ce->entries)
55 {
56 char *nick = sstrdup(cce->varname);
57 mowgli_node_add(nick, mowgli_node_create(), &guestnicks);
58 }
59
60 return 0;
61 }
62
guestnoreg_config_purge(void * unused)63 static void guestnoreg_config_purge(void *unused)
64 {
65 mowgli_node_t *n, *tn;
66
67 MOWGLI_ITER_FOREACH_SAFE(n, tn, guestnicks.head)
68 {
69 char *nick = n->data;
70
71 free(nick);
72 mowgli_node_delete(n, &guestnicks);
73 mowgli_node_free(n);
74 }
75 }
76
77 void
_modinit(module_t * m)78 _modinit(module_t *m)
79 {
80 hook_add_event("config_purge");
81 hook_add_config_purge(guestnoreg_config_purge);
82
83 hook_add_event("user_can_register");
84 hook_add_user_can_register(guestnoreg_hook);
85
86 add_conf_item("GUESTNICKS", &nicksvs.me->conf_table, guestnoreg_config_handler);
87 }
88
89 void
_moddeinit(module_unload_intent_t intent)90 _moddeinit(module_unload_intent_t intent)
91 {
92 hook_del_user_can_register(guestnoreg_hook);
93 hook_del_config_purge(guestnoreg_config_purge);
94
95 del_conf_item("GUESTNICKS", &nicksvs.me->conf_table);
96 }
97