]>
Commit | Line | Data |
---|---|---|
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 | ||
428ca87b | 42 | static int m_oper(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
212380e3 AC |
43 | |
44 | struct Message oper_msgtab = { | |
7baa37a9 | 45 | "OPER", 0, 0, 0, 0, |
212380e3 AC |
46 | {mg_unreg, {m_oper, 3}, mg_ignore, mg_ignore, mg_ignore, {m_oper, 3}} |
47 | }; | |
48 | ||
49 | mapi_clist_av1 oper_clist[] = { &oper_msgtab, NULL }; | |
105a4985 | 50 | DECLARE_MODULE_AV2(oper, NULL, NULL, oper_clist, NULL, NULL, NULL, NULL, NULL); |
212380e3 AC |
51 | |
52 | static int match_oper_password(const char *password, struct oper_conf *oper_p); | |
212380e3 AC |
53 | |
54 | /* | |
55 | * m_oper | |
212380e3 AC |
56 | * parv[1] = oper name |
57 | * parv[2] = oper password | |
58 | */ | |
59 | static int | |
428ca87b | 60 | m_oper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
61 | { |
62 | struct oper_conf *oper_p; | |
63 | const char *name; | |
64 | const char *password; | |
65 | ||
66 | name = parv[1]; | |
67 | password = parv[2]; | |
68 | ||
69 | if(IsOper(source_p)) | |
70 | { | |
71 | sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); | |
72 | send_oper_motd(source_p); | |
73 | return 0; | |
74 | } | |
75 | ||
76 | /* end the grace period */ | |
77 | if(!IsFloodDone(source_p)) | |
78 | flood_endgrace(source_p); | |
79 | ||
55abcbb2 | 80 | oper_p = find_oper_conf(source_p->username, source_p->orighost, |
212380e3 AC |
81 | source_p->sockhost, name); |
82 | ||
83 | if(oper_p == NULL) | |
84 | { | |
76169ea7 | 85 | sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); |
212380e3 AC |
86 | ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", |
87 | name, source_p->name, | |
88 | source_p->username, source_p->host, source_p->sockhost); | |
89 | ||
90 | if(ConfigFileEntry.failed_oper_notice) | |
91 | { | |
92 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
93 | "Failed OPER attempt - host mismatch by %s (%s@%s)", | |
94 | source_p->name, source_p->username, source_p->host); | |
95 | } | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
b1594414 JT |
100 | if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p)) |
101 | { | |
76169ea7 | 102 | sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); |
b1594414 JT |
103 | ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS", |
104 | name, source_p->name, | |
105 | source_p->username, source_p->host, source_p->sockhost); | |
106 | ||
107 | if(ConfigFileEntry.failed_oper_notice) | |
108 | { | |
109 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
110 | "Failed OPER attempt - missing SSL/TLS by %s (%s@%s)", | |
111 | source_p->name, source_p->username, source_p->host); | |
112 | } | |
113 | return 0; | |
114 | } | |
115 | ||
ff31db84 AC |
116 | if (oper_p->certfp != NULL) |
117 | { | |
118 | if (source_p->certfp == NULL || strcasecmp(source_p->certfp, oper_p->certfp)) | |
119 | { | |
76169ea7 | 120 | sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); |
ff31db84 AC |
121 | ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch", |
122 | name, source_p->name, | |
123 | source_p->username, source_p->host, source_p->sockhost); | |
124 | ||
125 | if(ConfigFileEntry.failed_oper_notice) | |
126 | { | |
127 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
128 | "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)", | |
129 | source_p->name, source_p->username, source_p->host); | |
130 | } | |
131 | return 0; | |
132 | } | |
133 | } | |
134 | ||
212380e3 AC |
135 | if(match_oper_password(password, oper_p)) |
136 | { | |
137 | oper_up(source_p, oper_p); | |
138 | ||
139 | ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)", | |
140 | name, source_p->name, source_p->username, source_p->host, | |
141 | source_p->sockhost); | |
142 | return 0; | |
143 | } | |
144 | else | |
145 | { | |
146 | sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), | |
147 | me.name, source_p->name); | |
148 | ||
149 | ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", | |
150 | name, source_p->name, source_p->username, source_p->host, | |
151 | source_p->sockhost); | |
152 | ||
153 | if(ConfigFileEntry.failed_oper_notice) | |
154 | { | |
155 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
156 | "Failed OPER attempt by %s (%s@%s)", | |
157 | source_p->name, source_p->username, source_p->host); | |
158 | } | |
159 | } | |
160 | ||
161 | return 0; | |
162 | } | |
163 | ||
164 | /* | |
165 | * match_oper_password | |
166 | * | |
167 | * inputs - pointer to given password | |
55abcbb2 | 168 | * - pointer to Conf |
212380e3 AC |
169 | * output - YES or NO if match |
170 | * side effects - none | |
171 | */ | |
172 | static int | |
173 | match_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)) | |
179 | return NO; | |
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) |
212380e3 AC |
198 | return YES; |
199 | else | |
200 | return NO; | |
201 | } |