14 /* if you're modifying this module, you'll probably to change this */
15 #define KEY 0x13748cfa
20 /* add the usermode to the available slot */
21 user_modes
['x'] = find_umode_slot();
30 /* disable the umode and remove it from the available list */
35 static void check_umode_change(void *data
);
36 static void check_new_user(void *data
);
37 mapi_hfn_list_av1 ip_cloaking_hfnlist
[] = {
38 { "umode_changed", (hookfn
) check_umode_change
},
39 { "new_local_user", (hookfn
) check_new_user
},
43 DECLARE_MODULE_AV1(ip_cloaking
, _modinit
, _moddeinit
, NULL
, NULL
,
44 ip_cloaking_hfnlist
, "$Revision: 3526 $");
47 distribute_hostchange(struct Client
*client
)
49 if (irccmp(client
->host
, client
->orighost
))
50 sendto_one_numeric(client
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
53 sendto_one_numeric(client
, RPL_HOSTHIDDEN
, "%s :hostname reset",
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
);
62 if (irccmp(client
->host
, client
->orighost
))
65 ClearDynSpoof(client
);
69 do_host_cloak_ip(const char *inbuf
, char *outbuf
)
71 /* None of the characters in this table can be valid in an IP */
72 char chartable
[] = "ghijklmnopqrstuvwxyz";
74 uint32_t accum
= fnv_hash((const unsigned char*) inbuf
, 32);
79 rb_strlcpy(outbuf
, inbuf
, HOSTLEN
+ 1);
81 if (strchr(outbuf
, ':'))
86 * We count the number of colons so we can calculate how much
87 * of the host to cloak. This is because some hostmasks may not
88 * have as many octets as we'd like.
90 * We have to do this ahead of time because doing this during
91 * the actual cloaking would get ugly
93 for (tptr
= outbuf
; *tptr
!= '\0'; tptr
++)
97 else if (!strchr(outbuf
, '.'))
100 for (tptr
= outbuf
; *tptr
!= '\0'; tptr
++)
102 if (*tptr
== ':' || *tptr
== '.')
108 if (ipv6
&& sepcount
< totalcount
/ 2)
111 if (!ipv6
&& sepcount
< 2)
114 *tptr
= chartable
[(*tptr
+ accum
) % 20];
115 accum
= (accum
<< 1) | (accum
>> 31);
120 do_host_cloak_host(const char *inbuf
, char *outbuf
)
122 char b26_alphabet
[] = "abcdefghijklmnopqrstuvwxyz";
124 uint32_t accum
= fnv_hash((const unsigned char*) inbuf
, 32);
126 rb_strlcpy(outbuf
, inbuf
, HOSTLEN
+ 1);
128 /* pass 1: scramble first section of hostname using base26
129 * alphabet toasted against the FNV hash of the string.
131 * numbers are not changed at this time, only letters.
133 for (tptr
= outbuf
; *tptr
!= '\0'; tptr
++)
138 if (isdigit(*tptr
) || *tptr
== '-')
141 *tptr
= b26_alphabet
[(*tptr
+ accum
) % 26];
143 /* Rotate one bit to avoid all digits being turned odd or even */
144 accum
= (accum
<< 1) | (accum
>> 31);
147 /* pass 2: scramble each number in the address */
148 for (tptr
= outbuf
; *tptr
!= '\0'; tptr
++)
151 *tptr
= '0' + (*tptr
+ accum
) % 10;
153 accum
= (accum
<< 1) | (accum
>> 31);
158 check_umode_change(void *vdata
)
160 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
161 struct Client
*source_p
= data
->client
;
163 if (!MyClient(source_p
))
166 /* didn't change +h umode, we don't need to do anything */
167 if (!((data
->oldumodes
^ source_p
->umodes
) & user_modes
['x']))
170 if (source_p
->umodes
& user_modes
['x'])
172 if (IsIPSpoof(source_p
) || source_p
->localClient
->mangledhost
== NULL
|| (IsDynSpoof(source_p
) && strcmp(source_p
->host
, source_p
->localClient
->mangledhost
)))
174 source_p
->umodes
&= ~user_modes
['x'];
177 if (strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
179 rb_strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, HOSTLEN
+ 1);
180 distribute_hostchange(source_p
);
182 else /* not really nice, but we need to send this numeric here */
183 sendto_one_numeric(source_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
186 else if (!(source_p
->umodes
& user_modes
['x']))
188 if (source_p
->localClient
->mangledhost
!= NULL
&&
189 !strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
191 rb_strlcpy(source_p
->host
, source_p
->orighost
, HOSTLEN
+ 1);
192 distribute_hostchange(source_p
);
198 check_new_user(void *vdata
)
200 struct Client
*source_p
= (void *)vdata
;
202 if (IsIPSpoof(source_p
))
204 source_p
->umodes
&= ~user_modes
['x'];
207 source_p
->localClient
->mangledhost
= rb_malloc(HOSTLEN
+ 1);
208 if (!irccmp(source_p
->orighost
, source_p
->sockhost
))
209 do_host_cloak_ip(source_p
->orighost
, source_p
->localClient
->mangledhost
);
211 do_host_cloak_host(source_p
->orighost
, source_p
->localClient
->mangledhost
);
212 if (IsDynSpoof(source_p
))
213 source_p
->umodes
&= ~user_modes
['x'];
214 if (source_p
->umodes
& user_modes
['x'])
216 rb_strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, sizeof(source_p
->host
));
217 if (irccmp(source_p
->host
, source_p
->orighost
))
218 SetDynSpoof(source_p
);