ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_challenge.c
Revision: 1632
Committed: Sun Nov 4 15:37:10 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 5777 byte(s)
Log Message:
- Initial rewrite of the configuration subsystem

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
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 michael 1309 #include "conf.h"
32 adx 30 #include "rsa.h"
33     #include "parse.h"
34     #include "irc_string.h"
35 michael 1309 #include "log.h"
36 adx 30 #include "s_user.h"
37    
38    
39 michael 1415 #ifdef HAVE_LIBCRYPTO
40 michael 1230 /* 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 adx 30 {
52 michael 1230 if (ConfigFileEntry.failed_oper_notice)
53 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
54     "Failed CHALLENGE attempt as %s "
55 michael 1230 "by %s (%s@%s) - %s", name, source_p->name,
56     source_p->username, source_p->host, reason);
57 michael 1247
58     ilog(LOG_TYPE_OPER, "Failed CHALLENGE attempt as %s "
59     "by %s (%s@%s) - %s", name, source_p->name,
60     source_p->username, source_p->host, reason);
61 adx 30 }
62    
63     /*
64     * m_challenge - generate RSA challenge for wouldbe oper
65     * parv[0] = sender prefix
66     * parv[1] = operator to challenge for, or +response
67     *
68     */
69     static void
70     m_challenge(struct Client *client_p, struct Client *source_p,
71     int parc, char *parv[])
72     {
73 michael 817 char *challenge = NULL;
74 michael 1632 struct MaskItem *conf = NULL;
75 adx 30
76     if (*parv[1] == '+')
77     {
78     /* Ignore it if we aren't expecting this... -A1kmm */
79 michael 817 if (source_p->localClient->response == NULL)
80 adx 30 return;
81    
82     if (irccmp(source_p->localClient->response, ++parv[1]))
83     {
84     sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name,
85 michael 1121 source_p->name);
86 adx 30 failed_challenge_notice(source_p, source_p->localClient->auth_oper,
87 michael 1121 "challenge failed");
88 adx 30 return;
89     }
90 michael 817
91 michael 1632 conf = find_exact_name_conf(CONF_OPER, source_p,
92 michael 1285 source_p->localClient->auth_oper, NULL, NULL);
93 michael 817 if (conf == NULL)
94 adx 30 {
95 michael 1247 /* XXX: logging */
96 michael 1230 sendto_one (source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
97 adx 30 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 michael 1247 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s",
111 adx 30 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 michael 1632 if ((conf = find_conf_exact(CONF_OPER,
127     parv[1], source_p->username, source_p->host)))
128     ;
129     else if ((conf = find_conf_exact(CONF_OPER, parv[1], source_p->username,
130     source_p->sockhost)))
131     ;
132 adx 30
133 michael 1632 if (!conf)
134 adx 30 {
135 michael 1230 sendto_one (source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
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     return;
140     }
141    
142 michael 1632 if (conf->rsa_public_key == NULL)
143 adx 30 {
144     sendto_one (source_p, ":%s NOTICE %s :I'm sorry, PK authentication "
145     "is not enabled for your oper{} block.", me.name,
146 michael 1230 source_p->name);
147 adx 30 return;
148     }
149    
150     if (!generate_challenge(&challenge, &(source_p->localClient->response),
151 michael 1632 conf->rsa_public_key))
152 adx 30 sendto_one(source_p, form_str(RPL_RSACHALLENGE),
153 michael 1230 me.name, source_p->name, challenge);
154 adx 30
155     DupString(source_p->localClient->auth_oper, conf->name);
156     MyFree(challenge);
157     }
158    
159 michael 1467 static void
160     mo_challenge(struct Client *client_p, struct Client *source_p,
161     int parc, char *parv[])
162     {
163     sendto_one(source_p, form_str(RPL_YOUREOPER),
164     me.name, source_p->name);
165     }
166    
167 michael 1230 static struct Message challenge_msgtab = {
168     "CHALLENGE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
169 michael 1467 { m_unregistered, m_challenge, m_ignore, m_ignore, mo_challenge, m_ignore }
170 michael 1230 };
171    
172 adx 30 static void
173 michael 1230 module_init(void)
174 adx 30 {
175 michael 1230 mod_add_cmd(&challenge_msgtab);
176 adx 30 }
177 michael 1230
178     static void
179     module_exit(void)
180     {
181     mod_del_cmd(&challenge_msgtab);
182     }
183    
184 michael 1415 #else
185    
186     static void
187     module_init(void)
188     {
189     }
190    
191     static void
192     module_exit(void)
193     {
194     }
195     #endif
196    
197 michael 1230 struct module module_entry = {
198     .node = { NULL, NULL, NULL },
199     .name = NULL,
200     .version = "$Revision$",
201     .handle = NULL,
202     .modinit = module_init,
203     .modexit = module_exit,
204     .flags = 0
205     };

Properties

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