ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/contrib/m_change.c
Revision: 1169
Committed: Fri Aug 12 18:45:03 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 7333 byte(s)
Log Message:
- rename find_server to hash_find_server to satisfy naming convention
- pull m_services.c and m_jupe.c from contrib/
- style fixes in some places

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 void
66 _modinit(void)
67 {
68 mod_add_cmd(&chgident_msgtab);
69 mod_add_cmd(&chghost_msgtab);
70 mod_add_cmd(&chgname_msgtab);
71 }
72
73 void
74 _moddeinit(void)
75 {
76 mod_del_cmd(&chgname_msgtab);
77 mod_del_cmd(&chghost_msgtab);
78 mod_del_cmd(&chgident_msgtab);
79 }
80
81 const char *_version = "$Revision$";
82
83 static void
84 mo_chgident(struct Client *client_p, struct Client *source_p,
85 int parc, char *parv[])
86 {
87 struct Client *target_p = NULL;
88
89 if (MyClient(source_p) && !IsOperAdmin(source_p))
90 {
91 sendto_one(source_p, form_str(ERR_NOPRIVS),
92 me.name, source_p->name, "CHGIDENT");
93 return;
94 }
95
96 if (EmptyString(parv[2]))
97 {
98 parv[2] = parv[1];
99 target_p = source_p;
100
101 if (!IsClient(target_p))
102 return;
103 }
104 else {
105 target_p = hash_find_client(parv[1]);
106
107 if (target_p == NULL || !IsClient(target_p))
108 {
109 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
110 me.name, source_p->name, parv[1]);
111 return;
112 }
113 }
114
115 if (strlen(parv[2]) > USERLEN || !*parv[2] || !valid_username(parv[2]))
116 {
117 sendto_one(source_p, ":%s NOTICE %s :Invalid username",
118 me.name, source_p->name);
119 return;
120 }
121
122 if (IsUserHostIp(target_p))
123 delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
124
125 strlcpy(target_p->username, parv[2], sizeof(target_p->username));
126
127 add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
128 SetUserHost(target_p);
129
130 if (MyClient(source_p))
131 {
132 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGIDENT %s %s",
133 source_p->name, target_p->name, parv[2]);
134 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
135 me.name, source_p->name, target_p->name, target_p->username,
136 target_p->host);
137 }
138
139 if (MyConnect(target_p) && IsClient(source_p))
140 sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s",
141 me.name, target_p->name, target_p->username, target_p->host);
142 }
143
144 static void
145 mo_chghost(struct Client *client_p, struct Client *source_p,
146 int parc, char *parv[])
147 {
148 struct Client *target_p = NULL;
149
150 if (MyClient(source_p) && !IsOperAdmin(source_p))
151 {
152 sendto_one(source_p, form_str(ERR_NOPRIVS),
153 me.name, source_p->name, "CHGHOST");
154 return;
155 }
156
157 if (EmptyString(parv[2]))
158 {
159 parv[2] = parv[1];
160 target_p = source_p;
161
162 if (!IsClient(target_p))
163 return;
164 }
165 else {
166 target_p = hash_find_client(parv[1]);
167
168 if (target_p == NULL || !IsClient(target_p))
169 {
170 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
171 me.name, source_p->name, parv[1]);
172 return;
173 }
174 }
175
176 if (strlen(parv[2]) > HOSTLEN || !*parv[2] || !valid_hostname(parv[2]))
177 {
178 sendto_one(source_p, ":%s NOTICE %s :Invalid hostname",
179 me.name, source_p->name);
180 return;
181 }
182
183 if (IsUserHostIp(target_p))
184 delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
185
186 strlcpy(target_p->host, parv[2], sizeof(target_p->host));
187 SetIPSpoof(target_p);
188
189 add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
190 SetUserHost(target_p);
191
192 if (MyClient(source_p))
193 {
194 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGHOST %s %s",
195 source_p->name, target_p->name, parv[2]);
196 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
197 me.name, source_p->name, target_p->name, target_p->username,
198 target_p->host);
199 }
200
201 if (MyConnect(target_p) && IsClient(source_p))
202 sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s",
203 me.name, target_p->name, target_p->username, target_p->host);
204 }
205
206 static void
207 mo_chgname(struct Client *client_p, struct Client *source_p,
208 int parc, char *parv[])
209 {
210 struct Client *target_p = NULL;
211
212 if (MyClient(source_p) && !IsOperAdmin(source_p))
213 {
214 sendto_one(source_p, form_str(ERR_NOPRIVS),
215 me.name, source_p->name, "CHGNAME");
216 return;
217 }
218
219 if (EmptyString(parv[2]))
220 {
221 parv[2] = parv[1];
222 target_p = source_p;
223 }
224 else if ((target_p = hash_find_client(parv[1])) == NULL)
225 {
226 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
227 me.name, source_p->name, parv[1]);
228 return;
229 }
230
231 if (strlen(parv[2]) > REALLEN || !*parv[2])
232 {
233 sendto_one(source_p, ":%s NOTICE %s :Invalid realname",
234 me.name, source_p->name);
235 return;
236 }
237
238 if (parc > 3 && MyClient(source_p))
239 sendto_one(source_p, ":%s NOTICE %s :Warning -- too many parameters "
240 "for CHGNAME. You are probably missing a : before the new "
241 "IRC name.", me.name, source_p->name);
242
243 strlcpy(target_p->info, parv[2], sizeof(target_p->info));
244
245 if (MyClient(source_p))
246 {
247 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGNAME %s :%s",
248 source_p->name, target_p->name, parv[2]);
249 sendto_one(source_p, ":%s NOTICE %s :%s realname changed to [%s]",
250 me.name, source_p->name, target_p->name, target_p->info);
251 }
252
253 if (MyClient(target_p) && IsClient(source_p))
254 sendto_one(target_p, ":%s NOTICE %s :Your realname is now [%s]",
255 me.name, target_p->name, target_p->info);
256 }

Properties

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