1 /* $Id: ip_cloaking_old.c 3522 2007-07-06 07:48:28Z nenolod $ */
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
['h'] = 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: 3522 $");
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(const char *inbuf
, char *outbuf
, int ipmask
)
72 unsigned int hosthash
= 1, hosthash2
= 1;
73 unsigned int maxcycle
= strlen(inbuf
);
75 const char *rest
, *next
;
77 for (cyc
= 0; cyc
< maxcycle
- 2; cyc
+= 2)
78 hosthash
*= (unsigned int) inbuf
[cyc
];
80 /* safety: decrement ourselves two steps back */
81 for (cyc
= maxcycle
- 1; cyc
>= 1; cyc
-= 2)
82 hosthash2
*= (unsigned int) inbuf
[cyc
];
84 /* lets do some bitshifting -- this pretty much destroys the IP
85 * sequence, while still providing a checksum. exactly what
86 * we're shooting for. --nenolod
88 hosthash
+= (hosthash2
/ KEY
);
89 hosthash2
+= (hosthash
/ KEY
);
93 rb_snprintf(outbuf
, HOSTLEN
, "%s-%X%X",
94 ServerInfo
.network_name
, hosthash2
, hosthash
);
95 len1
= strlen(outbuf
);
96 rest
= strchr(inbuf
, '.');
99 /* try to avoid truncation -- jilles */
100 while (len1
+ strlen(rest
) >= HOSTLEN
&& (next
= strchr(rest
+ 1, '.')) != NULL
)
102 rb_strlcat(outbuf
, rest
, HOSTLEN
);
105 rb_snprintf(outbuf
, HOSTLEN
, "%X%X.%s",
106 hosthash2
, hosthash
, ServerInfo
.network_name
);
110 check_umode_change(void *vdata
)
112 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
113 struct Client
*source_p
= data
->client
;
115 if (!MyClient(source_p
))
118 /* didn't change +h umode, we don't need to do anything */
119 if (!((data
->oldumodes
^ source_p
->umodes
) & user_modes
['h']))
122 if (source_p
->umodes
& user_modes
['h'])
124 if (IsIPSpoof(source_p
) || source_p
->localClient
->mangledhost
== NULL
|| (IsDynSpoof(source_p
) && strcmp(source_p
->host
, source_p
->localClient
->mangledhost
)))
126 source_p
->umodes
&= ~user_modes
['h'];
129 if (strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
131 rb_strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, HOSTLEN
);
132 distribute_hostchange(source_p
);
134 else /* not really nice, but we need to send this numeric here */
135 sendto_one_numeric(source_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
138 else if (!(source_p
->umodes
& user_modes
['h']))
140 if (source_p
->localClient
->mangledhost
!= NULL
&&
141 !strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
143 rb_strlcpy(source_p
->host
, source_p
->orighost
, HOSTLEN
);
144 distribute_hostchange(source_p
);
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
);