ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_challenge.c
Revision: 3007
Committed: Wed Feb 19 11:38:21 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 6575 byte(s)
Log Message:
- m_challenge.c:m_challenge(): fixed an XXX

File Contents

# Content
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 sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
99 conf = find_exact_name_conf(CONF_OPER, NULL, source_p->localClient->auth_oper, NULL, NULL);
100 failed_challenge_notice(source_p, source_p->localClient->auth_oper, (conf != NULL) ?
101 "host mismatch" : "no oper {} block");
102 return 0;
103 }
104
105 if (attach_conf(source_p, conf) != 0)
106 {
107 sendto_one(source_p,":%s NOTICE %s :Can't attach conf!",
108 me.name, source_p->name);
109 failed_challenge_notice(source_p, conf->name, "can't attach conf!");
110 return 0;
111 }
112
113 oper_up(source_p);
114
115 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s",
116 source_p->localClient->auth_oper, source_p->name, source_p->username,
117 source_p->host);
118
119 MyFree(source_p->localClient->response);
120 MyFree(source_p->localClient->auth_oper);
121 source_p->localClient->response = NULL;
122 source_p->localClient->auth_oper = NULL;
123 return 0;
124 }
125
126 MyFree(source_p->localClient->response);
127 MyFree(source_p->localClient->auth_oper);
128 source_p->localClient->response = NULL;
129 source_p->localClient->auth_oper = NULL;
130
131 conf = find_exact_name_conf(CONF_OPER, source_p, parv[1], NULL, NULL);
132
133 if (!conf)
134 {
135 sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
136 conf = find_exact_name_conf(CONF_OPER, NULL, parv[1], NULL, NULL);
137 failed_challenge_notice(source_p, parv[1], (conf != NULL)
138 ? "host mismatch" : "no oper {} block");
139 return 0;
140 }
141
142 if (conf->rsa_public_key == NULL)
143 {
144 sendto_one(source_p, ":%s NOTICE %s :I'm sorry, PK authentication "
145 "is not enabled for your oper{} block.", me.name,
146 source_p->name);
147 return 0;
148 }
149
150 if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL))
151 {
152 sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
153 failed_challenge_notice(source_p, conf->name, "requires SSL/TLS");
154 return 0;
155 }
156
157 if (!EmptyString(conf->certfp))
158 {
159 if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp))
160 {
161 sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
162 failed_challenge_notice(source_p, conf->name, "client certificate fingerprint mismatch");
163 return 0;
164 }
165 }
166
167 if (!generate_challenge(&challenge, &(source_p->localClient->response),
168 conf->rsa_public_key))
169 sendto_one(source_p, form_str(RPL_RSACHALLENGE),
170 me.name, source_p->name, challenge);
171
172 source_p->localClient->auth_oper = xstrdup(conf->name);
173 MyFree(challenge);
174 return 0;
175 }
176
177 static int
178 mo_challenge(struct Client *client_p, struct Client *source_p,
179 int parc, char *parv[])
180 {
181 sendto_one(source_p, form_str(RPL_YOUREOPER),
182 me.name, source_p->name);
183 return 0;
184 }
185
186 static struct Message challenge_msgtab =
187 {
188 "CHALLENGE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
189 { m_unregistered, m_challenge, m_ignore, m_ignore, mo_challenge, m_ignore }
190 };
191
192 static void
193 module_init(void)
194 {
195 mod_add_cmd(&challenge_msgtab);
196 }
197
198 static void
199 module_exit(void)
200 {
201 mod_del_cmd(&challenge_msgtab);
202 }
203
204 #else
205
206 static void
207 module_init(void)
208 {
209 }
210
211 static void
212 module_exit(void)
213 {
214 }
215 #endif
216
217 struct module module_entry =
218 {
219 .node = { NULL, NULL, NULL },
220 .name = NULL,
221 .version = "$Revision$",
222 .handle = NULL,
223 .modinit = module_init,
224 .modexit = module_exit,
225 .flags = 0
226 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision