]>
Commit | Line | Data |
---|---|---|
762cc38c AC |
1 | |
2 | #include "stdinc.h" | |
3 | #include "modules.h" | |
4 | #include "hook.h" | |
5 | #include "client.h" | |
6 | #include "ircd.h" | |
7 | #include "send.h" | |
8 | #include "s_conf.h" | |
9 | #include "s_user.h" | |
10 | #include "s_serv.h" | |
762cc38c AC |
11 | #include "numeric.h" |
12 | ||
dacd2aa8 | 13 | /* if you're modifying this module, you'll probably want to change this */ |
762cc38c AC |
14 | #define KEY 0x13748cfa |
15 | ||
16 | static int | |
17 | _modinit(void) | |
18 | { | |
19 | /* add the usermode to the available slot */ | |
20 | user_modes['h'] = find_umode_slot(); | |
21 | construct_umodebuf(); | |
22 | ||
23 | return 0; | |
24 | } | |
25 | ||
26 | static void | |
27 | _moddeinit(void) | |
28 | { | |
29 | /* disable the umode and remove it from the available list */ | |
30 | user_modes['h'] = 0; | |
31 | construct_umodebuf(); | |
32 | } | |
33 | ||
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 }, | |
39 | { NULL, NULL } | |
40 | }; | |
41 | ||
dacd2aa8 EM |
42 | static const char ip_cloaking_desc[] = "Very old IP cloaking mechanism"; |
43 | ||
44 | DECLARE_MODULE_AV2(ip_cloaking, _modinit, _moddeinit, NULL, NULL, | |
45 | ip_cloaking_hfnlist, NULL, NULL, ip_cloaking_desc); | |
762cc38c AC |
46 | |
47 | static void | |
29d224a1 | 48 | distribute_hostchange(struct Client *client_p, char *newhost) |
762cc38c | 49 | { |
29d224a1 KB |
50 | if (newhost != client_p->orighost) |
51 | sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", | |
9f409b63 | 52 | newhost); |
762cc38c | 53 | else |
29d224a1 | 54 | sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :hostname reset", |
9f409b63 | 55 | newhost); |
762cc38c AC |
56 | |
57 | sendto_server(NULL, NULL, | |
58 | CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s", | |
9f409b63 | 59 | use_id(&me), use_id(client_p), newhost); |
762cc38c AC |
60 | sendto_server(NULL, NULL, |
61 | CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", | |
9f409b63 | 62 | use_id(&me), use_id(client_p), newhost); |
29d224a1 KB |
63 | |
64 | change_nick_user_host(client_p, client_p->name, client_p->username, newhost, 0, "Changing host"); | |
65 | ||
66 | if (newhost != client_p->orighost) | |
67 | SetDynSpoof(client_p); | |
762cc38c | 68 | else |
29d224a1 | 69 | ClearDynSpoof(client_p); |
762cc38c AC |
70 | } |
71 | ||
72 | static void | |
73 | do_host_cloak(const char *inbuf, char *outbuf, int ipmask) | |
74 | { | |
29c92cf9 | 75 | unsigned int cyc; |
762cc38c | 76 | unsigned int hosthash = 1, hosthash2 = 1; |
55abcbb2 | 77 | unsigned int maxcycle = strlen(inbuf); |
762cc38c AC |
78 | int len1; |
79 | const char *rest, *next; | |
80 | ||
81 | for (cyc = 0; cyc < maxcycle - 2; cyc += 2) | |
82 | hosthash *= (unsigned int) inbuf[cyc]; | |
83 | ||
84 | /* safety: decrement ourselves two steps back */ | |
85 | for (cyc = maxcycle - 1; cyc >= 1; cyc -= 2) | |
86 | hosthash2 *= (unsigned int) inbuf[cyc]; | |
87 | ||
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 | |
91 | */ | |
92 | hosthash += (hosthash2 / KEY); | |
93 | hosthash2 += (hosthash / KEY); | |
94 | ||
95 | if (ipmask == 0) | |
96 | { | |
5203cba5 | 97 | snprintf(outbuf, HOSTLEN, "%s-%X%X", |
762cc38c AC |
98 | ServerInfo.network_name, hosthash2, hosthash); |
99 | len1 = strlen(outbuf); | |
100 | rest = strchr(inbuf, '.'); | |
101 | if (rest == NULL) | |
102 | rest = "."; | |
103 | /* try to avoid truncation -- jilles */ | |
104 | while (len1 + strlen(rest) >= HOSTLEN && (next = strchr(rest + 1, '.')) != NULL) | |
105 | rest = next; | |
1f9de103 | 106 | rb_strlcat(outbuf, rest, HOSTLEN); |
762cc38c AC |
107 | } |
108 | else | |
5203cba5 | 109 | snprintf(outbuf, HOSTLEN, "%X%X.%s", |
762cc38c AC |
110 | hosthash2, hosthash, ServerInfo.network_name); |
111 | } | |
112 | ||
113 | static void | |
114 | check_umode_change(void *vdata) | |
115 | { | |
116 | hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; | |
117 | struct Client *source_p = data->client; | |
118 | ||
119 | if (!MyClient(source_p)) | |
120 | return; | |
121 | ||
122 | /* didn't change +h umode, we don't need to do anything */ | |
123 | if (!((data->oldumodes ^ source_p->umodes) & user_modes['h'])) | |
124 | return; | |
125 | ||
126 | if (source_p->umodes & user_modes['h']) | |
127 | { | |
128 | if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) | |
129 | { | |
130 | source_p->umodes &= ~user_modes['h']; | |
131 | return; | |
132 | } | |
133 | if (strcmp(source_p->host, source_p->localClient->mangledhost)) | |
134 | { | |
29d224a1 | 135 | distribute_hostchange(source_p, source_p->localClient->mangledhost); |
762cc38c AC |
136 | } |
137 | else /* not really nice, but we need to send this numeric here */ | |
138 | sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", | |
139 | source_p->host); | |
140 | } | |
141 | else if (!(source_p->umodes & user_modes['h'])) | |
142 | { | |
143 | if (source_p->localClient->mangledhost != NULL && | |
144 | !strcmp(source_p->host, source_p->localClient->mangledhost)) | |
145 | { | |
29d224a1 | 146 | distribute_hostchange(source_p, source_p->orighost); |
762cc38c AC |
147 | } |
148 | } | |
149 | } | |
150 | ||
151 | static void | |
152 | check_new_user(void *vdata) | |
153 | { | |
154 | struct Client *source_p = (void *)vdata; | |
155 | ||
156 | if (IsIPSpoof(source_p)) | |
157 | { | |
158 | source_p->umodes &= ~user_modes['h']; | |
159 | return; | |
160 | } | |
954012d3 | 161 | source_p->localClient->mangledhost = rb_malloc(HOSTLEN); |
762cc38c AC |
162 | if (!irccmp(source_p->orighost, source_p->sockhost)) |
163 | do_host_cloak(source_p->orighost, source_p->localClient->mangledhost, 1); | |
164 | else | |
165 | do_host_cloak(source_p->orighost, source_p->localClient->mangledhost, 0); | |
166 | if (IsDynSpoof(source_p)) | |
167 | source_p->umodes &= ~user_modes['h']; | |
168 | if (source_p->umodes & user_modes['h']) | |
169 | { | |
f427c8b0 | 170 | rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); |
762cc38c AC |
171 | if (irccmp(source_p->host, source_p->orighost)) |
172 | SetDynSpoof(source_p); | |
173 | } | |
174 | } |