]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_oper.c
Add umode +R to doc/services.txt.
[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 * $Id: m_oper.c 1483 2006-05-27 18:58:12Z jilles $
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "common.h"
30 #include "match.h"
31 #include "ircd.h"
32 #include "numeric.h"
33 #include "s_conf.h"
34 #include "s_newconf.h"
35 #include "logger.h"
36 #include "s_user.h"
37 #include "send.h"
38 #include "msg.h"
39 #include "parse.h"
40 #include "modules.h"
41 #include "packet.h"
42 #include "cache.h"
43
44 static int m_oper(struct Client *, struct Client *, int, const char **);
45
46 struct Message oper_msgtab = {
47 "OPER", 0, 0, 0, MFLG_SLOW,
48 {mg_unreg, {m_oper, 3}, mg_ignore, mg_ignore, mg_ignore, {m_oper, 3}}
49 };
50
51 mapi_clist_av1 oper_clist[] = { &oper_msgtab, NULL };
52 DECLARE_MODULE_AV1(oper, NULL, NULL, oper_clist, NULL, NULL, "$Revision: 1483 $");
53
54 static int match_oper_password(const char *password, struct oper_conf *oper_p);
55
56 /*
57 * m_oper
58 * parv[1] = oper name
59 * parv[2] = oper password
60 */
61 static int
62 m_oper(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
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);
75 return 0;
76 }
77
78 /* end the grace period */
79 if(!IsFloodDone(source_p))
80 flood_endgrace(source_p);
81
82 oper_p = find_oper_conf(source_p->username, source_p->orighost,
83 source_p->sockhost, name);
84
85 if(oper_p == NULL)
86 {
87 sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
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
99 return 0;
100 }
101
102 if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p))
103 {
104 sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
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 }
115 return 0;
116 }
117
118 if(match_oper_password(password, oper_p))
119 {
120 oper_up(source_p, oper_p);
121
122 ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)",
123 name, source_p->name, source_p->username, source_p->host,
124 source_p->sockhost);
125 return 0;
126 }
127 else
128 {
129 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
130 me.name, source_p->name);
131
132 ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
133 name, source_p->name, source_p->username, source_p->host,
134 source_p->sockhost);
135
136 if(ConfigFileEntry.failed_oper_notice)
137 {
138 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
139 "Failed OPER attempt by %s (%s@%s)",
140 source_p->name, source_p->username, source_p->host);
141 }
142 }
143
144 return 0;
145 }
146
147 /*
148 * match_oper_password
149 *
150 * inputs - pointer to given password
151 * - pointer to Conf
152 * output - YES or NO if match
153 * side effects - none
154 */
155 static int
156 match_oper_password(const char *password, struct oper_conf *oper_p)
157 {
158 const char *encr;
159
160 /* passwd may be NULL pointer. Head it off at the pass... */
161 if(EmptyString(oper_p->passwd))
162 return NO;
163
164 if(IsOperConfEncrypted(oper_p))
165 {
166 /* use first two chars of the password they send in as salt */
167 /* If the password in the conf is MD5, and ircd is linked
168 * to scrypt on FreeBSD, or the standard crypt library on
169 * glibc Linux, then this code will work fine on generating
170 * the proper encrypted hash for comparison.
171 */
172 if(!EmptyString(password))
173 encr = rb_crypt(password, oper_p->passwd);
174 else
175 encr = "";
176 }
177 else
178 encr = password;
179
180 if(strcmp(encr, oper_p->passwd) == 0)
181 return YES;
182 else
183 return NO;
184 }