ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_oper.c
Revision: 5881
Committed: Sun May 3 16:04:15 2015 UTC (10 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 5526 byte(s)
Log Message:
- Use C99-style initializers in all struct Message items
- Removed MFLG_SLOW
- Removed DUMMY_HANDLER

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 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 "irc_string.h"
31 #include "ircd.h"
32 #include "numeric.h"
33 #include "conf.h"
34 #include "log.h"
35 #include "user.h"
36 #include "send.h"
37 #include "parse.h"
38 #include "modules.h"
39 #include "packet.h"
40
41
42
43 /*! \brief Notices all opers of the failed oper attempt if enabled
44 *
45 * \param source_p Client doing /oper ...
46 * \param name The nick they tried to oper as
47 * \param reason The reason why they have failed
48 */
49 static void
50 failed_oper_notice(struct Client *source_p, const char *name,
51 const char *reason)
52 {
53 if (ConfigGeneral.failed_oper_notice)
54 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
55 "Failed OPER attempt as %s by %s (%s@%s) - %s",
56 name, source_p->name, source_p->username,
57 source_p->host, reason);
58
59 ilog(LOG_TYPE_OPER, "Failed OPER attempt as %s by %s (%s@%s) - %s",
60 name, source_p->name, source_p->username,
61 source_p->host, reason);
62 }
63
64 /*! \brief OPER command handler
65 *
66 * \param source_p Pointer to allocated Client struct from which the message
67 * originally comes from. This can be a local or remote client.
68 * \param parc Integer holding the number of supplied arguments.
69 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
70 * pointers.
71 * \note Valid arguments for this command are:
72 * - parv[0] = command
73 * - parv[1] = oper name
74 * - parv[2] = oper password
75 */
76 static int
77 m_oper(struct Client *source_p, int parc, char *parv[])
78 {
79 struct MaskItem *conf = NULL;
80 const char *const opername = parv[1];
81 const char *const password = parv[2];
82
83 if (EmptyString(password))
84 {
85 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "OPER");
86 return 0;
87 }
88
89 /* end the grace period */
90 if (!IsFloodDone(source_p))
91 flood_endgrace(source_p);
92
93 if ((conf = find_exact_name_conf(CONF_OPER, source_p, opername, NULL, NULL)) == NULL)
94 {
95 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
96 conf = find_exact_name_conf(CONF_OPER, NULL, opername, NULL, NULL);
97 failed_oper_notice(source_p, opername, (conf != NULL) ?
98 "host mismatch" : "no operator {} block");
99 return 0;
100 }
101
102 if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL))
103 {
104 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
105 failed_oper_notice(source_p, opername, "requires SSL/TLS");
106 return 0;
107 }
108
109 if (!EmptyString(conf->certfp))
110 {
111 if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp))
112 {
113 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
114 failed_oper_notice(source_p, opername, "client certificate fingerprint mismatch");
115 return 0;
116 }
117 }
118
119 if (match_conf_password(password, conf))
120 {
121 if (attach_conf(source_p, conf))
122 {
123 sendto_one_notice(source_p, &me, ":Can't attach conf!");
124 failed_oper_notice(source_p, opername, "can't attach conf!");
125 return 0;
126 }
127
128 oper_up(source_p);
129
130 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", opername, source_p->name,
131 source_p->username, source_p->host);
132 }
133 else
134 {
135 sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
136 failed_oper_notice(source_p, opername, "password mismatch");
137 }
138
139 return 0;
140 }
141
142 /*! \brief OPER command handler
143 *
144 * \param source_p Pointer to allocated Client struct from which the message
145 * originally comes from. This can be a local or remote client.
146 * \param parc Integer holding the number of supplied arguments.
147 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
148 * pointers.
149 * \note Valid arguments for this command are:
150 * - parv[0] = command
151 * - parv[1] = oper name
152 * - parv[2] = oper password
153 */
154 static int
155 mo_oper(struct Client *source_p, int parc, char *parv[])
156 {
157 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
158 return 0;
159 }
160
161 static struct Message oper_msgtab =
162 {
163 .cmd = "OPER",
164 .args_min = 3,
165 .args_max = MAXPARA,
166 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
167 .handlers[CLIENT_HANDLER] = m_oper,
168 .handlers[SERVER_HANDLER] = m_ignore,
169 .handlers[ENCAP_HANDLER] = m_ignore,
170 .handlers[OPER_HANDLER] = mo_oper
171 };
172
173 static void
174 module_init(void)
175 {
176 mod_add_cmd(&oper_msgtab);
177 }
178
179 static void
180 module_exit(void)
181 {
182 mod_del_cmd(&oper_msgtab);
183 }
184
185 struct module module_entry =
186 {
187 .version = "$Revision$",
188 .modinit = module_init,
189 .modexit = module_exit,
190 };

Properties

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