1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2000-2014 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_challenge.c |
23 |
* \brief Includes required functions for processing the CHALLENGE command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "ircd.h" |
30 |
#include "modules.h" |
31 |
#include "numeric.h" |
32 |
#include "send.h" |
33 |
#include "conf.h" |
34 |
#include "rsa.h" |
35 |
#include "parse.h" |
36 |
#include "irc_string.h" |
37 |
#include "log.h" |
38 |
#include "s_user.h" |
39 |
#include "memory.h" |
40 |
|
41 |
|
42 |
#ifdef HAVE_LIBCRYPTO |
43 |
/* failed_challenge_notice() |
44 |
* |
45 |
* inputs - pointer to client doing /oper ... |
46 |
* - pointer to nick they tried to oper as |
47 |
* - pointer to reason they have failed |
48 |
* output - nothing |
49 |
* side effects - notices all opers of the failed oper attempt if enabled |
50 |
*/ |
51 |
static void |
52 |
failed_challenge_notice(struct Client *source_p, const char *name, |
53 |
const char *reason) |
54 |
{ |
55 |
if (ConfigFileEntry.failed_oper_notice) |
56 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
57 |
"Failed CHALLENGE attempt as %s " |
58 |
"by %s (%s@%s) - %s", name, source_p->name, |
59 |
source_p->username, source_p->host, reason); |
60 |
|
61 |
ilog(LOG_TYPE_OPER, "Failed CHALLENGE attempt as %s " |
62 |
"by %s (%s@%s) - %s", name, source_p->name, |
63 |
source_p->username, source_p->host, reason); |
64 |
} |
65 |
|
66 |
/* |
67 |
* m_challenge - generate RSA challenge for wouldbe oper |
68 |
* parv[0] = sender prefix |
69 |
* parv[1] = operator to challenge for, or +response |
70 |
* |
71 |
*/ |
72 |
static int |
73 |
m_challenge(struct Client *client_p, struct Client *source_p, |
74 |
int parc, char *parv[]) |
75 |
{ |
76 |
char *challenge = NULL; |
77 |
struct MaskItem *conf = NULL; |
78 |
|
79 |
if (*parv[1] == '+') |
80 |
{ |
81 |
/* Ignore it if we aren't expecting this... -A1kmm */ |
82 |
if (source_p->localClient->response == NULL) |
83 |
return 0; |
84 |
|
85 |
if (irccmp(source_p->localClient->response, ++parv[1])) |
86 |
{ |
87 |
sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, |
88 |
source_p->name); |
89 |
failed_challenge_notice(source_p, source_p->localClient->auth_oper, |
90 |
"challenge failed"); |
91 |
return 0; |
92 |
} |
93 |
|
94 |
conf = find_exact_name_conf(CONF_OPER, source_p, |
95 |
source_p->localClient->auth_oper, NULL, NULL); |
96 |
if (conf == NULL) |
97 |
{ |
98 |
/* XXX: logging */ |
99 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
100 |
return 0; |
101 |
} |
102 |
|
103 |
if (attach_conf(source_p, conf) != 0) |
104 |
{ |
105 |
sendto_one(source_p,":%s NOTICE %s :Can't attach conf!", |
106 |
me.name, source_p->name); |
107 |
failed_challenge_notice(source_p, conf->name, "can't attach conf!"); |
108 |
return 0; |
109 |
} |
110 |
|
111 |
oper_up(source_p); |
112 |
|
113 |
ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", |
114 |
source_p->localClient->auth_oper, source_p->name, source_p->username, |
115 |
source_p->host); |
116 |
|
117 |
MyFree(source_p->localClient->response); |
118 |
MyFree(source_p->localClient->auth_oper); |
119 |
source_p->localClient->response = NULL; |
120 |
source_p->localClient->auth_oper = NULL; |
121 |
return 0; |
122 |
} |
123 |
|
124 |
MyFree(source_p->localClient->response); |
125 |
MyFree(source_p->localClient->auth_oper); |
126 |
source_p->localClient->response = NULL; |
127 |
source_p->localClient->auth_oper = NULL; |
128 |
|
129 |
conf = find_exact_name_conf(CONF_OPER, source_p, parv[1], NULL, NULL); |
130 |
|
131 |
if (!conf) |
132 |
{ |
133 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
134 |
conf = find_exact_name_conf(CONF_OPER, NULL, parv[1], NULL, NULL); |
135 |
failed_challenge_notice(source_p, parv[1], (conf != NULL) |
136 |
? "host mismatch" : "no oper {} block"); |
137 |
return 0; |
138 |
} |
139 |
|
140 |
if (conf->rsa_public_key == NULL) |
141 |
{ |
142 |
sendto_one(source_p, ":%s NOTICE %s :I'm sorry, PK authentication " |
143 |
"is not enabled for your oper{} block.", me.name, |
144 |
source_p->name); |
145 |
return 0; |
146 |
} |
147 |
|
148 |
if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL)) |
149 |
{ |
150 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
151 |
failed_challenge_notice(source_p, conf->name, "requires SSL/TLS"); |
152 |
return 0; |
153 |
} |
154 |
|
155 |
if (!EmptyString(conf->certfp)) |
156 |
{ |
157 |
if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp)) |
158 |
{ |
159 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
160 |
failed_challenge_notice(source_p, conf->name, "client certificate fingerprint mismatch"); |
161 |
return 0; |
162 |
} |
163 |
} |
164 |
|
165 |
if (!generate_challenge(&challenge, &(source_p->localClient->response), |
166 |
conf->rsa_public_key)) |
167 |
sendto_one(source_p, form_str(RPL_RSACHALLENGE), |
168 |
me.name, source_p->name, challenge); |
169 |
|
170 |
source_p->localClient->auth_oper = xstrdup(conf->name); |
171 |
MyFree(challenge); |
172 |
return 0; |
173 |
} |
174 |
|
175 |
static int |
176 |
mo_challenge(struct Client *client_p, struct Client *source_p, |
177 |
int parc, char *parv[]) |
178 |
{ |
179 |
sendto_one(source_p, form_str(RPL_YOUREOPER), |
180 |
me.name, source_p->name); |
181 |
return 0; |
182 |
} |
183 |
|
184 |
static struct Message challenge_msgtab = |
185 |
{ |
186 |
"CHALLENGE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
187 |
{ m_unregistered, m_challenge, m_ignore, m_ignore, mo_challenge, m_ignore } |
188 |
}; |
189 |
|
190 |
static void |
191 |
module_init(void) |
192 |
{ |
193 |
mod_add_cmd(&challenge_msgtab); |
194 |
} |
195 |
|
196 |
static void |
197 |
module_exit(void) |
198 |
{ |
199 |
mod_del_cmd(&challenge_msgtab); |
200 |
} |
201 |
|
202 |
#else |
203 |
|
204 |
static void |
205 |
module_init(void) |
206 |
{ |
207 |
} |
208 |
|
209 |
static void |
210 |
module_exit(void) |
211 |
{ |
212 |
} |
213 |
#endif |
214 |
|
215 |
struct module module_entry = |
216 |
{ |
217 |
.node = { NULL, NULL, NULL }, |
218 |
.name = NULL, |
219 |
.version = "$Revision$", |
220 |
.handle = NULL, |
221 |
.modinit = module_init, |
222 |
.modexit = module_exit, |
223 |
.flags = 0 |
224 |
}; |