ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_oper.c
Revision: 8516
Committed: Fri Apr 6 20:17:10 2018 UTC (7 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 7021 byte(s)
Log Message:
- m_oper.c: oper_up() is called for local clients only; use NULL as first argument to sendto_server()

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 8279 * Copyright (c) 1997-2018 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_oper.c
23     * \brief Includes required functions for processing the OPER command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "client.h"
30 michael 8484 #include "client_svstag.h"
31 adx 30 #include "irc_string.h"
32     #include "ircd.h"
33     #include "numeric.h"
34 michael 1309 #include "conf.h"
35     #include "log.h"
36 michael 3347 #include "user.h"
37 adx 30 #include "send.h"
38     #include "parse.h"
39     #include "modules.h"
40     #include "packet.h"
41    
42    
43 michael 6694 /*! \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     */
47     static void
48     oper_up(struct Client *source_p)
49     {
50     const unsigned int old = source_p->umodes;
51     const struct MaskItem *const conf = source_p->connection->confs.head->data;
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 michael 6701 else if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
64 michael 6694 --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 michael 8484 svstag_attach(&source_p->svstags, RPL_WHOISOPERATOR, "+", conf->whois);
77 michael 8516 sendto_server(NULL, 0, 0, ":%s SVSTAG %s %ju %u + :%s",
78 michael 6782 me.id, source_p->id, source_p->tsinfo,
79 michael 6694 RPL_WHOISOPERATOR, conf->whois);
80     }
81    
82 michael 7898 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", conf->name, source_p->name,
83     source_p->username, source_p->host);
84 michael 6694 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 michael 8431
89 michael 6694 send_umode_out(source_p, old);
90     sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
91     }
92    
93 michael 3336 /*! \brief Notices all opers of the failed oper attempt if enabled
94 michael 1230 *
95 michael 3336 * \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 michael 1230 */
99     static void
100     failed_oper_notice(struct Client *source_p, const char *name,
101     const char *reason)
102 adx 30 {
103 michael 4340 if (ConfigGeneral.failed_oper_notice)
104 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
105 michael 1618 "Failed OPER attempt as %s by %s (%s@%s) - %s",
106     name, source_p->name, source_p->username,
107     source_p->host, reason);
108 michael 1247
109 michael 1618 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 adx 30 }
113    
114 michael 3266 /*! \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 michael 2820 static int
127 michael 3156 m_oper(struct Client *source_p, int parc, char *parv[])
128 adx 30 {
129 michael 4832 const char *const opername = parv[1];
130     const char *const password = parv[2];
131 adx 30
132     if (EmptyString(password))
133     {
134 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "OPER");
135 michael 2820 return 0;
136 adx 30 }
137    
138     /* end the grace period */
139     if (!IsFloodDone(source_p))
140     flood_endgrace(source_p);
141    
142 michael 8431 struct MaskItem *conf;
143 michael 7403 if ((conf = operator_find(source_p, opername)) == NULL)
144 adx 30 {
145 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
146 michael 8431
147 michael 7403 conf = operator_find(NULL, opername);
148 michael 8431 failed_oper_notice(source_p, opername, conf ? "host mismatch" : "no operator {} block");
149 michael 2820 return 0;
150 adx 30 }
151    
152 michael 2248 if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL))
153     {
154 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
155 michael 4829 failed_oper_notice(source_p, opername, "requires SSL/TLS");
156 michael 2820 return 0;
157 michael 2248 }
158    
159 michael 2228 if (!EmptyString(conf->certfp))
160     {
161 michael 2229 if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp))
162 michael 2228 {
163 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
164 michael 4829 failed_oper_notice(source_p, opername, "client certificate fingerprint mismatch");
165 michael 2820 return 0;
166 michael 2228 }
167     }
168    
169 michael 1632 if (match_conf_password(password, conf))
170 adx 30 {
171 michael 8395 if (conf_attach(source_p, conf))
172 adx 30 {
173 michael 3110 sendto_one_notice(source_p, &me, ":Can't attach conf!");
174 michael 4829 failed_oper_notice(source_p, opername, "can't attach conf!");
175 michael 2820 return 0;
176 adx 30 }
177    
178 michael 6694 oper_up(source_p);
179 adx 30 }
180     else
181     {
182 michael 3109 sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
183 michael 4829 failed_oper_notice(source_p, opername, "password mismatch");
184 adx 30 }
185 michael 2820
186     return 0;
187 adx 30 }
188    
189 michael 3266 /*! \brief OPER command handler
190     *
191     * \param source_p Pointer to allocated Client struct from which the message
192     * originally comes from. This can be a local or remote client.
193     * \param parc Integer holding the number of supplied arguments.
194     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
195     * pointers.
196     * \note Valid arguments for this command are:
197     * - parv[0] = command
198     * - parv[1] = oper name
199     * - parv[2] = oper password
200     */
201 michael 2820 static int
202 michael 3156 mo_oper(struct Client *source_p, int parc, char *parv[])
203 adx 30 {
204 michael 3109 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
205 michael 2820 return 0;
206 adx 30 }
207    
208 michael 2820 static struct Message oper_msgtab =
209     {
210 michael 5881 .cmd = "OPER",
211     .args_min = 3,
212     .args_max = MAXPARA,
213     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
214     .handlers[CLIENT_HANDLER] = m_oper,
215     .handlers[SERVER_HANDLER] = m_ignore,
216     .handlers[ENCAP_HANDLER] = m_ignore,
217     .handlers[OPER_HANDLER] = mo_oper
218 michael 1230 };
219    
220     static void
221     module_init(void)
222 adx 30 {
223 michael 1230 mod_add_cmd(&oper_msgtab);
224 adx 30 }
225    
226     static void
227 michael 1230 module_exit(void)
228 adx 30 {
229 michael 1230 mod_del_cmd(&oper_msgtab);
230 adx 30 }
231 michael 1230
232 michael 2820 struct module module_entry =
233     {
234 michael 1230 .version = "$Revision$",
235     .modinit = module_init,
236     .modexit = module_exit,
237     };

Properties

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