windows fix main.cpp for windows chrome
authorKevin Wasserman <krwasserman@hotmail.com>
Tue, 23 Dec 2014 19:01:22 +0000 (14:01 -0500)
committerKevin Wasserman <krwasserman@painless-security.com>
Thu, 15 Jan 2015 19:34:15 +0000 (14:34 -0500)
json_gssapi/main.cpp

index 6db2850..fb7f28a 100644 (file)
@@ -1,20 +1,13 @@
-#include <commands/GSSImportName.h>
-#include <commands/GSSInitSecContext.h>
-#include <commands/GSSAcquireCred.h>
-#include <datamodel/GSSBuffer.h>
-#include <exception>
+//
 #include <iostream>
-#include <string>
 #ifdef WIN32
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <stdio.h>
 #include <fcntl.h>
-#include <share.h>
+#include <io.h>
 #else
 #include <unistd.h>
 #include <string.h>
 #endif
-#include <util_json.h>
 #include <GSSRequest.h>
 
 
@@ -22,13 +15,12 @@ using std::cin;
 using std::cout;
 using std::endl;
 using std::getline;
-using std::string;
 
 int main(int argc, char **argv) {
   /* Variables */
-  string output;
   char *input;
-  size_t len;
+  char *output;
+  int32_t len;
   
   /* Error checking */
   
@@ -36,37 +28,9 @@ int main(int argc, char **argv) {
   
   /* Main processing */
 #ifdef WIN32
-  if (argc < 2) {
-      return -1;
-  }
-  int fd;
-  if (_sopen_s(&fd, argv[1], _O_BINARY, _SH_DENYNO, _S_IREAD) != 0)
-  {
-      cout << "error :" << errno << " opening file: " << argv[1] << "\n";
-      return -1;
-  }
-  struct _stat fs;
-  if (_fstat(fd, &fs) != 0) {
-      cout << "error: " << errno << " from _fstat.\n";
-      return -1;
-  }
-
-  FILE *f =_fdopen(fd, "rb");
-  if (f == NULL) {
-      cout << "error: " << errno << " from _fdopen.\n";
-      return -1;
-  }
-  len = fs.st_size;
-  input = new char[len+1];
-  size_t count = fread(input, 1, len, f) ;
-  if (count != len) {
-      cout << "expected " << len << " bytes from fread; got " << count << ".\n";
-      return -1;
-  }
-  fclose(f);
-#else
-  ssize_t readThisRound;
-  size_t readTotal, readRemaining;
+  _setmode(_fileno(stdin), _O_BINARY);
+#endif
+  int readThisRound, readTotal, readRemaining;
   do 
   {
     // Read 32 bit length
@@ -74,7 +38,7 @@ int main(int argc, char **argv) {
     readThisRound = readTotal = 0;
     while(4 != readTotal)
     {
-      readThisRound = read(0, ((&len) + readTotal), 4 - readTotal);
+      readThisRound = _read(0, ((&len) + readTotal), 4 - readTotal);
       readTotal += readThisRound;
     }
     
@@ -84,25 +48,22 @@ int main(int argc, char **argv) {
     while (readTotal < len)
     {
       readRemaining = len - readTotal;
-      readThisRound = read( 0, &(input[readTotal]), readRemaining);
+      readThisRound = _read( 0, &(input[readTotal]), readRemaining);
       if (-1 == readThisRound)
         break;
       else
         readTotal += readThisRound;
     }
     // ... and null-terminate it
-#endif
     input[len] = '\0';
     
-    char *out = gss_request(input);
-    len = strlen(out);
+    output = gss_request(input);
+    len = (int32_t )strlen(output);
     
     cout.write((char *)&len, 4);
-    cout << out;
-    deallocate_reply(out);
+    cout << output;
+    deallocate_reply(output);
     cout.flush();
-#ifndef WIN32
   } while(1);
-#endif
   return 0;
 }