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.
23 #include "s_newconf.h"
30 #include "sprintf_irc.h"
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 **);
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
}
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}}
49 mapi_clist_av1 chghost_clist
[] = { &chghost_msgtab
, &realhost_msgtab
, NULL
};
51 DECLARE_MODULE_AV1(chghost
, NULL
, NULL
, chghost_clist
, NULL
, NULL
, "$Revision: 1865 $");
55 * input - host to check
56 * output - 0 if erroneous, else 0
60 clean_host(const char *host
)
68 if(!IsHostChar(*host
))
83 * Yes this contains a little race condition if someone does a whois
84 * in between the UID and REALHOST and use_whois_actually is enabled.
85 * I don't think that's a big problem as the whole thing is a
89 me_realhost(struct Client
*client_p
, struct Client
*source_p
,
90 int parc
, const char *parv
[])
92 if (!IsPerson(source_p
))
95 del_from_hostname_hash(source_p
->orighost
, source_p
);
96 strlcpy(source_p
->orighost
, parv
[1], HOSTLEN
);
97 if (irccmp(source_p
->host
, source_p
->orighost
))
98 SetDynSpoof(source_p
);
100 ClearDynSpoof(source_p
);
101 add_to_hostname_hash(source_p
->orighost
, source_p
);
106 do_chghost(struct Client
*source_p
, struct Client
*target_p
,
107 const char *newhost
, int is_encap
)
109 if (!clean_host(newhost
))
111 sendto_realops_snomask(SNO_GENERAL
, is_encap
? L_ALL
: L_NETWIDE
, "%s attempted to change hostname for %s to %s (invalid)",
112 IsServer(source_p
) ? source_p
->name
: get_oper_name(source_p
),
113 target_p
->name
, newhost
);
114 /* sending this remotely may disclose important
115 * routing information -- jilles */
116 if (is_encap
? MyClient(target_p
) : !ConfigServerHide
.flatten_links
)
117 sendto_one_notice(target_p
, ":*** Notice -- %s attempted to change your hostname to %s (invalid)",
118 source_p
->name
, newhost
);
121 change_nick_user_host(target_p
, target_p
->name
, target_p
->username
, newhost
, 0, "Changing host");
122 if (irccmp(target_p
->host
, target_p
->orighost
))
124 SetDynSpoof(target_p
);
125 if (MyClient(target_p
))
126 sendto_one_numeric(target_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host (set by %s)", target_p
->host
, source_p
->name
);
130 ClearDynSpoof(target_p
);
131 if (MyClient(target_p
))
132 sendto_one_numeric(target_p
, RPL_HOSTHIDDEN
, "%s :hostname reset by %s", target_p
->host
, source_p
->name
);
134 if (MyClient(source_p
))
135 sendto_one_notice(source_p
, ":Changed hostname for %s to %s", target_p
->name
, target_p
->host
);
136 if (!IsServer(source_p
) && !IsService(source_p
))
137 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
);
148 ms_chghost(struct Client
*client_p
, struct Client
*source_p
,
149 int parc
, const char *parv
[])
151 struct Client
*target_p
;
153 if (!(target_p
= find_person(parv
[1])))
156 if (do_chghost(source_p
, target_p
, parv
[2], 0))
158 sendto_server(client_p
, NULL
,
159 CAP_EUID
| CAP_TS6
, NOCAPS
, ":%s CHGHOST %s %s",
160 use_id(source_p
), use_id(target_p
), parv
[2]);
161 sendto_server(client_p
, NULL
,
162 CAP_TS6
, CAP_EUID
, ":%s ENCAP * CHGHOST %s :%s",
163 use_id(source_p
), use_id(target_p
), parv
[2]);
164 sendto_server(client_p
, NULL
,
165 NOCAPS
, CAP_TS6
, ":%s ENCAP * CHGHOST %s :%s",
166 source_p
->name
, target_p
->name
, parv
[2]);
179 me_chghost(struct Client
*client_p
, struct Client
*source_p
,
180 int parc
, const char *parv
[])
182 struct Client
*target_p
;
184 if (!(target_p
= find_person(parv
[1])))
187 do_chghost(source_p
, target_p
, parv
[2], 1);
198 /* Disable this because of the abuse potential -- jilles
199 * No, make it toggleable via ./configure. --nenolod
202 mo_chghost(struct Client
*client_p
, struct Client
*source_p
,
203 int parc
, const char *parv
[])
205 #ifdef ENABLE_OPER_CHGHOST
206 struct Client
*target_p
;
208 if(!IsOperAdmin(source_p
))
210 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
211 me
.name
, source_p
->name
, "admin");
215 if (!(target_p
= find_named_person(parv
[1])))
217 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
218 form_str(ERR_NOSUCHNICK
), parv
[1]);
222 if (!clean_host(parv
[2]))
224 sendto_one_notice(source_p
, ":Hostname %s is invalid", parv
[2]);
228 do_chghost(source_p
, target_p
, parv
[2], 0);
230 sendto_server(NULL
, NULL
,
231 CAP_EUID
| CAP_TS6
, NOCAPS
, ":%s CHGHOST %s %s",
232 use_id(source_p
), use_id(target_p
), parv
[2]);
233 sendto_server(NULL
, NULL
,
234 CAP_TS6
, CAP_EUID
, ":%s ENCAP * CHGHOST %s :%s",
235 use_id(source_p
), use_id(target_p
), parv
[2]);
236 sendto_server(NULL
, NULL
,
237 NOCAPS
, CAP_TS6
, ":%s ENCAP * CHGHOST %s :%s",
238 source_p
->name
, target_p
->name
, parv
[2]);
240 sendto_one_notice(source_p
, ":CHGHOST is disabled");