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