ReactOS  0.4.15-dev-499-g1f31905
wsautil.c File Reference
#include <ws2_32.h>
Include dependency graph for wsautil.c:

Go to the source code of this file.

Functions

HKEY WSAAPI WsOpenRegistryRoot (VOID)
 
BOOL WSAAPI WsCheckCatalogState (IN HANDLE Event)
 
INT WSAAPI WsApiProlog (OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
 
INT WSAAPI WsSlowProlog (VOID)
 
INT WSAAPI WsSlowPrologTid (OUT LPWSATHREADID *ThreadId)
 
INT WSAAPI WsSetupCatalogProtection (IN HKEY CatalogKey, IN HANDLE CatalogEvent, OUT LPDWORD UniqueId)
 
INT WSAAPI MapUnicodeProtocolInfoToAnsi (IN LPWSAPROTOCOL_INFOW UnicodeInfo, OUT LPWSAPROTOCOL_INFOA AnsiInfo)
 
VOID WSAAPI WEP (VOID)
 

Function Documentation

◆ MapUnicodeProtocolInfoToAnsi()

INT WSAAPI MapUnicodeProtocolInfoToAnsi ( IN LPWSAPROTOCOL_INFOW  UnicodeInfo,
OUT LPWSAPROTOCOL_INFOA  AnsiInfo 
)

Definition at line 224 of file wsautil.c.

226 {
228 
229  /* Copy all the data that doesn't need converting */
230  RtlCopyMemory(AnsiInfo,
231  UnicodeInfo,
232  FIELD_OFFSET(WSAPROTOCOL_INFOA, szProtocol));
233 
234  /* Now convert the protocol string */
236  0,
237  UnicodeInfo->szProtocol,
238  -1,
239  AnsiInfo->szProtocol,
240  sizeof(AnsiInfo->szProtocol),
241  NULL,
242  NULL);
243  if (!ReturnValue) return WSASYSCALLFAILURE;
244 
245  /* Return success */
246  return ERROR_SUCCESS;
247 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
int32_t INT
Definition: typedefs.h:57
UINT32 void void ** ReturnValue
Definition: acevents.h:214
smooth NULL
Definition: ftsmooth.c:416
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254

Referenced by getsockopt(), and WSADuplicateSocketA().

◆ WEP()

VOID WSAAPI WEP ( VOID  )

Definition at line 254 of file wsautil.c.

255 {
256  return;
257 }

◆ WsApiProlog()

INT WSAAPI WsApiProlog ( OUT PWSPROCESS Process,
OUT PWSTHREAD Thread 
)

Definition at line 91 of file wsautil.c.

93 {
95 
96  /* Try to get the current process */
97  if ((*Process = WsGetProcess()))
98  {
99  /* And the current thread */
101  }
102 
103  /* Return init status */
104  return ErrorCode;
105 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
int32_t INT
Definition: typedefs.h:57
FORCEINLINE PWSPROCESS WsGetProcess(VOID)
Definition: ws2_32p.h:885
#define WSANOTINITIALISED
Definition: winerror.h:1987
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
DWORD WSAAPI WsThreadGetCurrentThread(IN PWSPROCESS Process, IN PWSTHREAD *Thread)
Definition: dthread.c:279
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by connect(), gethostbyaddr(), gethostbyname(), getprotobyname(), getprotobynumber(), getservbyname(), getservbyport(), getsockopt(), inet_ntoa(), setsockopt(), socket(), WPUQueryBlockingCallback(), WSAAccept(), WSAAddressToStringA(), WSAAddressToStringW(), WSAAsyncGetHostByAddr(), WSAAsyncGetHostByName(), WSAAsyncGetProtoByName(), WSAAsyncGetProtoByNumber(), WSAAsyncGetServByName(), WSAAsyncGetServByPort(), WSACancelAsyncRequest(), WSACancelBlockingCall(), WSACleanup(), WSAIsBlocking(), WSAJoinLeaf(), WSALookupServiceBeginW(), WSALookupServiceEnd(), WSALookupServiceNextW(), WSARecvDisconnect(), WSASendDisconnect(), WSASetBlockingHook(), WSASocketW(), WSAStringToAddressA(), WSAStringToAddressW(), WSAUnhookBlockingHook(), WSCGetProviderPath(), WsSlowProlog(), and WsSlowPrologTid().

◆ WsCheckCatalogState()

BOOL WSAAPI WsCheckCatalogState ( IN HANDLE  Event)

Definition at line 75 of file wsautil.c.

76 {
77  DWORD Return;
78 
79  /* Wait for the object */
80  Return = WaitForSingleObject(Event, 0);
81 
82  /* Check for the value */
83  if (Return == WAIT_OBJECT_0) return TRUE;
84 
85  /* If it timedout or anything else, return false */
86  return FALSE;
87 }
#define TRUE
Definition: types.h:120
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define WAIT_OBJECT_0
Definition: winbase.h:387
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by WsNcRefreshFromRegistry(), WsProcGetNsCatalog(), WsProcGetTCatalog(), and WsTcRefreshFromRegistry().

◆ WsOpenRegistryRoot()

HKEY WSAAPI WsOpenRegistryRoot ( VOID  )

Definition at line 17 of file wsautil.c.

18 {
19  HKEY WinsockRootKey;
20  INT ErrorCode;
22 
23  /* Open Registry Key */
26  0,
28  &WinsockRootKey);
29 
30  /* Check if it wasn't found */
32  {
33  /* Create it */
36  0,
37  NULL,
40  NULL,
41  &WinsockRootKey,
43  }
44  else if (ErrorCode == ERROR_SUCCESS)
45  {
46  /* It already exists */
48  }
49 
50  /* Check for failure */
51  if (ErrorCode != ERROR_SUCCESS) return NULL;
52 
53  /* Check if we had to create a new key */
55  {
56  /* Write the Winsock Version */
57  RegSetValueEx(WinsockRootKey,
58  "WinSock_Registry_Version",
59  0,
60  REG_SZ,
61  (BYTE*)"2.2",
62  4);
63  }
64  else
65  {
66  /* Read the Winsock Version */
67  }
68 
69  /* Return the key */
70  return WinsockRootKey;
71 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
int32_t INT
Definition: typedefs.h:57
#define WINSOCK_ROOT
Definition: ws2_32p.h:10
smooth NULL
Definition: ftsmooth.c:416
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
unsigned char BYTE
Definition: xxhash.c:193
#define RegOpenKeyEx
Definition: winreg.h:520
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
unsigned int ULONG
Definition: retypes.h:1
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT _In_ ULONG CreateDisposition
Definition: create.c:4137
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by OpenInitializedCatalog(), WsProcInitialize(), and WsRasLoadHelperDll().

◆ WsSetupCatalogProtection()

INT WSAAPI WsSetupCatalogProtection ( IN HKEY  CatalogKey,
IN HANDLE  CatalogEvent,
OUT LPDWORD  UniqueId 
)

Definition at line 142 of file wsautil.c.

145 {
146  INT ErrorCode;
147  HKEY RegistryKey;
148  DWORD NewUniqueId;
149  CHAR KeyBuffer[32];
150  DWORD RegType = REG_DWORD;
151  DWORD RegSize = sizeof(DWORD);
152 
153  /* Start loop */
154  do
155  {
156 #if 0
157  /* Ask for notifications */
158  ErrorCode = RegNotifyChangeKeyValue(CatalogKey,
159  FALSE,
161  CatalogEvent,
162  TRUE);
163  if (ErrorCode != ERROR_SUCCESS)
164  {
165  /* Normalize error code */
167  break;
168  }
169 #endif
170 
171  /* Read the current ID */
172  ErrorCode = RegQueryValueEx(CatalogKey,
173  "Serial_Access_Num",
174  0,
175  &RegType,
176  (LPBYTE)&NewUniqueId,
177  &RegSize);
178  if (ErrorCode != ERROR_SUCCESS)
179  {
180  /* Critical failure */
182  break;
183  }
184 
185  /* Try to open it for writing */
186  sprintf(KeyBuffer, "%8.8lX", NewUniqueId);
187  ErrorCode = RegOpenKeyEx(CatalogKey,
188  KeyBuffer,
189  0,
191  &RegistryKey);
192 
193  /* If the key doesn't exist or is being delete, that's ok for us */
194  if ((ErrorCode == ERROR_FILE_NOT_FOUND) ||
196  {
197  /* Set success and return the new ID */
199  *UniqueId = NewUniqueId;
200  break;
201  }
202  else if (ErrorCode != ERROR_SUCCESS)
203  {
204  /* Any other failure is bad */
206  break;
207  }
208 
209  /* If we could actually open the key, someone is using it :/ */
210  ErrorCode = RegCloseKey(RegistryKey);
211 
212  /* In case we break out prematurely */
214 
215  /* Keep looping until they let go of the registry writing */
216  } while (!WaitForSingleObject(CatalogEvent, 180 * 1000));
217 
218  /* Return error code */
219  return ErrorCode;
220 }
#define RegQueryValueEx
Definition: winreg.h:524
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
char CHAR
Definition: xmlstorage.h:175
#define REG_NOTIFY_CHANGE_NAME
Definition: winreg.h:38
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:57
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define ERROR_KEY_DELETED
Definition: winerror.h:597
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define WSANO_RECOVERY
Definition: winerror.h:2002
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define RegOpenKeyEx
Definition: winreg.h:520
LONG WINAPI RegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, DWORD dwNotifyFilter, HANDLE hEvent, BOOL fAsynchronous)
Definition: reg.c:3175
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by WsNcRefreshFromRegistry(), and WsTcRefreshFromRegistry().

◆ WsSlowProlog()

INT WSAAPI WsSlowProlog ( VOID  )

Definition at line 109 of file wsautil.c.

110 {
113 
114  /* Call the prolog */
115  return WsApiProlog(&Process, &Thread);
116 }
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by WsQuickProlog().

◆ WsSlowPrologTid()

INT WSAAPI WsSlowPrologTid ( OUT LPWSATHREADID ThreadId)

Definition at line 120 of file wsautil.c.

121 {
124  INT ErrorCode;
125 
126  /* Call the prolog */
128 
129  /* Check for success */
130  if (ErrorCode == ERROR_SUCCESS)
131  {
132  /* Return the Thread ID */
133  *ThreadId = &Thread->WahThreadId;
134  }
135 
136  /* Return status */
137  return ErrorCode;
138 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
int32_t INT
Definition: typedefs.h:57
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by WsQuickPrologTid().