Debian Codegraph @

modules/protocol/ircd-seven.c

raw
1 /*
2 * Copyright (c) 2003-2004 E. Will et al.
3 * Copyright (c) 2005-2007 Atheme Development Group
4 * Rights to this code are documented in doc/LICENSE.
5 *
6 * This file contains protocol support for ircd-seven.
7 *
8 */
9
10 #include "atheme.h"
11 #include "uplink.h"
12 #include "pmodule.h"
13 #include "protocol/charybdis.h"
14 #include "protocol/ircd-seven.h"
15
16 DECLARE_MODULE_V1("protocol/ircd-seven", true, _modinit, NULL, PACKAGE_STRING, VENDOR_STRING);
17
18 /* *INDENT-OFF* */
19
20 ircd_t Seven = {
21 .ircdname = "ircd-seven",
22 .tldprefix = "$$",
23 .uses_uid = true,
24 .uses_rcommand = false,
25 .uses_owner = false,
26 .uses_protect = false,
27 .uses_halfops = false,
28 .uses_p10 = false,
29 .uses_vhost = false,
30 .oper_only_modes = CMODE_EXLIMIT | CMODE_PERM | CMODE_IMMUNE,
31 .owner_mode = 0,
32 .protect_mode = 0,
33 .halfops_mode = 0,
34 .owner_mchar = "+",
35 .protect_mchar = "+",
36 .halfops_mchar = "+",
37 .type = PROTOCOL_CHARYBDIS,
38 .perm_mode = CMODE_PERM,
39 .oimmune_mode = CMODE_IMMUNE,
40 .ban_like_modes = "beIq",
41 .except_mchar = 'e',
42 .invex_mchar = 'I',
43 .flags = IRCD_CIDR_BANS | IRCD_HOLDNICK | IRCD_TOPIC_NOCOLOUR,
44 };
45
46 struct cmode_ seven_mode_list[] = {
47 { 'i', CMODE_INVITE },
48 { 'm', CMODE_MOD },
49 { 'n', CMODE_NOEXT },
50 { 'p', CMODE_PRIV },
51 { 's', CMODE_SEC },
52 { 't', CMODE_TOPIC },
53 { 'c', CMODE_NOCOLOR},
54 { 'r', CMODE_REGONLY},
55 { 'z', CMODE_OPMOD },
56 { 'g', CMODE_FINVITE},
57 { 'L', CMODE_EXLIMIT},
58 { 'P', CMODE_PERM },
59 { 'F', CMODE_FTARGET},
60 { 'Q', CMODE_DISFWD },
61 { 'M', CMODE_IMMUNE },
62 { 'C', CMODE_NOCTCP },
63
64 /* following modes are added as extensions */
65 { 'N', CMODE_NPC },
66 { 'S', CMODE_SSLONLY },
67 { 'O', CMODE_OPERONLY },
68 { 'A', CMODE_ADMINONLY },
69
70 { '\0', 0 }
71 };
72
73 struct cmode_ seven_user_mode_list[] = {
74 { 'p', UF_IMMUNE },
75 { 'a', UF_ADMIN },
76 { 'i', UF_INVIS },
77 { 'o', UF_IRCOP },
78 { 'D', UF_DEAF },
79 { 'S', UF_SERVICE },
80 { '\0', 0 }
81 };
82
83 /* *INDENT-ON* */
84
85 static bool seven_is_valid_hostslash(const char *host)
86 {
87 const char *p;
88 bool dot = false;
89
90 if (*host == '.' || *host == '/' || *host == ':')
91 return false;
92
93 for (p = host; *p != '\0'; p++)
94 {
95 if (*p == '.' || *p == ':' || *p == '/')
96 dot = true;
97 else if (!((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'Z') ||
98 (*p >= 'a' && *p <= 'z') || *p == '-'))
99 return false;
100 }
101 /* hyperion allows a trailing / but RichiH does not want it, whatever */
102 if (dot && p[-1] == '/')
103 return false;
104 return dot;
105 }
106
107 static void seven_wallops_sts(const char *reason)
108 {
109 sts(":%s ENCAP * SNOTE s :%s", ME, reason);
110 }
111
112 /* The following m_functions are copied from generic_ts6, with additions to handle the
113 * "identified" / "owns this nick" flag.
114 */
115
116 static void m_euid(sourceinfo_t *si, int parc, char *parv[])
117 {
118 server_t *s;
119 user_t *u;
120
121 /* got the right number of args for an introduction? */
122 if (parc >= 11)
123 {
124 s = si->s;
125 slog(LG_DEBUG, "m_euid(): new user on `%s': %s", s->name, parv[0]);
126
127 u = user_add(parv[0], /* nick */
128 parv[4], /* user */
129 *parv[8] != '*' ? parv[8] : parv[5], /* hostname */
130 parv[5], /* hostname (visible) */
131 parv[6], /* ip */
132 parv[7], /* uid */
133 parv[parc - 1], /* gecos */
134 s, /* object parent (server) */
135 atoi(parv[2])); /* hopcount */
136 if (u == NULL)
137 return;
138
139 user_mode(u, parv[3]);
140 if (*parv[9] != '*')
141 {
142 handle_burstlogin(u, parv[9], 0);
143 /* If an account is given in burst, then either they logged in with sasl,
144 * or they logged in before a split and are now returning. Either way we need
145 * to check for identified-to-nick status and update the ircd state accordingly.
146 * For sasl they should be marked identified, and when returning from a split
147 * their nick may have been ungrouped, they may have changed nicks, or their account
148 * may have been dropped.
149 */
150 if (authservice_loaded)
151 sts(":%s ENCAP * IDENTIFIED %s %s %s", ME, CLIENT_NAME(u), u->nick,
152 should_reg_umode(u) ? "" : "OFF");
153 }
154
155 /* server_eob() cannot know if a user was introduced
156 * with NICK/UID or EUID and handle_nickchange() must
157 * be called exactly once for each new user -- jilles */
158 if (s->flags & SF_EOB)
159 handle_nickchange(u);
160 }
161 else
162 {
163 int i;
164 slog(LG_DEBUG, "m_euid(): got EUID with wrong number of params");
165
166 for (i = 0; i < parc; i++)
167 slog(LG_DEBUG, "m_euid(): parv[%d] = %s", i, parv[i]);
168 }
169 }
170
171 static void m_nick(sourceinfo_t *si, int parc, char *parv[])
172 {
173 server_t *s;
174 user_t *u;
175
176 /* got the right number of args for an introduction? */
177 if (parc == 8)
178 {
179 s = server_find(parv[6]);
180 if (!s)
181 {
182 slog(LG_DEBUG, "m_nick(): new user on nonexistent server: %s", parv[6]);
183 return;
184 }
185
186 slog(LG_DEBUG, "m_nick(): new user on `%s': %s", s->name, parv[0]);
187
188 u = user_add(parv[0], parv[4], parv[5], NULL, NULL, NULL, parv[7], s, atoi(parv[2]));
189 if (u == NULL)
190 return;
191
192 user_mode(u, parv[3]);
193
194 /* If server is not yet EOB we will do this later.
195 * This avoids useless "please identify" -- jilles */
196 if (s->flags & SF_EOB)
197 handle_nickchange(user_find(parv[0]));
198 }
199
200 /* if it's only 2 then it's a nickname change */
201 else if (parc == 2)
202 {
203 bool realchange;
204
205 if (!si->su)
206 {
207 slog(LG_DEBUG, "m_nick(): server trying to change nick: %s", si->s != NULL ? si->s->name : "<none>");
208 return;
209 }
210
211 slog(LG_DEBUG, "m_nick(): nickname change from `%s': %s", si->su->nick, parv[0]);
212
213 realchange = irccasecmp(si->su->nick, parv[0]);
214
215 if (user_changenick(si->su, parv[0], atoi(parv[1])))
216 return;
217
218 /* fix up +e if necessary -- jilles */
219 if (realchange && should_reg_umode(si->su))
220 /* changed nick to registered one, reset +e */
221 sts(":%s ENCAP * IDENTIFIED %s %s", ME, CLIENT_NAME(si->su), si->su->nick);
222
223 /* It could happen that our PING arrived late and the
224 * server didn't acknowledge EOB yet even though it is
225 * EOB; don't send double notices in that case -- jilles */
226 if (si->su->server->flags & SF_EOB)
227 handle_nickchange(si->su);
228 }
229 else
230 {
231 int i;
232 slog(LG_DEBUG, "m_nick(): got NICK with wrong number of params");
233
234 for (i = 0; i < parc; i++)
235 slog(LG_DEBUG, "m_nick(): parv[%d] = %s", i, parv[i]);
236 }
237 }
238
239 /* protocol-specific stuff to do on login */
240 static void seven_on_login(user_t *u, myuser_t *mu, const char *wantedhost)
241 {
242 return_if_fail(u != NULL);
243
244 sts(":%s ENCAP * SU %s %s", ME, CLIENT_NAME(u), entity(mu)->name);
245
246 if (should_reg_umode(u))
247 sts(":%s ENCAP * IDENTIFIED %s %s", ME, CLIENT_NAME(u), u->nick);
248 }
249
250 static bool seven_on_logout(user_t *u, const char *account)
251 {
252 return_val_if_fail(u != NULL, false);
253
254 sts(":%s ENCAP * SU %s", ME, CLIENT_NAME(u));
255 sts(":%s ENCAP * IDENTIFIED %s %s OFF", ME, CLIENT_NAME(u), u->nick);
256 return false;
257 }
258
259 static void nick_group(hook_user_req_t *hdata)
260 {
261 user_t *u;
262
263 u = hdata->si->su != NULL && !irccasecmp(hdata->si->su->nick, hdata->mn->nick) ? hdata->si->su : user_find_named(hdata->mn->nick);
264 if (u != NULL && should_reg_umode(u))
265 sts(":%s ENCAP * IDENTIFIED %s %s", ME, CLIENT_NAME(u), u->nick);
266 }
267
268 static void nick_ungroup(hook_user_req_t *hdata)
269 {
270 user_t *u;
271
272 u = hdata->si->su != NULL && !irccasecmp(hdata->si->su->nick, hdata->mn->nick) ? hdata->si->su : user_find_named(hdata->mn->nick);
273 if (u != NULL && !nicksvs.no_nick_ownership)
274 sts(":%s ENCAP * IDENTIFIED %s %s OFF", ME, CLIENT_NAME(u), u->nick);
275 }
276
277 void _modinit(module_t * m)
278 {
279 MODULE_TRY_REQUEST_DEPENDENCY(m, "protocol/charybdis");
280
281 mode_list = seven_mode_list;
282 user_mode_list = seven_user_mode_list;
283
284 wallops_sts = &seven_wallops_sts;
285 ircd_on_login = &seven_on_login;
286 ircd_on_logout = &seven_on_logout;
287 is_valid_host = &seven_is_valid_hostslash;
288
289 pcommand_delete("NICK");
290 pcommand_add("NICK", m_nick, 2, MSRC_USER | MSRC_SERVER);
291 pcommand_delete("EUID");
292 pcommand_add("EUID", m_euid, 11, MSRC_SERVER);
293
294 ircd = &Seven;
295
296 hook_add_event("nick_group");
297 hook_add_nick_group(nick_group);
298 hook_add_event("nick_ungroup");
299 hook_add_nick_ungroup(nick_ungroup);
300
301 m->mflags = MODTYPE_CORE;
302
303 pmodule_loaded = true;
304 }
305
306 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
307 * vim:ts=8
308 * vim:sw=8
309 * vim:noexpandtab
310 */