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