[srvx-commits] CVS: services/src sockcheck.c,1.54.2.19,1.54.2.20
Brought to you by:
entrope
From: Miles P. <pet...@us...> - 2001-08-12 22:49:19
|
Update of /cvsroot/srvx/services/src In directory usw-pr-cvs1:/tmp/cvs-serv26897 Modified Files: Tag: rel-1_0 sockcheck.c Log Message: no longer storing hostname in cache structs Index: sockcheck.c =================================================================== RCS file: /cvsroot/srvx/services/src/sockcheck.c,v retrieving revision 1.54.2.19 retrieving revision 1.54.2.20 diff -C2 -r1.54.2.19 -r1.54.2.20 *** sockcheck.c 2001/08/12 13:09:34 1.54.2.19 --- sockcheck.c 2001/08/12 22:49:17 1.54.2.20 *************** *** 87,91 **** const char *reason; unsigned long addr; - unsigned char hostname[0]; } *sockcheck_cache_info; --- 87,90 ---- *************** *** 217,224 **** sockcheck_issue_gline(sockcheck_cache_info sci) { ! char *target = alloca(3+strlen(sci->hostname)); strcpy(target, "*@"); ! strcpy(target+2, sci->hostname); ! log(PC_LOG, LOG_INFO, "Issuing gline for client at IP %08x hostname %s: %s\n", sci->addr, sci->hostname, sci->reason); irc_gline(target, 3600, sci->reason); } --- 216,224 ---- sockcheck_issue_gline(sockcheck_cache_info sci) { ! char *targetip = intoa(sci->addr); ! char *target = alloca(3+strlen(targetip)); strcpy(target, "*@"); ! strcpy(target+2, targetip); ! log(PC_LOG, LOG_INFO, "Issuing gline for client at IP %08x (%s): %s\n", sci->addr, targetip, sci->reason); irc_gline(target, 3600, sci->reason); } *************** *** 251,256 **** sci->reason = NULL; sci->addr = addr; ! memcpy(sci->hostname, name, namelen); ! dict_insert(checked_ip_dict, sci->hostname, sci); } else { sci->addr = addr; --- 251,255 ---- sci->reason = NULL; sci->addr = addr; ! dict_insert(checked_ip_dict, intoa(addr), sci); } else { sci->addr = addr; *************** *** 270,276 **** if ((sci = dict_find(checked_ip_dict, name, NULL))) { ! if ((sci->decision == PENDING) || (sci->decision == CHECKING)) { ! return -1; ! } } --- 269,275 ---- if ((sci = dict_find(checked_ip_dict, name, NULL))) { ! if ((sci->decision == PENDING) || (sci->decision == CHECKING)) { ! return -1; ! } } *************** *** 280,283 **** --- 279,283 ---- return 0; } + res = dict_remove(checked_ip_dict, name); pthread_mutex_unlock(&checked_ip_mutex); *************** *** 320,329 **** { static const char *decs[] = {"PENDING", "CHECKING", "ACCEPT", "REJECT"}; ! log(PC_LOG, LOG_INFO, "client %p: { addr = %p { decision = %s; last_touched = " FMT_TIME_T "; reason = %s; addr = %08lx; hostname = \"%s\" }; " "test_index = %d; state = %p { port = %d; type = %s; template = \"%s\"; ... }; " "send = %p; send_size = %d; send_used = %d; send_pos = %d; " "read = %p; read_size = %d; read_used = %d; read_pos = %d; " "connected = %d; writing = %d; }\n", ! client, client->addr, decs[client->addr->decision], client->addr->last_touched, client->addr->reason, client->addr->addr, client->addr->hostname, client->test_index, client->state, client->state ? client->state->port : 0, --- 320,329 ---- { static const char *decs[] = {"PENDING", "CHECKING", "ACCEPT", "REJECT"}; ! log(PC_LOG, LOG_INFO, "client %p: { addr = %p { decision = %s; last_touched = " FMT_TIME_T "; reason = %s; addr = %08lx; ip = \"%s\" }; " "test_index = %d; state = %p { port = %d; type = %s; template = \"%s\"; ... }; " "send = %p; send_size = %d; send_used = %d; send_pos = %d; " "read = %p; read_size = %d; read_used = %d; read_pos = %d; " "connected = %d; writing = %d; }\n", ! client, client->addr, decs[client->addr->decision], client->addr->last_touched, client->addr->reason, client->addr->addr, intoa(client->addr->addr), client->test_index, client->state, client->state ? client->state->port : 0, *************** *** 375,379 **** switch (var) { case 'c': ! expansion = client->addr->hostname; exp_length = strlen(expansion); break; --- 375,379 ---- switch (var) { case 'c': ! expansion = intoa(client->addr->addr); exp_length = strlen(expansion); break; *************** *** 435,439 **** unsigned int exp_length; expand_var(client, template[1], &expansion, &exp_length); ! log(PC_LOG, LOG_INFO, "Expanded var %c for client %s to \"%s\" (len %d, pos %d)\n", template[1], client->addr->hostname, expansion, exp_length, client->send_used); if (client->send_used+exp_length >= client->send_size) { do { --- 435,439 ---- unsigned int exp_length; expand_var(client, template[1], &expansion, &exp_length); ! log(PC_LOG, LOG_INFO, "Expanded var %c for client %s to \"%s\" (len %d, pos %d)\n", template[1], intoa(client->addr->addr), expansion, exp_length, client->send_used); if (client->send_used+exp_length >= client->send_size) { do { *************** *** 495,499 **** poller->revents = 0; /* otherwise we get confused this poll iteration.. */ if ((poller->fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { ! log(PC_LOG, LOG_ERROR, "Error: socket() for client %s returned errno %d (%s)\n", client->addr->hostname, errno, strerror(errno)); goto cleanup_1; } --- 495,499 ---- poller->revents = 0; /* otherwise we get confused this poll iteration.. */ if ((poller->fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { ! log(PC_LOG, LOG_ERROR, "Error: socket() for client %s returned errno %d (%s)\n", intoa(client->addr->addr), errno, strerror(errno)); goto cleanup_1; } *************** *** 502,506 **** if (sockcheck_conf.local_addr) { if (bind(poller->fd, (struct sockaddr*) sockcheck_conf.local_addr, sizeof(struct sockaddr)) < 0) { ! log(PC_LOG, LOG_ERROR, "Error: bind() for client %s returned errno %d (%s)\n", client->addr->hostname, errno, strerror(errno)); } } --- 502,506 ---- if (sockcheck_conf.local_addr) { if (bind(poller->fd, (struct sockaddr*) sockcheck_conf.local_addr, sizeof(struct sockaddr)) < 0) { ! log(PC_LOG, LOG_ERROR, "Error: bind() for client %s returned errno %d (%s)\n", intoa(client->addr->addr), errno, strerror(errno)); } } *************** *** 510,519 **** if (connect(poller->fd, (struct sockaddr*)&sin, sizeof(sin)) < 0) { if (errno != EINPROGRESS) { ! log(PC_LOG, LOG_ERROR, "Error: connect() returned errno %d (%s) for port %d on client %s\n", errno, strerror(errno), client->state->port, client->addr->hostname); /* progress to next test.. */ goto cleanup_2; } } ! log(PC_LOG, LOG_INFO, "Starting proxy check on port %d (test %d) for client %s, fd %d\n", client->state->port, client->test_index, client->addr->hostname, poller->fd); return; --- 510,519 ---- if (connect(poller->fd, (struct sockaddr*)&sin, sizeof(sin)) < 0) { if (errno != EINPROGRESS) { ! log(PC_LOG, LOG_ERROR, "Error: connect() returned errno %d (%s) for port %d on client %s\n", errno, strerror(errno), client->state->port, intoa(client->addr->addr)); /* progress to next test.. */ goto cleanup_2; } } ! log(PC_LOG, LOG_INFO, "Starting proxy check on port %d (test %d) for client %s, fd %d\n", client->state->port, client->test_index, intoa(client->addr->addr), poller->fd); return; *************** *** 578,582 **** } if (!tests) return 0; ! log(PC_LOG, LOG_INFO, "Proxy-checking client at %08x (%s) as client %d (now %d in progress)\n", sci->addr, sci->hostname, idx, sockcheck_num_sockets); client_list[idx] = sockcheck_alloc_client(sci); client_list[idx]->test_rep = 0; --- 578,582 ---- } if (!tests) return 0; ! log(PC_LOG, LOG_INFO, "Proxy-checking client at %08x (%s) as client %d (now %d in progress)\n", sci->addr, intoa(sci->addr), idx, sockcheck_num_sockets); client_list[idx] = sockcheck_alloc_client(sci); client_list[idx]->test_rep = 0; *************** *** 596,604 **** if (decision == ACCEPT) { /* do nothing */ ! log(PC_LOG, LOG_INFO, "Proxy check passed for client at IP %08x hostname %s\n", client->addr->addr, client->addr->hostname); } else if (decision == REJECT) { proxies_detected++; sockcheck_issue_gline(client->addr); ! log(PC_LOG, LOG_INFO, "Proxy check failed for client at IP %08x hostname %s (%s)\n", client->addr->addr, client->addr->hostname, client->addr->reason); /* don't compare idx != 0 directly, because somebody else may have * reordered the tests already --- 596,605 ---- if (decision == ACCEPT) { /* do nothing */ ! log(PC_LOG, LOG_INFO, "Proxy check passed for client at IP %08x (%s)\n", client->addr->addr, intoa(client->addr->addr)); ! log(PC_LOG, LOG_INFO, "Size of ADDR is: %d\n", sizeof(sockcheck_cache_info)); } else if (decision == REJECT) { proxies_detected++; sockcheck_issue_gline(client->addr); ! log(PC_LOG, LOG_INFO, "Proxy check failed for client at IP %08x (%s)\n", client->addr->addr, client->addr->reason); /* don't compare idx != 0 directly, because somebody else may have * reordered the tests already *************** *** 613,617 **** } } else { ! log(PC_LOG, LOG_ERROR, "BUG: sockcheck_decide(\"%s\", %d): unrecognized decision\n", client->addr->hostname, decision); } sockcheck_list_unref(client->tests); --- 614,618 ---- } } else { ! log(PC_LOG, LOG_ERROR, "BUG: sockcheck_decide(\"%s\", %d): unrecognized decision\n", intoa(client->addr->addr), decision); } sockcheck_list_unref(client->tests); *************** *** 635,639 **** if (res < 0) { if (errno == EAGAIN) return; ! log(PC_LOG, LOG_ERROR, "BUG: sockcheck_try_write(%s): write() returned errno %d (%s)\n", client->addr->hostname, errno, strerror(errno)); } else { client->send_pos += res; --- 636,640 ---- if (res < 0) { if (errno == EAGAIN) return; ! log(PC_LOG, LOG_ERROR, "BUG: sockcheck_try_write(%s): write() returned errno %d (%s)\n", intoa(client->addr->addr), errno, strerror(errno)); } else { client->send_pos += res; *************** *** 651,658 **** unsigned int n; ! res = read(fd, client->read + client->read_used, client->read_size - client->read_used); if (res < 0) { if (errno != EAGAIN) { ! log(PC_LOG, LOG_ERROR, "BUG: sockcheck_try_read(%d, %s): read() returned errno %d (%s)\n", fd, client->addr->hostname, errno, strerror(errno)); return -1; } --- 652,659 ---- unsigned int n; ! res = read(fd, client->read + client->read_used, client->read_size - client->read_used + 1); if (res < 0) { if (errno != EAGAIN) { ! log(PC_LOG, LOG_ERROR, "BUG: sockcheck_try_read(%d, %s): read() returned errno %d (%s)\n", fd, intoa(client->addr->addr), errno, strerror(errno)); return -1; } *************** *** 668,672 **** /* since we have nothing to read we will never enter the while() loop */ if (client->resp_state[n] && !strlen(client->resp_state[n])) { ! log(PC_LOG, LOG_ERROR, "Choosing response %d for client %s\n", n, client->addr->hostname); return n; } --- 669,673 ---- /* since we have nothing to read we will never enter the while() loop */ if (client->resp_state[n] && !strlen(client->resp_state[n])) { ! log(PC_LOG, LOG_ERROR, "Choosing response %d for client %s\n", n, intoa(client->addr->addr)); return n; } *************** *** 675,679 **** /* See if what's been read matches any of the expected responses */ ! while (client->read_pos < client->read_used) { unsigned char curr, bleh; const unsigned char *resp_state; --- 676,680 ---- /* See if what's been read matches any of the expected responses */ ! while (client->read_pos <= client->read_used) { unsigned char curr, bleh; const unsigned char *resp_state; *************** *** 718,722 **** client->resp_state[n] = resp_state = resp_state + 2; if (!*resp_state) { ! log(PC_LOG, LOG_ERROR, "Choosing response %d for client %s\n", n, client->addr->hostname); return n; } --- 719,723 ---- client->resp_state[n] = resp_state = resp_state + 2; if (!*resp_state) { ! log(PC_LOG, LOG_ERROR, "Choosing response %d for client %s\n", n, intoa(client->addr->addr)); return n; } *************** *** 730,738 **** if (client->read_used >= client->read_size) { /* we got more data than we expected to get .. don't read any more */ ! log(PC_LOG, LOG_INFO, "Buffer filled (unmatched) for client %s\n", client->addr->hostname); return client->state->responses.used - 1; } else if (TV_CMP(tv_now, >, client->read_timeout)) { /* read timed out, use default handler. */ ! log(PC_LOG, LOG_INFO, "Read timeout expired for client %s\n", client->addr->hostname); return client->state->responses.used - 1; } else { --- 731,739 ---- if (client->read_used >= client->read_size) { /* we got more data than we expected to get .. don't read any more */ ! log(PC_LOG, LOG_INFO, "Buffer filled (unmatched) for client %s\n", intoa(client->addr->addr)); return client->state->responses.used - 1; } else if (TV_CMP(tv_now, >, client->read_timeout)) { /* read timed out, use default handler. */ ! log(PC_LOG, LOG_INFO, "Read timeout expired for client %s\n", intoa(client->addr->addr)); return client->state->responses.used - 1; } else { *************** *** 755,759 **** /* disconnected -- next test! */ close(poller->fd); ! log(PC_LOG, LOG_ERROR, "Client %s gave us a POLLHUP on fd %d\n", client->addr->hostname, poller->fd); goto next_test; } else if (poller->revents & (POLLOUT|POLLIN)) { --- 756,760 ---- /* disconnected -- next test! */ close(poller->fd); ! log(PC_LOG, LOG_ERROR, "Client %s gave us a POLLHUP on fd %d\n", intoa(client->addr->addr), poller->fd); goto next_test; } else if (poller->revents & (POLLOUT|POLLIN)) { *************** *** 765,769 **** case ECONNREFUSED: case ETIMEDOUT: ! log(PC_LOG, LOG_INFO, "Client %s gave us errno %d (%s)\n", client->addr->hostname, rc, strerror(rc)); goto disconn; case 0: break; --- 766,770 ---- case ECONNREFUSED: case ETIMEDOUT: ! log(PC_LOG, LOG_INFO, "Client %s gave us errno %d (%s)\n", intoa(client->addr->addr), rc, strerror(rc)); goto disconn; case 0: break; *************** *** 806,810 **** char buffer[201]; static const char *hexmap = "0123456789ABCDEF"; ! log(PC_LOG, LOG_INFO, "sockcheck_advance(%s) following response %d (type %d) of %d\n", client->addr->hostname, next_state+1, ns->type, client->state->responses.used); for (n=0; n<client->send_used; n++) { for (m=0; (m<(sizeof(buffer)-1)>>1) && ((n+m) < client->send_used); m++) { --- 807,811 ---- char buffer[201]; static const char *hexmap = "0123456789ABCDEF"; ! log(PC_LOG, LOG_INFO, "sockcheck_advance(%s) following response %d (type %d) of %d\n", intoa(client->addr->addr), next_state+1, ns->type, client->state->responses.used); for (n=0; n<client->send_used; n++) { for (m=0; (m<(sizeof(buffer)-1)>>1) && ((n+m) < client->send_used); m++) { *************** *** 884,888 **** /* no work to do, so swap something down */ #if SOCKCHECK_DEBUG ! log(PC_LOG, LOG_INFO, "sockcheck moving client %s (at %d) to fill hole at %d\n", client_list[sockcheck_num_sockets]->addr->hostname, sockcheck_num_sockets, n); #endif poll_list[n+1] = poll_list[sockcheck_num_sockets+1]; --- 885,889 ---- /* no work to do, so swap something down */ #if SOCKCHECK_DEBUG ! log(PC_LOG, LOG_INFO, "sockcheck moving client %s (at %d) to fill hole at %d\n", intoa(client_list[sockcheck_num_sockets]->addr->addr), sockcheck_num_sockets, n); #endif poll_list[n+1] = poll_list[sockcheck_num_sockets+1]; |