1 /* $Id: ip_cloaking_old.c 3522 2007-07-06 07:48:28Z 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: 3522 $");
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
);
73 do_host_cloak(const char *inbuf
, char *outbuf
, int ipmask
)
76 unsigned int hosthash
= 1, hosthash2
= 1;
77 unsigned int maxcycle
= strlen(inbuf
);
79 const char *rest
, *next
;
81 for (cyc
= 0; cyc
< maxcycle
- 2; cyc
+= 2)
82 hosthash
*= (unsigned int) inbuf
[cyc
];
84 /* safety: decrement ourselves two steps back */
85 for (cyc
= maxcycle
- 1; cyc
>= 1; cyc
-= 2)
86 hosthash2
*= (unsigned int) inbuf
[cyc
];
88 /* lets do some bitshifting -- this pretty much destroys the IP
89 * sequence, while still providing a checksum. exactly what
90 * we're shooting for. --nenolod
92 hosthash
+= (hosthash2
/ KEY
);
93 hosthash2
+= (hosthash
/ KEY
);
97 ircsnprintf(outbuf
, HOSTLEN
, "%s-%X%X",
98 ServerInfo
.network_name
, hosthash2
, hosthash
);
99 len1
= strlen(outbuf
);
100 rest
= strchr(inbuf
, '.');
103 /* try to avoid truncation -- jilles */
104 while (len1
+ strlen(rest
) >= HOSTLEN
&& (next
= strchr(rest
+ 1, '.')) != NULL
)
106 strlcat(outbuf
, rest
, HOSTLEN
);
109 ircsnprintf(outbuf
, HOSTLEN
, "%X%X.%s",
110 hosthash2
, hosthash
, ServerInfo
.network_name
);
114 check_umode_change(void *vdata
)
116 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
117 struct Client
*source_p
= data
->client
;
119 if (!MyClient(source_p
))
122 /* didn't change +h umode, we don't need to do anything */
123 if (!((data
->oldumodes
^ source_p
->umodes
) & user_modes
['h']))
126 if (source_p
->umodes
& user_modes
['h'])
128 if (IsIPSpoof(source_p
) || source_p
->localClient
->mangledhost
== NULL
|| (IsDynSpoof(source_p
) && strcmp(source_p
->host
, source_p
->localClient
->mangledhost
)))
130 source_p
->umodes
&= ~user_modes
['h'];
133 if (strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
135 strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, HOSTLEN
);
136 distribute_hostchange(source_p
);
138 else /* not really nice, but we need to send this numeric here */
139 sendto_one_numeric(source_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
142 else if (!(source_p
->umodes
& user_modes
['h']))
144 if (source_p
->localClient
->mangledhost
!= NULL
&&
145 !strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
147 strlcpy(source_p
->host
, source_p
->orighost
, HOSTLEN
);
148 distribute_hostchange(source_p
);
154 check_new_user(void *vdata
)
156 struct Client
*source_p
= (void *)vdata
;
158 if (IsIPSpoof(source_p
))
160 source_p
->umodes
&= ~user_modes
['h'];
163 source_p
->localClient
->mangledhost
= MyMalloc(HOSTLEN
);
164 if (!irccmp(source_p
->orighost
, source_p
->sockhost
))
165 do_host_cloak(source_p
->orighost
, source_p
->localClient
->mangledhost
, 1);
167 do_host_cloak(source_p
->orighost
, source_p
->localClient
->mangledhost
, 0);
168 if (IsDynSpoof(source_p
))
169 source_p
->umodes
&= ~user_modes
['h'];
170 if (source_p
->umodes
& user_modes
['h'])
172 strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, sizeof(source_p
->host
));
173 if (irccmp(source_p
->host
, source_p
->orighost
))
174 SetDynSpoof(source_p
);