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