Debian Codegraph @

modules/nickserv/main.c

raw
1 /*
2 * Copyright (c) 2005 Atheme Development Group
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * This file contains the main() routine.
6 *
7 */
8
9 #include "atheme.h"
10 #include "conf.h" /* XXX conf_ni_table */
11 #include <limits.h>
12
13 DECLARE_MODULE_V1
14 (
15 "nickserv/main", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 struct
21 {
22 const char *nickstring, *accountstring;
23 } nick_account_trans[] =
24 {
25 /* command descriptions */
26 { "Reclaims use of a nickname.", N_("Disconnects an old session.") },
27 { "Registers a nickname.", N_("Registers an account.") },
28 { "Lists nicknames registered matching a given pattern.", N_("Lists accounts matching a given pattern.") },
29
30 /* messages */
31 { "\2%s\2 is not a registered nickname.", N_("\2%s\2 is not a registered account.") },
32 { "Syntax: INFO <nickname>", N_("Syntax: INFO <account>") },
33 { "No nicknames matched pattern \2%s\2", N_("No accounts matched pattern \2%s\2") },
34 { "An email containing nickname activation instructions has been sent to \2%s\2.", N_("An email containing account activation instructions has been sent to \2%s\2.") },
35 { "If you do not complete registration within one day your nickname will expire.", N_("If you do not complete registration within one day your account will expire.") },
36 { "%s registered the nick \2%s\2 and gained services operator privileges.", N_("%s registered the account \2%s\2 and gained services operator privileges.") },
37 { "You cannot use your nickname as a password.", N_("You cannot use your account name as a password.") },
38 { NULL, NULL }
39 };
40
41 static void nickserv_handle_nickchange(user_t *u)
42 {
43 mynick_t *mn;
44 hook_nick_enforce_t hdata;
45
46 if (nicksvs.me == NULL || nicksvs.no_nick_ownership)
47 return;
48
49 /* They're logged in, don't send them spam -- jilles */
50 if (u->myuser)
51 u->flags |= UF_SEENINFO;
52
53 /* Also don't send it if they came back from a split -- jilles */
54 if (!(u->server->flags & SF_EOB))
55 u->flags |= UF_SEENINFO;
56
57 if (!(mn = mynick_find(u->nick)))
58 {
59 if (!nicksvs.spam)
60 return;
61
62 if (!(u->flags & UF_SEENINFO) && chansvs.me != NULL)
63 {
64 notice(nicksvs.nick, u->nick, _("Welcome to %s, %s! Here on %s, we provide services to enable the "
65 "registration of nicknames and channels! For details, type \2/%s%s help\2 and \2/%s%s help\2."),
66 me.netname, u->nick, me.netname, (ircd->uses_rcommand == false) ? "msg " : "", nicksvs.me->disp, (ircd->uses_rcommand == false) ? "msg " : "", chansvs.me->disp);
67
68 u->flags |= UF_SEENINFO;
69 }
70
71 return;
72 }
73
74 if (u->myuser == mn->owner)
75 {
76 mn->lastseen = CURRTIME;
77 return;
78 }
79
80 /* OpenServices: is user on access list? -nenolod */
81 if (myuser_access_verify(u, mn->owner))
82 {
83 notice(nicksvs.nick, u->nick, _("Please identify via \2/%s%s identify <password>\2."),
84 (ircd->uses_rcommand == false) ? "msg " : "", nicksvs.me->disp);
85 return;
86 }
87
88 notice(nicksvs.nick, u->nick, _("This nickname is registered. Please choose a different nickname, or identify via \2/%s%s identify <password>\2."),
89 (ircd->uses_rcommand == false) ? "msg " : "", nicksvs.me->disp);
90 hdata.u = u;
91 hdata.mn = mn;
92 hook_call_nick_enforce(&hdata);
93 }
94
95 static void nickserv_config_ready(void *unused)
96 {
97 int i;
98
99 nicksvs.nick = nicksvs.me->nick;
100 nicksvs.user = nicksvs.me->user;
101 nicksvs.host = nicksvs.me->host;
102 nicksvs.real = nicksvs.me->real;
103
104 if (nicksvs.no_nick_ownership)
105 for (i = 0; nick_account_trans[i].nickstring != NULL; i++)
106 itranslation_create(_(nick_account_trans[i].nickstring),
107 _(nick_account_trans[i].accountstring));
108 else
109 for (i = 0; nick_account_trans[i].nickstring != NULL; i++)
110 itranslation_destroy(_(nick_account_trans[i].nickstring));
111 }
112
113 static int c_ni_emailexempts(mowgli_config_file_entry_t *ce)
114 {
115 mowgli_config_file_entry_t *subce;
116 mowgli_node_t *n, *tn;
117
118 if (!ce->entries)
119 return 0;
120
121 MOWGLI_ITER_FOREACH_SAFE(n, tn, nicksvs.emailexempts.head)
122 {
123 free(n->data);
124 mowgli_node_delete(n, &nicksvs.emailexempts);
125 mowgli_node_free(n);
126 }
127
128 MOWGLI_ITER_FOREACH(subce, ce->entries)
129 {
130 if (subce->entries != NULL)
131 {
132 conf_report_warning(ce, "Invalid email exempt entry");
133 continue;
134 }
135
136 mowgli_node_add(sstrdup(subce->varname), mowgli_node_create(), &nicksvs.emailexempts);
137 }
138
139 return 0;
140 }
141
142 void _modinit(module_t *m)
143 {
144 hook_add_event("config_ready");
145 hook_add_config_ready(nickserv_config_ready);
146
147 hook_add_event("nick_check");
148 hook_add_nick_check(nickserv_handle_nickchange);
149
150 nicksvs.me = service_add("nickserv", NULL);
151 authservice_loaded++;
152
153 add_bool_conf_item("SPAM", &nicksvs.me->conf_table, 0, &nicksvs.spam, false);
154 add_bool_conf_item("NO_NICK_OWNERSHIP", &nicksvs.me->conf_table, 0, &nicksvs.no_nick_ownership, false);
155 add_duration_conf_item("EXPIRE", &nicksvs.me->conf_table, 0, &nicksvs.expiry, "d", 0);
156 add_duration_conf_item("ENFORCE_EXPIRE", &nicksvs.me->conf_table, 0, &nicksvs.enforce_expiry, "d", 0);
157 add_duration_conf_item("ENFORCE_DELAY", &nicksvs.me->conf_table, 0, &nicksvs.enforce_delay, "s", 30);
158 add_dupstr_conf_item("ENFORCE_PREFIX", &nicksvs.me->conf_table, 0, &nicksvs.enforce_prefix, "Guest");
159 add_dupstr_conf_item("CRACKLIB_DICT", &nicksvs.me->conf_table, 0, &nicksvs.cracklib_dict, NULL);
160 add_conf_item("EMAILEXEMPTS", &nicksvs.me->conf_table, c_ni_emailexempts);
161 add_uint_conf_item("MAXNICKS", &nicksvs.me->conf_table, 9, &nicksvs.maxnicks, 1, INT_MAX, 5);
162 }
163
164 void _moddeinit(module_unload_intent_t intent)
165 {
166 if (nicksvs.me)
167 {
168 nicksvs.nick = NULL;
169 nicksvs.user = NULL;
170 nicksvs.host = NULL;
171 nicksvs.real = NULL;
172 service_delete(nicksvs.me);
173 nicksvs.me = NULL;
174 }
175 authservice_loaded--;
176
177 hook_del_config_ready(nickserv_config_ready);
178 hook_del_nick_check(nickserv_handle_nickchange);
179 }
180
181 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
182 * vim:ts=8
183 * vim:sw=8
184 * vim:noexpandtab
185 */