2 * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
3 * and Jilles Tjoelker <jilles -at- stack.nl>
6 * Redistribution in both source and binary forms are permitted
7 * provided that the above copyright notice remains unchanged.
9 * m_chghost.c: A module for handling spoofing dynamically.
21 #include "s_newconf.h"
31 static const char chghost_desc
[] = "Provides commands used to change and retrieve client hostnames";
33 static void me_realhost(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
34 static void ms_chghost(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
35 static void me_chghost(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
36 static void mo_chghost(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
38 struct Message realhost_msgtab
= {
39 "REALHOST", 0, 0, 0, 0,
40 {mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {me_realhost
, 2}, mg_ignore
}
43 struct Message chghost_msgtab
= {
44 "CHGHOST", 0, 0, 0, 0,
45 {mg_ignore
, mg_not_oper
, {ms_chghost
, 3}, {ms_chghost
, 3}, {me_chghost
, 3}, {mo_chghost
, 3}}
48 mapi_clist_av1 chghost_clist
[] = { &chghost_msgtab
, &realhost_msgtab
, NULL
};
50 DECLARE_MODULE_AV2(chghost
, NULL
, NULL
, chghost_clist
, NULL
, NULL
, NULL
, NULL
, chghost_desc
);
54 * input - host to check
55 * output - 0 if erroneous, else 1
59 clean_host(const char *host
)
62 const char *last_slash
= 0;
64 if (*host
== '\0' || *host
== ':')
71 if(!IsHostChar(*host
))
80 if(last_slash
&& IsDigit(last_slash
[1]))
90 * Yes this contains a little race condition if someone does a whois
91 * in between the UID and REALHOST and use_whois_actually is enabled.
92 * I don't think that's a big problem as the whole thing is a
96 me_realhost(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
,
97 int parc
, const char *parv
[])
99 if (!IsPerson(source_p
))
102 del_from_hostname_hash(source_p
->orighost
, source_p
);
103 rb_strlcpy(source_p
->orighost
, parv
[1], sizeof source_p
->orighost
);
104 if (irccmp(source_p
->host
, source_p
->orighost
))
105 SetDynSpoof(source_p
);
107 ClearDynSpoof(source_p
);
108 add_to_hostname_hash(source_p
->orighost
, source_p
);
113 do_chghost(struct Client
*source_p
, struct Client
*target_p
,
114 const char *newhost
, int is_encap
)
116 if (!clean_host(newhost
))
118 sendto_realops_snomask(SNO_GENERAL
, is_encap
? L_ALL
: L_NETWIDE
, "%s attempted to change hostname for %s to %s (invalid)",
119 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
120 target_p
->name
, newhost
);
121 /* sending this remotely may disclose important
122 * routing information -- jilles */
123 if (is_encap
? MyClient(target_p
) : !ConfigServerHide
.flatten_links
)
124 sendto_one_notice(target_p
, ":*** Notice -- %s attempted to change your hostname to %s (invalid)",
125 source_p
->name
, newhost
);
128 change_nick_user_host(target_p
, target_p
->name
, target_p
->username
, newhost
, 0, "Changing host");
129 if (irccmp(target_p
->host
, target_p
->orighost
))
131 SetDynSpoof(target_p
);
132 if (MyClient(target_p
))
133 sendto_one_numeric(target_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host (set by %s)", target_p
->host
, source_p
->name
);
137 ClearDynSpoof(target_p
);
138 if (MyClient(target_p
))
139 sendto_one_numeric(target_p
, RPL_HOSTHIDDEN
, "%s :hostname reset by %s", target_p
->host
, source_p
->name
);
141 if (MyClient(source_p
))
142 sendto_one_notice(source_p
, ":Changed hostname for %s to %s", target_p
->name
, target_p
->host
);
143 if (!IsServer(source_p
) && !IsService(source_p
))
144 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
);
154 ms_chghost(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
,
155 int parc
, const char *parv
[])
157 struct Client
*target_p
;
159 if (!(target_p
= find_person(parv
[1])))
162 if (do_chghost(source_p
, target_p
, parv
[2], 0))
164 sendto_server(client_p
, NULL
,
165 CAP_EUID
| CAP_TS6
, NOCAPS
, ":%s CHGHOST %s %s",
166 use_id(source_p
), use_id(target_p
), parv
[2]);
167 sendto_server(client_p
, NULL
,
168 CAP_TS6
, CAP_EUID
, ":%s ENCAP * CHGHOST %s :%s",
169 use_id(source_p
), use_id(target_p
), parv
[2]);
181 me_chghost(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
,
182 int parc
, const char *parv
[])
184 struct Client
*target_p
;
186 if (!(target_p
= find_person(parv
[1])))
189 do_chghost(source_p
, target_p
, parv
[2], 1);
199 /* Disable this because of the abuse potential -- jilles
200 * No, make it toggleable via ./configure. --nenolod
203 mo_chghost(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
,
204 int parc
, const char *parv
[])
206 #ifdef ENABLE_OPER_CHGHOST
207 struct Client
*target_p
;
209 if(!IsOperAdmin(source_p
))
211 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
212 me
.name
, source_p
->name
, "admin");
216 if (!(target_p
= find_named_person(parv
[1])))
218 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
219 form_str(ERR_NOSUCHNICK
), parv
[1]);
223 if (!clean_host(parv
[2]))
225 sendto_one_notice(source_p
, ":Hostname %s is invalid", parv
[2]);
229 do_chghost(source_p
, target_p
, parv
[2], 0);
231 sendto_server(NULL
, NULL
,
232 CAP_EUID
| CAP_TS6
, NOCAPS
, ":%s CHGHOST %s %s",
233 use_id(source_p
), use_id(target_p
), parv
[2]);
234 sendto_server(NULL
, NULL
,
235 CAP_TS6
, CAP_EUID
, ":%s ENCAP * CHGHOST %s :%s",
236 use_id(source_p
), use_id(target_p
), parv
[2]);
238 sendto_one_numeric(source_p
, ERR_DISABLED
, form_str(ERR_DISABLED
),