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 "s_user.h" |
36 |
#include "send.h" |
37 |
#include "parse.h" |
38 |
#include "modules.h" |
39 |
#include "packet.h" |
40 |
|
41 |
|
42 |
|
43 |
/* failed_oper_notice() |
44 |
* |
45 |
* inputs - pointer to client doing /oper ... |
46 |
* - pointer to nick they tried to oper as |
47 |
* - pointer to reason they have failed |
48 |
* output - nothing |
49 |
* side effects - notices all opers of the failed oper attempt if enabled |
50 |
*/ |
51 |
static void |
52 |
failed_oper_notice(struct Client *source_p, const char *name, |
53 |
const char *reason) |
54 |
{ |
55 |
if (ConfigFileEntry.failed_oper_notice) |
56 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
57 |
"Failed OPER attempt as %s by %s (%s@%s) - %s", |
58 |
name, source_p->name, source_p->username, |
59 |
source_p->host, reason); |
60 |
|
61 |
ilog(LOG_TYPE_OPER, "Failed OPER attempt as %s by %s (%s@%s) - %s", |
62 |
name, source_p->name, source_p->username, |
63 |
source_p->host, reason); |
64 |
} |
65 |
|
66 |
/* |
67 |
** m_oper |
68 |
** parv[0] = sender prefix |
69 |
** parv[1] = oper name |
70 |
** parv[2] = oper password |
71 |
*/ |
72 |
static int |
73 |
m_oper(struct Client *client_p, struct Client *source_p, |
74 |
int parc, char *parv[]) |
75 |
{ |
76 |
struct MaskItem *conf = NULL; |
77 |
const char *name = parv[1]; |
78 |
const char *password = parv[2]; |
79 |
|
80 |
if (EmptyString(password)) |
81 |
{ |
82 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
83 |
me.name, source_p->name, "OPER"); |
84 |
return 0; |
85 |
} |
86 |
|
87 |
/* end the grace period */ |
88 |
if (!IsFloodDone(source_p)) |
89 |
flood_endgrace(source_p); |
90 |
|
91 |
if ((conf = find_exact_name_conf(CONF_OPER, source_p, name, NULL, NULL)) == NULL) |
92 |
{ |
93 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
94 |
conf = find_exact_name_conf(CONF_OPER, NULL, name, NULL, NULL); |
95 |
failed_oper_notice(source_p, name, (conf != NULL) ? |
96 |
"host mismatch" : "no oper {} block"); |
97 |
return 0; |
98 |
} |
99 |
|
100 |
if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL)) |
101 |
{ |
102 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
103 |
failed_oper_notice(source_p, name, "requires SSL/TLS"); |
104 |
return 0; |
105 |
} |
106 |
|
107 |
if (!EmptyString(conf->certfp)) |
108 |
{ |
109 |
if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp)) |
110 |
{ |
111 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
112 |
failed_oper_notice(source_p, name, "client certificate fingerprint mismatch"); |
113 |
return 0; |
114 |
} |
115 |
} |
116 |
|
117 |
if (match_conf_password(password, conf)) |
118 |
{ |
119 |
if (attach_conf(source_p, conf) != 0) |
120 |
{ |
121 |
sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!", |
122 |
me.name, source_p->name); |
123 |
failed_oper_notice(source_p, name, "can't attach conf!"); |
124 |
return 0; |
125 |
} |
126 |
|
127 |
oper_up(source_p); |
128 |
|
129 |
ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", |
130 |
name, source_p->name, source_p->username, source_p->host); |
131 |
} |
132 |
else |
133 |
{ |
134 |
sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); |
135 |
failed_oper_notice(source_p, name, "password mismatch"); |
136 |
} |
137 |
|
138 |
return 0; |
139 |
} |
140 |
|
141 |
/* |
142 |
** mo_oper |
143 |
** parv[0] = sender prefix |
144 |
** parv[1] = oper name |
145 |
** parv[2] = oper password |
146 |
*/ |
147 |
static int |
148 |
mo_oper(struct Client *client_p, struct Client *source_p, |
149 |
int parc, char *parv[]) |
150 |
{ |
151 |
sendto_one(source_p, form_str(RPL_YOUREOPER), |
152 |
me.name, source_p->name); |
153 |
return 0; |
154 |
} |
155 |
|
156 |
static struct Message oper_msgtab = |
157 |
{ |
158 |
"OPER", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
159 |
{ m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore } |
160 |
}; |
161 |
|
162 |
static void |
163 |
module_init(void) |
164 |
{ |
165 |
mod_add_cmd(&oper_msgtab); |
166 |
} |
167 |
|
168 |
static void |
169 |
module_exit(void) |
170 |
{ |
171 |
mod_del_cmd(&oper_msgtab); |
172 |
} |
173 |
|
174 |
struct module module_entry = |
175 |
{ |
176 |
.node = { NULL, NULL, NULL }, |
177 |
.name = NULL, |
178 |
.version = "$Revision$", |
179 |
.handle = NULL, |
180 |
.modinit = module_init, |
181 |
.modexit = module_exit, |
182 |
.flags = 0 |
183 |
}; |