unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

win.c (12667B)

      1 /************************************************************************
      2  *   IRC - Internet Relay Chat, windows/win.c
      3  *   Copyright (C) 2004 Dominick Meglio (codemastr)
      4  *   
      5  *   This program is free software; you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation; either version 1, or (at your option)
      8  *   any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  *   GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program; if not, write to the Free Software
     17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18  */
     19 
     20 #include <windows.h>
     21 #include <tchar.h>
     22 #include <strsafe.h>
     23 
     24 #include "win.h"
     25 
     26 #pragma comment(lib, "User32.lib")
     27 
     28 // Newer product types than what is currently defined in
     29 //   Visual Studio 2005
     30 #ifndef PRODUCT_ULTIMATE
     31 #define PRODUCT_ULTIMATE                        0x00000001
     32 #endif
     33 #ifndef PRODUCT_HOME_BASIC
     34 #define PRODUCT_HOME_BASIC                      0x00000002
     35 #endif
     36 #ifndef PRODUCT_HOME_PREMIUM
     37 #define PRODUCT_HOME_PREMIUM                    0x00000003
     38 #endif
     39 #ifndef PRODUCT_ENTERPRISE
     40 #define PRODUCT_ENTERPRISE                      0x00000004
     41 #endif
     42 #ifndef PRODUCT_HOME_BASIC_N
     43 #define PRODUCT_HOME_BASIC_N                    0x00000005
     44 #endif
     45 #ifndef PRODUCT_BUSINESS
     46 #define PRODUCT_BUSINESS                        0x00000006
     47 #endif
     48 #ifndef PRODUCT_STANDARD_SERVER
     49 #define PRODUCT_STANDARD_SERVER                 0x00000007
     50 #endif
     51 #ifndef PRODUCT_DATACENTER_SERVER
     52 #define PRODUCT_DATACENTER_SERVER               0x00000008
     53 #endif
     54 #ifndef PRODUCT_SMALLBUSINESS_SERVER
     55 #define PRODUCT_SMALLBUSINESS_SERVER            0x00000009
     56 #endif
     57 #ifndef PRODUCT_ENTERPRISE_SERVER
     58 #define PRODUCT_ENTERPRISE_SERVER               0x0000000A
     59 #endif
     60 #ifndef PRODUCT_STARTER
     61 #define PRODUCT_STARTER                         0x0000000B
     62 #endif
     63 #ifndef PRODUCT_DATACENTER_SERVER_CORE
     64 #define PRODUCT_DATACENTER_SERVER_CORE          0x0000000C
     65 #endif
     66 #ifndef PRODUCT_STANDARD_SERVER_CORE
     67 #define PRODUCT_STANDARD_SERVER_CORE            0x0000000D
     68 #endif
     69 #ifndef PRODUCT_ENTERPRISE_SERVER_CORE
     70 #define PRODUCT_ENTERPRISE_SERVER_CORE          0x0000000E
     71 #endif
     72 #ifndef PRODUCT_ENTERPRISE_SERVER_IA64
     73 #define PRODUCT_ENTERPRISE_SERVER_IA64          0x0000000F
     74 #endif
     75 #ifndef PRODUCT_BUSINESS_N
     76 #define PRODUCT_BUSINESS_N                      0x00000010
     77 #endif
     78 #ifndef PRODUCT_WEB_SERVER
     79 #define PRODUCT_WEB_SERVER                      0x00000011
     80 #endif
     81 #ifndef PRODUCT_CLUSTER_SERVER
     82 #define PRODUCT_CLUSTER_SERVER                  0x00000012
     83 #endif
     84 #ifndef PRODUCT_HOME_SERVER
     85 #define PRODUCT_HOME_SERVER                     0x00000013
     86 #endif
     87 #ifndef PRODUCT_STORAGE_EXPRESS_SERVER
     88 #define PRODUCT_STORAGE_EXPRESS_SERVER          0x00000014
     89 #endif
     90 #ifndef PRODUCT_STORAGE_STANDARD_SERVER
     91 #define PRODUCT_STORAGE_STANDARD_SERVER         0x00000015
     92 #endif
     93 #ifndef PRODUCT_STORAGE_WORKGROUP_SERVER
     94 #define PRODUCT_STORAGE_WORKGROUP_SERVER        0x00000016
     95 #endif
     96 #ifndef PRODUCT_STORAGE_ENTERPRISE_SERVER
     97 #define PRODUCT_STORAGE_ENTERPRISE_SERVER       0x00000017
     98 #endif
     99 #ifndef PRODUCT_SERVER_FOR_SMALLBUSINESS
    100 #define PRODUCT_SERVER_FOR_SMALLBUSINESS        0x00000018
    101 #endif
    102 #ifndef PRODUCT_SMALLBUSINESS_SERVER_PREMIUM
    103 #define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM    0x00000019
    104 #endif
    105 
    106 // Newer system metrics values
    107 #ifndef SM_SERVERR2
    108 #define SM_SERVERR2 89   
    109 #endif
    110 
    111 #ifndef VER_SUITE_WH_SERVER
    112 #define VER_SUITE_WH_SERVER                     0x00008000
    113 #endif
    114 
    115 #ifndef VER_SUITE_STORAGE_SERVER
    116 #define VER_SUITE_STORAGE_SERVER                0x00002000
    117 #endif
    118 
    119 #ifndef VER_SUITE_COMPUTE_SERVER
    120 #define VER_SUITE_COMPUTE_SERVER                0x00004000
    121 #endif
    122 
    123 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
    124 typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
    125 
    126 
    127 
    128 /* Retrieves the OS name as a string
    129  * Parameters:
    130  * pszOS  - The buffer to write the OS name to (size at least OSVER_SIZE)
    131  */
    132 int GetOSName(char *pszOS)
    133 {
    134    OSVERSIONINFOEX osvi;
    135    SYSTEM_INFO si;
    136    PGNSI pGNSI;
    137    PGPI pGPI;
    138    BOOL bOsVersionInfoEx;
    139    DWORD dwType;
    140 
    141    ZeroMemory(&si, sizeof(SYSTEM_INFO));
    142    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    143 
    144    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    145 
    146    if ( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
    147       return -1;
    148 
    149    // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
    150 
    151    pGNSI = (PGNSI) GetProcAddress(
    152       GetModuleHandle(TEXT("kernel32.dll")), 
    153       "GetNativeSystemInfo");
    154    if (NULL != pGNSI)
    155       pGNSI(&si);
    156    else GetSystemInfo(&si);
    157 
    158    if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && 
    159         osvi.dwMajorVersion > 4 )
    160    {
    161       StringCchCopy(pszOS, OSVER_SIZE, TEXT("Microsoft "));
    162 
    163       // Test for the specific product.
    164 
    165       if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 )
    166       {
    167          if ( osvi.wProductType == VER_NT_WORKSTATION )
    168              StringCchCat(pszOS, OSVER_SIZE, TEXT("Windows 7 "));
    169          else StringCchCat(pszOS, OSVER_SIZE, TEXT("Windows Server 2008 R2 " ));
    170       }
    171       
    172       if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
    173       {
    174          if ( osvi.wProductType == VER_NT_WORKSTATION )
    175              StringCchCat(pszOS, OSVER_SIZE, TEXT("Windows Vista "));
    176          else StringCchCat(pszOS, OSVER_SIZE, TEXT("Windows Server 2008 " ));
    177 
    178          pGPI = (PGPI) GetProcAddress(
    179             GetModuleHandle(TEXT("kernel32.dll")), 
    180             "GetProductInfo");
    181 
    182          pGPI( 6, 0, 0, 0, &dwType);
    183 
    184          switch( dwType )
    185          {
    186             case PRODUCT_ULTIMATE:
    187                StringCchCat(pszOS, OSVER_SIZE, TEXT("Ultimate Edition" ));
    188                break;
    189             case PRODUCT_HOME_PREMIUM:
    190                StringCchCat(pszOS, OSVER_SIZE, TEXT("Home Premium Edition" ));
    191                break;
    192             case PRODUCT_HOME_BASIC:
    193                StringCchCat(pszOS, OSVER_SIZE, TEXT("Home Basic Edition" ));
    194                break;
    195             case PRODUCT_ENTERPRISE:
    196                StringCchCat(pszOS, OSVER_SIZE, TEXT("Enterprise Edition" ));
    197                break;
    198             case PRODUCT_BUSINESS:
    199                StringCchCat(pszOS, OSVER_SIZE, TEXT("Business Edition" ));
    200                break;
    201             case PRODUCT_STARTER:
    202                StringCchCat(pszOS, OSVER_SIZE, TEXT("Starter Edition" ));
    203                break;
    204             case PRODUCT_CLUSTER_SERVER:
    205                StringCchCat(pszOS, OSVER_SIZE, TEXT("Cluster Server Edition" ));
    206                break;
    207             case PRODUCT_DATACENTER_SERVER:
    208                StringCchCat(pszOS, OSVER_SIZE, TEXT("Datacenter Edition" ));
    209                break;
    210             case PRODUCT_DATACENTER_SERVER_CORE:
    211                StringCchCat(pszOS, OSVER_SIZE, TEXT("Datacenter Edition (core installation)" ));
    212                break;
    213             case PRODUCT_ENTERPRISE_SERVER:
    214                StringCchCat(pszOS, OSVER_SIZE, TEXT("Enterprise Edition" ));
    215                break;
    216             case PRODUCT_ENTERPRISE_SERVER_CORE:
    217                StringCchCat(pszOS, OSVER_SIZE, TEXT("Enterprise Edition (core installation)" ));
    218                break;
    219             case PRODUCT_ENTERPRISE_SERVER_IA64:
    220                StringCchCat(pszOS, OSVER_SIZE, TEXT("Enterprise Edition for Itanium-based Systems" ));
    221                break;
    222             case PRODUCT_SMALLBUSINESS_SERVER:
    223                StringCchCat(pszOS, OSVER_SIZE, TEXT("Small Business Server" ));
    224                break;
    225             case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
    226                StringCchCat(pszOS, OSVER_SIZE, TEXT("Small Business Server Premium Edition" ));
    227                break;
    228             case PRODUCT_STANDARD_SERVER:
    229                StringCchCat(pszOS, OSVER_SIZE, TEXT("Standard Edition" ));
    230                break;
    231             case PRODUCT_STANDARD_SERVER_CORE:
    232                StringCchCat(pszOS, OSVER_SIZE, TEXT("Standard Edition (core installation)" ));
    233                break;
    234             case PRODUCT_WEB_SERVER:
    235                StringCchCat(pszOS, OSVER_SIZE, TEXT("Web Server Edition" ));
    236                break;
    237          }
    238          if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
    239             StringCchCat(pszOS, OSVER_SIZE, TEXT( ", 64-bit" ));
    240          else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
    241             StringCchCat(pszOS, OSVER_SIZE, TEXT(", 32-bit"));
    242       }
    243 
    244       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
    245       {
    246          if ( GetSystemMetrics(SM_SERVERR2) )
    247             StringCchCat(pszOS, OSVER_SIZE, TEXT( "Windows Server 2003 R2, "));
    248          else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )
    249             StringCchCat(pszOS, OSVER_SIZE, TEXT( "Windows Storage Server 2003"));
    250          else if ( osvi.wSuiteMask==VER_SUITE_WH_SERVER )
    251             StringCchCat(pszOS, OSVER_SIZE, TEXT( "Windows Home Server"));
    252          else if ( osvi.wProductType == VER_NT_WORKSTATION &&
    253                   si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
    254          {
    255             StringCchCat(pszOS, OSVER_SIZE, TEXT( "Windows XP Professional x64 Edition"));
    256          }
    257          else StringCchCat(pszOS, OSVER_SIZE, TEXT("Windows Server 2003, "));
    258 
    259          // Test for the server type.
    260          if ( osvi.wProductType != VER_NT_WORKSTATION )
    261          {
    262             if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
    263             {
    264                 if ( osvi.wSuiteMask & VER_SUITE_DATACENTER )
    265                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Datacenter Edition for Itanium-based Systems" ));
    266                 else if ( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
    267                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Enterprise Edition for Itanium-based Systems" ));
    268             }
    269 
    270             else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
    271             {
    272                 if ( osvi.wSuiteMask & VER_SUITE_DATACENTER )
    273                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Datacenter x64 Edition" ));
    274                 else if ( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
    275                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Enterprise x64 Edition" ));
    276                 else StringCchCat(pszOS, OSVER_SIZE, TEXT( "Standard x64 Edition" ));
    277             }
    278 
    279             else
    280             {
    281                 if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
    282                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Compute Cluster Edition" ));
    283                 else if ( osvi.wSuiteMask & VER_SUITE_DATACENTER )
    284                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Datacenter Edition" ));
    285                 else if ( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
    286                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Enterprise Edition" ));
    287                 else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
    288                    StringCchCat(pszOS, OSVER_SIZE, TEXT( "Web Edition" ));
    289                 else StringCchCat(pszOS, OSVER_SIZE, TEXT( "Standard Edition" ));
    290             }
    291          }
    292       }
    293 
    294       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
    295       {
    296          StringCchCat(pszOS, OSVER_SIZE, TEXT("Windows XP "));
    297          if ( osvi.wSuiteMask & VER_SUITE_PERSONAL )
    298             StringCchCat(pszOS, OSVER_SIZE, TEXT( "Home Edition" ));
    299          else StringCchCat(pszOS, OSVER_SIZE, TEXT( "Professional" ));
    300       }
    301 
    302       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
    303       {
    304          StringCchCat(pszOS, OSVER_SIZE, TEXT("Windows 2000 "));
    305 
    306          if ( osvi.wProductType == VER_NT_WORKSTATION )
    307          {
    308             StringCchCat(pszOS, OSVER_SIZE, TEXT( "Professional" ));
    309          }
    310          else 
    311          {
    312             if ( osvi.wSuiteMask & VER_SUITE_DATACENTER )
    313               StringCchCat(pszOS, OSVER_SIZE, TEXT( "Datacenter Server" ));
    314             else if ( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
    315                StringCchCat(pszOS, OSVER_SIZE, TEXT( "Advanced Server" ));
    316             else StringCchCat(pszOS, OSVER_SIZE, TEXT( "Server" ));
    317          }
    318       }
    319 
    320        // Include service pack (if any) and build number.
    321 
    322       if ( _tcslen(osvi.szCSDVersion) > 0 )
    323       {
    324           StringCchCat(pszOS, OSVER_SIZE, TEXT(" ") );
    325           StringCchCat(pszOS, OSVER_SIZE, osvi.szCSDVersion);
    326       }
    327 
    328       {
    329           TCHAR buf[80];
    330 
    331           StringCchPrintf( buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);
    332           StringCchCat(pszOS, OSVER_SIZE, buf);
    333       }
    334 
    335       return 0; 
    336    }
    337    else
    338    {  
    339       return -1;
    340    }
    341 }