Windows fixes for gss-client.c
authorSam Hartman <hartmans@mit.edu>
Tue, 9 Aug 2011 20:07:39 +0000 (20:07 +0000)
committerSam Hartman <hartmans@mit.edu>
Tue, 9 Aug 2011 20:07:39 +0000 (20:07 +0000)
close(s) -> closesocket(s)
#include "port-sockets.h" (for closesocket())
#include "winsock.h" -> #include "winsock2.h" for consistency with port-sockets.h
call WSAStartup() before using sockets functions on Windows

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>
Signed-off-by: Sam Hartman <hartmans@painless-security.com>
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25089 dc483132-0cff-0310-8789-dd5450dbe970

src/appl/gss-sample/gss-client.c

index d439f23fbcc8f226b78e1ace44fd4c5ce3099514..c8213edfda5dc26fa99b7912122838ddbabfb7b1 100644 (file)
@@ -49,7 +49,7 @@
 #include <string.h>
 #ifdef _WIN32
 #include <windows.h>
-#include <winsock.h>
+#include <winsock2.h>
 #else
 #include <assert.h>
 #include <unistd.h>
@@ -67,6 +67,7 @@
 #include <gssapi/gssapi_krb5.h>
 #include <gssapi/gssapi_ext.h>
 #include "gss-misc.h"
+#include "port-sockets.h"
 
 static int verbose = 1;
 static int spnego = 0;
@@ -113,6 +114,15 @@ connect_to_server(char *host, u_short port)
     struct sockaddr_in saddr;
     struct hostent *hp;
     int     s;
+#ifdef _WIN32
+    WSADATA wsadata;
+    int wsastartuperror = WSAStartup(0x202, &wsadata);
+    if (wsastartuperror)
+    {
+        fprintf(stderr, "WSAStartup error: %x\n", wsastartuperror);
+        return -1;
+    }
+#endif
 
     if ((hp = gethostbyname(host)) == NULL) {
         fprintf(stderr, "Unknown host: %s\n", host);
@@ -129,7 +139,7 @@ connect_to_server(char *host, u_short port)
     }
     if (connect(s, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
         perror("connecting to server");
-        (void) close(s);
+        (void) closesocket(s);
         return -1;
     }
     return s;
@@ -462,7 +472,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag,
     if (client_establish_context(s, service_name, gss_flags, auth_flag,
                                  v1_format, oid, username, password,
                                  &context, &ret_flags) < 0) {
-        (void) close(s);
+        (void) closesocket(s);
         return -1;
     }
 
@@ -560,7 +570,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag,
                          &in_buf, &state, &out_buf);
             if (maj_stat != GSS_S_COMPLETE) {
                 display_status("wrapping message", maj_stat, min_stat);
-                (void) close(s);
+                (void) closesocket(s);
                 (void) gss_delete_sec_context(&min_stat, &context,
                                               GSS_C_NO_BUFFER);
                 return -1;
@@ -578,7 +588,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag,
                               (encrypt_flag ? TOKEN_ENCRYPTED : 0) |
                               (mic_flag ? TOKEN_SEND_MIC : 0))),
                        &out_buf) < 0) {
-            (void) close(s);
+            (void) closesocket(s);
             (void) gss_delete_sec_context(&min_stat, &context,
                                           GSS_C_NO_BUFFER);
             return -1;
@@ -588,7 +598,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag,
 
         /* Read signature block into out_buf */
         if (recv_token(s, &token_flags, &out_buf) < 0) {
-            (void) close(s);
+            (void) closesocket(s);
             (void) gss_delete_sec_context(&min_stat, &context,
                                           GSS_C_NO_BUFFER);
             return -1;
@@ -600,7 +610,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag,
                                       &out_buf, &qop_state);
             if (maj_stat != GSS_S_COMPLETE) {
                 display_status("verifying signature", maj_stat, min_stat);
-                (void) close(s);
+                (void) closesocket(s);
                 (void) gss_delete_sec_context(&min_stat, &context,
                                               GSS_C_NO_BUFFER);
                 return -1;
@@ -628,7 +638,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag,
         maj_stat = gss_delete_sec_context(&min_stat, &context, &out_buf);
         if (maj_stat != GSS_S_COMPLETE) {
             display_status("deleting context", maj_stat, min_stat);
-            (void) close(s);
+            (void) closesocket(s);
             (void) gss_delete_sec_context(&min_stat, &context,
                                           GSS_C_NO_BUFFER);
             return -1;
@@ -637,7 +647,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag,
         (void) gss_release_buffer(&min_stat, &out_buf);
     }
 
-    (void) close(s);
+    (void) closesocket(s);
 
     return 0;
 }