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_p
, char *newhost
)
49 if (newhost
!= client_p
->orighost
)
50 sendto_one_numeric(client_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
53 sendto_one_numeric(client_p
, 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_p
), newhost
);
59 sendto_server(NULL
, NULL
,
60 CAP_TS6
, CAP_EUID
, ":%s ENCAP * CHGHOST %s :%s",
61 use_id(&me
), use_id(client_p
), newhost
);
63 change_nick_user_host(client_p
, client_p
->name
, client_p
->username
, newhost
, 0, "Changing host");
65 if (newhost
!= client_p
->orighost
)
66 SetDynSpoof(client_p
);
68 ClearDynSpoof(client_p
);
72 do_host_cloak(const char *inbuf
, char *outbuf
, int ipmask
)
75 unsigned int hosthash
= 1, hosthash2
= 1;
76 unsigned int maxcycle
= strlen(inbuf
);
78 const char *rest
, *next
;
80 for (cyc
= 0; cyc
< maxcycle
- 2; cyc
+= 2)
81 hosthash
*= (unsigned int) inbuf
[cyc
];
83 /* safety: decrement ourselves two steps back */
84 for (cyc
= maxcycle
- 1; cyc
>= 1; cyc
-= 2)
85 hosthash2
*= (unsigned int) inbuf
[cyc
];
87 /* lets do some bitshifting -- this pretty much destroys the IP
88 * sequence, while still providing a checksum. exactly what
89 * we're shooting for. --nenolod
91 hosthash
+= (hosthash2
/ KEY
);
92 hosthash2
+= (hosthash
/ KEY
);
96 rb_snprintf(outbuf
, HOSTLEN
, "%s-%X%X",
97 ServerInfo
.network_name
, hosthash2
, hosthash
);
98 len1
= strlen(outbuf
);
99 rest
= strchr(inbuf
, '.');
102 /* try to avoid truncation -- jilles */
103 while (len1
+ strlen(rest
) >= HOSTLEN
&& (next
= strchr(rest
+ 1, '.')) != NULL
)
105 rb_strlcat(outbuf
, rest
, HOSTLEN
);
108 rb_snprintf(outbuf
, HOSTLEN
, "%X%X.%s",
109 hosthash2
, hosthash
, ServerInfo
.network_name
);
113 check_umode_change(void *vdata
)
115 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
116 struct Client
*source_p
= data
->client
;
118 if (!MyClient(source_p
))
121 /* didn't change +h umode, we don't need to do anything */
122 if (!((data
->oldumodes
^ source_p
->umodes
) & user_modes
['h']))
125 if (source_p
->umodes
& user_modes
['h'])
127 if (IsIPSpoof(source_p
) || source_p
->localClient
->mangledhost
== NULL
|| (IsDynSpoof(source_p
) && strcmp(source_p
->host
, source_p
->localClient
->mangledhost
)))
129 source_p
->umodes
&= ~user_modes
['h'];
132 if (strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
134 distribute_hostchange(source_p
, source_p
->localClient
->mangledhost
);
136 else /* not really nice, but we need to send this numeric here */
137 sendto_one_numeric(source_p
, RPL_HOSTHIDDEN
, "%s :is now your hidden host",
140 else if (!(source_p
->umodes
& user_modes
['h']))
142 if (source_p
->localClient
->mangledhost
!= NULL
&&
143 !strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
145 distribute_hostchange(source_p
, source_p
->orighost
);
151 check_new_user(void *vdata
)
153 struct Client
*source_p
= (void *)vdata
;
155 if (IsIPSpoof(source_p
))
157 source_p
->umodes
&= ~user_modes
['h'];
160 source_p
->localClient
->mangledhost
= rb_malloc(HOSTLEN
);
161 if (!irccmp(source_p
->orighost
, source_p
->sockhost
))
162 do_host_cloak(source_p
->orighost
, source_p
->localClient
->mangledhost
, 1);
164 do_host_cloak(source_p
->orighost
, source_p
->localClient
->mangledhost
, 0);
165 if (IsDynSpoof(source_p
))
166 source_p
->umodes
&= ~user_modes
['h'];
167 if (source_p
->umodes
& user_modes
['h'])
169 rb_strlcpy(source_p
->host
, source_p
->localClient
->mangledhost
, sizeof(source_p
->host
));
170 if (irccmp(source_p
->host
, source_p
->orighost
))
171 SetDynSpoof(source_p
);