ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_challenge.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 6058 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.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     #include "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "modules.h"
30     #include "numeric.h"
31     #include "send.h"
32     #include "s_conf.h"
33     /* -lcrypto is implicit for building this module! */
34     #include "rsa.h"
35     #include "msg.h"
36     #include "parse.h"
37     #include "s_user.h"
38    
39     static void failed_challenge_notice(struct Client *, const char *,
40     const char *);
41     static void m_challenge(struct Client *, struct Client *, int, char **);
42    
43     /* We have openssl support, so include /CHALLENGE */
44     struct Message challenge_msgtab = {
45     "CHALLENGE", 0, 0, 2, 0, MFLG_SLOW, 0,
46     { m_unregistered, m_challenge, m_ignore, m_ignore, m_challenge, m_ignore }
47     };
48    
49     #ifndef STATIC_MODULES
50     void
51     _modinit(void)
52     {
53     mod_add_cmd(&challenge_msgtab);
54     }
55    
56     void
57     _moddeinit(void)
58     {
59     mod_del_cmd(&challenge_msgtab);
60     }
61    
62 knight 31 const char *_version = "$Revision$";
63 adx 30 #endif
64    
65     /*
66     * m_challenge - generate RSA challenge for wouldbe oper
67     * parv[0] = sender prefix
68     * parv[1] = operator to challenge for, or +response
69     *
70     */
71     static void
72     m_challenge(struct Client *client_p, struct Client *source_p,
73     int parc, char *parv[])
74     {
75     char *challenge;
76     struct ConfItem *conf=NULL;
77     struct AccessItem *aconf=NULL;
78    
79     assert(source_p->localClient);
80    
81     /* if theyre an oper, reprint oper motd and ignore */
82     if (IsOper(source_p))
83     {
84     sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, parv[0]);
85     send_message_file(source_p, &ConfigFileEntry.opermotd);
86     return;
87     }
88    
89     if (*parv[1] == '+')
90     {
91     /* Ignore it if we aren't expecting this... -A1kmm */
92     if (!source_p->localClient->response)
93     return;
94    
95     if (irccmp(source_p->localClient->response, ++parv[1]))
96     {
97     sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name,
98     source_p->name);
99     failed_challenge_notice(source_p, source_p->localClient->auth_oper,
100     "challenge failed");
101     return;
102     }
103    
104     if ((conf = find_exact_name_conf(OPER_TYPE,
105     source_p->localClient->auth_oper,
106     source_p->username, source_p->host
107     )) == NULL)
108     {
109     sendto_one (source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
110     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
111     source_p->localClient->auth_oper);
112     return;
113     }
114    
115     if (attach_conf(source_p, conf) != 0)
116     {
117     sendto_one(source_p,":%s NOTICE %s :Can't attach conf!",
118     me.name, source_p->name);
119     failed_challenge_notice(source_p, conf->name, "can't attach conf!");
120     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
121     source_p->localClient->auth_oper);
122     return;
123     }
124    
125     oper_up(source_p);
126    
127     ilog(L_TRACE, "OPER %s by %s!%s@%s",
128     source_p->localClient->auth_oper, source_p->name, source_p->username,
129     source_p->host);
130     log_oper_action(LOG_OPER_TYPE, source_p,
131     "%s\n", source_p->localClient->auth_oper);
132    
133     MyFree(source_p->localClient->response);
134     MyFree(source_p->localClient->auth_oper);
135     source_p->localClient->response = NULL;
136     source_p->localClient->auth_oper = NULL;
137     return;
138     }
139    
140     MyFree(source_p->localClient->response);
141     MyFree(source_p->localClient->auth_oper);
142     source_p->localClient->response = NULL;
143     source_p->localClient->auth_oper = NULL;
144    
145     if ((conf = find_conf_exact(OPER_TYPE,
146     parv[1], source_p->username, source_p->host
147     )) != NULL)
148     {
149     aconf = (struct AccessItem *)map_to_conf(conf);
150     }
151     else if ((conf = find_conf_exact(OPER_TYPE,
152     parv[1], source_p->username,
153     source_p->sockhost)) != NULL)
154     {
155     aconf = (struct AccessItem *)map_to_conf(conf);
156     }
157    
158     if(aconf == NULL)
159     {
160     sendto_one (source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
161     conf = find_exact_name_conf(OPER_TYPE, parv[1], NULL, NULL);
162     failed_challenge_notice(source_p, parv[1], (conf != NULL)
163     ? "host mismatch" : "no oper {} block");
164     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", parv[1]);
165     return;
166     }
167    
168     if (aconf->rsa_public_key == NULL)
169     {
170     sendto_one (source_p, ":%s NOTICE %s :I'm sorry, PK authentication "
171     "is not enabled for your oper{} block.", me.name,
172     parv[0]);
173     return;
174     }
175    
176     if (!generate_challenge(&challenge, &(source_p->localClient->response),
177     aconf->rsa_public_key))
178     sendto_one(source_p, form_str(RPL_RSACHALLENGE),
179     me.name, parv[0], challenge);
180    
181     DupString(source_p->localClient->auth_oper, conf->name);
182     MyFree(challenge);
183     }
184    
185     /* failed_challenge_notice()
186     *
187     * inputs - pointer to client doing /oper ...
188     * - pointer to nick they tried to oper as
189     * - pointer to reason they have failed
190     * output - nothing
191     * side effects - notices all opers of the failed oper attempt if enabled
192     */
193     static void
194     failed_challenge_notice(struct Client *source_p, const char *name,
195     const char *reason)
196     {
197     if (ConfigFileEntry.failed_oper_notice)
198     sendto_realops_flags(UMODE_ALL, L_ALL, "Failed CHALLENGE attempt as %s "
199     "by %s (%s@%s) - %s", name, source_p->name,
200     source_p->username, source_p->host, reason);
201     }

Properties

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