]> jfr.im git - solanum.git/blame - modules/m_oper.c
hash.c: Save some more bytes
[solanum.git] / modules / m_oper.c
CommitLineData
212380e3
AC
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
212380e3
AC
23 */
24
25#include "stdinc.h"
212380e3 26#include "client.h"
4562c604 27#include "match.h"
212380e3
AC
28#include "ircd.h"
29#include "numeric.h"
212380e3
AC
30#include "s_conf.h"
31#include "s_newconf.h"
4016731b 32#include "logger.h"
212380e3
AC
33#include "s_user.h"
34#include "send.h"
35#include "msg.h"
36#include "parse.h"
37#include "modules.h"
38#include "packet.h"
39#include "cache.h"
40
eeabf33a
EM
41static const char oper_desc[] = "Provides the OPER command to become an IRC operator";
42
3c7d6fcc
EM
43static void m_oper(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
44
45static bool match_oper_password(const char *password, struct oper_conf *oper_p);
212380e3
AC
46
47struct Message oper_msgtab = {
7baa37a9 48 "OPER", 0, 0, 0, 0,
212380e3
AC
49 {mg_unreg, {m_oper, 3}, mg_ignore, mg_ignore, mg_ignore, {m_oper, 3}}
50};
51
52mapi_clist_av1 oper_clist[] = { &oper_msgtab, NULL };
1fe7d608 53
1fe7d608 54DECLARE_MODULE_AV2(oper, NULL, NULL, oper_clist, NULL, NULL, NULL, NULL, oper_desc);
212380e3 55
212380e3
AC
56/*
57 * m_oper
212380e3
AC
58 * parv[1] = oper name
59 * parv[2] = oper password
60 */
3c7d6fcc 61static void
428ca87b 62m_oper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
63{
64 struct oper_conf *oper_p;
65 const char *name;
66 const char *password;
67
68 name = parv[1];
69 password = parv[2];
70
71 if(IsOper(source_p))
72 {
73 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
74 send_oper_motd(source_p);
3c7d6fcc 75 return;
212380e3
AC
76 }
77
78 /* end the grace period */
79 if(!IsFloodDone(source_p))
80 flood_endgrace(source_p);
81
55abcbb2 82 oper_p = find_oper_conf(source_p->username, source_p->orighost,
212380e3
AC
83 source_p->sockhost, name);
84
85 if(oper_p == NULL)
86 {
76169ea7 87 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
212380e3
AC
88 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
89 name, source_p->name,
90 source_p->username, source_p->host, source_p->sockhost);
91
92 if(ConfigFileEntry.failed_oper_notice)
93 {
94 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
95 "Failed OPER attempt - host mismatch by %s (%s@%s)",
96 source_p->name, source_p->username, source_p->host);
97 }
98
3c7d6fcc 99 return;
212380e3
AC
100 }
101
b1594414
JT
102 if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p))
103 {
76169ea7 104 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
b1594414
JT
105 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS",
106 name, source_p->name,
107 source_p->username, source_p->host, source_p->sockhost);
108
109 if(ConfigFileEntry.failed_oper_notice)
110 {
111 sendto_realops_snomask(SNO_GENERAL, L_ALL,
112 "Failed OPER attempt - missing SSL/TLS by %s (%s@%s)",
113 source_p->name, source_p->username, source_p->host);
114 }
3c7d6fcc 115 return;
b1594414
JT
116 }
117
ff31db84
AC
118 if (oper_p->certfp != NULL)
119 {
120 if (source_p->certfp == NULL || strcasecmp(source_p->certfp, oper_p->certfp))
121 {
76169ea7 122 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
ff31db84
AC
123 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch",
124 name, source_p->name,
125 source_p->username, source_p->host, source_p->sockhost);
126
127 if(ConfigFileEntry.failed_oper_notice)
128 {
129 sendto_realops_snomask(SNO_GENERAL, L_ALL,
130 "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)",
131 source_p->name, source_p->username, source_p->host);
132 }
3c7d6fcc 133 return;
ff31db84
AC
134 }
135 }
136
212380e3
AC
137 if(match_oper_password(password, oper_p))
138 {
139 oper_up(source_p, oper_p);
140
141 ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)",
142 name, source_p->name, source_p->username, source_p->host,
143 source_p->sockhost);
3c7d6fcc 144 return;
212380e3
AC
145 }
146 else
147 {
148 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
149 me.name, source_p->name);
150
151 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
152 name, source_p->name, source_p->username, source_p->host,
153 source_p->sockhost);
154
155 if(ConfigFileEntry.failed_oper_notice)
156 {
157 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
158 "Failed OPER attempt by %s (%s@%s)",
159 source_p->name, source_p->username, source_p->host);
160 }
161 }
212380e3
AC
162}
163
164/*
165 * match_oper_password
166 *
167 * inputs - pointer to given password
55abcbb2 168 * - pointer to Conf
3c7d6fcc 169 * output - true if match, false otherwise
212380e3
AC
170 * side effects - none
171 */
3c7d6fcc 172static bool
212380e3
AC
173match_oper_password(const char *password, struct oper_conf *oper_p)
174{
175 const char *encr;
176
177 /* passwd may be NULL pointer. Head it off at the pass... */
178 if(EmptyString(oper_p->passwd))
3c7d6fcc 179 return false;
212380e3
AC
180
181 if(IsOperConfEncrypted(oper_p))
182 {
183 /* use first two chars of the password they send in as salt */
55abcbb2 184 /* If the password in the conf is MD5, and ircd is linked
212380e3
AC
185 * to scrypt on FreeBSD, or the standard crypt library on
186 * glibc Linux, then this code will work fine on generating
187 * the proper encrypted hash for comparison.
188 */
189 if(!EmptyString(password))
d20b49d5 190 encr = rb_crypt(password, oper_p->passwd);
212380e3
AC
191 else
192 encr = "";
193 }
194 else
195 encr = password;
196
e69375f3 197 if(encr != NULL && strcmp(encr, oper_p->passwd) == 0)
3c7d6fcc 198 return true;
212380e3 199 else
3c7d6fcc 200 return false;
212380e3 201}