]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Windows port: always shutdown winsocks on program termination
authorGuido Serassio <serassio@squid-cache.org>
Mon, 30 Jun 2008 17:02:39 +0000 (19:02 +0200)
committerGuido Serassio <serassio@squid-cache.org>
Mon, 30 Jun 2008 17:02:39 +0000 (19:02 +0200)
WSACleanup() should called always before program termination.
Also ran indent on squid_radius_auth.c.

helpers/basic_auth/squid_radius_auth/squid_rad_auth.c
src/ICMPPinger.cc [changed mode: 0644->0755]
src/dnsserver.cc [changed mode: 0644->0755]
tools/squidclient.cc [changed mode: 0644->0755]

index fe5fa141034bf1c54ad1014ae4b318ec4c324e2f..fc5d16774a827dcfbbf6772d741f6e0cc4c91370 100755 (executable)
@@ -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
     /*
old mode 100644 (file)
new mode 100755 (executable)
index 1d97469..2daf562
@@ -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");
old mode 100644 (file)
new mode 100755 (executable)
index 29a0df2..14a2877
@@ -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');
 
old mode 100644 (file)
new mode 100755 (executable)
index 5e32acf..8b87959
@@ -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 */