]> jfr.im git - solanum.git/blame - extensions/m_webirc.c
Stop using chm_nosuch as a sentinel value (#53)
[solanum.git] / extensions / m_webirc.c
CommitLineData
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
eeabf33a
EM
56static const char webirc_desc[] = "Adds support for the WebIRC system";
57
3c7d6fcc 58static void mr_webirc(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
212380e3
AC
59
60struct Message webirc_msgtab = {
7baa37a9 61 "WEBIRC", 0, 0, 0, 0,
4636e5cb 62 {{mr_webirc, 5}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg}
212380e3
AC
63};
64
65mapi_clist_av1 webirc_clist[] = { &webirc_msgtab, NULL };
02369fa7 66
8ffc5173
EK
67static void new_local_user(void *data);
68mapi_hfn_list_av1 webirc_hfnlist[] = {
c500b0bd
EK
69 /* unintuitive but correct--we want to be called first */
70 { "new_local_user", (hookfn) new_local_user, HOOK_LOWEST },
8ffc5173
EK
71 { NULL, NULL }
72};
73
74DECLARE_MODULE_AV2(webirc, NULL, NULL, webirc_clist, NULL, webirc_hfnlist, NULL, NULL, webirc_desc);
212380e3
AC
75
76/*
06c3a319 77 * mr_webirc - webirc message handler
861a5445
EK
78 * parv[1] = password
79 * parv[2] = fake username (we ignore this)
55abcbb2 80 * parv[3] = fake hostname
212380e3
AC
81 * parv[4] = fake ip
82 */
3c7d6fcc 83static void
760bafda 84mr_webirc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
85{
86 struct ConfItem *aconf;
87 const char *encr;
0391874c 88 struct rb_sockaddr_storage addr;
212380e3 89
d6c81378
EK
90 int secure = 0;
91
861a5445
EK
92 if (source_p->flags & FLAGS_SENTUSER || !EmptyString(source_p->name))
93 {
94 exit_client(client_p, source_p, &me, "WEBIRC may not follow NICK/USER");
95 }
96
55abcbb2 97 aconf = find_address_conf(client_p->host, client_p->sockhost,
bdbe991f 98 IsGotId(client_p) ? client_p->username : "webirc",
212380e3
AC
99 IsGotId(client_p) ? client_p->username : "webirc",
100 (struct sockaddr *) &client_p->localClient->ip,
c0949eb0 101 GET_SS_FAMILY(&client_p->localClient->ip), NULL);
861a5445 102
212380e3 103 if (aconf == NULL || !(aconf->status & CONF_CLIENT))
3c7d6fcc 104 return;
861a5445 105
27f616dd 106 if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->info.name, "webirc."))
212380e3
AC
107 {
108 /* XXX */
109 sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block");
3c7d6fcc 110 return;
212380e3
AC
111 }
112 if (EmptyString(aconf->passwd))
113 {
114 sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password");
3c7d6fcc 115 return;
212380e3 116 }
bbdc439a 117 if (!IsSecure(source_p) && aconf->flags & CONF_FLAGS_NEED_SSL)
ab4420cb 118 {
cccda2ff 119 sendto_one(source_p, "NOTICE * :Your CGI:IRC block requires TLS");
ab4420cb
EK
120 return;
121 }
212380e3
AC
122
123 if (EmptyString(parv[1]))
124 encr = "";
125 else if (IsConfEncrypted(aconf))
f85a5a3f 126 encr = rb_crypt(parv[1], aconf->passwd);
212380e3
AC
127 else
128 encr = parv[1];
129
e69375f3 130 if (encr == NULL || strcmp(encr, aconf->passwd))
212380e3
AC
131 {
132 sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect");
3c7d6fcc 133 return;
212380e3
AC
134 }
135
17809d2d 136 if (rb_inet_pton_sock(parv[4], &addr) <= 0)
0391874c
JT
137 {
138 sendto_one(source_p, "NOTICE * :Invalid IP");
3c7d6fcc 139 return;
0391874c 140 }
bdbe991f 141
2355be38 142 source_p->localClient->ip = addr;
861a5445
EK
143 source_p->username[0] = '\0';
144 ClearGotId(source_p);
2355be38 145
d6c81378
EK
146 if (parc >= 6)
147 {
a6b97b7d
EK
148 const char *s;
149 for (s = parv[5]; s != NULL; (s = strchr(s, ' ')) && s++)
d6c81378 150 {
a6b97b7d 151 if (!ircncmp(s, "secure", 6) && (s[6] == '=' || s[6] == ' ' || s[6] == '\0'))
d6c81378
EK
152 secure = 1;
153 }
154 }
155
bbdc439a 156 if (secure && !IsSecure(source_p))
d6c81378
EK
157 {
158 sendto_one(source_p, "NOTICE * :CGI:IRC is not connected securely; marking you as insecure");
11ef0e2b 159 secure = 0;
d6c81378
EK
160 }
161
162 if (!secure)
163 {
bbdc439a 164 ClearSecure(source_p);
d6c81378
EK
165 }
166
2355be38
SA
167 rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, source_p->sockhost, sizeof(source_p->sockhost));
168
212380e3 169 if(strlen(parv[3]) <= HOSTLEN)
f427c8b0 170 rb_strlcpy(source_p->host, parv[3], sizeof(source_p->host));
212380e3 171 else
f427c8b0 172 rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
0391874c 173
170703fe 174 /* Check dlines now, klines will be checked on registration */
55abcbb2 175 if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip,
c0949eb0 176 GET_SS_FAMILY(&source_p->localClient->ip))))
212380e3
AC
177 {
178 if(!(aconf->status & CONF_EXEMPTDLINE))
179 {
180 exit_client(client_p, source_p, &me, "D-lined");
3c7d6fcc 181 return;
212380e3
AC
182 }
183 }
184
185 sendto_one(source_p, "NOTICE * :CGI:IRC host/IP set to %s %s", parv[3], parv[4]);
212380e3 186}
8ffc5173
EK
187
188static void
189new_local_user(void *data)
190{
191 struct Client *source_p = data;
192 struct ConfItem *aconf = source_p->localClient->att_conf;
193
194 if (!irccmp(aconf->info.name, "webirc."))
195 exit_client(source_p, source_p, &me, "Cannot log in using a WEBIRC block");
196}