]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
libimcv: Port os_info (partially) to Windows
authorMartin Willi <martin@revosec.ch>
Wed, 8 Jan 2014 10:56:55 +0000 (11:56 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:53:06 +0000 (15:53 +0200)
src/libimcv/imc/imc_os_info.c
src/libimcv/os_info/os_info.c
src/libimcv/os_info/os_info.h

index 86a7f82e21df94398a52b89870cc9e8f2e031b4a..33f9bf5afa46f2f2a91ad94ebbc8af82a8b4afb0 100644 (file)
  * for more details.
  */
 
+/* for GetTickCount64, Windows 7 */
+#ifdef WIN32
+# define _WIN32_WINNT 0x0601
+#endif
+
 #include "imc_os_info.h"
 
-#include <sys/utsname.h>
 #include <stdio.h>
 #include <stdarg.h>
 
@@ -86,6 +90,69 @@ METHOD(imc_os_info_t, get_version, chunk_t,
        return this->version;
 }
 
+#ifdef WIN32
+
+METHOD(imc_os_info_t, get_fwd_status, os_fwd_status_t,
+       private_imc_os_info_t *this)
+{
+       return OS_FWD_UNKNOWN;
+}
+
+METHOD(imc_os_info_t, get_uptime, time_t,
+       private_imc_os_info_t *this)
+{
+       return GetTickCount64() / 1000;
+}
+
+METHOD(imc_os_info_t, get_setting, chunk_t,
+       private_imc_os_info_t *this, char *name)
+{
+       return chunk_empty;
+}
+
+METHOD(imc_os_info_t, create_package_enumerator, enumerator_t*,
+       private_imc_os_info_t *this)
+{
+       return NULL;
+}
+
+/**
+ * Determine Windows release
+ */
+static bool extract_platform_info(os_type_t *type, chunk_t *name,
+                                                                 chunk_t *version)
+{
+       OSVERSIONINFOEX osvie;
+       char buf[64];
+
+       memset(&osvie, 0, sizeof(osvie));
+       osvie.dwOSVersionInfoSize = sizeof(osvie);
+
+       if (!GetVersionEx((LPOSVERSIONINFO)&osvie))
+       {
+               return FALSE;
+       }
+       *type = OS_TYPE_WINDOWS;
+       if (osvie.wProductType == VER_NT_WORKSTATION)
+       {
+               *name = chunk_clone(chunk_from_str("Client"));
+       }
+       else
+       {
+               *name = chunk_clone(chunk_from_str("Server"));
+       }
+       snprintf(buf, sizeof(buf), "%d.%d.%d (SP %d.%d)",
+                        osvie.dwMajorVersion, osvie.dwMinorVersion, osvie.dwBuildNumber,
+                        osvie.wServicePackMajor, osvie.wServicePackMinor);
+       *version = chunk_clone(chunk_from_str(buf));
+
+       return TRUE;
+}
+
+#else /* !WIN32 */
+
+#include <sys/utsname.h>
+
 METHOD(imc_os_info_t, get_fwd_status, os_fwd_status_t,
        private_imc_os_info_t *this)
 {
@@ -294,15 +361,6 @@ METHOD(imc_os_info_t, create_package_enumerator, enumerator_t*,
        return (enumerator_t*)enumerator;
 }
 
-
-METHOD(imc_os_info_t, destroy, void,
-       private_imc_os_info_t *this)
-{
-       free(this->name.ptr);
-       free(this->version.ptr);
-       free(this);
-}
-
 #define RELEASE_LSB            0
 #define RELEASE_DEBIAN 1
 
@@ -505,6 +563,16 @@ static bool extract_platform_info(os_type_t *type, chunk_t *name,
        return TRUE;
 }
 
+#endif /* !WIN32 */
+
+METHOD(imc_os_info_t, destroy, void,
+       private_imc_os_info_t *this)
+{
+       free(this->name.ptr);
+       free(this->version.ptr);
+       free(this);
+}
+
 /**
  * See header
  */
index 67b09cd2f0ef2ba19ee46f5ac095afb087bab9aa..258b8b4427e1d76fb1d4a0390890ab83311b3a32 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "os_info.h"
 
-ENUM(os_type_names, OS_TYPE_UNKNOWN, OS_TYPE_ANDROID,
+ENUM(os_type_names, OS_TYPE_UNKNOWN, OS_TYPE_WINDOWS,
        "Unknown",
        "Debian",
        "Ubuntu",
@@ -24,7 +24,8 @@ ENUM(os_type_names, OS_TYPE_UNKNOWN, OS_TYPE_ANDROID,
        "CentOS",
        "SUSE",
        "Gentoo",
-       "Android"
+       "Android",
+       "Windows",
 );
 
 ENUM(os_fwd_status_names, OS_FWD_DISABLED, OS_FWD_UNKNOWN,
index e77d888a76d85ae6d0d595c340143b4039ede2db..031355458018e36ae4477df7371e2ec8eab0c30a 100644 (file)
@@ -40,6 +40,7 @@ enum os_type_t {
        OS_TYPE_SUSE,
        OS_TYPE_GENTOO,
        OS_TYPE_ANDROID,
+       OS_TYPE_WINDOWS,
        OS_TYPE_ROOF
 };