]> git.sur5r.net Git - bacula/bacula/commitdiff
Get full Windows Version display string
authorKern Sibbald <kern@sibbald.com>
Sat, 5 Mar 2011 20:47:41 +0000 (21:47 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:43:39 +0000 (14:43 +0200)
bacula/src/filed/job.c
bacula/src/filed/status.c
bacula/src/win32/compat/winhost.h
bacula/src/win32/libwin32/main.cpp

index 3071af4e33dc57cd77622bf10d72186f09039b48..69eb367279827aa711d945a08e98c0618d3c0a94 100644 (file)
@@ -543,7 +543,11 @@ static int job_cmd(JCR *jcr)
    Mmsg(jcr->errmsg, "JobId=%d Job=%s", jcr->JobId, jcr->Job);
    new_plugins(jcr);                  /* instantiate plugins for this jcr */
    generate_plugin_event(jcr, bEventJobStart, (void *)jcr->errmsg);
+#ifdef HAVE_WIN32
+   return dir->fsend(OKjob, VERSION, LSMDATE, win_os, DISTNAME, DISTVER);
+#else
    return dir->fsend(OKjob, VERSION, LSMDATE, HOST_OS, DISTNAME, DISTVER);
+#endif
 }
 
 static int runbefore_cmd(JCR *jcr)
index 3f10fd49da6b60551b063d1b8681ea256ab4ffa7..e29dd5d5e43d8abba97614a1683070e469dca851 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2001-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2001-2011 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -38,6 +38,9 @@
 
 extern void *start_heap;
 
+extern bool GetWindowsVersionString(char *buf, int maxsiz);
+
+
 /* Forward referenced functions */
 static void  list_terminated_jobs(STATUS_PKT *sp);
 static void  list_running_jobs(STATUS_PKT *sp);
@@ -87,6 +90,11 @@ static void  list_status_header(STATUS_PKT *sp)
         dt, num_jobs_run, job_count());
    sendit(msg.c_str(), len, sp);
 #if defined(HAVE_WIN32)
+   char buf[300];
+   if (GetWindowsVersionString(buf, sizeof(buf))) {
+      len = Mmsg(msg, "%s\n", buf);
+      sendit(msg.c_str(), len, sp);
+   }
    if (debug_level > 0) {
       if (!privs) {
          privs = enable_backup_privileges(NULL, 1);
index 58ecca2c9c3fc07fec456b2fd1909297c57c4a4b..9ca2ca204054cb1fb2e8525591a9f34255d0fae1 100644 (file)
@@ -37,7 +37,7 @@
 #undef DISTVER
 
 #ifdef HAVE_MINGW
-
+extern char win_os[];
 #define HOST_OS  "Linux"
 #define DISTNAME "Cross-compile"
 #ifndef BACULA
index 2c28b34d1686f787d03e335a6abe12dffacb7bb0..f744a6bb5e8a7755625a83c93f7e9f1fdd46977a 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
 #define _WIN32_WINNT 0x0501
 #include <commctrl.h>
 
+
 /* Globals */
 HINSTANCE appInstance;
 DWORD mainthreadId;
 bool opt_debug = false;
 bool have_service_api;
 DWORD service_thread_id = 0;
+char win_os[300];
+
+bool GetWindowsVersionString(LPTSTR osbuf, int maxsiz);
 
 
 #define MAX_COMMAND_ARGS 100
@@ -102,6 +106,8 @@ int WINAPI WinMain(HINSTANCE Instance, HINSTANCE /*PrevInstance*/, PSTR CmdLine,
       have_service_api = true;
    }
 
+   GetWindowsVersionString(win_os, sizeof(win_os));
+
    main_pid = getpid();
    main_tid = pthread_self();
 
@@ -393,3 +399,289 @@ void pause_msg(const char *file, const char *func, int line, const char *msg)
    }
    MessageBox(NULL, buf, "Pause", MB_OK);
 }
