henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_BASE_WIN32_H_ |
| 12 | #define RTC_BASE_WIN32_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | e062385 | 2018-02-01 11:17:40 +0100 | [diff] [blame] | 14 | #ifndef WEBRTC_WIN |
| 15 | #error "Only #include this header in Windows builds" |
| 16 | #endif |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 17 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 18 | #ifndef WIN32_LEAN_AND_MEAN |
| 19 | #define WIN32_LEAN_AND_MEAN |
| 20 | #endif |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 21 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 22 | // Make sure we don't get min/max macros |
| 23 | #ifndef NOMINMAX |
| 24 | #define NOMINMAX |
| 25 | #endif |
| 26 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 27 | // clang-format off |
| 28 | // clang formating would change include order. |
| 29 | #include <winsock2.h> // must come first |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 30 | #include <windows.h> |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 31 | // clang-format on |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 32 | |
Niels Möller | d7b9131 | 2018-05-24 11:21:34 +0200 | [diff] [blame] | 33 | typedef int socklen_t; |
| 34 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 35 | #ifndef SECURITY_MANDATORY_LABEL_AUTHORITY |
| 36 | // Add defines that we use if we are compiling against older sdks |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 37 | #define SECURITY_MANDATORY_MEDIUM_RID (0x00002000L) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 38 | #define TokenIntegrityLevel static_cast<TOKEN_INFORMATION_CLASS>(0x19) |
| 39 | typedef struct _TOKEN_MANDATORY_LABEL { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 40 | SID_AND_ATTRIBUTES Label; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 41 | } TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL; |
| 42 | #endif // SECURITY_MANDATORY_LABEL_AUTHORITY |
| 43 | |
| 44 | #undef SetPort |
| 45 | |
| 46 | #include <string> |
| 47 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 48 | namespace rtc { |
| 49 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 50 | const char* win32_inet_ntop(int af, const void* src, char* dst, socklen_t size); |
| 51 | int win32_inet_pton(int af, const char* src, void* dst); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 52 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 53 | // Convert a Utf8 path representation to a non-length-limited Unicode pathname. |
| 54 | bool Utf8ToWindowsFilename(const std::string& utf8, std::wstring* filename); |
| 55 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 56 | enum WindowsMajorVersions { |
| 57 | kWindows2000 = 5, |
| 58 | kWindowsVista = 6, |
braveyao | 8944f6a | 2018-04-06 10:59:50 -0700 | [diff] [blame] | 59 | kWindows10 = 10, |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 60 | }; |
| 61 | bool GetOsVersion(int* major, int* minor, int* build); |
| 62 | |
| 63 | inline bool IsWindowsVistaOrLater() { |
| 64 | int major; |
| 65 | return (GetOsVersion(&major, nullptr, nullptr) && major >= kWindowsVista); |
| 66 | } |
| 67 | |
| 68 | inline bool IsWindowsXpOrLater() { |
| 69 | int major, minor; |
| 70 | return (GetOsVersion(&major, &minor, nullptr) && |
| 71 | (major >= kWindowsVista || (major == kWindows2000 && minor >= 1))); |
| 72 | } |
| 73 | |
| 74 | inline bool IsWindows8OrLater() { |
| 75 | int major, minor; |
| 76 | return (GetOsVersion(&major, &minor, nullptr) && |
| 77 | (major > kWindowsVista || (major == kWindowsVista && minor >= 2))); |
| 78 | } |
| 79 | |
braveyao | 8944f6a | 2018-04-06 10:59:50 -0700 | [diff] [blame] | 80 | inline bool IsWindows10OrLater() { |
| 81 | int major; |
| 82 | return (GetOsVersion(&major, nullptr, nullptr) && (major >= kWindows10)); |
| 83 | } |
| 84 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 85 | // Determine the current integrity level of the process. |
| 86 | bool GetCurrentProcessIntegrityLevel(int* level); |
| 87 | |
| 88 | inline bool IsCurrentProcessLowIntegrity() { |
| 89 | int level; |
| 90 | return (GetCurrentProcessIntegrityLevel(&level) && |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 91 | level < SECURITY_MANDATORY_MEDIUM_RID); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | } // namespace rtc |
| 95 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 96 | #endif // RTC_BASE_WIN32_H_ |