ReactOS 0.4.16-dev-297-gc569aee
network.c File Reference
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winsvc.h>
#include <ntddndis.h>
#include <ndk/exfuncs.h>
#include <ntsecapi.h>
#include <debug.h>
Include dependency graph for network.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define NDEBUG
 
#define SEED_BUFFER_SIZE   6
 

Functions

static BOOLEAN getMacAddress (UCHAR *MacAddress)
 
static VOID CookupNodeId (UCHAR *NodeId)
 
VOID DealWithDeviceEvent (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 21 of file network.c.

◆ SEED_BUFFER_SIZE

#define SEED_BUFFER_SIZE   6

Definition at line 24 of file network.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file network.c.

Function Documentation

◆ CookupNodeId()

static VOID CookupNodeId ( UCHAR NodeId)
static

Definition at line 37 of file network.c.

38{
39 CHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
40 CHAR * CurrentChar;
41 DWORD Size;
42 LARGE_INTEGER PerformanceCount;
43 PDWORD NodeBegin, NodeMiddle;
44 DWORD dwValue;
45 MEMORYSTATUS MemoryStatus;
46 LUID Luid;
47 WCHAR szSystem[MAX_PATH];
48 ULARGE_INTEGER FreeBytesToCaller, TotalBytes, TotalFreeBytes;
49
50 /* Initialize node id */
51 memset(NodeId, 0x11, SEED_BUFFER_SIZE * sizeof(UCHAR));
52
53 /* Randomize it with computer name */
55 if (GetComputerNameA(ComputerName, &Size))
56 {
57 Size = 0;
58 CurrentChar = &ComputerName[0];
59 while (*CurrentChar != ANSI_NULL)
60 {
61 NodeId[Size] ^= *CurrentChar;
62 ++CurrentChar;
63
64 /* Don't overflow our NodeId */
65 if (++Size >= SEED_BUFFER_SIZE)
66 {
67 Size = 0;
68 }
69 }
70 }
71
72 /* Now, we'll work directly on DWORD values */
73 NodeBegin = (DWORD *)&NodeId[0];
74 NodeMiddle = (DWORD *)&NodeId[2];
75
76 /* Randomize with performance counter */
77 if (QueryPerformanceCounter(&PerformanceCount))
78 {
79 *NodeMiddle = *NodeMiddle ^ PerformanceCount.u.HighPart ^ PerformanceCount.u.LowPart;
80
81 dwValue = PerformanceCount.u.HighPart ^ PerformanceCount.u.LowPart ^ *NodeBegin;
82 }
83 else
84 {
85 dwValue = *NodeBegin;
86 }
87
88 *NodeBegin = *NodeBegin ^ dwValue;
89 *NodeMiddle = *NodeMiddle ^ *NodeBegin;
90
91 /* Then, with memory status */
92 MemoryStatus.dwLength = sizeof(MemoryStatus);
93 GlobalMemoryStatus(&MemoryStatus);
94
95 *NodeBegin = *NodeBegin ^ MemoryStatus.dwMemoryLoad;
96 *NodeMiddle = *NodeMiddle ^ MemoryStatus.dwTotalPhys;
97 *NodeBegin = *NodeBegin ^ MemoryStatus.dwTotalPageFile ^ MemoryStatus.dwAvailPhys;
98 *NodeMiddle = *NodeMiddle ^ MemoryStatus.dwTotalVirtual ^ MemoryStatus.dwAvailPageFile;
99 *NodeBegin = *NodeBegin ^ MemoryStatus.dwAvailVirtual;
100
101 /* With a LUID */
102 if (AllocateLocallyUniqueId(&Luid))
103 {
104 *NodeBegin = *NodeBegin ^ Luid.LowPart;
105 *NodeMiddle = *NodeMiddle ^ Luid.HighPart;
106 }
107
108 /* Get system directory */
109 GetSystemDirectoryW(szSystem, ARRAYSIZE(szSystem));
110
111 /* And finally with free disk space */
112 if (GetDiskFreeSpaceExW(szSystem, &FreeBytesToCaller, &TotalBytes, &TotalFreeBytes))
113 {
114 *NodeMiddle ^= FreeBytesToCaller.LowPart ^ TotalFreeBytes.HighPart;
115 *NodeMiddle ^= FreeBytesToCaller.HighPart ^ TotalFreeBytes.LowPart;
116 *NodeBegin ^= TotalBytes.LowPart ^ TotalFreeBytes.LowPart;
117 *NodeBegin ^= TotalBytes.HighPart ^ TotalFreeBytes.HighPart;
118 }
119
120 /*
121 * Because it was locally generated, force the seed to be local
122 * setting this, will trigger the check for validness in the kernel
123 * and make the seed local
124 */
125 NodeId[0] |= 0x80u;
126}
#define SEED_BUFFER_SIZE
Definition: network.c:24
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI AllocateLocallyUniqueId(PLUID Luid)
Definition: security.c:1218
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, OUT PULARGE_INTEGER lpFreeBytesAvailableToCaller, OUT PULARGE_INTEGER lpTotalNumberOfBytes, OUT PULARGE_INTEGER lpTotalNumberOfFreeBytes)
Definition: disk.c:342
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
BOOL WINAPI QueryPerformanceCounter(OUT PLARGE_INTEGER lpPerformanceCount)
Definition: perfcnt.c:23
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID NTAPI GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
Definition: heapmem.c:1365
#define ANSI_NULL
DWORD * PDWORD
Definition: pedump.c:68
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
LONG HighPart
DWORD LowPart
SIZE_T dwTotalPhys
Definition: winbase.h:1243
DWORD dwLength
Definition: winbase.h:1241
DWORD dwMemoryLoad
Definition: winbase.h:1242
SIZE_T dwAvailPageFile
Definition: winbase.h:1246
SIZE_T dwAvailVirtual
Definition: winbase.h:1248
SIZE_T dwAvailPhys
Definition: winbase.h:1244
SIZE_T dwTotalPageFile
Definition: winbase.h:1245
SIZE_T dwTotalVirtual
Definition: winbase.h:1247
$ULONG LowPart
Definition: ntbasedef.h:577
$ULONG HighPart
Definition: ntbasedef.h:578
struct _LARGE_INTEGER::@2302 u
ULONG LowPart
Definition: typedefs.h:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:269
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS _In_ SIZE_T TotalBytes
Definition: mmfuncs.h:228
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by DealWithDeviceEvent().

