ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_oper.c
Revision: 3915
Committed: Sun Jun 8 13:23:19 2014 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 5408 byte(s)
Log Message:
- m_oper.c:m_oper(): style corrections

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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 (ConfigFileEntry.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 *name = parv[1];
81 const char *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, name, NULL, NULL)) == NULL)
94 {
95 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
96 conf = find_exact_name_conf(CONF_OPER, NULL, name, NULL, NULL);
97 failed_oper_notice(source_p, name, (conf != NULL) ?
98 "host mismatch" : "no oper {} 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, name, "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, name, "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, name, "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",
131 name, source_p->name, 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, name, "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 "OPER", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
164 { m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore }
165 };
166
167 static void
168 module_init(void)
169 {
170 mod_add_cmd(&oper_msgtab);
171 }
172
173 static void
174 module_exit(void)
175 {
176 mod_del_cmd(&oper_msgtab);
177 }
178
179 struct module module_entry =
180 {
181 .node = { NULL, NULL, NULL },
182 .name = NULL,
183 .version = "$Revision$",
184 .handle = NULL,
185 .modinit = module_init,
186 .modexit = module_exit,
187 .flags = 0
188 };

Properties

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