ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/contrib/m_change.c
Revision: 1219
Committed: Sun Sep 18 09:02:38 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 7381 byte(s)
Log Message:
- Start cleaning up macros in client.h. Replace several ClientHasSomeCoolFlag()
with simple HasFlag/HasUMode macros.

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
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 michael 1110 #include "userhost.h"
45 adx 30
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 michael 1178 "CHGIDENT", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
52 adx 30 {m_unregistered, m_not_oper, mo_chgident, mo_chgident, mo_chgident, m_ignore}
53     };
54    
55     struct Message chghost_msgtab = {
56 michael 1178 "CHGHOST", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
57 adx 30 {m_unregistered, m_not_oper, mo_chghost, mo_chghost, mo_chghost, m_ignore}
58     };
59    
60     struct Message chgname_msgtab = {
61 michael 1178 "CHGNAME", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
62 adx 30 {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 knight 31 const char *_version = "$Revision$";
82 adx 30
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 michael 1219 if (MyClient(source_p) && !HasUMode(source_p, UMODE_ADMIN))
90 adx 30 {
91     sendto_one(source_p, form_str(ERR_NOPRIVS),
92 michael 1110 me.name, source_p->name, "CHGIDENT");
93 adx 30 return;
94     }
95    
96     if (EmptyString(parv[2]))
97     {
98     parv[2] = parv[1];
99 michael 1110 target_p = source_p;
100 adx 30
101     if (!IsClient(target_p))
102     return;
103     }
104     else {
105 michael 1169 target_p = hash_find_client(parv[1]);
106 adx 30
107     if (target_p == NULL || !IsClient(target_p))
108     {
109 michael 1110 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
110     me.name, source_p->name, parv[1]);
111 adx 30 return;
112     }
113     }
114    
115     if (strlen(parv[2]) > USERLEN || !*parv[2] || !valid_username(parv[2]))
116     {
117 michael 1110 sendto_one(source_p, ":%s NOTICE %s :Invalid username",
118     me.name, source_p->name);
119 adx 30 return;
120     }
121    
122 michael 1110 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 adx 30 if (MyClient(source_p))
131     {
132 michael 1110 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGIDENT %s %s",
133     source_p->name, target_p->name, parv[2]);
134 adx 30 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
135 michael 1110 me.name, source_p->name, target_p->name, target_p->username,
136 adx 30 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 michael 1219 if (MyClient(source_p) && !HasUMode(source_p, UMODE_ADMIN))
151 adx 30 {
152     sendto_one(source_p, form_str(ERR_NOPRIVS),
153 michael 1110 me.name, source_p->name, "CHGHOST");
154 adx 30 return;
155     }
156    
157     if (EmptyString(parv[2]))
158     {
159     parv[2] = parv[1];
160 michael 1110 target_p = source_p;
161 adx 30
162     if (!IsClient(target_p))
163     return;
164     }
165     else {
166 michael 1169 target_p = hash_find_client(parv[1]);
167 michael 1110
168 adx 30 if (target_p == NULL || !IsClient(target_p))
169     {
170 michael 1110 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
171     me.name, source_p->name, parv[1]);
172 adx 30 return;
173     }
174     }
175    
176     if (strlen(parv[2]) > HOSTLEN || !*parv[2] || !valid_hostname(parv[2]))
177     {
178 michael 1110 sendto_one(source_p, ":%s NOTICE %s :Invalid hostname",
179     me.name, source_p->name);
180 adx 30 return;
181     }
182    
183 michael 1110 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 michael 343 SetIPSpoof(target_p);
188 michael 1110
189     add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
190     SetUserHost(target_p);
191    
192 adx 30 if (MyClient(source_p))
193     {
194 michael 1110 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGHOST %s %s",
195     source_p->name, target_p->name, parv[2]);
196 adx 30 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
197 michael 1110 me.name, source_p->name, target_p->name, target_p->username,
198 adx 30 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 michael 1219 if (MyClient(source_p) && !HasUMode(source_p, UMODE_ADMIN))
213 adx 30 {
214     sendto_one(source_p, form_str(ERR_NOPRIVS),
215 michael 1110 me.name, source_p->name, "CHGNAME");
216 adx 30 return;
217     }
218    
219     if (EmptyString(parv[2]))
220     {
221     parv[2] = parv[1];
222     target_p = source_p;
223     }
224 michael 1169 else if ((target_p = hash_find_client(parv[1])) == NULL)
225 adx 30 {
226 michael 1110 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
227     me.name, source_p->name, parv[1]);
228 adx 30 return;
229     }
230    
231     if (strlen(parv[2]) > REALLEN || !*parv[2])
232     {
233 michael 1110 sendto_one(source_p, ":%s NOTICE %s :Invalid realname",
234     me.name, source_p->name);
235 adx 30 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 michael 1110 "IRC name.", me.name, source_p->name);
242 adx 30
243 michael 1110 strlcpy(target_p->info, parv[2], sizeof(target_p->info));
244    
245 adx 30 if (MyClient(source_p))
246     {
247 michael 1110 sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s ENCAP * CHGNAME %s :%s",
248     source_p->name, target_p->name, parv[2]);
249 adx 30 sendto_one(source_p, ":%s NOTICE %s :%s realname changed to [%s]",
250 michael 1110 me.name, source_p->name, target_p->name, target_p->info);
251 adx 30 }
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