ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_challenge.c
Revision: 3786
Committed: Mon Jun 2 23:27:06 2014 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 7023 byte(s)
Log Message:
- m_challenge.c: whitespace commit

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 2000-2014 ircd-hybrid development team
5 adx 30 *
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 michael 2820 /*! \file m_challenge.c
23     * \brief Includes required functions for processing the CHALLENGE command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "ircd.h"
30     #include "modules.h"
31     #include "numeric.h"
32     #include "send.h"
33 michael 1309 #include "conf.h"
34 adx 30 #include "rsa.h"
35     #include "parse.h"
36     #include "irc_string.h"
37 michael 1309 #include "log.h"
38 michael 3347 #include "user.h"
39 michael 1666 #include "memory.h"
40 adx 30
41    
42 michael 1415 #ifdef HAVE_LIBCRYPTO
43 michael 3336 /*! \brief Notices all opers of the failed challenge attempt if enabled
44 michael 1230 *
45 michael 3336 * \param source_p Client doing /challenge ...
46     * \param name The nick they tried to oper as
47     * \param reason The reason why they have failed
48 michael 1230 */
49     static void
50     failed_challenge_notice(struct Client *source_p, const char *name,
51     const char *reason)
52 adx 30 {
53 michael 1230 if (ConfigFileEntry.failed_oper_notice)
54 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
55     "Failed CHALLENGE attempt as %s "
56 michael 1230 "by %s (%s@%s) - %s", name, source_p->name,
57     source_p->username, source_p->host, reason);
58 michael 1247
59     ilog(LOG_TYPE_OPER, "Failed CHALLENGE attempt as %s "
60     "by %s (%s@%s) - %s", name, source_p->name,
61     source_p->username, source_p->host, reason);
62 adx 30 }
63    
64 michael 3300 /*! \brief CHALLENGE command handler
65 adx 30 *
66 michael 3300 * \param source_p Pointer to allocated Client struct from which the message
67     * originally comes from. This can be a local or remote client.
68     * \param parc Integer holding the number of supplied arguments.
69     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
70     * pointers.
71     * \note Valid arguments for this command are:
72     * - parv[0] = command
73     * - parv[1] = operator to challenge for, or +response
74 adx 30 */
75 michael 2820 static int
76 michael 3156 m_challenge(struct Client *source_p, int parc, char *parv[])
77 adx 30 {
78 michael 817 char *challenge = NULL;
79 michael 1632 struct MaskItem *conf = NULL;
80 adx 30
81     if (*parv[1] == '+')
82     {
83     /* Ignore it if we aren't expecting this... -A1kmm */
84 michael 817 if (source_p->localClient->response == NULL)
85 michael 2820 return 0;
86 adx 30
87     if (irccmp(source_p->localClient->response, ++parv[1]))
88     {
89 michael 3109 sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
90 adx 30 failed_challenge_notice(source_p, source_p->localClient->auth_oper,
91 michael 1121 "challenge failed");
92 michael 2820 return 0;
93 adx 30 }
94 michael 3786
95 michael 1632 conf = find_exact_name_conf(CONF_OPER, source_p,
96 michael 1285 source_p->localClient->auth_oper, NULL, NULL);
97 michael 817 if (conf == NULL)
98 adx 30 {
99 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
100 michael 3007 conf = find_exact_name_conf(CONF_OPER, NULL, source_p->localClient->auth_oper, NULL, NULL);
101     failed_challenge_notice(source_p, source_p->localClient->auth_oper, (conf != NULL) ?
102     "host mismatch" : "no oper {} block");
103 michael 2820 return 0;
104 adx 30 }
105    
106     if (attach_conf(source_p, conf) != 0)
107     {
108 michael 3786 sendto_one_notice(source_p, &me, ":Can't attach conf!");
109 adx 30 failed_challenge_notice(source_p, conf->name, "can't attach conf!");
110 michael 2820 return 0;
111 adx 30 }
112    
113     oper_up(source_p);
114    
115 michael 1247 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s",
116 michael 2224 source_p->localClient->auth_oper, source_p->name, source_p->username,
117     source_p->host);
118 adx 30
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 michael 2820 return 0;
124 adx 30 }
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 michael 1636 conf = find_exact_name_conf(CONF_OPER, source_p, parv[1], NULL, NULL);
132 adx 30
133 michael 1632 if (!conf)
134 adx 30 {
135 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
136 michael 1632 conf = find_exact_name_conf(CONF_OPER, NULL, parv[1], NULL, NULL);
137 adx 30 failed_challenge_notice(source_p, parv[1], (conf != NULL)
138     ? "host mismatch" : "no oper {} block");
139 michael 2820 return 0;
140 adx 30 }
141    
142 michael 1632 if (conf->rsa_public_key == NULL)
143 adx 30 {
144 michael 3110 sendto_one_notice(source_p, &me, ":I'm sorry, PK authentication "
145     "is not enabled for your oper{} block.");
146 michael 2820 return 0;
147 adx 30 }
148    
149 michael 2248 if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL))
150     {
151 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
152 michael 2248 failed_challenge_notice(source_p, conf->name, "requires SSL/TLS");
153 michael 2820 return 0;
154 michael 2248 }
155    
156 michael 2232 if (!EmptyString(conf->certfp))
157     {
158     if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp))
159     {
160 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
161 michael 2232 failed_challenge_notice(source_p, conf->name, "client certificate fingerprint mismatch");
162 michael 2820 return 0;
163 michael 2232 }
164     }
165    
166 adx 30 if (!generate_challenge(&challenge, &(source_p->localClient->response),
167 michael 1632 conf->rsa_public_key))
168 michael 3109 sendto_one_numeric(source_p, &me, RPL_RSACHALLENGE, challenge);
169 adx 30
170 michael 1646 source_p->localClient->auth_oper = xstrdup(conf->name);
171 adx 30 MyFree(challenge);
172 michael 2820 return 0;
173 adx 30 }
174    
175 michael 3300 /*! \brief CHALLENGE command handler
176     *
177     * \param source_p Pointer to allocated Client struct from which the message
178     * originally comes from. This can be a local or remote client.
179     * \param parc Integer holding the number of supplied arguments.
180     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
181     * pointers.
182     * \note Valid arguments for this command are:
183     * - parv[0] = command
184     * - parv[1] = operator to challenge for, or +response
185     */
186 michael 2820 static int
187 michael 3156 mo_challenge(struct Client *source_p, int parc, char *parv[])
188 michael 1467 {
189 michael 3109 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
190 michael 2820 return 0;
191 michael 1467 }
192    
193 michael 2820 static struct Message challenge_msgtab =
194     {
195 michael 1230 "CHALLENGE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
196 michael 1467 { m_unregistered, m_challenge, m_ignore, m_ignore, mo_challenge, m_ignore }
197 michael 1230 };
198    
199 adx 30 static void
200 michael 1230 module_init(void)
201 adx 30 {
202 michael 1230 mod_add_cmd(&challenge_msgtab);
203 adx 30 }
204 michael 1230
205     static void
206     module_exit(void)
207     {
208     mod_del_cmd(&challenge_msgtab);
209     }
210    
211 michael 1415 #else
212    
213     static void
214     module_init(void)
215     {
216     }
217    
218     static void
219     module_exit(void)
220     {
221     }
222     #endif
223    
224 michael 2820 struct module module_entry =
225     {
226 michael 1230 .node = { NULL, NULL, NULL },
227     .name = NULL,
228     .version = "$Revision$",
229     .handle = NULL,
230     .modinit = module_init,
231     .modexit = module_exit,
232     .flags = 0
233     };

Properties

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