]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_webirc.c: Makes CGI:IRC users appear as coming from their real host | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2006 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | /* Usage: | |
25 | * auth { | |
26 | * user = "webirc@<cgiirc ip>"; # if identd used, put ident username instead | |
27 | * password = "<password>"; # encryption possible | |
28 | * spoof = "webirc." | |
29 | * class = "users"; | |
30 | * }; | |
31 | * Possible flags: | |
32 | * encrypted - password is encrypted (recommended) | |
aae358c0 | 33 | * kline_exempt - klines on the cgiirc ip are ignored |
212380e3 | 34 | * dlines are checked on the cgiirc ip (of course). |
170703fe | 35 | * k/d/x lines, auth blocks, user limits, etc are checked using the |
212380e3 AC |
36 | * real host/ip. |
37 | * The password should be specified unencrypted in webirc_password in | |
38 | * cgiirc.config | |
39 | */ | |
40 | ||
41 | #include "stdinc.h" | |
42 | #include "client.h" /* client struct */ | |
4562c604 | 43 | #include "match.h" |
212380e3 AC |
44 | #include "hostmask.h" |
45 | #include "send.h" /* sendto_one */ | |
46 | #include "numeric.h" /* ERR_xxx */ | |
47 | #include "ircd.h" /* me */ | |
48 | #include "msg.h" | |
49 | #include "parse.h" | |
50 | #include "modules.h" | |
51 | #include "s_serv.h" | |
52 | #include "hash.h" | |
53 | #include "s_conf.h" | |
477bbce4 | 54 | #include "reject.h" |
212380e3 | 55 | |
760bafda | 56 | static int mr_webirc(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **); |
212380e3 AC |
57 | |
58 | struct Message webirc_msgtab = { | |
7baa37a9 | 59 | "WEBIRC", 0, 0, 0, 0, |
4636e5cb | 60 | {{mr_webirc, 5}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} |
212380e3 AC |
61 | }; |
62 | ||
63 | mapi_clist_av1 webirc_clist[] = { &webirc_msgtab, NULL }; | |
04f832b7 | 64 | DECLARE_MODULE_AV2(webirc, NULL, NULL, webirc_clist, NULL, NULL, NULL, NULL, NULL); |
212380e3 AC |
65 | |
66 | /* | |
06c3a319 | 67 | * mr_webirc - webirc message handler |
212380e3 AC |
68 | * parv[1] = password |
69 | * parv[2] = fake username (we ignore this) | |
55abcbb2 | 70 | * parv[3] = fake hostname |
212380e3 AC |
71 | * parv[4] = fake ip |
72 | */ | |
73 | static int | |
760bafda | 74 | mr_webirc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
75 | { |
76 | struct ConfItem *aconf; | |
77 | const char *encr; | |
0391874c | 78 | struct rb_sockaddr_storage addr; |
212380e3 | 79 | |
0391874c JT |
80 | if ((!strchr(parv[4], '.') && !strchr(parv[4], ':')) || |
81 | strlen(parv[4]) + (*parv[4] == ':') >= | |
82 | sizeof(source_p->sockhost)) | |
212380e3 AC |
83 | { |
84 | sendto_one(source_p, "NOTICE * :Invalid IP"); | |
85 | return 0; | |
86 | } | |
87 | ||
55abcbb2 | 88 | aconf = find_address_conf(client_p->host, client_p->sockhost, |
bdbe991f | 89 | IsGotId(client_p) ? client_p->username : "webirc", |
212380e3 AC |
90 | IsGotId(client_p) ? client_p->username : "webirc", |
91 | (struct sockaddr *) &client_p->localClient->ip, | |
40c1fd47 | 92 | client_p->localClient->ip.ss_family, NULL); |
212380e3 AC |
93 | if (aconf == NULL || !(aconf->status & CONF_CLIENT)) |
94 | return 0; | |
27f616dd | 95 | if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->info.name, "webirc.")) |
212380e3 AC |
96 | { |
97 | /* XXX */ | |
98 | sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block"); | |
99 | return 0; | |
100 | } | |
101 | if (EmptyString(aconf->passwd)) | |
102 | { | |
103 | sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password"); | |
104 | return 0; | |
105 | } | |
106 | ||
107 | if (EmptyString(parv[1])) | |
108 | encr = ""; | |
109 | else if (IsConfEncrypted(aconf)) | |
f85a5a3f | 110 | encr = rb_crypt(parv[1], aconf->passwd); |
212380e3 AC |
111 | else |
112 | encr = parv[1]; | |
113 | ||
e69375f3 | 114 | if (encr == NULL || strcmp(encr, aconf->passwd)) |
212380e3 AC |
115 | { |
116 | sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect"); | |
117 | return 0; | |
118 | } | |
119 | ||
0391874c JT |
120 | if (rb_inet_pton_sock(parv[4], (struct sockaddr *)&addr) <= 0) |
121 | { | |
122 | sendto_one(source_p, "NOTICE * :Invalid IP"); | |
123 | return 0; | |
124 | } | |
bdbe991f | 125 | |
0391874c JT |
126 | if (*parv[4] == ':') |
127 | { | |
128 | source_p->sockhost[0] = '0'; | |
129 | rb_strlcpy(source_p->sockhost + 1, parv[4], | |
130 | sizeof(source_p->sockhost) - 1); | |
131 | } | |
132 | else | |
133 | rb_strlcpy(source_p->sockhost, parv[4], | |
134 | sizeof(source_p->sockhost)); | |
bdbe991f | 135 | |
212380e3 | 136 | if(strlen(parv[3]) <= HOSTLEN) |
f427c8b0 | 137 | rb_strlcpy(source_p->host, parv[3], sizeof(source_p->host)); |
212380e3 | 138 | else |
f427c8b0 | 139 | rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); |
0391874c JT |
140 | |
141 | source_p->localClient->ip = addr; | |
212380e3 | 142 | |
170703fe | 143 | /* Check dlines now, klines will be checked on registration */ |
55abcbb2 | 144 | if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip, |
54ac8b60 | 145 | source_p->localClient->ip.ss_family))) |
212380e3 AC |
146 | { |
147 | if(!(aconf->status & CONF_EXEMPTDLINE)) | |
148 | { | |
149 | exit_client(client_p, source_p, &me, "D-lined"); | |
150 | return 0; | |
151 | } | |
152 | } | |
153 | ||
154 | sendto_one(source_p, "NOTICE * :CGI:IRC host/IP set to %s %s", parv[3], parv[4]); | |
155 | return 0; | |
156 | } |