]>
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 | |
23 | * | |
477bbce4 | 24 | * $Id: m_webirc.c 3458 2007-05-18 19:51:22Z jilles $ |
212380e3 AC |
25 | */ |
26 | /* Usage: | |
27 | * auth { | |
28 | * user = "webirc@<cgiirc ip>"; # if identd used, put ident username instead | |
29 | * password = "<password>"; # encryption possible | |
30 | * spoof = "webirc." | |
31 | * class = "users"; | |
32 | * }; | |
33 | * Possible flags: | |
34 | * encrypted - password is encrypted (recommended) | |
35 | * kline_exempt - k/g lines on the cgiirc ip are ignored | |
36 | * gline_exempt - glines on the cgiirc ip are ignored | |
37 | * dlines are checked on the cgiirc ip (of course). | |
38 | * k/d/g/x lines, auth blocks, user limits, etc are checked using the | |
39 | * real host/ip. | |
40 | * The password should be specified unencrypted in webirc_password in | |
41 | * cgiirc.config | |
42 | */ | |
43 | ||
44 | #include "stdinc.h" | |
45 | #include "client.h" /* client struct */ | |
46 | #include "irc_string.h" | |
47 | #include "hostmask.h" | |
48 | #include "send.h" /* sendto_one */ | |
49 | #include "numeric.h" /* ERR_xxx */ | |
50 | #include "ircd.h" /* me */ | |
51 | #include "msg.h" | |
52 | #include "parse.h" | |
53 | #include "modules.h" | |
54 | #include "s_serv.h" | |
55 | #include "hash.h" | |
56 | #include "s_conf.h" | |
477bbce4 | 57 | #include "reject.h" |
212380e3 AC |
58 | |
59 | static int mr_webirc(struct Client *, struct Client *, int, const char **); | |
60 | ||
61 | struct Message webirc_msgtab = { | |
62 | "WEBIRC", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, | |
4636e5cb | 63 | {{mr_webirc, 5}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} |
212380e3 AC |
64 | }; |
65 | ||
66 | mapi_clist_av1 webirc_clist[] = { &webirc_msgtab, NULL }; | |
67 | DECLARE_MODULE_AV1(webirc, NULL, NULL, webirc_clist, NULL, NULL, "$Revision: 20702 $"); | |
68 | ||
69 | /* | |
70 | * mr_webirc - webirc message handler | |
71 | * parv[0] = sender prefix | |
72 | * parv[1] = password | |
73 | * parv[2] = fake username (we ignore this) | |
74 | * parv[3] = fake hostname | |
75 | * parv[4] = fake ip | |
76 | */ | |
77 | static int | |
78 | mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
79 | { | |
80 | struct ConfItem *aconf; | |
81 | const char *encr; | |
82 | ||
83 | if (!strchr(parv[4], '.') && !strchr(parv[4], ':')) | |
84 | { | |
85 | sendto_one(source_p, "NOTICE * :Invalid IP"); | |
86 | return 0; | |
87 | } | |
88 | ||
89 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
90 | IsGotId(client_p) ? client_p->username : "webirc", | |
91 | IsGotId(client_p) ? client_p->username : "webirc", | |
92 | (struct sockaddr *) &client_p->localClient->ip, | |
93 | client_p->localClient->ip.ss_family); | |
94 | if (aconf == NULL || !(aconf->status & CONF_CLIENT)) | |
95 | return 0; | |
96 | if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->name, "webirc.")) | |
97 | { | |
98 | /* XXX */ | |
99 | sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block"); | |
100 | return 0; | |
101 | } | |
102 | if (EmptyString(aconf->passwd)) | |
103 | { | |
104 | sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password"); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | if (EmptyString(parv[1])) | |
109 | encr = ""; | |
110 | else if (IsConfEncrypted(aconf)) | |
111 | encr = crypt(parv[1], aconf->passwd); | |
112 | else | |
113 | encr = parv[1]; | |
114 | ||
115 | if (strcmp(encr, aconf->passwd)) | |
116 | { | |
117 | sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect"); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | ||
122 | strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost)); | |
123 | ||
124 | if(strlen(parv[3]) <= HOSTLEN) | |
125 | strlcpy(source_p->host, parv[3], sizeof(source_p->host)); | |
126 | else | |
127 | strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); | |
128 | ||
477bbce4 | 129 | del_unknown_ip(source_p); |
212380e3 AC |
130 | inetpton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip); |
131 | ||
132 | /* Check dlines now, k/glines will be checked on registration */ | |
133 | if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip, | |
134 | source_p->localClient->ip.ss_family))) | |
135 | { | |
136 | if(!(aconf->status & CONF_EXEMPTDLINE)) | |
137 | { | |
138 | exit_client(client_p, source_p, &me, "D-lined"); | |
139 | return 0; | |
140 | } | |
141 | } | |
142 | ||
143 | sendto_one(source_p, "NOTICE * :CGI:IRC host/IP set to %s %s", parv[3], parv[4]); | |
144 | return 0; | |
145 | } |