15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
|
*/ |
21 |
|
|
80 |
|
#define sendheader(c, i) sendto_one_notice((c), &me, HeaderMessages[(i)]) |
81 |
|
|
82 |
|
static dlink_list auth_pending_list; |
83 |
< |
static PF read_auth_reply; |
84 |
< |
static CNCB auth_connect_callback; |
83 |
> |
static void read_auth_reply(fde_t *, void *); |
84 |
> |
static void auth_connect_callback(fde_t *, int, void *); |
85 |
|
|
86 |
|
|
87 |
|
/* |
90 |
|
static struct AuthRequest * |
91 |
|
make_auth_request(struct Client *client) |
92 |
|
{ |
93 |
< |
struct AuthRequest *request = &client->localClient->auth; |
93 |
> |
struct AuthRequest *const request = &client->connection->auth; |
94 |
|
|
95 |
|
memset(request, 0, sizeof(*request)); |
96 |
|
|
108 |
|
void |
109 |
|
release_auth_client(struct AuthRequest *auth) |
110 |
|
{ |
111 |
< |
struct Client *client = auth->client; |
111 |
> |
struct Client *const client = auth->client; |
112 |
|
|
113 |
|
if (IsDoingAuth(auth) || IsDNSPending(auth)) |
114 |
|
return; |
124 |
|
* us. This is what read_packet() does. |
125 |
|
* -- adrian |
126 |
|
*/ |
127 |
< |
client->localClient->allow_read = MAX_FLOOD; |
128 |
< |
comm_setflush(&client->localClient->fd, 1000, flood_recalc, client); |
127 |
> |
client->connection->allow_read = MAX_FLOOD; |
128 |
> |
comm_setflush(&client->connection->fd, 1000, flood_recalc, client); |
129 |
|
|
130 |
< |
client->localClient->since = CurrentTime; |
131 |
< |
client->localClient->lasttime = CurrentTime; |
132 |
< |
client->localClient->firsttime = CurrentTime; |
130 |
> |
client->connection->since = CurrentTime; |
131 |
> |
client->connection->lasttime = CurrentTime; |
132 |
> |
client->connection->firsttime = CurrentTime; |
133 |
|
client->flags |= FLAGS_FINISHED_AUTH; |
134 |
|
|
135 |
< |
read_packet(&client->localClient->fd, client); |
135 |
> |
read_packet(&client->connection->fd, client); |
136 |
|
} |
137 |
|
|
138 |
|
/* |
143 |
|
* of success of failure |
144 |
|
*/ |
145 |
|
static void |
146 |
< |
auth_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
146 |
> |
auth_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength) |
147 |
|
{ |
148 |
< |
struct AuthRequest *auth = vptr; |
148 |
> |
struct AuthRequest *const auth = vptr; |
149 |
|
|
150 |
|
ClearDNSPending(auth); |
151 |
|
|
152 |
< |
if (name) |
152 |
> |
if (!EmptyString(name)) |
153 |
|
{ |
154 |
< |
const struct sockaddr_in *v4, *v4dns; |
155 |
< |
#ifdef IPV6 |
156 |
< |
const struct sockaddr_in6 *v6, *v6dns; |
157 |
< |
#endif |
158 |
< |
int good = 1; |
159 |
< |
|
160 |
< |
#ifdef IPV6 |
161 |
< |
if (auth->client->localClient->ip.ss.ss_family == AF_INET6) |
154 |
> |
if (auth->client->connection->ip.ss.ss_family == AF_INET6) |
155 |
|
{ |
156 |
< |
v6 = (const struct sockaddr_in6 *)&auth->client->localClient->ip; |
157 |
< |
v6dns = (const struct sockaddr_in6 *)addr; |
156 |
> |
const struct sockaddr_in6 *const v6 = (const struct sockaddr_in6 *)&auth->client->connection->ip; |
157 |
> |
const struct sockaddr_in6 *const v6dns = (const struct sockaddr_in6 *)addr; |
158 |
|
|
159 |
|
if (memcmp(&v6->sin6_addr, &v6dns->sin6_addr, sizeof(struct in6_addr)) != 0) |
160 |
|
{ |
161 |
|
sendheader(auth->client, REPORT_IP_MISMATCH); |
162 |
< |
good = 0; |
162 |
> |
release_auth_client(auth); |
163 |
> |
return; |
164 |
|
} |
165 |
|
} |
166 |
|
else |
173 |
– |
#endif |
167 |
|
{ |
168 |
< |
v4 = (const struct sockaddr_in *)&auth->client->localClient->ip; |
169 |
< |
v4dns = (const struct sockaddr_in *)addr; |
168 |
> |
const struct sockaddr_in *const v4 = (const struct sockaddr_in *)&auth->client->connection->ip; |
169 |
> |
const struct sockaddr_in *const v4dns = (const struct sockaddr_in *)addr; |
170 |
|
|
171 |
|
if (v4->sin_addr.s_addr != v4dns->sin_addr.s_addr) |
172 |
|
{ |
173 |
|
sendheader(auth->client, REPORT_IP_MISMATCH); |
174 |
< |
good = 0; |
174 |
> |
release_auth_client(auth); |
175 |
> |
return; |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
< |
if (good && strlen(name) <= HOSTLEN) |
179 |
> |
if (namelength > HOSTLEN) |
180 |
> |
sendheader(auth->client, REPORT_HOST_TOOLONG); |
181 |
> |
else |
182 |
|
{ |
183 |
< |
strlcpy(auth->client->host, name, |
188 |
< |
sizeof(auth->client->host)); |
183 |
> |
strlcpy(auth->client->host, name, sizeof(auth->client->host)); |
184 |
|
sendheader(auth->client, REPORT_FIN_DNS); |
185 |
|
} |
191 |
– |
else if (strlen(name) > HOSTLEN) |
192 |
– |
sendheader(auth->client, REPORT_HOST_TOOLONG); |
186 |
|
} |
187 |
|
else |
188 |
|
sendheader(auth->client, REPORT_FAIL_DNS); |
220 |
|
{ |
221 |
|
struct irc_ssaddr localaddr; |
222 |
|
socklen_t locallen = sizeof(struct irc_ssaddr); |
230 |
– |
#ifdef IPV6 |
223 |
|
struct sockaddr_in6 *v6; |
232 |
– |
#else |
233 |
– |
struct sockaddr_in *v4; |
234 |
– |
#endif |
224 |
|
|
225 |
|
/* open a socket of the same type as the client socket */ |
226 |
< |
if (comm_open(&auth->fd, auth->client->localClient->ip.ss.ss_family, |
226 |
> |
if (comm_open(&auth->fd, auth->client->connection->ip.ss.ss_family, |
227 |
|
SOCK_STREAM, 0, "ident") == -1) |
228 |
|
{ |
229 |
|
report_error(L_ALL, "creating auth stream socket %s:%s", |
230 |
|
get_client_name(auth->client, SHOW_IP), errno); |
242 |
– |
ilog(LOG_TYPE_IRCD, "Unable to create auth socket for %s", |
243 |
– |
get_client_name(auth->client, SHOW_IP)); |
231 |
|
++ServerStats.is_abad; |
232 |
|
return 0; |
233 |
|
} |
242 |
|
* and machines with multiple IP addresses are common now |
243 |
|
*/ |
244 |
|
memset(&localaddr, 0, locallen); |
245 |
< |
getsockname(auth->client->localClient->fd.fd, (struct sockaddr*)&localaddr, |
245 |
> |
getsockname(auth->client->connection->fd.fd, (struct sockaddr*)&localaddr, |
246 |
|
&locallen); |
247 |
|
|
261 |
– |
#ifdef IPV6 |
248 |
|
remove_ipv6_mapping(&localaddr); |
249 |
|
v6 = (struct sockaddr_in6 *)&localaddr; |
250 |
|
v6->sin6_port = htons(0); |
265 |
– |
#else |
266 |
– |
localaddr.ss_len = locallen; |
267 |
– |
v4 = (struct sockaddr_in *)&localaddr; |
268 |
– |
v4->sin_port = htons(0); |
269 |
– |
#endif |
251 |
|
localaddr.ss_port = htons(0); |
252 |
|
|
253 |
|
comm_connect_tcp(&auth->fd, auth->client->sockhost, RFC1413_PORT, |
254 |
|
(struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback, |
255 |
< |
auth, auth->client->localClient->ip.ss.ss_family, |
255 |
> |
auth, auth->client->connection->ip.ss.ss_family, |
256 |
|
GlobalSetOptions.ident_timeout); |
257 |
|
return 1; /* We suceed here for now */ |
258 |
|
} |
267 |
|
void |
268 |
|
start_auth(struct Client *client_p) |
269 |
|
{ |
270 |
< |
struct AuthRequest *auth = NULL; |
290 |
< |
|
291 |
< |
assert(client_p); |
270 |
> |
struct AuthRequest *const auth = make_auth_request(client_p); |
271 |
|
|
293 |
– |
auth = make_auth_request(client_p); |
272 |
|
SetInAuth(auth); |
273 |
|
dlinkAddTail(auth, &auth->node, &auth_pending_list); |
274 |
|
|
282 |
|
start_auth_query(auth); |
283 |
|
} |
284 |
|
|
285 |
< |
gethost_byaddr(auth_dns_callback, auth, &client_p->localClient->ip); |
285 |
> |
gethost_byaddr(auth_dns_callback, auth, &client_p->connection->ip); |
286 |
|
} |
287 |
|
|
288 |
|
/* |
292 |
|
static void |
293 |
|
timeout_auth_queries_event(void *notused) |
294 |
|
{ |
295 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
295 |
> |
dlink_node *node = NULL, *node_next = NULL; |
296 |
|
|
297 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, auth_pending_list.head) |
297 |
> |
DLINK_FOREACH_SAFE(node, node_next, auth_pending_list.head) |
298 |
|
{ |
299 |
< |
struct AuthRequest *auth = ptr->data; |
299 |
> |
struct AuthRequest *auth = node->data; |
300 |
|
|
301 |
|
if (auth->timeout > CurrentTime) |
302 |
|
break; |
316 |
|
sendheader(auth->client, REPORT_FAIL_DNS); |
317 |
|
} |
318 |
|
|
341 |
– |
ilog(LOG_TYPE_IRCD, "DNS/AUTH timeout %s", |
342 |
– |
get_client_name(auth->client, SHOW_IP)); |
319 |
|
release_auth_client(auth); |
320 |
|
} |
321 |
|
} |
334 |
|
static void |
335 |
|
auth_connect_callback(fde_t *fd, int error, void *data) |
336 |
|
{ |
337 |
< |
struct AuthRequest *auth = data; |
337 |
> |
struct AuthRequest *const auth = data; |
338 |
|
struct irc_ssaddr us; |
339 |
|
struct irc_ssaddr them; |
340 |
< |
char authbuf[32]; |
340 |
> |
char authbuf[16]; |
341 |
|
socklen_t ulen = sizeof(struct irc_ssaddr); |
342 |
|
socklen_t tlen = sizeof(struct irc_ssaddr); |
343 |
|
uint16_t uport, tport; |
368 |
– |
#ifdef IPV6 |
344 |
|
struct sockaddr_in6 *v6; |
370 |
– |
#else |
371 |
– |
struct sockaddr_in *v4; |
372 |
– |
#endif |
345 |
|
|
346 |
|
if (error != COMM_OK) |
347 |
|
{ |
349 |
|
return; |
350 |
|
} |
351 |
|
|
352 |
< |
if (getsockname(auth->client->localClient->fd.fd, (struct sockaddr *)&us, &ulen) || |
353 |
< |
getpeername(auth->client->localClient->fd.fd, (struct sockaddr *)&them, &tlen)) |
352 |
> |
if (getsockname(auth->client->connection->fd.fd, (struct sockaddr *)&us, &ulen) || |
353 |
> |
getpeername(auth->client->connection->fd.fd, (struct sockaddr *)&them, &tlen)) |
354 |
|
{ |
355 |
|
ilog(LOG_TYPE_IRCD, "auth get{sock,peer}name error for %s", |
356 |
|
get_client_name(auth->client, SHOW_IP)); |
358 |
|
return; |
359 |
|
} |
360 |
|
|
389 |
– |
#ifdef IPV6 |
361 |
|
v6 = (struct sockaddr_in6 *)&us; |
362 |
|
uport = ntohs(v6->sin6_port); |
363 |
|
v6 = (struct sockaddr_in6 *)&them; |
364 |
|
tport = ntohs(v6->sin6_port); |
365 |
|
remove_ipv6_mapping(&us); |
366 |
|
remove_ipv6_mapping(&them); |
396 |
– |
#else |
397 |
– |
v4 = (struct sockaddr_in *)&us; |
398 |
– |
uport = ntohs(v4->sin_port); |
399 |
– |
v4 = (struct sockaddr_in *)&them; |
400 |
– |
tport = ntohs(v4->sin_port); |
401 |
– |
us.ss_len = ulen; |
402 |
– |
them.ss_len = tlen; |
403 |
– |
#endif |
367 |
|
|
368 |
|
snprintf(authbuf, sizeof(authbuf), "%u, %u\r\n", tport, uport); |
369 |
|
|
391 |
|
* \return The userid, or NULL on parse failure. |
392 |
|
*/ |
393 |
|
static const char * |
394 |
< |
check_ident_reply(char *reply) |
394 |
> |
check_ident_reply(char *const reply) |
395 |
|
{ |
396 |
|
char *token = NULL, *end = NULL; |
397 |
|
char *vector[USERID_TOKEN_COUNT]; |
398 |
< |
int count = token_vector(reply, ':', vector, USERID_TOKEN_COUNT); |
398 |
> |
const int count = token_vector(reply, ':', vector, USERID_TOKEN_COUNT); |
399 |
|
|
400 |
|
if (USERID_TOKEN_COUNT != count) |
401 |
|
return NULL; |
475 |
|
static void |
476 |
|
read_auth_reply(fde_t *fd, void *data) |
477 |
|
{ |
478 |
< |
struct AuthRequest *auth = data; |
478 |
> |
struct AuthRequest *const auth = data; |
479 |
|
const char *username = NULL; |
480 |
|
ssize_t len = 0; |
481 |
|
char buf[RFC1413_BUFSIZ + 1]; |