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
, NULL
);
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
);
71 do_host_cloak(const char *inbuf
, char *outbuf
, int ipmask
)
74 unsigned int hosthash
= 1, hosthash2
= 1;
75 unsigned int maxcycle
= strlen(inbuf
);
77 const char *rest
, *next
;
79 for (cyc
= 0; cyc
< maxcycle
- 2; cyc
+= 2)
80 hosthash
*= (unsigned int) inbuf
[cyc
];
82 /* safety: decrement ourselves two steps back */
83 for (cyc
= maxcycle
- 1; cyc
>= 1; cyc
-= 2)
84 hosthash2
*= (unsigned int) inbuf
[cyc
];
86 /* lets do some bitshifting -- this pretty much destroys the IP
87 * sequence, while still providing a checksum. exactly what
88 * we're shooting for. --nenolod
90 hosthash
+= (hosthash2
/ KEY
);
91 hosthash2
+= (hosthash
/ KEY
);
95 snprintf(outbuf
, HOSTLEN
, "%s-%X%X",
96 ServerInfo
.network_name
, hosthash2
, hosthash
);
97 len1
= strlen(outbuf
);
98 rest
= strchr(inbuf
, '.');
101 /* try to avoid truncation -- jilles */
102 while (len1
+ strlen(rest
) >= HOSTLEN
&& (next
= strchr(rest
+ 1, '.')) != NULL
)
104 rb_strlcat(outbuf
, rest
, HOSTLEN
);
107 snprintf(outbuf
, HOSTLEN
, "%X%X.%s",
108 hosthash2
, hosthash
, ServerInfo
.network_name
);
112 check_umode_change(void *vdata
)
114 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
115 struct Client
*source_p
= data
->client
;
117 if (!MyClient(source_p
))
120 /* didn't change +h umode, we don't need to do anything */
121 if (!((data
->oldumodes
^ source_p
->umodes
) & user_modes
['h']))
124 if (source_p
->umodes
& user_modes
['h'])
126 if (IsIPSpoof(source_p
) || source_p
->localClient
->mangledhost
== NULL
|| (IsDynSpoof(source_p
) && strcmp(source_p
->host
, source_p
->localClient
->mangledhost
)))
128 source_p
->umodes
&= ~user_modes
['h'];
131 if (strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
133 distribute_hostchange(source_p
, source_p
->localClient
->mangledhost
);
135 else /* not really nice, but we need to send this numeric here */
136 sendto_one_numeric(source_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
139 else if (!(source_p
->umodes
& user_modes
['h']))
141 if (source_p
->localClient
->mangledhost
!= NULL
&&
142 !strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
144 distribute_hostchange(source_p
, source_p
->orighost
);
150 check_new_user(void *vdata
)
152 struct Client
*source_p
= (void *)vdata
;
154 if (IsIPSpoof(source_p
))
156 source_p
->umodes
&= ~user_modes
['h'];
159 source_p
->localClient
->mangledhost
= rb_malloc(HOSTLEN
);
160 if (!irccmp(source_p
->orighost
, source_p
->sockhost
))
161 do_host_cloak(source_p
->orighost
, source_p
->localClient
->mangledhost
, 1);
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'])
168 rb_strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, sizeof(source_p
->host
));
169 if (irccmp(source_p
->host
, source_p
->orighost
))
170 SetDynSpoof(source_p
);