]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_oper.c
Fix VERSION and RPL_MYINFO to only show modes that are enabled. Also fix up some...
[irc/rqf/shadowircd.git] / modules / m_oper.c
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
26 #include "stdinc.h"
27 #include "client.h"
28 #include "common.h"
29 #include "match.h"
30 #include "ircd.h"
31 #include "numeric.h"
32 #include "s_conf.h"
33 #include "s_newconf.h"
34 #include "logger.h"
35 #include "s_user.h"
36 #include "send.h"
37 #include "msg.h"
38 #include "parse.h"
39 #include "modules.h"
40 #include "packet.h"
41 #include "cache.h"
42
43 static int m_oper(struct Client *, struct Client *, int, const char **);
44
45 struct Message oper_msgtab = {
46 "OPER", 0, 0, 0, MFLG_SLOW,
47 {mg_unreg, {m_oper, 3}, mg_ignore, mg_ignore, mg_ignore, {m_oper, 3}}
48 };
49
50 mapi_clist_av1 oper_clist[] = { &oper_msgtab, NULL };
51 DECLARE_MODULE_AV1(oper, NULL, NULL, oper_clist, NULL, NULL, "$Revision: 1483 $");
52
53 static int match_oper_password(const char *password, struct oper_conf *oper_p);
54
55 /*
56 * m_oper
57 * parv[1] = oper name
58 * parv[2] = oper password
59 */
60 static int
61 m_oper(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
62 {
63 struct oper_conf *oper_p;
64 const char *name;
65 const char *password;
66
67 name = parv[1];
68 password = parv[2];
69
70 if(IsOper(source_p))
71 {
72 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
73 send_oper_motd(source_p);
74 return 0;
75 }
76
77 /* end the grace period */
78 if(!IsFloodDone(source_p))
79 flood_endgrace(source_p);
80
81 oper_p = find_oper_conf(source_p->username, source_p->orighost,
82 source_p->sockhost, name);
83
84 if(oper_p == NULL)
85 {
86 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
87 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
88 name, source_p->name,
89 source_p->username, source_p->host, source_p->sockhost);
90
91 if(ConfigFileEntry.failed_oper_notice)
92 {
93 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
94 "Failed OPER attempt - host mismatch by %s (%s@%s)",
95 source_p->name, source_p->username, source_p->host);
96 }
97
98 return 0;
99 }
100
101 if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p))
102 {
103 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
104 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS",
105 name, source_p->name,
106 source_p->username, source_p->host, source_p->sockhost);
107
108 if(ConfigFileEntry.failed_oper_notice)
109 {
110 sendto_realops_snomask(SNO_GENERAL, L_ALL,
111 "Failed OPER attempt - missing SSL/TLS by %s (%s@%s)",
112 source_p->name, source_p->username, source_p->host);
113 }
114 return 0;
115 }
116
117 if (oper_p->certfp != NULL)
118 {
119 if (source_p->certfp == NULL || strcasecmp(source_p->certfp, oper_p->certfp))
120 {
121 sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST));
122 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch",
123 name, source_p->name,
124 source_p->username, source_p->host, source_p->sockhost);
125
126 if(ConfigFileEntry.failed_oper_notice)
127 {
128 sendto_realops_snomask(SNO_GENERAL, L_ALL,
129 "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)",
130 source_p->name, source_p->username, source_p->host);
131 }
132 return 0;
133 }
134 }
135
136 if(match_oper_password(password, oper_p))
137 {
138 oper_up(source_p, oper_p);
139
140 ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)",
141 name, source_p->name, source_p->username, source_p->host,
142 source_p->sockhost);
143 return 0;
144 }
145 else
146 {
147 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
148 me.name, source_p->name);
149
150 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
151 name, source_p->name, source_p->username, source_p->host,
152 source_p->sockhost);
153
154 if(ConfigFileEntry.failed_oper_notice)
155 {
156 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
157 "Failed OPER attempt by %s (%s@%s)",
158 source_p->name, source_p->username, source_p->host);
159 }
160 }
161
162 return 0;
163 }
164
165 /*
166 * match_oper_password
167 *
168 * inputs - pointer to given password
169 * - pointer to Conf
170 * output - YES or NO if match
171 * side effects - none
172 */
173 static int
174 match_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))
180 return NO;
181
182 if(IsOperConfEncrypted(oper_p))
183 {
184 /* use first two chars of the password they send in as salt */
185 /* If the password in the conf is MD5, and ircd is linked
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))
191 encr = rb_crypt(password, oper_p->passwd);
192 else
193 encr = "";
194 }
195 else
196 encr = password;
197
198 if(strcmp(encr, oper_p->passwd) == 0)
199 return YES;
200 else
201 return NO;
202 }