Debian Codegraph @

modules/contrib/src/ns_guestnoreg.c

raw
1 /*
2 * Copyright (c) 2010 William Pitcock <[email protected]>
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 #include "atheme-compat.h"
17
18 #if (CURRENT_ABI_REVISION < 730000)
19 # include "conf.h"
20 #endif
21
22 static mowgli_list_t guestnicks = { NULL, NULL, 0 };
23
24 static void
25 guestnoreg_hook(hook_user_register_check_t *hdata)
26 {
27 mowgli_node_t *n;
28
29 return_if_fail(hdata != NULL);
30 return_if_fail(hdata->si != NULL);
31
32 MOWGLI_ITER_FOREACH(n, guestnicks.head)
33 {
34 char *nick = n->data;
35 int nicklen = strlen(nick);
36
37 if (!strncasecmp(hdata->account, nick, nicklen))
38 {
39 command_fail(hdata->si, fault_badparams, _("Registering of guest nicknames is disallowed."));
40 hdata->approved++;
41 }
42 }
43
44 }
45
46 static int
47 guestnoreg_config_handler(mowgli_config_file_entry_t *ce)
48 {
49 mowgli_config_file_entry_t *cce;
50
51 MOWGLI_ITER_FOREACH(cce, ce->entries)
52 {
53 char *nick = sstrdup(cce->varname);
54 mowgli_node_add(nick, mowgli_node_create(), &guestnicks);
55 }
56
57 return 0;
58 }
59
60 static void
61 guestnoreg_config_purge(void *unused)
62 {
63 mowgli_node_t *n, *tn;
64
65 MOWGLI_ITER_FOREACH_SAFE(n, tn, guestnicks.head)
66 {
67 char *nick = n->data;
68
69 sfree(nick);
70 mowgli_node_delete(n, &guestnicks);
71 mowgli_node_free(n);
72 }
73 }
74
75 static void
76 mod_init(module_t *m)
77 {
78 hook_add_event("config_purge");
79 hook_add_config_purge(guestnoreg_config_purge);
80
81 hook_add_event("user_can_register");
82 hook_add_user_can_register(guestnoreg_hook);
83
84 add_conf_item("GUESTNICKS", &nicksvs.me->conf_table, guestnoreg_config_handler);
85 }
86
87 static void
88 mod_deinit(module_unload_intent_t intent)
89 {
90 hook_del_user_can_register(guestnoreg_hook);
91 hook_del_config_purge(guestnoreg_config_purge);
92
93 del_conf_item("GUESTNICKS", &nicksvs.me->conf_table);
94 }
95
96 SIMPLE_DECLARE_MODULE_V1("contrib/ns_guestnoreg", MODULE_UNLOAD_CAPABILITY_OK)