1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_capab.c: Negotiates capabilities with a remote server. |
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 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "handlers.h" |
27 |
#include "client.h" |
28 |
#include "irc_string.h" |
29 |
#include "s_serv.h" |
30 |
#include "s_conf.h" |
31 |
#include "msg.h" |
32 |
#include "parse.h" |
33 |
#include "modules.h" |
34 |
|
35 |
|
36 |
/* |
37 |
* mr_capab - CAPAB message handler |
38 |
* parv[0] = sender prefix |
39 |
* parv[1] = space-separated list of capabilities |
40 |
* |
41 |
*/ |
42 |
static void |
43 |
mr_capab(struct Client *client_p, struct Client *source_p, |
44 |
int parc, char *parv[]) |
45 |
{ |
46 |
int i; |
47 |
int cap; |
48 |
char *p = NULL; |
49 |
char *s = NULL; |
50 |
#ifdef HAVE_LIBCRYPTO |
51 |
const struct EncCapability *ecap; |
52 |
unsigned int cipher = 0; |
53 |
#endif |
54 |
|
55 |
if (client_p->localClient->caps && !(IsCapable(client_p, CAP_TS6))) |
56 |
{ |
57 |
exit_client(client_p, client_p, "CAPAB received twice"); |
58 |
return; |
59 |
} |
60 |
|
61 |
SetCapable(client_p, CAP_CAP); |
62 |
|
63 |
for (i = 1; i < parc; ++i) |
64 |
{ |
65 |
for (s = strtoken(&p, parv[i], " "); s; |
66 |
s = strtoken(&p, NULL, " ")) |
67 |
{ |
68 |
#ifdef HAVE_LIBCRYPTO |
69 |
if (!strncmp(s, "ENC:", 4)) |
70 |
{ |
71 |
/* Skip the "ENC:" portion */ |
72 |
s += 4; |
73 |
|
74 |
/* Check the remaining portion against the list of ciphers we |
75 |
* have available (CipherTable). |
76 |
*/ |
77 |
for (ecap = CipherTable; ecap->name; ++ecap) |
78 |
{ |
79 |
if (!irccmp(ecap->name, s) && (ecap->cap & CAP_ENC_MASK)) |
80 |
{ |
81 |
cipher = ecap->cap; |
82 |
break; |
83 |
} |
84 |
} |
85 |
|
86 |
/* Since the name and capabilities matched, use it. */ |
87 |
if (cipher != 0) |
88 |
{ |
89 |
SetCapable(client_p, CAP_ENC); |
90 |
client_p->localClient->enc_caps |= cipher; |
91 |
} |
92 |
else |
93 |
{ |
94 |
/* cipher is still zero; we didn't find a matching entry. */ |
95 |
exit_client(client_p, client_p, |
96 |
"Cipher selected is not available here."); |
97 |
return; |
98 |
} |
99 |
} |
100 |
else /* normal capab */ |
101 |
#endif |
102 |
if ((cap = find_capability(s)) != 0) |
103 |
SetCapable(client_p, cap); |
104 |
} |
105 |
} |
106 |
} |
107 |
|
108 |
static struct Message capab_msgtab = { |
109 |
"CAPAB", 0, 0, 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0, |
110 |
{ mr_capab, m_ignore, m_ignore, m_ignore, m_ignore, m_ignore } |
111 |
}; |
112 |
|
113 |
static void |
114 |
module_init(void) |
115 |
{ |
116 |
mod_add_cmd(&capab_msgtab); |
117 |
} |
118 |
|
119 |
static void |
120 |
module_exit(void) |
121 |
{ |
122 |
mod_del_cmd(&capab_msgtab); |
123 |
} |
124 |
|
125 |
struct module module_entry = { |
126 |
.node = { NULL, NULL, NULL }, |
127 |
.name = NULL, |
128 |
.version = "$Revision$", |
129 |
.handle = NULL, |
130 |
.modinit = module_init, |
131 |
.modexit = module_exit, |
132 |
.flags = 0 |
133 |
}; |