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