◆ DealWithDeviceEvent()

VOID DealWithDeviceEvent ( VOID  )

Definition at line 128 of file network.c.

129{
131 UCHAR UuidSeed[SEED_BUFFER_SIZE];
132
133 /* First, try to get a multicast MAC address */
134 if (!getMacAddress(UuidSeed))
135 {
136 DPRINT1("Failed finding a proper MAC address, will generate seed\n");
137 CookupNodeId(UuidSeed);
138 }
139
140 /* Seed our UUID generator */
141 Status = NtSetUuidSeed(UuidSeed);
142 if (!NT_SUCCESS(Status))
143 {
144 DPRINT1("NtSetUuidSeed failed with status: %lx\n", Status);
145 }
146}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
static VOID CookupNodeId(UCHAR *NodeId)
Definition: network.c:37
static BOOLEAN getMacAddress(UCHAR *MacAddress)
Definition: network.c:29
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI NtSetUuidSeed(IN PUCHAR Seed)
Definition: uuid.c:547

◆ getMacAddress()

static BOOLEAN getMacAddress ( UCHAR MacAddress)
static

Definition at line 29 of file network.c.

30{
31 /* FIXME: query NDIS for all the interfaces */
33 return FALSE;
34}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define FALSE
Definition: types.h:117

Referenced by DealWithDeviceEvent().