]> jfr.im git - solanum.git/blame_incremental - modules/m_oper.c
Merge pull request #355 from edk0/kline-cidr
[solanum.git] / modules / m_oper.c
... / ...
CommitLineData
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_oper.c: Makes a user an IRC Operator.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25#include "stdinc.h"
26#include "client.h"
27#include "match.h"
28#include "ircd.h"
29#include "numeric.h"
30#include "s_conf.h"
31#include "s_newconf.h"
32#include "logger.h"
33#include "s_user.h"
34#include "s_serv.h"
35#include "send.h"
36#include "msg.h"
37#include "parse.h"
38#include "modules.h"
39#include "packet.h"
40#include "cache.h"
41
42static const char oper_desc[] = "Provides the OPER command to become an IRC operator";
43
44static void m_oper(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
45static void mc_oper(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
46
47static bool match_oper_password(const char *password, struct oper_conf *oper_p);
48
49struct Message oper_msgtab = {
50 "OPER", 0, 0, 0, 0,
51 {mg_unreg, {m_oper, 3}, {mc_oper, 3}, mg_ignore, mg_ignore, {m_oper, 3}}
52};
53
54mapi_clist_av1 oper_clist[] = { &oper_msgtab, NULL };
55
56DECLARE_MODULE_AV2(oper, NULL, NULL, oper_clist, NULL, NULL, NULL, NULL, oper_desc);
57
58/*
59 * m_oper
60 * parv[1] = oper name
61 * parv[2] = oper password
62 */
63static void
64m_oper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
65{
66 struct oper_conf *oper_p;
67 const char *name;
68 const char *password;
69
70 name = parv[1];
71 password = parv[2];
72
73 if(IsOper(source_p))
74 {
75 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
76 send_oper_motd(source_p);
77 return;
78 }
79
80 /* end the grace period */
81 if(!IsFloodDone(source_p))
82 flood_endgrace(source_p);
83
84 oper_p = find_oper_conf(source_p->username, source_p->orighost,
85 source_p->sockhost, name);
86
87 if(oper_p == NULL)
88 {
89 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
90 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
91 name, source_p->name,
92 source_p->username, source_p->host, source_p->sockhost);
93
94 if(ConfigFileEntry.failed_oper_notice)
95 {
96 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
97 "Failed OPER attempt - host mismatch by %s (%s@%s)",
98 source_p->name, source_p->username, source_p->host);
99 }
100
101 return;
102 }
103
104 if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p))
105 {
106 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
107 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS",
108 name, source_p->name,
109 source_p->username, source_p->host, source_p->sockhost);
110
111 if(ConfigFileEntry.failed_oper_notice)
112 {
113 sendto_realops_snomask(SNO_GENERAL, L_ALL,
114 "Failed OPER attempt - missing SSL/TLS by %s (%s@%s)",
115 source_p->name, source_p->username, source_p->host);
116 }
117 return;
118 }
119
120 if (oper_p->certfp != NULL)
121 {
122 if (source_p->certfp == NULL || rb_strcasecmp(source_p->certfp, oper_p->certfp))
123 {
124 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
125 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch",
126 name, source_p->name,
127 source_p->username, source_p->host, source_p->sockhost);
128
129 if(ConfigFileEntry.failed_oper_notice)
130 {
131 sendto_realops_snomask(SNO_GENERAL, L_ALL,
132 "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)",
133 source_p->name, source_p->username, source_p->host);
134 }
135 return;
136 }
137 }
138
139 if(match_oper_password(password, oper_p))
140 {
141 oper_up(source_p, oper_p);
142
143 ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)",
144 name, source_p->name, source_p->username, source_p->host,
145 source_p->sockhost);
146 return;
147 }
148 else
149 {
150 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
151 me.name, source_p->name);
152
153 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
154 name, source_p->name, source_p->username, source_p->host,
155 source_p->sockhost);
156
157 if(ConfigFileEntry.failed_oper_notice)
158 {
159 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
160 "Failed OPER attempt by %s (%s@%s)",
161 source_p->name, source_p->username, source_p->host);
162 }
163 }
164}
165
166/*
167 * mc_oper - server-to-server OPER propagation
168 * parv[1] = opername
169 * parv[2] = privset
170 */
171static void
172mc_oper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
173{
174 struct PrivilegeSet *privset;
175 sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s OPER %s %s", use_id(source_p), parv[1], parv[2]);
176
177 privset = privilegeset_get(parv[2]);
178 if(privset == NULL)
179 {
180 /* if we don't have a matching privset, we'll create an empty one and
181 * mark it illegal, so it gets picked up on a rehash later */
182 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Received OPER for %s with unknown privset %s", source_p->name, parv[2]);
183 privset = privilegeset_set_new(parv[2], "", 0);
184 privset->status |= CONF_ILLEGAL;
185 }
186
187 privset = privilegeset_ref(privset);
188 if (source_p->user->privset != NULL)
189 privilegeset_unref(source_p->user->privset);
190
191 source_p->user->privset = privset;
192 source_p->user->opername = rb_strdup(parv[1]);
193}
194
195/*
196 * match_oper_password
197 *
198 * inputs - pointer to given password
199 * - pointer to Conf
200 * output - true if match, false otherwise
201 * side effects - none
202 */
203static bool
204match_oper_password(const char *password, struct oper_conf *oper_p)
205{
206 const char *encr;
207
208 /* passwd may be NULL pointer. Head it off at the pass... */
209 if(EmptyString(oper_p->passwd))
210 return false;
211
212 if(IsOperConfEncrypted(oper_p))
213 {
214 /* use first two chars of the password they send in as salt */
215 /* If the password in the conf is MD5, and ircd is linked
216 * to scrypt on FreeBSD, or the standard crypt library on
217 * glibc Linux, then this code will work fine on generating
218 * the proper encrypted hash for comparison.
219 */
220 if(!EmptyString(password))
221 encr = rb_crypt(password, oper_p->passwd);
222 else
223 encr = "";
224 }
225 else
226 encr = password;
227
228 if(encr != NULL && strcmp(encr, oper_p->passwd) == 0)
229 return true;
230 else
231 return false;
232}