13 /* if you're modifying this module, you'll probably to change this */
14 #define KEY 0x13748cfa
19 /* add the usermode to the available slot */
20 user_modes
['h'] = find_umode_slot();
29 /* disable the umode and remove it from the available list */
34 static void check_umode_change(void *data
);
35 static void check_new_user(void *data
);
36 mapi_hfn_list_av1 ip_cloaking_hfnlist
[] = {
37 { "umode_changed", (hookfn
) check_umode_change
},
38 { "new_local_user", (hookfn
) check_new_user
},
42 DECLARE_MODULE_AV1(ip_cloaking
, _modinit
, _moddeinit
, NULL
, NULL
,
43 ip_cloaking_hfnlist
, "$Revision: 3526 $");
46 distribute_hostchange(struct Client
*client_p
, char *newhost
)
48 if (newhost
!= client_p
->orighost
)
49 sendto_one_numeric(client_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
52 sendto_one_numeric(client_p
, RPL_HOSTHIDDEN
, "%s :hostname reset",
55 sendto_server(NULL
, NULL
,
56 CAP_EUID
| CAP_TS6
, NOCAPS
, ":%s CHGHOST %s :%s",
57 use_id(&me
), use_id(client_p
), newhost
);
58 sendto_server(NULL
, NULL
,
59 CAP_TS6
, CAP_EUID
, ":%s ENCAP * CHGHOST %s :%s",
60 use_id(&me
), use_id(client_p
), newhost
);
62 change_nick_user_host(client_p
, client_p
->name
, client_p
->username
, newhost
, 0, "Changing host");
64 if (newhost
!= client_p
->orighost
)
65 SetDynSpoof(client_p
);
67 ClearDynSpoof(client_p
);
70 #define Nval 0x8c3a48ac
72 #define INITDATA "98fwqefnoiqefv03f423t34gbv3vb89tg432t3b8" /* change this */
74 static inline unsigned int
75 get_string_entropy(const char *inbuf
)
77 unsigned int accum
= 1;
85 /* calls get_string_entropy() and toasts it against INITDATA */
86 static inline unsigned int
87 get_string_weighted_entropy(const char *inbuf
)
89 static int base_entropy
= 0;
90 unsigned int accum
= get_string_entropy(inbuf
);
92 /* initialize the algorithm if it is not yet ready */
93 if (base_entropy
== 0)
94 base_entropy
= get_string_entropy(INITDATA
);
96 return (Nval
* accum
) ^ base_entropy
;
100 do_host_cloak_ip(const char *inbuf
, char *outbuf
)
103 unsigned int accum
= get_string_weighted_entropy(inbuf
);
107 strncpy(buf
, inbuf
, HOSTLEN
);
108 tptr
= strrchr(buf
, '.');
112 tptr
= strrchr(buf
, ':');
118 strncpy(outbuf
, inbuf
, HOSTLEN
);
126 snprintf(outbuf
, HOSTLEN
, "%s:%x", buf
, accum
);
130 snprintf(outbuf
, HOSTLEN
, "%s.%x", buf
, accum
);
135 do_host_cloak_host(const char *inbuf
, char *outbuf
)
137 char b26_alphabet
[] = "abcdefghijklmnopqrstuvwxyz";
139 unsigned int accum
= get_string_weighted_entropy(inbuf
);
141 strncpy(outbuf
, inbuf
, HOSTLEN
);
143 /* pass 1: scramble first section of hostname using base26
144 * alphabet toasted against the weighted entropy of the string.
146 * numbers are not changed at this time, only letters.
148 for (tptr
= outbuf
; *tptr
!= '\0'; tptr
++)
153 if (isdigit((unsigned char)*tptr
) || *tptr
== '-')
156 *tptr
= b26_alphabet
[(*tptr
* accum
) % 26];
159 /* pass 2: scramble each number in the address */
160 for (tptr
= outbuf
; *tptr
!= '\0'; tptr
++)
162 if (isdigit((unsigned char)*tptr
))
164 *tptr
= 48 + ((*tptr
* accum
) % 10);
170 check_umode_change(void *vdata
)
172 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
173 struct Client
*source_p
= data
->client
;
175 if (!MyClient(source_p
))
178 /* didn't change +h umode, we don't need to do anything */
179 if (!((data
->oldumodes
^ source_p
->umodes
) & user_modes
['h']))
182 if (source_p
->umodes
& user_modes
['h'])
184 if (IsIPSpoof(source_p
) || source_p
->localClient
->mangledhost
== NULL
|| (IsDynSpoof(source_p
) && strcmp(source_p
->host
, source_p
->localClient
->mangledhost
)))
186 source_p
->umodes
&= ~user_modes
['h'];
189 if (strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
191 distribute_hostchange(source_p
, source_p
->localClient
->mangledhost
);
193 else /* not really nice, but we need to send this numeric here */
194 sendto_one_numeric(source_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
197 else if (!(source_p
->umodes
& user_modes
['h']))
199 if (source_p
->localClient
->mangledhost
!= NULL
&&
200 !strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
202 distribute_hostchange(source_p
, source_p
->orighost
);
208 check_new_user(void *vdata
)
210 struct Client
*source_p
= (void *)vdata
;
212 if (IsIPSpoof(source_p
))
214 source_p
->umodes
&= ~user_modes
['h'];
217 source_p
->localClient
->mangledhost
= rb_malloc(HOSTLEN
);
218 if (!irccmp(source_p
->orighost
, source_p
->sockhost
))
219 do_host_cloak_ip(source_p
->orighost
, source_p
->localClient
->mangledhost
);
221 do_host_cloak_host(source_p
->orighost
, source_p
->localClient
->mangledhost
);
222 if (IsDynSpoof(source_p
))
223 source_p
->umodes
&= ~user_modes
['h'];
224 if (source_p
->umodes
& user_modes
['h'])
226 rb_strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, sizeof(source_p
->host
));
227 if (irccmp(source_p
->host
, source_p
->orighost
))
228 SetDynSpoof(source_p
);