/[svn]/ircd-hybrid/branches/8.2.x/modules/m_oper.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_oper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9406 - (show annotations)
Sun May 31 07:23:05 2020 UTC (3 months, 2 weeks ago) by michael
File MIME type: text/x-chdr
File size: 6807 byte(s)
- m_oper.c: replace %s!%s@%s combo with client_get_name

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2020 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",
83 conf->name, client_get_name(source_p, HIDE_IP));
84
85 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s is now an operator",
86 get_oper_name(source_p));
87 sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator",
88 me.id, get_oper_name(source_p));
89
90 send_umode_out(source_p, old);
91 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
92 }
93
94 /*! \brief Notices all opers of the failed oper attempt if enabled
95 *
96 * \param source_p Client doing /oper ...
97 * \param name The nick they tried to oper as
98 * \param reason The reason why they have failed
99 */
100 static void
101 failed_oper_notice(struct Client *source_p, const char *name,
102 const char *reason)
103 {
104 if (ConfigGeneral.failed_oper_notice)
105 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
106 "Failed OPER attempt as %s by %s - %s",
107 name, client_get_name(source_p, HIDE_IP), reason);
108
109 ilog(LOG_TYPE_OPER, "Failed OPER attempt as %s by %s - %s",
110 name, client_get_name(source_p, HIDE_IP), reason);
111 }
112
113 /*! \brief OPER command handler
114 *
115 * \param source_p Pointer to allocated Client struct from which the message
116 * originally comes from. This can be a local or remote client.
117 * \param parc Integer holding the number of supplied arguments.
118 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
119 * pointers.
120 * \note Valid arguments for this command are:
121 * - parv[0] = command
122 * - parv[1] = oper name
123 * - parv[2] = oper password
124 */
125 static void
126 m_oper(struct Client *source_p, int parc, char *parv[])
127 {
128 const char *const opername = parv[1];
129 const char *const password = parv[2];
130
131 struct MaskItem *conf = operator_find(source_p, opername);
132 if (conf == NULL)
133 {
134 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
135
136 conf = operator_find(NULL, opername);
137 failed_oper_notice(source_p, opername, conf ? "host mismatch" : "no operator {} block");
138 return;
139 }
140
141 if (IsConfTLS(conf) && !HasUMode(source_p, UMODE_SECURE))
142 {
143 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
144 failed_oper_notice(source_p, opername, "requires TLS");
145 return;
146 }
147
148 if (!EmptyString(conf->certfp))
149 {
150 if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp))
151 {
152 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
153 failed_oper_notice(source_p, opername, "client certificate fingerprint mismatch");
154 return;
155 }
156 }
157
158 if (match_conf_password(password, conf) == true)
159 {
160 if (conf_attach(source_p, conf))
161 {
162 sendto_one_notice(source_p, &me, ":Can't attach conf!");
163 failed_oper_notice(source_p, opername, "can't attach conf!");
164 return;
165 }
166
167 oper_up(source_p, conf);
168 }
169 else
170 {
171 sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
172 failed_oper_notice(source_p, opername, "password mismatch");
173 }
174 }
175
176 /*! \brief OPER command handler
177 *
178 * \param source_p Pointer to allocated Client struct from which the message
179 * originally comes from. This can be a local or remote client.
180 * \param parc Integer holding the number of supplied arguments.
181 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
182 * pointers.
183 * \note Valid arguments for this command are:
184 * - parv[0] = command
185 * - parv[1] = oper name
186 * - parv[2] = oper password
187 */
188 static void
189 mo_oper(struct Client *source_p, int parc, char *parv[])
190 {
191 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
192 }
193
194 static struct Message oper_msgtab =
195 {
196 .cmd = "OPER",
197 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
198 .handlers[CLIENT_HANDLER] = { .handler = m_oper, .args_min = 3, .end_grace_period = true },
199 .handlers[SERVER_HANDLER] = { .handler = m_ignore },
200 .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
201 .handlers[OPER_HANDLER] = { .handler = mo_oper, .args_min = 3, .end_grace_period = true }
202 };
203
204 static void
205 module_init(void)
206 {
207 mod_add_cmd(&oper_msgtab);
208 }
209
210 static void
211 module_exit(void)
212 {
213 mod_del_cmd(&oper_msgtab);
214 }
215
216 struct module module_entry =
217 {
218 .version = "$Revision$",
219 .modinit = module_init,
220 .modexit = module_exit,
221 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28