ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_challenge.c
Revision: 1309
Committed: Sun Mar 25 11:24:18 2012 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_challenge.c
File size: 5836 byte(s)
Log Message:
- renaming files:

  ircd_parser.y -> conf_parser.y
  ircd_lexer.l  -> conf_lexer.l
  s_conf.c      -> conf.c
  s_conf.h      -> conf.h
  s_log.c       -> log.c
  s_log.h       -> log.h

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 michael 912 #ifdef HAVE_LIBCRYPTO
27 adx 30 #include "client.h"
28     #include "ircd.h"
29     #include "modules.h"
30     #include "numeric.h"
31     #include "send.h"
32 michael 1309 #include "conf.h"
33 adx 30 #include "rsa.h"
34     #include "parse.h"
35     #include "irc_string.h"
36 michael 1309 #include "log.h"
37 adx 30 #include "s_user.h"
38    
39    
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     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 michael 1247
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 adx 30 }
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 michael 817 char *challenge = NULL;
73     struct ConfItem *conf = NULL;
74     struct AccessItem *aconf = NULL;
75 adx 30
76     /* if theyre an oper, reprint oper motd and ignore */
77 michael 1219 if (HasUMode(source_p, UMODE_OPER))
78 adx 30 {
79 michael 1230 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
80 adx 30 send_message_file(source_p, &ConfigFileEntry.opermotd);
81     return;
82     }
83    
84     if (*parv[1] == '+')
85     {
86     /* Ignore it if we aren't expecting this... -A1kmm */
87 michael 817 if (source_p->localClient->response == NULL)
88 adx 30 return;
89    
90     if (irccmp(source_p->localClient->response, ++parv[1]))
91     {
92     sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name,
93 michael 1121 source_p->name);
94 adx 30 failed_challenge_notice(source_p, source_p->localClient->auth_oper,
95 michael 1121 "challenge failed");
96 adx 30 return;
97     }
98 michael 817
99 michael 1285 conf = find_exact_name_conf(OPER_TYPE, source_p,
100     source_p->localClient->auth_oper, NULL, NULL);
101 michael 817 if (conf == NULL)
102 adx 30 {
103 michael 1247 /* XXX: logging */
104 michael 1230 sendto_one (source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
105 adx 30 return;
106     }
107    
108     if (attach_conf(source_p, conf) != 0)
109     {
110     sendto_one(source_p,":%s NOTICE %s :Can't attach conf!",
111     me.name, source_p->name);
112     failed_challenge_notice(source_p, conf->name, "can't attach conf!");
113     return;
114     }
115    
116     oper_up(source_p);
117    
118 michael 1247 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s",
119 adx 30 source_p->localClient->auth_oper, source_p->name, source_p->username,
120     source_p->host);
121    
122     MyFree(source_p->localClient->response);
123     MyFree(source_p->localClient->auth_oper);
124     source_p->localClient->response = NULL;
125     source_p->localClient->auth_oper = NULL;
126     return;
127     }
128    
129     MyFree(source_p->localClient->response);
130     MyFree(source_p->localClient->auth_oper);
131     source_p->localClient->response = NULL;
132     source_p->localClient->auth_oper = NULL;
133    
134     if ((conf = find_conf_exact(OPER_TYPE,
135     parv[1], source_p->username, source_p->host
136     )) != NULL)
137 michael 817 aconf = map_to_conf(conf);
138 adx 30 else if ((conf = find_conf_exact(OPER_TYPE,
139     parv[1], source_p->username,
140     source_p->sockhost)) != NULL)
141 michael 817 aconf = map_to_conf(conf);
142 adx 30
143 michael 817 if (aconf == NULL)
144 adx 30 {
145 michael 1230 sendto_one (source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
146 michael 1285 conf = find_exact_name_conf(OPER_TYPE, NULL, parv[1], NULL, NULL);
147 adx 30 failed_challenge_notice(source_p, parv[1], (conf != NULL)
148     ? "host mismatch" : "no oper {} block");
149     return;
150     }
151    
152     if (aconf->rsa_public_key == NULL)
153     {
154     sendto_one (source_p, ":%s NOTICE %s :I'm sorry, PK authentication "
155     "is not enabled for your oper{} block.", me.name,
156 michael 1230 source_p->name);
157 adx 30 return;
158     }
159    
160     if (!generate_challenge(&challenge, &(source_p->localClient->response),
161     aconf->rsa_public_key))
162     sendto_one(source_p, form_str(RPL_RSACHALLENGE),
163 michael 1230 me.name, source_p->name, challenge);
164 adx 30
165     DupString(source_p->localClient->auth_oper, conf->name);
166     MyFree(challenge);
167     }
168    
169 michael 1230 static struct Message challenge_msgtab = {
170     "CHALLENGE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
171     { m_unregistered, m_challenge, m_ignore, m_ignore, m_challenge, m_ignore }
172     };
173    
174 adx 30 static void
175 michael 1230 module_init(void)
176 adx 30 {
177 michael 1230 mod_add_cmd(&challenge_msgtab);
178 adx 30 }
179 michael 1230
180     static void
181     module_exit(void)
182     {
183     mod_del_cmd(&challenge_msgtab);
184     }
185    
186     struct module module_entry = {
187     .node = { NULL, NULL, NULL },
188     .name = NULL,
189     .version = "$Revision$",
190     .handle = NULL,
191     .modinit = module_init,
192     .modexit = module_exit,
193     .flags = 0
194     };
195 michael 912 #endif

Properties

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