From: Guido Serassio Date: Mon, 30 Jun 2008 17:02:39 +0000 (+0200) Subject: Windows port: always shutdown winsocks on program termination X-Git-Tag: SQUID_3_1_0_1~49^2~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec5561939947fbd80f04944ad598e4d80f9639b5;p=thirdparty%2Fsquid.git Windows port: always shutdown winsocks on program termination WSACleanup() should called always before program termination. Also ran indent on squid_radius_auth.c. --- diff --git a/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c b/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c index fe5fa14103..fc5d16774a 100755 --- a/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c +++ b/helpers/basic_auth/squid_radius_auth/squid_rad_auth.c @@ -129,6 +129,15 @@ static int retries = 30; char *progname = "squid_rad_auth"; int debug_flag = 0; +#ifdef _SQUID_MSWIN_ +void +Win32SockCleanup(void) +{ + WSACleanup(); + return; +} +#endif /* ifdef _SQUID_MSWIN_ */ + /* * Diff two timeval, b - a */ @@ -183,12 +192,10 @@ result_recv(u_int32_t host, u_short udp_port, char *buffer, int length) totallen, length); return -1; } - if (auth->id != request_id) { /* Duplicate response of an earlier query, ignore */ return -1; } - /* Verify the reply digest */ memcpy(reply_digest, auth->vector, AUTH_VECTOR_LEN); memcpy(auth->vector, vector, AUTH_VECTOR_LEN); @@ -200,7 +207,6 @@ result_recv(u_int32_t host, u_short udp_port, char *buffer, int length) fprintf(stderr, "Warning: Received invalid reply digest from server\n"); return -1; } - if (auth->code != PW_AUTHENTICATION_ACK) return 1; @@ -251,9 +257,9 @@ rad_auth_config(const char *cfname) crt = sscanf(line, "secret %s", secretkey); if (!memcmp(line, "identifier", 10)) sscanf(line, "identifier %s", identifier); - if (!memcmp(line, "service", 7)) + if (!memcmp(line, "service", 7)) sscanf(line, "service %s", svc_name); - if (!memcmp(line, "port", 4)) + if (!memcmp(line, "port", 4)) sscanf(line, "port %s", svc_name); } if (srv && crt) @@ -347,7 +353,7 @@ authenticate(int sockfd, const char *username, const char *passwd) memcpy(cbc, auth->vector, AUTH_VECTOR_LEN); for (j = 0; j < length; j += AUTH_VECTOR_LEN) { /* Calculate the MD5 Digest */ - strcpy((char *)md5buf, secretkey); + strcpy((char *) md5buf, secretkey); memcpy(md5buf + secretlen, cbc, AUTH_VECTOR_LEN); md5_calc(cbc, md5buf, secretlen + AUTH_VECTOR_LEN); @@ -400,7 +406,7 @@ authenticate(int sockfd, const char *username, const char *passwd) */ auth->length = htons(total_length); - while(retry--) { + while (retry--) { int time_spent; struct timeval sent; /* @@ -433,7 +439,7 @@ authenticate(int sockfd, const char *username, const char *passwd) if (rc == 0) return 1; if (rc == 1) - return 0; + return 0; } } @@ -459,7 +465,7 @@ main(int argc, char **argv) int c; while ((c = getopt(argc, argv, "h:p:f:w:i:t:")) != -1) { - switch(c) { + switch (c) { case 'f': cfname = optarg; break; @@ -490,21 +496,19 @@ main(int argc, char **argv) exit(1); } } - if (!*server) { fprintf(stderr, "%s: Server not specified\n", argv[0]); exit(1); } - if (!*secretkey) { fprintf(stderr, "%s: Shared secret not specified\n", argv[0]); exit(1); } - #ifdef _SQUID_MSWIN_ { WSADATA wsaData; WSAStartup(2, &wsaData); + atexit(Win32SockCleanup); } #endif /* diff --git a/src/ICMPPinger.cc b/src/ICMPPinger.cc old mode 100644 new mode 100755 index 1d974692f4..2daf56286f --- a/src/ICMPPinger.cc +++ b/src/ICMPPinger.cc @@ -56,6 +56,15 @@ ICMPPinger::~ICMPPinger() Close(); } +#ifdef _SQUID_MSWIN_ +void +Win32SockCleanup(void) +{ + WSACleanup(); + return; +} +#endif + int ICMPPinger::Open(void) { @@ -69,6 +78,7 @@ ICMPPinger::Open(void) struct sockaddr_in PS; WSAStartup(2, &wsaData); + atexit(Win32SockCleanup); getCurrentTime(); _db_init(NULL, "ALL,1"); diff --git a/src/dnsserver.cc b/src/dnsserver.cc old mode 100644 new mode 100755 index 29a0df2e22..14a2877a0c --- a/src/dnsserver.cc +++ b/src/dnsserver.cc @@ -517,8 +517,12 @@ main(int argc, char *argv[]) for (;;) { memset(request, '\0', REQ_SZ); - if (fgets(request, REQ_SZ, stdin) == NULL) - exit(1); + if (fgets(request, REQ_SZ, stdin) == NULL) { +#ifdef _SQUID_MSWIN_ + WSACleanup(); +#endif + exit(1); + } t = strrchr(request, '\n'); diff --git a/tools/squidclient.cc b/tools/squidclient.cc old mode 100644 new mode 100755 index 5e32acf7de..8b879599dd --- a/tools/squidclient.cc +++ b/tools/squidclient.cc @@ -113,6 +113,15 @@ static struct stat sb; int total_bytes = 0; int io_timeout = 120; +#ifdef _SQUID_MSWIN_ +void +Win32SockCleanup(void) +{ + WSACleanup(); + return; +} +#endif /* ifdef _SQUID_MSWIN_ */ + static void usage(const char *progname) { @@ -317,6 +326,7 @@ main(int argc, char *argv[]) { WSADATA wsaData; WSAStartup(2, &wsaData); + atexit(Win32SockCleanup); } #endif /* Build the HTTP request */