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: 7925
Committed: Sat Dec 31 13:57:24 2016 UTC (7 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 7033 byte(s)
Log Message:
- Update copyright years

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

Properties

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