+
+#include <windows.h>
+#include <tchar.h>
+#include <stdio.h>
+
+#ifndef PRODUCT_UNLICENSED
+#define PRODUCT_UNLICENSED 0xABCDABCD
+#define PRODUCT_BUSINESS 0x00000006
+#define PRODUCT_BUSINESS_N 0x00000010
+#define PRODUCT_CLUSTER_SERVER 0x00000012
+#define PRODUCT_DATACENTER_SERVER 0x00000008
+#define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C
+#define PRODUCT_DATACENTER_SERVER_CORE_V 0x00000027
+#define PRODUCT_DATACENTER_SERVER_V 0x00000025
+#define PRODUCT_ENTERPRISE 0x00000004
+#define PRODUCT_ENTERPRISE_E 0x00000046
+#define PRODUCT_ENTERPRISE_N 0x0000001B
+#define PRODUCT_ENTERPRISE_SERVER 0x0000000A
+#define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E
+#define PRODUCT_ENTERPRISE_SERVER_CORE_V 0x00000029
+#define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F
+#define PRODUCT_ENTERPRISE_SERVER_V 0x00000026
+#define PRODUCT_HOME_BASIC 0x00000002
+#define PRODUCT_HOME_BASIC_E 0x00000043
+#define PRODUCT_HOME_BASIC_N 0x00000005
+#define PRODUCT_HOME_PREMIUM 0x00000003
+#define PRODUCT_HOME_PREMIUM_E 0x00000044
+#define PRODUCT_HOME_PREMIUM_N 0x0000001A
+#define PRODUCT_HYPERV 0x0000002A
+#define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT 0x0000001E
+#define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING 0x00000020
+#define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY 0x0000001F
+#define PRODUCT_PROFESSIONAL 0x00000030
+#define PRODUCT_PROFESSIONAL_E 0x00000045
+#define PRODUCT_PROFESSIONAL_N 0x00000031
+#define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018
+#define PRODUCT_SERVER_FOR_SMALLBUSINESS_V 0x00000023
+#define PRODUCT_SERVER_FOUNDATION 0x00000021
+#define PRODUCT_SMALLBUSINESS_SERVER 0x00000009
+#define PRODUCT_SOLUTION_EMBEDDEDSERVER 0x00000038
+#define PRODUCT_STANDARD_SERVER 0x00000007
+#define PRODUCT_STANDARD_SERVER_CORE 0x0000000D
+#define PRODUCT_STANDARD_SERVER_CORE_V 0x00000028
+#define PRODUCT_STANDARD_SERVER_V 0x00000024
+#define PRODUCT_STARTER 0x0000000B
+#define PRODUCT_STARTER_E 0x00000042
+#define PRODUCT_STARTER_N 0x0000002F
+#define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017
+#define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014
+#define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015
+#define PRODUCT_STORAGE_WORKGROUP_SERVER  0x00000016
+#define PRODUCT_UNDEFINED 0x00000000
+#define PRODUCT_ULTIMATE 0x00000001
+#define PRODUCT_ULTIMATE_E 0x00000047
+#define PRODUCT_ULTIMATE_N 0x0000001C
+#define PRODUCT_WEB_SERVER 0x00000011
+#define PRODUCT_WEB_SERVER_CORE 0x0000001D
+
+#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x19
+#define SM_SERVERR2 89
+#define VER_SERVER_NT 0x80000000
+
+#endif
+
+#ifndef PRODUCT_PROFESSIONAL
+#define PRODUCT_PROFESSIONAL 0x00000030
+#endif
+#ifndef VER_SUITE_STORAGE_SERVER
+#define VER_SUITE_STORAGE_SERVER 0x00002000
+#endif
+#ifndef VER_SUITE_COMPUTE_SERVER
+#define VER_SUITE_COMPUTE_SERVER 0x00004000
+#endif
+
+/* Unknown value */
+#define VER_SUITE_WH_SERVER -1
+
+
+typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
+typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
+
+/*
+ * Get Windows version display string
+ */
+bool GetWindowsVersionString(LPTSTR osbuf, int maxsiz)
+{
+   OSVERSIONINFOEX osvi;
+   SYSTEM_INFO si;
+   PGNSI pGNSI;
+   PGPI pGPI;
+   BOOL bOsVersionInfoEx;
+   DWORD dwType;
+
+   memset(&si, 0, sizeof(SYSTEM_INFO));
+   memset(&osvi, 0, sizeof(OSVERSIONINFOEX));
+
+   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+
+   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
+      return 1;
+
+   // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
+
+   pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), 
+           "GetNativeSystemInfo");
+   if (pGNSI) {
+      pGNSI(&si);
+   } else {
+      GetSystemInfo(&si);
+   }
+
+   if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion > 4) { 
+      bstrncpy(osbuf, TEXT("Microsoft "), maxsiz);
+
+      // Test for the specific product.
+
+      if (osvi.dwMajorVersion == 6) {
+         if (osvi.dwMinorVersion == 0) {
+            if (osvi.wProductType == VER_NT_WORKSTATION)
+                bstrncat(osbuf, TEXT("Windows Vista "), maxsiz);
+            else 
+                bstrncat(osbuf, TEXT("Windows Server 2008 " ), maxsiz);
+         }
+
+         if (osvi.dwMinorVersion == 1) {
+            if (osvi.wProductType == VER_NT_WORKSTATION )
+                bstrncat(osbuf, TEXT("Windows 7 "), maxsiz);
+            else 
+                bstrncat(osbuf, TEXT("Windows Server 2008 R2 " ), maxsiz);
+         }
+         
+         pGPI = (PGPI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), 
+            "GetProductInfo");
+
+         if (pGPI) {
+            pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
+         } else {
+            dwType = PRODUCT_HOME_BASIC;
+         }
+
+         switch (dwType) {
+            case PRODUCT_ULTIMATE:
+               bstrncat(osbuf, TEXT("Ultimate Edition" ), maxsiz);
+               break;
+            case PRODUCT_PROFESSIONAL:
+               bstrncat(osbuf, TEXT("Professional" ), maxsiz);
+               break;
+            case PRODUCT_HOME_PREMIUM:
+               bstrncat(osbuf, TEXT("Home Premium Edition" ), maxsiz);
+               break;
+            case PRODUCT_HOME_BASIC:
+               bstrncat(osbuf, TEXT("Home Basic Edition" ), maxsiz);
+               break;
+            case PRODUCT_ENTERPRISE:
+               bstrncat(osbuf, TEXT("Enterprise Edition" ), maxsiz);
+               break;
+            case PRODUCT_BUSINESS:
+               bstrncat(osbuf, TEXT("Business Edition" ), maxsiz);
+               break;
+            case PRODUCT_STARTER:
+               bstrncat(osbuf, TEXT("Starter Edition" ), maxsiz);
+               break;
+            case PRODUCT_CLUSTER_SERVER:
+               bstrncat(osbuf, TEXT("Cluster Server Edition" ), maxsiz);
+               break;
+            case PRODUCT_DATACENTER_SERVER:
+               bstrncat(osbuf, TEXT("Datacenter Edition" ), maxsiz);
+               break;
+            case PRODUCT_DATACENTER_SERVER_CORE:
+               bstrncat(osbuf, TEXT("Datacenter Edition (core installation)" ), maxsiz);
+               break;
+            case PRODUCT_ENTERPRISE_SERVER:
+               bstrncat(osbuf, TEXT("Enterprise Edition" ), maxsiz);
+               break;
+            case PRODUCT_ENTERPRISE_SERVER_CORE:
+               bstrncat(osbuf, TEXT("Enterprise Edition (core installation)" ), maxsiz);
+               break;
+            case PRODUCT_ENTERPRISE_SERVER_IA64:
+               bstrncat(osbuf, TEXT("Enterprise Edition for Itanium-based Systems" ), maxsiz);
+               break;
+            case PRODUCT_SMALLBUSINESS_SERVER:
+               bstrncat(osbuf, TEXT("Small Business Server" ), maxsiz);
+               break;
+            case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
+               bstrncat(osbuf, TEXT("Small Business Server Premium Edition" ), maxsiz);
+               break;
+            case PRODUCT_STANDARD_SERVER:
+               bstrncat(osbuf, TEXT("Standard Edition" ), maxsiz);
+               break;
+            case PRODUCT_STANDARD_SERVER_CORE:
+               bstrncat(osbuf, TEXT("Standard Edition (core installation)" ), maxsiz);
+               break;
+            case PRODUCT_WEB_SERVER:
+               bstrncat(osbuf, TEXT("Web Server Edition" ), maxsiz);
+               break;
+         }
+      }
+
+      if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) {
+         if( GetSystemMetrics(SM_SERVERR2) )
+            bstrncat(osbuf, TEXT( "Windows Server 2003 R2 "), maxsiz);
+         else if (osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER)
+            bstrncat(osbuf, TEXT( "Windows Storage Server 2003"), maxsiz);
+         else if (osvi.wSuiteMask & VER_SUITE_WH_SERVER )
+            bstrncat(osbuf, TEXT( "Windows Home Server"), maxsiz);
+         else if (osvi.wProductType == VER_NT_WORKSTATION &&
+                  si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
+            bstrncat(osbuf, TEXT( "Windows XP Professional x64 Edition"), maxsiz);
+         else 
+            bstrncat(osbuf, TEXT("Windows Server 2003 "), maxsiz);
+
+         // Test for the server type.
+         if (osvi.wProductType != VER_NT_WORKSTATION) {
+            if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64) {
+                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+                   bstrncat(osbuf, TEXT( "Datacenter Edition for Itanium-based Systems" ), maxsiz);
+                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+                   bstrncat(osbuf, TEXT( "Enterprise Edition for Itanium-based Systems" ), maxsiz);
+            }
+
+            else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
+                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+                   bstrncat(osbuf, TEXT( "Datacenter x64 Edition" ), maxsiz);
+                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+                   bstrncat(osbuf, TEXT( "Enterprise x64 Edition" ), maxsiz);
+                else bstrncat(osbuf, TEXT( "Standard x64 Edition" ), maxsiz);
+            } else {
+                if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
+                   bstrncat(osbuf, TEXT( "Compute Cluster Edition" ), maxsiz);
+                else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+                   bstrncat(osbuf, TEXT( "Datacenter Edition" ), maxsiz);
+                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+                   bstrncat(osbuf, TEXT( "Enterprise Edition" ), maxsiz);
+                else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
+                   bstrncat(osbuf, TEXT( "Web Edition" ), maxsiz);
+                else bstrncat(osbuf, TEXT( "Standard Edition" ), maxsiz);
+            }
+         }
+      }
+
+      if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) {
+         bstrncat(osbuf, TEXT("Windows XP "), maxsiz);
+         if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
+            bstrncat(osbuf, TEXT( "Home Edition" ), maxsiz);
+         else 
+            bstrncat(osbuf, TEXT( "Professional" ), maxsiz);
+      }
+
+      if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) {
+         bstrncat(osbuf, TEXT("Windows 2000 "), maxsiz);
+         if ( osvi.wProductType == VER_NT_WORKSTATION ) {
+            bstrncat(osbuf, TEXT( "Professional" ), maxsiz);
+         } else {
+            if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+               bstrncat(osbuf, TEXT( "Datacenter Server" ), maxsiz);
+            else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+               bstrncat(osbuf, TEXT( "Advanced Server" ), maxsiz);
+            else bstrncat(osbuf, TEXT( "Server" ), maxsiz);
+         }
+      }
+
+       // Include service pack (if any) and build number.
+
+      if (_tcslen(osvi.szCSDVersion) > 0) {
+          bstrncat(osbuf, TEXT(" ") , maxsiz);
+          bstrncat(osbuf, osvi.szCSDVersion, maxsiz);
+      }
+
+      char buf[80];
+
+      snprintf(buf, 80, " (build %d)", (int)osvi.dwBuildNumber);
+      bstrncat(osbuf, buf, maxsiz);
+
+      if (osvi.dwMajorVersion >= 6) {
+         if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
+            bstrncat(osbuf, TEXT( ", 64-bit" ), maxsiz);
+         else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
+            bstrncat(osbuf, TEXT(", 32-bit"), maxsiz);
+      }
+      
+      return true; 
+   } else {
+      bstrncpy(osbuf, "Unknown Windows version.", maxsiz);
+      return true;
+   }
+}