ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/contrib/m_change.c
Revision: 1110
Committed: Wed Nov 3 15:57:22 2010 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 7348 byte(s)
Log Message:
- m_change.c: Fixed bug where exiting clients got not removed from userhost hash
  in case CHGHOST has been used on them

File Contents

# Content
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$
23 */
24
25 /* List of ircd includes from ../include/ */
26 #include "stdinc.h"
27 #include "handlers.h"
28 #include "client.h"
29 #include "common.h" /* FALSE bleah */
30 #include "ircd.h"
31 #include "irc_string.h"
32 #include "numeric.h"
33 #include "fdlist.h"
34 #include "s_bsd.h"
35 #include "s_conf.h"
36 #include "s_log.h"
37 #include "s_serv.h"
38 #include "send.h"
39 #include "msg.h"
40 #include "parse.h"
41 #include "modules.h"
42 #include "s_user.h"
43 #include "hash.h"
44 #include "userhost.h"
45
46 static void mo_chgident(struct Client *, struct Client *, int, char *[]);
47 static void mo_chghost(struct Client *, struct Client *, int, char *[]);
48 static void mo_chgname(struct Client *, struct Client *, int, char *[]);
49
50 struct Message chgident_msgtab = {
51 "CHGIDENT", 0, 0, 2, 0, MFLG_SLOW, 0,
52 {m_unregistered, m_not_oper, mo_chgident, mo_chgident, mo_chgident, m_ignore}
53 };
54
55 struct Message chghost_msgtab = {
56 "CHGHOST", 0, 0, 2, 0, MFLG_SLOW, 0,
57 {m_unregistered, m_not_oper, mo_chghost, mo_chghost, mo_chghost, m_ignore}
58 };
59
60 struct Message chgname_msgtab = {
61 "CHGNAME", 0, 0, 2, 0, MFLG_SLOW, 0,
62 {m_unregistered, m_not_oper, mo_chgname, mo_chgname, mo_chgname, m_ignore}
63 };
64
65 #ifndef STATIC_MODULES
66 void
67 _modinit(void)
68 {
69 mod_add_cmd(&chgident_msgtab);
70 mod_add_cmd(&chghost_msgtab);
71 mod_add_cmd(&chgname_msgtab);
72 }
73
74 void
75 _moddeinit(void)
76 {
77 mod_del_cmd(&chgname_msgtab);
78 mod_del_cmd(&chghost_msgtab);
79 mod_del_cmd(&chgident_msgtab);
80 }
81
82 const char *_version = "$Revision$";
83 #endif
84
85 static void
86 mo_chgident(struct Client *client_p, struct Client *source_p,
87 int parc, char *parv[])
88 {
89 struct Client *target_p = NULL;
90
91 if (MyClient(source_p) && !IsOperAdmin(source_p))
92 {
93 sendto_one(source_p, form_str(ERR_NOPRIVS),
94 me.name, source_p->name, "CHGIDENT");
95 return;
96 }
97
98 if (EmptyString(parv[2]))
99 {
100 parv[2] = parv[1];
101 target_p = source_p;
102
103 if (!IsClient(target_p))
104 return;
105 }
106 else {
107 target_p = find_client(parv[1]);
108
109 if (target_p == NULL || !IsClient(target_p))
110 {
111 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
112 me.name, source_p->name, parv[1]);
113 return;
114 }
115 }
116
117 if (strlen(parv[2]) > USERLEN || !*parv[2] || !valid_username(parv[2]))
118 {
119 sendto_one(source_p, ":%s NOTICE %s :Invalid username",
120 me.name, source_p->name);
121 return;
122 }
123
124 if (IsUserHostIp(target_p))
125 delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
126
127 strlcpy(target_p->username, parv[2], sizeof(target_p->username));
128
129 add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
130 SetUserHost(target_p);
131
132 if (MyClient(source_p))
133 {
134 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGIDENT %s %s",
135 source_p->name, target_p->name, parv[2]);
136 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
137 me.name, source_p->name, target_p->name, target_p->username,
138 target_p->host);
139 }
140
141 if (MyConnect(target_p) && IsClient(source_p))
142 sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s",
143 me.name, target_p->name, target_p->username, target_p->host);
144 }
145
146 static void
147 mo_chghost(struct Client *client_p, struct Client *source_p,
148 int parc, char *parv[])
149 {
150 struct Client *target_p = NULL;
151
152 if (MyClient(source_p) && !IsOperAdmin(source_p))
153 {
154 sendto_one(source_p, form_str(ERR_NOPRIVS),
155 me.name, source_p->name, "CHGHOST");
156 return;
157 }
158
159 if (EmptyString(parv[2]))
160 {
161 parv[2] = parv[1];
162 target_p = source_p;
163
164 if (!IsClient(target_p))
165 return;
166 }
167 else {
168 target_p = find_client(parv[1]);
169
170 if (target_p == NULL || !IsClient(target_p))
171 {
172 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
173 me.name, source_p->name, parv[1]);
174 return;
175 }
176 }
177
178 if (strlen(parv[2]) > HOSTLEN || !*parv[2] || !valid_hostname(parv[2]))
179 {
180 sendto_one(source_p, ":%s NOTICE %s :Invalid hostname",
181 me.name, source_p->name);
182 return;
183 }
184
185 if (IsUserHostIp(target_p))
186 delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
187
188 strlcpy(target_p->host, parv[2], sizeof(target_p->host));
189 SetIPSpoof(target_p);
190
191 add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
192 SetUserHost(target_p);
193
194 if (MyClient(source_p))
195 {
196 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGHOST %s %s",
197 source_p->name, target_p->name, parv[2]);
198 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
199 me.name, source_p->name, target_p->name, target_p->username,
200 target_p->host);
201 }
202
203 if (MyConnect(target_p) && IsClient(source_p))
204 sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s",
205 me.name, target_p->name, target_p->username, target_p->host);
206 }
207
208 static void
209 mo_chgname(struct Client *client_p, struct Client *source_p,
210 int parc, char *parv[])
211 {
212 struct Client *target_p = NULL;
213
214 if (MyClient(source_p) && !IsOperAdmin(source_p))
215 {
216 sendto_one(source_p, form_str(ERR_NOPRIVS),
217 me.name, source_p->name, "CHGNAME");
218 return;
219 }
220
221 if (EmptyString(parv[2]))
222 {
223 parv[2] = parv[1];
224 target_p = source_p;
225 }
226 else if ((target_p = find_client(parv[1])) == NULL)
227 {
228 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
229 me.name, source_p->name, parv[1]);
230 return;
231 }
232
233 if (strlen(parv[2]) > REALLEN || !*parv[2])
234 {
235 sendto_one(source_p, ":%s NOTICE %s :Invalid realname",
236 me.name, source_p->name);
237 return;
238 }
239
240 if (parc > 3 && MyClient(source_p))
241 sendto_one(source_p, ":%s NOTICE %s :Warning -- too many parameters "
242 "for CHGNAME. You are probably missing a : before the new "
243 "IRC name.", me.name, source_p->name);
244
245 strlcpy(target_p->info, parv[2], sizeof(target_p->info));
246
247 if (MyClient(source_p))
248 {
249 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGNAME %s :%s",
250 source_p->name, target_p->name, parv[2]);
251 sendto_one(source_p, ":%s NOTICE %s :%s realname changed to [%s]",
252 me.name, source_p->name, target_p->name, target_p->info);
253 }
254
255 if (MyClient(target_p) && IsClient(source_p))
256 sendto_one(target_p, ":%s NOTICE %s :Your realname is now [%s]",
257 me.name, target_p->name, target_p->info);
258 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision