1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_change.c: Allows changing user/host/real of connected clients. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id: m_change.c 801 2006-08-30 16:54:25Z adx $ |
23 |
*/ |
24 |
|
25 |
/* List of ircd includes from ../include/ */ |
26 |
#include "stdinc.h" |
27 |
#include "conf/conf.h" |
28 |
#include "handlers.h" |
29 |
#include "client.h" |
30 |
#include "common.h" /* FALSE bleah */ |
31 |
#include "ircd.h" |
32 |
#include "numeric.h" |
33 |
#include "server.h" |
34 |
#include "send.h" |
35 |
#include "msg.h" |
36 |
#include "parse.h" |
37 |
#include "user.h" |
38 |
#include "hash.h" |
39 |
#include "userhost.h" |
40 |
|
41 |
static void mo_chgident(struct Client *, struct Client *, int, char *[]); |
42 |
static void mo_chghost(struct Client *, struct Client *, int, char *[]); |
43 |
static void mo_chgname(struct Client *, struct Client *, int, char *[]); |
44 |
|
45 |
struct Message chgident_msgtab = { |
46 |
"CHGIDENT", 0, 0, 2, 0, MFLG_SLOW, 0, |
47 |
{ m_unregistered, m_not_oper, mo_chgident, mo_chgident, mo_chgident, m_ignore } |
48 |
}; |
49 |
|
50 |
struct Message chghost_msgtab = { |
51 |
"CHGHOST", 0, 0, 2, 0, MFLG_SLOW, 0, |
52 |
{ m_unregistered, m_not_oper, mo_chghost, mo_chghost, mo_chghost, m_ignore } |
53 |
}; |
54 |
|
55 |
struct Message chgname_msgtab = { |
56 |
"CHGNAME", 0, 0, 2, 0, MFLG_SLOW, 0, |
57 |
{ m_unregistered, m_not_oper, mo_chgname, mo_chgname, mo_chgname, m_ignore } |
58 |
}; |
59 |
|
60 |
INIT_MODULE(m_change, "$Revision: 801 $") |
61 |
{ |
62 |
mod_add_cmd(&chgident_msgtab); |
63 |
mod_add_cmd(&chghost_msgtab); |
64 |
mod_add_cmd(&chgname_msgtab); |
65 |
} |
66 |
|
67 |
CLEANUP_MODULE |
68 |
{ |
69 |
mod_del_cmd(&chgname_msgtab); |
70 |
mod_del_cmd(&chghost_msgtab); |
71 |
mod_del_cmd(&chgident_msgtab); |
72 |
} |
73 |
|
74 |
static void |
75 |
mo_chgident(struct Client *client_p, struct Client *source_p, |
76 |
int parc, char *parv[]) |
77 |
{ |
78 |
struct Client *target_p = NULL; |
79 |
|
80 |
if (MyClient(source_p) && !IsOperAdmin(source_p)) |
81 |
{ |
82 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
83 |
me.name, parv[0], "CHGIDENT"); |
84 |
return; |
85 |
} |
86 |
|
87 |
if (EmptyString(parv[2])) |
88 |
{ |
89 |
parv[2] = parv[1]; |
90 |
|
91 |
target_p = source_p; |
92 |
if (!IsClient(target_p)) |
93 |
return; |
94 |
} |
95 |
else { |
96 |
target_p = find_client(parv[1]); |
97 |
|
98 |
if (target_p == NULL || !IsClient(target_p)) |
99 |
{ |
100 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
101 |
me.name, parv[0], parv[1]); |
102 |
return; |
103 |
} |
104 |
} |
105 |
|
106 |
if (strlen(parv[2]) > USERLEN || !*parv[2] || !valid_username(parv[2])) |
107 |
{ |
108 |
sendto_one(source_p, ":%s NOTICE %s :Invalid username", me.name, parv[0]); |
109 |
return; |
110 |
} |
111 |
|
112 |
delete_user_host(target_p->username, target_p->host, !MyConnect(target_p)); |
113 |
strcpy(target_p->username, parv[2]); |
114 |
add_user_host(target_p->username, target_p->host, !MyConnect(target_p)); |
115 |
|
116 |
if (MyClient(source_p)) |
117 |
{ |
118 |
sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, |
119 |
":%s ENCAP * CHGIDENT %s %s", |
120 |
parv[0], target_p->name, parv[2]); |
121 |
sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s", |
122 |
me.name, parv[0], target_p->name, target_p->username, |
123 |
target_p->host); |
124 |
} |
125 |
|
126 |
if (MyConnect(target_p) && IsClient(source_p)) |
127 |
sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s", |
128 |
me.name, target_p->name, target_p->username, target_p->host); |
129 |
} |
130 |
|
131 |
static void |
132 |
mo_chghost(struct Client *client_p, struct Client *source_p, |
133 |
int parc, char *parv[]) |
134 |
{ |
135 |
struct Client *target_p = NULL; |
136 |
|
137 |
if (MyClient(source_p) && !IsOperAdmin(source_p)) |
138 |
{ |
139 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
140 |
me.name, parv[0], "CHGHOST"); |
141 |
return; |
142 |
} |
143 |
|
144 |
if (EmptyString(parv[2])) |
145 |
{ |
146 |
parv[2] = parv[1]; |
147 |
|
148 |
target_p = source_p; |
149 |
if (!IsClient(target_p)) |
150 |
return; |
151 |
} |
152 |
else { |
153 |
target_p = find_client(parv[1]); |
154 |
if (target_p == NULL || !IsClient(target_p)) |
155 |
{ |
156 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
157 |
me.name, parv[0], parv[1]); |
158 |
return; |
159 |
} |
160 |
} |
161 |
|
162 |
if (strlen(parv[2]) > HOSTLEN || !*parv[2] || !valid_hostname(parv[2])) |
163 |
{ |
164 |
sendto_one(source_p, ":%s NOTICE %s :Invalid hostname", me.name, parv[0]); |
165 |
return; |
166 |
} |
167 |
|
168 |
delete_user_host(target_p->username, target_p->host, !MyConnect(target_p)); |
169 |
strcpy(target_p->host, parv[2]); |
170 |
add_user_host(target_p->username, target_p->host, !MyConnect(target_p)); |
171 |
SetIPSpoof(target_p); |
172 |
|
173 |
if (MyClient(source_p)) |
174 |
{ |
175 |
sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, |
176 |
":%s ENCAP * CHGHOST %s :%s", |
177 |
parv[0], target_p->name, parv[2]); |
178 |
sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s", |
179 |
me.name, parv[0], target_p->name, target_p->username, |
180 |
target_p->host); |
181 |
} |
182 |
|
183 |
if (MyConnect(target_p) && IsClient(source_p)) |
184 |
sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s", |
185 |
me.name, target_p->name, target_p->username, target_p->host); |
186 |
} |
187 |
|
188 |
static void |
189 |
mo_chgname(struct Client *client_p, struct Client *source_p, |
190 |
int parc, char *parv[]) |
191 |
{ |
192 |
struct Client *target_p = NULL; |
193 |
|
194 |
if (MyClient(source_p) && !IsOperAdmin(source_p)) |
195 |
{ |
196 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
197 |
me.name, parv[0], "CHGNAME"); |
198 |
return; |
199 |
} |
200 |
|
201 |
if (EmptyString(parv[2])) |
202 |
{ |
203 |
parv[2] = parv[1]; |
204 |
target_p = source_p; |
205 |
} |
206 |
else if ((target_p = find_client(parv[1])) == NULL) |
207 |
{ |
208 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
209 |
me.name, parv[0], parv[1]); |
210 |
return; |
211 |
} |
212 |
|
213 |
if (strlen(parv[2]) > REALLEN || !*parv[2]) |
214 |
{ |
215 |
sendto_one(source_p, ":%s NOTICE %s :Invalid realname", me.name, parv[0]); |
216 |
return; |
217 |
} |
218 |
|
219 |
if (parc > 3 && MyClient(source_p)) |
220 |
sendto_one(source_p, ":%s NOTICE %s :Warning -- too many parameters " |
221 |
"for CHGNAME. You are probably missing a : before the new " |
222 |
"IRC name.", me.name, parv[0]); |
223 |
|
224 |
strcpy(target_p->info, parv[2]); |
225 |
|
226 |
if (MyClient(source_p)) |
227 |
{ |
228 |
sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, |
229 |
":%s ENCAP * CHGNAME %s :%s", |
230 |
parv[0], target_p->name, parv[2]); |
231 |
sendto_one(source_p, ":%s NOTICE %s :%s realname changed to [%s]", |
232 |
me.name, parv[0], target_p->name, target_p->info); |
233 |
} |
234 |
|
235 |
if (MyClient(target_p) && IsClient(source_p)) |
236 |
sendto_one(target_p, ":%s NOTICE %s :Your realname is now [%s]", |
237 |
me.name, target_p->name, target_p->info); |
238 |
} |