1 /* $Id: ip_cloaking.c 3524 2007-07-06 07:54:54Z nenolod $ */
15 /* if you're modifying this module, you'll probably to change this */
16 #define KEY 0x13748cfa
21 /* add the usermode to the available slot */
22 user_modes
['h'] = find_umode_slot();
31 /* disable the umode and remove it from the available list */
36 static void check_umode_change(void *data
);
37 static void check_new_user(void *data
);
38 mapi_hfn_list_av1 ip_cloaking_hfnlist
[] = {
39 { "umode_changed", (hookfn
) check_umode_change
},
40 { "new_local_user", (hookfn
) check_new_user
},
44 DECLARE_MODULE_AV1(ip_cloaking
, _modinit
, _moddeinit
, NULL
, NULL
,
45 ip_cloaking_hfnlist
, "$Revision: 3524 $");
48 distribute_hostchange(struct Client
*client
)
50 if (irccmp(client
->host
, client
->orighost
))
51 sendto_one_numeric(client
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
54 sendto_one_numeric(client
, RPL_HOSTHIDDEN
, "%s :hostname reset",
57 sendto_server(NULL
, NULL
,
58 CAP_EUID
| CAP_TS6
, NOCAPS
, ":%s CHGHOST %s :%s",
59 use_id(&me
), use_id(client
), client
->host
);
60 sendto_server(NULL
, NULL
,
61 CAP_TS6
, CAP_EUID
, ":%s ENCAP * CHGHOST %s :%s",
62 use_id(&me
), use_id(client
), client
->host
);
63 sendto_server(NULL
, NULL
,
64 NOCAPS
, CAP_TS6
, ":%s ENCAP * CHGHOST %s :%s",
65 me
.name
, client
->name
, client
->host
);
66 if (irccmp(client
->host
, client
->orighost
))
69 ClearDynSpoof(client
);
72 #define Nval 0x8c3a48ac
74 #define INITDATA "98fwqefnoiqefv03f423t34gbv3vb89tg432t3b8" /* change this */
76 static inline unsigned int
77 get_string_entropy(const char *inbuf
)
79 unsigned int accum
= 1;
87 /* calls get_string_entropy() and toasts it against INITDATA */
88 static inline unsigned int
89 get_string_weighted_entropy(const char *inbuf
)
91 static int base_entropy
= 0;
92 unsigned int accum
= get_string_entropy(inbuf
);
94 /* initialize the algorithm if it is not yet ready */
95 if (base_entropy
== 0)
96 base_entropy
= get_string_entropy(INITDATA
);
98 return (Nval
* accum
) ^ base_entropy
;
102 do_host_cloak_ip(const char *inbuf
, char *outbuf
)
105 unsigned int accum
= get_string_weighted_entropy(inbuf
);
108 strncpy(buf
, inbuf
, HOSTLEN
);
109 tptr
= strrchr(buf
, '.');
116 snprintf(outbuf
, HOSTLEN
, "%s.%x", buf
, accum
);
120 do_host_cloak_host(const char *inbuf
, char *outbuf
)
122 char b26_alphabet
[] = "abcdefghijklmnopqrstuvwxyz";
124 unsigned int accum
= get_string_weighted_entropy(inbuf
);
126 strncpy(outbuf
, inbuf
, HOSTLEN
);
128 /* pass 1: scramble first section of hostname using base26
129 * alphabet toasted against the weighted entropy 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];
144 /* pass 2: scramble each number in the address */
145 for (tptr
= outbuf
; *tptr
!= '\0'; tptr
++)
149 *tptr
= 48 + ((*tptr
* accum
) % 10);
155 check_umode_change(void *vdata
)
157 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
158 struct Client
*source_p
= data
->client
;
160 if (!MyClient(source_p
))
163 /* didn't change +h umode, we don't need to do anything */
164 if (!((data
->oldumodes
^ source_p
->umodes
) & user_modes
['h']))
167 if (source_p
->umodes
& user_modes
['h'])
169 if (IsIPSpoof(source_p
) || source_p
->localClient
->mangledhost
== NULL
|| (IsDynSpoof(source_p
) && strcmp(source_p
->host
, source_p
->localClient
->mangledhost
)))
171 source_p
->umodes
&= ~user_modes
['h'];
174 if (strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
176 strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, HOSTLEN
);
177 distribute_hostchange(source_p
);
179 else /* not really nice, but we need to send this numeric here */
180 sendto_one_numeric(source_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
183 else if (!(source_p
->umodes
& user_modes
['h']))
185 if (source_p
->localClient
->mangledhost
!= NULL
&&
186 !strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
188 strlcpy(source_p
->host
, source_p
->orighost
, HOSTLEN
);
189 distribute_hostchange(source_p
);
195 check_new_user(void *vdata
)
197 struct Client
*source_p
= (void *)vdata
;
199 if (IsIPSpoof(source_p
))
201 source_p
->umodes
&= ~user_modes
['h'];
204 source_p
->localClient
->mangledhost
= MyMalloc(HOSTLEN
);
205 if (!irccmp(source_p
->orighost
, source_p
->sockhost
))
206 do_host_cloak_ip(source_p
->orighost
, source_p
->localClient
->mangledhost
);
208 do_host_cloak_host(source_p
->orighost
, source_p
->localClient
->mangledhost
);
209 if (IsDynSpoof(source_p
))
210 source_p
->umodes
&= ~user_modes
['h'];
211 if (source_p
->umodes
& user_modes
['h'])
213 strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, sizeof(source_p
->host
));
214 if (irccmp(source_p
->host
, source_p
->orighost
))
215 SetDynSpoof(source_p
);