]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net> | |
3 | * and Jilles Tjoelker <jilles -at- stack.nl> | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution in both source and binary forms are permitted | |
7 | * provided that the above copyright notice remains unchanged. | |
8 | * | |
9 | * m_chghost.c: A module for handling spoofing dynamically. | |
10 | */ | |
11 | ||
12 | #include "stdinc.h" | |
13 | #include "tools.h" | |
14 | #include "send.h" | |
15 | #include "channel.h" | |
16 | #include "client.h" | |
17 | #include "common.h" | |
18 | #include "config.h" | |
19 | #include "ircd.h" | |
20 | #include "numeric.h" | |
21 | #include "memory.h" | |
22 | #include "s_conf.h" | |
23 | #include "s_newconf.h" | |
24 | #include "s_serv.h" | |
25 | #include "s_user.h" | |
26 | #include "hash.h" | |
27 | #include "msg.h" | |
28 | #include "parse.h" | |
29 | #include "modules.h" | |
30 | #include "sprintf_irc.h" | |
31 | #include "whowas.h" | |
32 | #include "monitor.h" | |
33 | ||
34 | static int me_realhost(struct Client *, struct Client *, int, const char **); | |
35 | static int ms_chghost(struct Client *, struct Client *, int, const char **); | |
36 | static int me_chghost(struct Client *, struct Client *, int, const char **); | |
37 | static int mo_chghost(struct Client *, struct Client *, int, const char **); | |
38 | ||
39 | struct Message realhost_msgtab = { | |
40 | "REALHOST", 0, 0, 0, MFLG_SLOW, | |
41 | {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_realhost, 2}, mg_ignore} | |
42 | }; | |
43 | ||
44 | struct Message chghost_msgtab = { | |
45 | "CHGHOST", 0, 0, 0, MFLG_SLOW, | |
46 | {mg_ignore, mg_not_oper, {ms_chghost, 3}, {ms_chghost, 3}, {me_chghost, 3}, {mo_chghost, 3}} | |
47 | }; | |
48 | ||
49 | mapi_clist_av1 chghost_clist[] = { &chghost_msgtab, &realhost_msgtab, NULL }; | |
50 | ||
822a4a25 | 51 | DECLARE_MODULE_AV1(chghost, NULL, NULL, chghost_clist, NULL, NULL, "$Revision: 3424 $"); |
212380e3 AC |
52 | |
53 | /* clean_host() | |
54 | * | |
55 | * input - host to check | |
56 | * output - 0 if erroneous, else 0 | |
57 | * side effects - | |
58 | */ | |
59 | static int | |
60 | clean_host(const char *host) | |
61 | { | |
62 | int len = 0; | |
822a4a25 JT |
63 | |
64 | if (*host == '\0' || *host == ':') | |
65 | return 0; | |
212380e3 AC |
66 | |
67 | for(; *host; host++) | |
68 | { | |
69 | len++; | |
70 | ||
71 | if(!IsHostChar(*host)) | |
72 | return 0; | |
73 | } | |
74 | ||
75 | if(len > HOSTLEN) | |
76 | return 0; | |
77 | ||
78 | return 1; | |
79 | } | |
80 | ||
81 | /* | |
82 | * me_realhost | |
83 | * parv[0] = origin | |
84 | * parv[1] = real host | |
85 | * | |
86 | * Yes this contains a little race condition if someone does a whois | |
87 | * in between the UID and REALHOST and use_whois_actually is enabled. | |
88 | * I don't think that's a big problem as the whole thing is a | |
89 | * race condition. | |
90 | */ | |
91 | static int | |
92 | me_realhost(struct Client *client_p, struct Client *source_p, | |
93 | int parc, const char *parv[]) | |
94 | { | |
95 | if (!IsPerson(source_p)) | |
96 | return 0; | |
97 | ||
98 | del_from_hostname_hash(source_p->orighost, source_p); | |
14e23b0e | 99 | strlcpy(source_p->orighost, parv[1], sizeof source_p->orighost); |
212380e3 AC |
100 | if (irccmp(source_p->host, source_p->orighost)) |
101 | SetDynSpoof(source_p); | |
102 | else | |
103 | ClearDynSpoof(source_p); | |
104 | add_to_hostname_hash(source_p->orighost, source_p); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | static int | |
109 | do_chghost(struct Client *source_p, struct Client *target_p, | |
110 | const char *newhost, int is_encap) | |
111 | { | |
112 | if (!clean_host(newhost)) | |
113 | { | |
114 | sendto_realops_snomask(SNO_GENERAL, is_encap ? L_ALL : L_NETWIDE, "%s attempted to change hostname for %s to %s (invalid)", | |
115 | IsServer(source_p) ? source_p->name : get_oper_name(source_p), | |
116 | target_p->name, newhost); | |
117 | /* sending this remotely may disclose important | |
118 | * routing information -- jilles */ | |
119 | if (is_encap ? MyClient(target_p) : !ConfigServerHide.flatten_links) | |
120 | sendto_one_notice(target_p, ":*** Notice -- %s attempted to change your hostname to %s (invalid)", | |
121 | source_p->name, newhost); | |
122 | return 0; | |
123 | } | |
124 | change_nick_user_host(target_p, target_p->name, target_p->username, newhost, 0, "Changing host"); | |
125 | if (irccmp(target_p->host, target_p->orighost)) | |
126 | { | |
127 | SetDynSpoof(target_p); | |
128 | if (MyClient(target_p)) | |
129 | sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :is now your hidden host (set by %s)", target_p->host, source_p->name); | |
130 | } | |
131 | else | |
132 | { | |
133 | ClearDynSpoof(target_p); | |
134 | if (MyClient(target_p)) | |
135 | sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :hostname reset by %s", target_p->host, source_p->name); | |
136 | } | |
137 | if (MyClient(source_p)) | |
138 | sendto_one_notice(source_p, ":Changed hostname for %s to %s", target_p->name, target_p->host); | |
139 | if (!IsServer(source_p) && !IsService(source_p)) | |
140 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s changed hostname for %s to %s", get_oper_name(source_p), target_p->name, target_p->host); | |
141 | return 1; | |
142 | } | |
143 | ||
144 | /* | |
145 | * ms_chghost | |
146 | * parv[0] = origin | |
147 | * parv[1] = target | |
148 | * parv[2] = host | |
149 | */ | |
150 | static int | |
151 | ms_chghost(struct Client *client_p, struct Client *source_p, | |
152 | int parc, const char *parv[]) | |
153 | { | |
154 | struct Client *target_p; | |
155 | ||
156 | if (!(target_p = find_person(parv[1]))) | |
157 | return -1; | |
158 | ||
159 | if (do_chghost(source_p, target_p, parv[2], 0)) | |
160 | { | |
161 | sendto_server(client_p, NULL, | |
162 | CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s", | |
163 | use_id(source_p), use_id(target_p), parv[2]); | |
164 | sendto_server(client_p, NULL, | |
165 | CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", | |
166 | use_id(source_p), use_id(target_p), parv[2]); | |
167 | sendto_server(client_p, NULL, | |
168 | NOCAPS, CAP_TS6, ":%s ENCAP * CHGHOST %s :%s", | |
169 | source_p->name, target_p->name, parv[2]); | |
170 | } | |
171 | ||
172 | return 0; | |
173 | } | |
174 | ||
175 | /* | |
176 | * me_chghost | |
177 | * parv[0] = origin | |
178 | * parv[1] = target | |
179 | * parv[2] = host | |
180 | */ | |
181 | static int | |
182 | me_chghost(struct Client *client_p, struct Client *source_p, | |
183 | int parc, const char *parv[]) | |
184 | { | |
185 | struct Client *target_p; | |
186 | ||
187 | if (!(target_p = find_person(parv[1]))) | |
188 | return -1; | |
189 | ||
190 | do_chghost(source_p, target_p, parv[2], 1); | |
191 | ||
192 | return 0; | |
193 | } | |
194 | ||
195 | /* | |
196 | * mo_chghost | |
197 | * parv[0] = origin | |
198 | * parv[1] = target | |
199 | * parv[2] = host | |
200 | */ | |
201 | /* Disable this because of the abuse potential -- jilles | |
202 | * No, make it toggleable via ./configure. --nenolod | |
203 | */ | |
204 | static int | |
205 | mo_chghost(struct Client *client_p, struct Client *source_p, | |
206 | int parc, const char *parv[]) | |
207 | { | |
208 | #ifdef ENABLE_OPER_CHGHOST | |
209 | struct Client *target_p; | |
210 | ||
211 | if(!IsOperAdmin(source_p)) | |
212 | { | |
213 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
214 | me.name, source_p->name, "admin"); | |
215 | return 0; | |
216 | } | |
217 | ||
218 | if (!(target_p = find_named_person(parv[1]))) | |
219 | { | |
220 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
221 | form_str(ERR_NOSUCHNICK), parv[1]); | |
222 | return 0; | |
223 | } | |
224 | ||
225 | if (!clean_host(parv[2])) | |
226 | { | |
227 | sendto_one_notice(source_p, ":Hostname %s is invalid", parv[2]); | |
228 | return 0; | |
229 | } | |
230 | ||
231 | do_chghost(source_p, target_p, parv[2], 0); | |
232 | ||
233 | sendto_server(NULL, NULL, | |
234 | CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s", | |
235 | use_id(source_p), use_id(target_p), parv[2]); | |
236 | sendto_server(NULL, NULL, | |
237 | CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", | |
238 | use_id(source_p), use_id(target_p), parv[2]); | |
239 | sendto_server(NULL, NULL, | |
240 | NOCAPS, CAP_TS6, ":%s ENCAP * CHGHOST %s :%s", | |
241 | source_p->name, target_p->name, parv[2]); | |
242 | #else | |
243 | sendto_one_notice(source_p, ":CHGHOST is disabled"); | |
244 | #endif | |
245 | ||
246 | return 0; | |
247 | } | |
248 |