2 * IRC - Internet Relay Chat, ircd/m_fakehost.c
3 * Copyright (C) 2004 Zoot <zoot@gamesurge.net>
5 * See file AUTHORS in IRC package for additional names of
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 1, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * m_functions execute protocol messages on this server:
28 * cptr is always NON-NULL, pointing to a *LOCAL* client
29 * structure (with an open socket connected!). This
30 * identifies the physical socket where the message
31 * originated (or which caused the m_function to be
32 * executed--some m_functions may call others...).
34 * sptr is the source of the message, defined by the
35 * prefix part of the message if present. If not
36 * or prefix not found, then sptr==cptr.
38 * (!IsServer(cptr)) => (cptr == sptr), because
39 * prefixes are taken *only* from servers...
42 * (sptr == cptr) => the message didn't
45 * (sptr != cptr && IsServer(sptr) means
46 * the prefix specified servername. (?)
48 * (sptr != cptr && !IsServer(sptr) means
49 * that message originated from a remote
54 * (!IsServer(sptr)) means that, sptr can safely
55 * taken as defining the target structure of the
56 * message in this server.
58 * *Always* true (if 'parse' and others are working correct):
60 * 1) sptr->from == cptr (note: cptr->from == cptr)
62 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
63 * *cannot* be a local connection, unless it's
64 * actually cptr!). [MyConnect(x) should probably
65 * be defined as (x == x->from) --msa ]
67 * parc number of variable parameter strings (if zero,
68 * parv is allowed to be NULL)
70 * parv a NULL terminated list of parameter pointers,
72 * parv[0], sender (prefix string), if not present
73 * this points to an empty string.
74 * parv[1]...parv[parc-1]
75 * pointers to additional parameters
76 * parv[parc] == NULL, *always*
78 * note: it is guaranteed that parv[0]..parv[parc-1] are all
86 #include "ircd_reply.h"
87 #include "ircd_string.h"
97 * m_fakehost - fakehost user message handler
99 * parv[0] = sender prefix
100 * parv[1] = new fake host
102 int m_fakehost(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
104 struct Client *acptr,*another;
106 if (!IsNetServ(sptr) || !HasFlag(sptr, FLAG_SECURITY_SERV))
107 return send_reply(sptr, ERR_NOPRIVILEGES);
110 return need_more_params(sptr, "FAKEHOST");
114 /* Assign and propagate the fakehost */
115 ircd_strncpy(cli_user(cptr)->fakehost, parv[1], HOSTLEN);
116 hide_hostmask(cptr, FLAG_FAKEHOST);
118 /*for(i = HighestFd; i >= 0; i--) {
119 if((another = LocalClientArray[i]) && IsServer(another)) {
120 sendcmdto_one(cptr, CMD_MODE, another, "%s +f :%s", cli_name(cptr), parv[2]);
123 sendcmdto_serv_butone(sptr, CMD_FAKEHOST_OLD, cptr, "%C %s", cptr,cli_user(cptr)->fakehost);
130 acptr = FindUser(parv[1]);
133 send_reply(sptr, ERR_NOSUCHCHANNEL, parv[1]);
138 /* Assign and propagate the fakehost */
139 ircd_strncpy(cli_user(acptr)->fakehost, parv[2], HOSTLEN);
140 hide_hostmask(acptr, FLAG_FAKEHOST);
142 for(i = HighestFd; i >= 0; i--) {
143 if((another = LocalClientArray[i]) && IsServer(another)) {
144 sendcmdto_one(acptr, CMD_MODE, another, "%s +f :%s", cli_name(acptr), parv[2]);
148 sendcmdto_serv_butone(sptr, CMD_FAKEHOST_OLD, cptr, "%C %s", acptr,
149 cli_user(acptr)->fakehost);
155 * IRC - Internet Relay Chat, ircd/m_fakehost.c
156 * Written by David Herrmann.
160 * m_functions execute protocol messages on this server:
162 * cptr is always NON-NULL, pointing to a *LOCAL* client
163 * structure (with an open socket connected!). This
164 * identifies the physical socket where the message
165 * originated (or which caused the m_function to be
166 * executed--some m_functions may call others...).
168 * sptr is the source of the message, defined by the
169 * prefix part of the message if present. If not
170 * or prefix not found, then sptr==cptr.
172 * (!IsServer(cptr)) => (cptr == sptr), because
173 * prefixes are taken *only* from servers...
176 * (sptr == cptr) => the message didn't
179 * (sptr != cptr && IsServer(sptr) means
180 * the prefix specified servername. (?)
182 * (sptr != cptr && !IsServer(sptr) means
183 * that message originated from a remote
188 * (!IsServer(sptr)) means that, sptr can safely
189 * taken as defining the target structure of the
190 * message in this server.
192 * *Always* true (if 'parse' and others are working correct):
194 * 1) sptr->from == cptr (note: cptr->from == cptr)
196 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
197 * *cannot* be a local connection, unless it's
198 * actually cptr!). [MyConnect(x) should probably
199 * be defined as (x == x->from) --msa ]
201 * parc number of variable parameter strings (if zero,
202 * parv is allowed to be NULL)
204 * parv a NULL terminated list of parameter pointers,
206 * parv[0], sender (prefix string), if not present
207 * this points to an empty string.
208 * parv[1]...parv[parc-1]
209 * pointers to additional parameters
210 * parv[parc] == NULL, *always*
212 * note: it is guaranteed that parv[0]..parv[parc-1] are all
217 /* ms_fakehost - fakehost server message handler
219 * parv[0] = sender prefix
220 * parv[1] = target user numeric
221 * parv[2] = target user's new fake host
224 * Allows servers to force a fakehost on remote users.
226 * The FAKEHOST request can be generated by EVERY server. It is forwarded to the server
227 * of the user which then sets the fakehost and broadcasts the new fakehost.
229 int ms_fakehost(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) {
230 struct Client *target, *acptr;
234 return need_more_params(sptr, "FAKEHOST");
237 if(!(target = findNUser(parv[1]))) {
238 /* Silently ignore FAKEHOSTs for disconnected users. */
242 /* Ignore the assignment if it changes nothing. */
243 if(IsFakeHost(target) && strcmp(cli_user(target)->fakehost, parv[2]) == 0) {
247 /* If the user is no local user, we forward the message to the user's server. */
248 if(!MyConnect(target)) {
249 sendcmdto_one(sptr, CMD_FAKEHOST, cli_user(target)->server, "%C %s", target, parv[2]);
253 /* Set fakehost and propagate the changed host. */
254 ircd_strncpy(cli_user(target)->fakehost, parv[2], HOSTLEN);
255 hide_hostmask(target, FLAG_FAKEHOST);
257 /* Borrowed from send_umode_out().
258 * I found no better way to do this. However, maybe someone has the time to check out
259 * s_user.c to change this.
261 for(i = HighestFd; i >= 0; i--) {
262 if((acptr = LocalClientArray[i]) && IsServer(acptr)) {
263 sendcmdto_one(target, CMD_MODE, acptr, "%s +f :%s", cli_name(target), parv[2]);
270 /* ms_fakehost2 - new fakehost server message handler (SRVX initialized)
272 * parv[0] = sender prefix
273 * parv[1] = target user numeric
274 * parv[2] = target user's new ident
275 * parv[3] = target user's new fake host
276 * parv[4] = FORCE (optional)
279 * Allows servers to force a fakehost on remote users.
281 * The FAKEHOST request can be generated by EVERY server. It is forwarded to the server
282 * of the user which then sets the fakehost and broadcasts the new fakehost.
284 int ms_fakehost2(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) {
285 struct Client *target, *acptr;
289 return need_more_params(sptr, "FAKEHOST");
292 if(!(target = findNUser(parv[1]))) {
293 /* Silently ignore FAKEHOSTs for disconnected users. */
297 /* Ignore the assignment if it changes nothing. */
298 if(IsFakeHost(target) && strcmp(cli_user(target)->fakehost, parv[3]) == 0 && strcmp(cli_user(target)->fakeuser, parv[2]) == 0) {
302 /* Set fakehost and propagate the changed host. */
303 ircd_strncpy(cli_user(target)->fakehost, parv[3], HOSTLEN);
304 ircd_strncpy(cli_user(target)->fakeuser, parv[2], USERLEN);
305 hide_hostmask(target, FLAG_FAKEHOST | FLAG_FAKEIDENT);
307 sendcmdto_serv_butone(sptr, CMD_FAKEHOST2, cptr, "%C %s %s", target, cli_user(target)->fakeuser, cli_user(target)->fakehost);
313 * ms_fakehost_old - old fakehost server message handler
315 * parv[0] = sender prefix
316 * parv[1] = target user numeric
317 * parv[2] = target user's new fake host
318 * parv[3] = target user's new fake ident
320 int ms_fakehost_old(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) {
321 struct Client *target;
324 return need_more_params(sptr, "FAKE");
326 /* Locate our target user; ignore the message if we can't */
327 if(!(target = findNUser(parv[1])))
330 /* Ignore the assignment if it changes nothing */
331 if(IsFakeHost(target) && strcmp(cli_user(target)->fakehost, parv[2]) == 0) {
335 /* Assign and propagate the fakehost */
336 ircd_strncpy(cli_user(target)->fakehost, parv[2], HOSTLEN);
337 hide_hostmask(target, FLAG_FAKEHOST);
339 sendcmdto_serv_butone(sptr, CMD_FAKEHOST_OLD, cptr, "%C %s", target,
340 cli_user(target)->fakehost);