ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_challenge.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6361 byte(s)
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

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

Properties

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