ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_oper.c
Revision: 9078
Committed: Sat Oct 12 20:15:30 2019 UTC (4 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 6937 byte(s)
Log Message:
- Command handlers are now of type void again

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2019 ircd-hybrid development team
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 2 of the License, or
9 * (at your option) 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_oper.c
23 * \brief Includes required functions for processing the OPER command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "client_svstag.h"
31 #include "irc_string.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "conf.h"
35 #include "log.h"
36 #include "user.h"
37 #include "send.h"
38 #include "parse.h"
39 #include "modules.h"
40 #include "packet.h"
41
42
43 /*! \brief Blindly opers up given source_p, using conf info.
44 * All checks on passwords have already been done.
45 * \param source_p Pointer to given client to oper
46 * \param conf operator {} configuration record
47 */
48 static void
49 oper_up(struct Client *source_p, const struct MaskItem *conf)
50 {
51 const unsigned int old = source_p->umodes;
52
53 ++Count.oper;
54 SetOper(source_p);
55
56 if (conf->modes)
57 AddUMode(source_p, conf->modes);
58 else if (ConfigGeneral.oper_umodes)
59 AddUMode(source_p, ConfigGeneral.oper_umodes);
60
61 if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
62 ++Count.invisi;
63 else if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
64 --Count.invisi;
65
66 assert(dlinkFind(&oper_list, source_p) == NULL);
67 dlinkAdd(source_p, make_dlink_node(), &oper_list);
68
69 AddOFlag(source_p, conf->port);
70
71 if (HasOFlag(source_p, OPER_FLAG_ADMIN))
72 AddUMode(source_p, UMODE_ADMIN);
73
74 if (!EmptyString(conf->whois))
75 {
76 svstag_attach(&source_p->svstags, RPL_WHOISOPERATOR, "+", conf->whois);
77 sendto_server(NULL, 0, 0, ":%s SVSTAG %s %ju %u + :%s",
78 me.id, source_p->id, source_p->tsinfo,
79 RPL_WHOISOPERATOR, conf->whois);
80 }
81
82 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", conf->name, source_p->name,
83 source_p->username, source_p->host);
84 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s is now an operator",
85 get_oper_name(source_p));
86 sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator",
87 me.id, get_oper_name(source_p));
88
89 send_umode_out(source_p, old);
90 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
91 }
92
93 /*! \brief Notices all opers of the failed oper attempt if enabled
94 *
95 * \param source_p Client doing /oper ...
96 * \param name The nick they tried to oper as
97 * \param reason The reason why they have failed
98 */
99 static void
100 failed_oper_notice(struct Client *source_p, const char *name,
101 const char *reason)
102 {
103 if (ConfigGeneral.failed_oper_notice)
104 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
105 "Failed OPER attempt as %s by %s (%s@%s) - %s",
106 name, source_p->name, source_p->username,
107 source_p->host, reason);
108
109 ilog(LOG_TYPE_OPER, "Failed OPER attempt as %s by %s (%s@%s) - %s",
110 name, source_p->name, source_p->username,
111 source_p->host, reason);
112 }
113
114 /*! \brief OPER command handler
115 *
116 * \param source_p Pointer to allocated Client struct from which the message
117 * originally comes from. This can be a local or remote client.
118 * \param parc Integer holding the number of supplied arguments.
119 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
120 * pointers.
121 * \note Valid arguments for this command are:
122 * - parv[0] = command
123 * - parv[1] = oper name
124 * - parv[2] = oper password
125 */
126 static void
127 m_oper(struct Client *source_p, int parc, char *parv[])
128 {
129 const char *const opername = parv[1];
130 const char *const password = parv[2];
131
132 if (EmptyString(password))
133 {
134 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "OPER");
135 return;
136 }
137
138 struct MaskItem *conf;
139 if ((conf = operator_find(source_p, opername)) == NULL)
140 {
141 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
142
143 conf = operator_find(NULL, opername);
144 failed_oper_notice(source_p, opername, conf ? "host mismatch" : "no operator {} block");
145 return;
146 }
147
148 if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL))
149 {
150 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
151 failed_oper_notice(source_p, opername, "requires SSL/TLS");
152 return;
153 }
154
155 if (!EmptyString(conf->certfp))
156 {
157 if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp))
158 {
159 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
160 failed_oper_notice(source_p, opername, "client certificate fingerprint mismatch");
161 return;
162 }
163 }
164
165 if (match_conf_password(password, conf) == true)
166 {
167 if (conf_attach(source_p, conf))
168 {
169 sendto_one_notice(source_p, &me, ":Can't attach conf!");
170 failed_oper_notice(source_p, opername, "can't attach conf!");
171 return;
172 }
173
174 oper_up(source_p, conf);
175 }
176 else
177 {
178 sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
179 failed_oper_notice(source_p, opername, "password mismatch");
180 }
181 }
182
183 /*! \brief OPER command handler
184 *
185 * \param source_p Pointer to allocated Client struct from which the message
186 * originally comes from. This can be a local or remote client.
187 * \param parc Integer holding the number of supplied arguments.
188 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
189 * pointers.
190 * \note Valid arguments for this command are:
191 * - parv[0] = command
192 * - parv[1] = oper name
193 * - parv[2] = oper password
194 */
195 static void
196 mo_oper(struct Client *source_p, int parc, char *parv[])
197 {
198 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
199 }
200
201 static struct Message oper_msgtab =
202 {
203 .cmd = "OPER",
204 .args_min = 3,
205 .args_max = MAXPARA,
206 .flags = MFLG_ENDGRACE,
207 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
208 .handlers[CLIENT_HANDLER] = m_oper,
209 .handlers[SERVER_HANDLER] = m_ignore,
210 .handlers[ENCAP_HANDLER] = m_ignore,
211 .handlers[OPER_HANDLER] = mo_oper
212 };
213
214 static void
215 module_init(void)
216 {
217 mod_add_cmd(&oper_msgtab);
218 }
219
220 static void
221 module_exit(void)
222 {
223 mod_del_cmd(&oper_msgtab);
224 }
225
226 struct module module_entry =
227 {
228 .version = "$Revision$",
229 .modinit = module_init,
230 .modexit = module_exit,
231 };

Properties

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