1 /*
2 * Unreal Internet Relay Chat Daemon, src/modules/m_chgname.c
3 * (C) 2000-2001 Carsten V. Munk and the UnrealIRCd Team
4 * Moved to modules by Fish (Justin Hammond)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 1, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 /**
21 * 2003-01-06
22 * - Added ability to log command usage to ircd.log
23 * XeRXeS
24 */
25
26 #include "config.h"
27 #include "struct.h"
28 #include "common.h"
29 #include "sys.h"
30 #include "numeric.h"
31 #include "msg.h"
32 #include "channel.h"
33 #include <time.h>
34 #include <sys/stat.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #ifdef _WIN32
39 #include <io.h>
40 #endif
41 #include <fcntl.h>
42 #include "h.h"
43 #include "proto.h"
44 #ifdef STRIPBADWORDS
45 #include "badwords.h"
46 #endif
47 #ifdef _WIN32
48 #include "version.h"
49 #endif
50
51 DLLFUNC int m_chgname(aClient *cptr, aClient *sptr, int parc, char *parv[]);
52
53 /* Place includes here */
54 #define MSG_CHGNAME "CHGNAME"
55 #define TOK_CHGNAME "BK"
56
57
58 ModuleHeader MOD_HEADER(m_chgname)
59 = {
60 "chgname", /* Name of module */
61 "$Id$", /* Version */
62 "command /chgname", /* Short description of module */
63 "3.2-b8-1",
64 NULL
65 };
66
67
68 /* This is called on module init, before Server Ready */
MOD_INIT(m_chgname)69 DLLFUNC int MOD_INIT(m_chgname)(ModuleInfo *modinfo)
70 {
71 /*
72 * We call our add_Command crap here
73 */
74 add_Command(MSG_CHGNAME, TOK_CHGNAME, m_chgname, 2);
75 add_Command(MSG_SVSNAME, NULL, m_chgname, 2);
76 MARK_AS_OFFICIAL_MODULE(modinfo);
77 return MOD_SUCCESS;
78 }
79
80 /* Is first run when server is 100% ready */
MOD_LOAD(m_chgname)81 DLLFUNC int MOD_LOAD(m_chgname)(int module_load)
82 {
83 return MOD_SUCCESS;
84
85 }
86
87
88 /* Called when module is unloaded */
MOD_UNLOAD(m_chgname)89 DLLFUNC int MOD_UNLOAD(m_chgname)(int module_unload)
90 {
91 if (del_Command(MSG_CHGNAME, TOK_CHGNAME, m_chgname) < 0)
92 {
93 sendto_realops("Failed to delete command chgname when unloading %s",
94 MOD_HEADER(m_chgname).name);
95 }
96 if (del_Command(MSG_SVSNAME, NULL, m_chgname) < 0)
97 {
98 sendto_realops("Failed to delete command svsname when unloading %s",
99 MOD_HEADER(m_chgname).name);
100 }
101 return MOD_SUCCESS;
102
103 }
104
105
106 /*
107 * m_chgname - Tue May 23 13:06:35 BST 200 (almost a year after I made CHGIDENT) - Stskeeps
108 * :prefix CHGNAME <nick> <new realname>
109 * parv[0] - sender
110 * parv[1] - nickname
111 * parv[2] - realname
112 *
113 */
114
m_chgname(aClient * cptr,aClient * sptr,int parc,char * parv[])115 DLLFUNC int m_chgname(aClient *cptr, aClient *sptr, int parc, char *parv[])
116 {
117 aClient *acptr;
118
119 if (MyClient(sptr) && !IsAnOper(sptr))
120 {
121 sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,
122 parv[0]);
123 return 0;
124 }
125
126 #ifdef DISABLE_USERMOD
127 if (MyClient(sptr))
128 {
129 sendto_one(sptr, err_str(ERR_DISABLED), me.name, sptr->name, "CHGNAME",
130 "This command is disabled on this server");
131 return 0;
132 }
133 #endif
134
135 if ((parc < 3) || !*parv[2])
136 {
137 sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, sptr->name, "CHGNAME");
138 return 0;
139 }
140
141 if (strlen(parv[2]) > (REALLEN))
142 {
143 sendnotice(sptr, "*** ChgName Error: Requested realname too long -- rejected.");
144 return 0;
145 }
146
147 if ((acptr = find_person(parv[1], NULL)))
148 {
149 if (MyClient(sptr) && (IsLocOp(sptr) && !MyClient(acptr)))
150 {
151 sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,
152 parv[0]);
153 return 0;
154 }
155
156 /* set the realname first to make n:line checking work */
157 ircsprintf(acptr->info, "%s", parv[2]);
158 /* only check for n:lines if the person who's name is being changed is not an oper */
159 if (!IsAnOper(acptr) && Find_ban(NULL, acptr->info, CONF_BAN_REALNAME)) {
160 int xx;
161 xx =
162 exit_client(cptr, sptr, &me,
163 "Your GECOS (real name) is banned from this server");
164 return xx;
165 }
166 if (!IsULine(sptr))
167 {
168 sendto_snomask(SNO_EYES,
169 "%s changed the GECOS of %s (%s@%s) to be %s",
170 sptr->name, acptr->name, acptr->user->username,
171 GetHost(acptr), parv[2]);
172 /* Logging ability added by XeRXeS */
173 ircd_log(LOG_CHGCMDS,
174 "CHGNAME: %s changed the GECOS of %s (%s@%s) to be %s",
175 sptr->name, acptr->name, acptr->user->username,
176 GetHost(acptr), parv[2]);
177 }
178
179
180 sendto_serv_butone_token(cptr, sptr->name,
181 MSG_CHGNAME, TOK_CHGNAME, "%s :%s", acptr->name, parv[2]);
182 return 0;
183 }
184 else
185 {
186 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, sptr->name,
187 parv[1]);
188 return 0;
189 }
190 return 0;
191 }
192
193