]> jfr.im git - irc/rqf/shadowircd.git/blame - extensions/ip_cloaking_old.c
report logfile access issues
[irc/rqf/shadowircd.git] / extensions / ip_cloaking_old.c
CommitLineData
762cc38c 1/* $Id: ip_cloaking_old.c 3522 2007-07-06 07:48:28Z nenolod $ */
2
3#include "stdinc.h"
4#include "modules.h"
5#include "hook.h"
6#include "client.h"
7#include "ircd.h"
8#include "send.h"
9#include "s_conf.h"
10#include "s_user.h"
11#include "s_serv.h"
762cc38c 12#include "numeric.h"
13
14/* if you're modifying this module, you'll probably to change this */
15#define KEY 0x13748cfa
16
17static int
18_modinit(void)
19{
20 /* add the usermode to the available slot */
21 user_modes['h'] = find_umode_slot();
22 construct_umodebuf();
23
24 return 0;
25}
26
27static void
28_moddeinit(void)
29{
30 /* disable the umode and remove it from the available list */
31 user_modes['h'] = 0;
32 construct_umodebuf();
33}
34
35static void check_umode_change(void *data);
36static void check_new_user(void *data);
37mapi_hfn_list_av1 ip_cloaking_hfnlist[] = {
38 { "umode_changed", (hookfn) check_umode_change },
39 { "new_local_user", (hookfn) check_new_user },
40 { NULL, NULL }
41};
42
43DECLARE_MODULE_AV1(ip_cloaking, _modinit, _moddeinit, NULL, NULL,
44 ip_cloaking_hfnlist, "$Revision: 3522 $");
45
46static void
47distribute_hostchange(struct Client *client)
48{
49 if (irccmp(client->host, client->orighost))
50 sendto_one_numeric(client, RPL_HOSTHIDDEN, "%s :is now your hidden host",
51 client->host);
52 else
53 sendto_one_numeric(client, RPL_HOSTHIDDEN, "%s :hostname reset",
54 client->host);
55
56 sendto_server(NULL, NULL,
57 CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s",
58 use_id(&me), use_id(client), client->host);
59 sendto_server(NULL, NULL,
60 CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s",
61 use_id(&me), use_id(client), client->host);
762cc38c 62 if (irccmp(client->host, client->orighost))
63 SetDynSpoof(client);
64 else
65 ClearDynSpoof(client);
66}
67
68static void
69do_host_cloak(const char *inbuf, char *outbuf, int ipmask)
70{
71 int cyc;
72 unsigned int hosthash = 1, hosthash2 = 1;
73 unsigned int maxcycle = strlen(inbuf);
74 int len1;
75 const char *rest, *next;
76
77 for (cyc = 0; cyc < maxcycle - 2; cyc += 2)
78 hosthash *= (unsigned int) inbuf[cyc];
79
80 /* safety: decrement ourselves two steps back */
81 for (cyc = maxcycle - 1; cyc >= 1; cyc -= 2)
82 hosthash2 *= (unsigned int) inbuf[cyc];
83
84 /* lets do some bitshifting -- this pretty much destroys the IP
85 * sequence, while still providing a checksum. exactly what
86 * we're shooting for. --nenolod
87 */
88 hosthash += (hosthash2 / KEY);
89 hosthash2 += (hosthash / KEY);
90
91 if (ipmask == 0)
92 {
71f6ebfa 93 rb_snprintf(outbuf, HOSTLEN, "%s-%X%X",
762cc38c 94 ServerInfo.network_name, hosthash2, hosthash);
95 len1 = strlen(outbuf);
96 rest = strchr(inbuf, '.');
97 if (rest == NULL)
98 rest = ".";
99 /* try to avoid truncation -- jilles */
100 while (len1 + strlen(rest) >= HOSTLEN && (next = strchr(rest + 1, '.')) != NULL)
101 rest = next;
a64c5173 102 rb_strlcat(outbuf, rest, HOSTLEN);
762cc38c 103 }
104 else
71f6ebfa 105 rb_snprintf(outbuf, HOSTLEN, "%X%X.%s",
762cc38c 106 hosthash2, hosthash, ServerInfo.network_name);
107}
108
109static void
110check_umode_change(void *vdata)
111{
112 hook_data_umode_changed *data = (hook_data_umode_changed *)vdata;
113 struct Client *source_p = data->client;
114
115 if (!MyClient(source_p))
116 return;
117
118 /* didn't change +h umode, we don't need to do anything */
119 if (!((data->oldumodes ^ source_p->umodes) & user_modes['h']))
120 return;
121
122 if (source_p->umodes & user_modes['h'])
123 {
124 if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost)))
125 {
126 source_p->umodes &= ~user_modes['h'];
127 return;
128 }
129 if (strcmp(source_p->host, source_p->localClient->mangledhost))
130 {
907468c4 131 rb_strlcpy(source_p->host, source_p->localClient->mangledhost, HOSTLEN);
762cc38c 132 distribute_hostchange(source_p);
133 }
134 else /* not really nice, but we need to send this numeric here */
135 sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host",
136 source_p->host);
137 }
138 else if (!(source_p->umodes & user_modes['h']))
139 {
140 if (source_p->localClient->mangledhost != NULL &&
141 !strcmp(source_p->host, source_p->localClient->mangledhost))
142 {
907468c4 143 rb_strlcpy(source_p->host, source_p->orighost, HOSTLEN);
762cc38c 144 distribute_hostchange(source_p);
145 }
146 }
147}
148
149static void
150check_new_user(void *vdata)
151{
152 struct Client *source_p = (void *)vdata;
153
154 if (IsIPSpoof(source_p))
155 {
156 source_p->umodes &= ~user_modes['h'];
157 return;
158 }
c51d32ba 159 source_p->localClient->mangledhost = rb_malloc(HOSTLEN);
762cc38c 160 if (!irccmp(source_p->orighost, source_p->sockhost))
161 do_host_cloak(source_p->orighost, source_p->localClient->mangledhost, 1);
162 else
163 do_host_cloak(source_p->orighost, source_p->localClient->mangledhost, 0);
164 if (IsDynSpoof(source_p))
165 source_p->umodes &= ~user_modes['h'];
166 if (source_p->umodes & user_modes['h'])
167 {
907468c4 168 rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host));
762cc38c 169 if (irccmp(source_p->host, source_p->orighost))
170 SetDynSpoof(source_p);
171 }
172}