ReactOS  0.4.15-dev-3182-g7b62228
nscatalo.c File Reference
#include <ws2_32.h>
#include <debug.h>
Include dependency graph for nscatalo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define WsNcLock()   EnterCriticalSection(&Catalog->Lock)
 
#define WsNcUnlock()   LeaveCriticalSection(&Catalog->Lock)
 

Functions

PNSCATALOG WSAAPI WsNcAllocate (VOID)
 
BOOLEAN WSAAPI WsNcOpen (IN PNSCATALOG Catalog, IN HKEY ParentKey)
 
INT WSAAPI WsNcInitializeFromRegistry (IN PNSCATALOG Catalog, IN HKEY ParentKey, IN HANDLE CatalogEvent)
 
INT WSAAPI WsNcRefreshFromRegistry (IN PNSCATALOG Catalog, IN HANDLE CatalogEvent)
 
VOID WSAAPI WsNcEnumerateCatalogItems (IN PNSCATALOG Catalog, IN PNSCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
 
INT WSAAPI WsNcLoadProvider (IN PNSCATALOG Catalog, IN PNSCATALOG_ENTRY CatalogEntry)
 
INT WSAAPI WsNcGetServiceClassInfo (IN PNSCATALOG Catalog, IN OUT LPDWORD BugSize, IN OUT LPWSASERVICECLASSINFOW lpServiceClassInfo)
 
VOID WSAAPI WsNcUpdateNamespaceList (IN PNSCATALOG Catalog, IN PLIST_ENTRY List)
 
INT WSAAPI WsNcGetCatalogFromProviderId (IN PNSCATALOG Catalog, IN LPGUID ProviderId, OUT PNSCATALOG_ENTRY *CatalogEntry)
 
BOOL WSAAPI WsNcMatchProtocols (IN DWORD NameSpace, IN LONG AddressFamily, IN LPWSAQUERYSETW QuerySet)
 
VOID WSAAPI WsNcRemoveCatalogItem (IN PNSCATALOG Catalog, IN PNSCATALOG_ENTRY Entry)
 
VOID WSAAPI WsNcDelete (IN PNSCATALOG Catalog)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file nscatalo.c.

◆ WsNcLock

#define WsNcLock ( )    EnterCriticalSection(&Catalog->Lock)

Definition at line 18 of file nscatalo.c.

◆ WsNcUnlock

#define WsNcUnlock ( )    LeaveCriticalSection(&Catalog->Lock)

Definition at line 19 of file nscatalo.c.

Function Documentation

◆ WsNcAllocate()

PNSCATALOG WSAAPI WsNcAllocate ( VOID  )

Definition at line 25 of file nscatalo.c.

26 {
27  PNSCATALOG Catalog;
28 
29  /* Allocate the catalog */
30  Catalog = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Catalog));
31 
32  /* Return it */
33  return Catalog;
34 }
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HANDLE WsSockHeap
Definition: dllmain.c:21

Referenced by WsProcInitialize().

◆ WsNcDelete()

VOID WSAAPI WsNcDelete ( IN PNSCATALOG  Catalog)

Definition at line 624 of file nscatalo.c.

625 {
627  PNSCATALOG_ENTRY CatalogEntry;
628 
629  /* Check if we're initialized */
630  if (!Catalog->CatalogList.Flink) return;
631 
632  /* Acquire lock */
633  WsNcLock();
634 
635  /* Loop every entry */
636  Entry = Catalog->CatalogList.Flink;
637  while (Entry != &Catalog->CatalogList)
638  {
639  /* Get this entry */
640  CatalogEntry = CONTAINING_RECORD(Entry, NSCATALOG_ENTRY, CatalogLink);
641 
642  /* Remove it and dereference it */
643  WsNcRemoveCatalogItem(Catalog, CatalogEntry);
644  WsNcEntryDereference(CatalogEntry);
645 
646  /* Move to the next entry */
647  Entry = Catalog->CatalogList.Flink;
648  }
649 
650  /* Check if the catalog key is opened */
651  if (Catalog->CatalogKey)
652  {
653  /* Close it */
654  RegCloseKey(Catalog->CatalogKey);
655  Catalog->CatalogKey = NULL;
656  }
657 
658  /* Release and delete the lock */
659  WsNcUnlock();
660  DeleteCriticalSection(&Catalog->Lock);
661 
662  /* Delete the object */
663  HeapFree(WsSockHeap, 0, Catalog);
664 }
struct _Entry Entry
Definition: kefuncs.h:627
VOID WSAAPI WsNcEntryDereference(IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatent.c:53
Definition: ws2_32p.h:121
#define WsNcUnlock()
Definition: nscatalo.c:19
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define WsNcLock()
Definition: nscatalo.c:18
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
Definition: typedefs.h:119
VOID WSAAPI WsNcRemoveCatalogItem(IN PNSCATALOG Catalog, IN PNSCATALOG_ENTRY Entry)
Definition: nscatalo.c:612
#define NULL
Definition: types.h:112
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:594
base of all file and directory entries
Definition: entries.h:82

Referenced by WsProcDelete().

◆ WsNcEnumerateCatalogItems()

VOID WSAAPI WsNcEnumerateCatalogItems ( IN PNSCATALOG  Catalog,
IN PNSCATALOG_ENUMERATE_PROC  Callback,
IN PVOID  Context 
)

Definition at line 371 of file nscatalo.c.

374 {
376  PNSCATALOG_ENTRY CatalogEntry;
377  BOOL GoOn = TRUE;
378 
379  /* Lock the catalog */
380  WsNcLock();
381 
382  /* Loop the entries */
383  Entry = Catalog->CatalogList.Flink;
384  while (GoOn && (Entry != &Catalog->CatalogList))
385  {
386  /* Get the entry */
387  CatalogEntry = CONTAINING_RECORD(Entry, NSCATALOG_ENTRY, CatalogLink);
388 
389  /* Move to the next one and call the callback */
390  Entry = Entry->Flink;
391  GoOn = Callback(Context, CatalogEntry);
392  }
393 
394  /* Release the lock */
395  WsNcUnlock();
396 }
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
Definition: ws2_32p.h:121
#define WsNcUnlock()
Definition: nscatalo.c:19
#define WsNcLock()
Definition: nscatalo.c:18
unsigned int BOOL
Definition: ntddk_ex.h:94
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: typedefs.h:119
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
base of all file and directory entries
Definition: entries.h:82

Referenced by WSAEnumNameSpaceProvidersInternal(), WSCGetProviderPath(), WsNqLookupServiceBegin(), and WsProcDelete().

◆ WsNcGetCatalogFromProviderId()

INT WSAAPI WsNcGetCatalogFromProviderId ( IN PNSCATALOG  Catalog,
IN LPGUID  ProviderId,
OUT PNSCATALOG_ENTRY CatalogEntry 
)

Definition at line 517 of file nscatalo.c.

520 {
522  PLIST_ENTRY NextEntry;
524 
525  /* Lock the catalog */
526  WsNcLock();
527 
528  /* Match the Id with all the entries in the List */
529  NextEntry = Catalog->CatalogList.Flink;
530  while (NextEntry != &Catalog->CatalogList)
531  {
532  /* Get the Current Entry */
533  Entry = CONTAINING_RECORD(NextEntry, NSCATALOG_ENTRY, CatalogLink);
534  NextEntry = NextEntry->Flink;
535 
536  /* Check if this is the Catalog Entry ID we want */
537  if (IsEqualGUID(&Entry->ProviderId, ProviderId))
538  {
539  /* If it doesn't already have a provider, load the provider */
540  if (!Entry->Provider)
541  ErrorCode = WsNcLoadProvider(Catalog, Entry);
542 
543  /* If we succeeded, reference the entry and return it */
544  if (Entry->Provider /* || ErrorCode == ERROR_SUCCESS */)
545  {
546  InterlockedIncrement(&Entry->RefCount);
547  *CatalogEntry = Entry;
549  break;
550  }
551  }
552  }
553 
554  /* Release the lock and return */
555  WsNcUnlock();
556  return ErrorCode;
557 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
struct _Entry Entry
Definition: kefuncs.h:627
#define WSAEINVAL
Definition: winerror.h:1946
Definition: ws2_32p.h:121
int32_t INT
Definition: typedefs.h:58
#define WsNcUnlock()
Definition: nscatalo.c:19
#define WsNcLock()
Definition: nscatalo.c:18
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: typedefs.h:119
#define InterlockedIncrement
Definition: armddk.h:53
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
INT WSAAPI WsNcLoadProvider(IN PNSCATALOG Catalog, IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatalo.c:400
base of all file and directory entries
Definition: entries.h:82

Referenced by WsNqLookupServiceBegin().

◆ WsNcGetServiceClassInfo()

INT WSAAPI WsNcGetServiceClassInfo ( IN PNSCATALOG  Catalog,
IN OUT LPDWORD  BugSize,
IN OUT LPWSASERVICECLASSINFOW  lpServiceClassInfo 
)

Definition at line 444 of file nscatalo.c.

447 {
448  /* Not yet implemented in the spec? */
450  return SOCKET_ERROR;
451 }
#define SOCKET_ERROR
Definition: winsock.h:333
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SetLastError(x)
Definition: compat.h:611

Referenced by WsNqLookupServiceBegin().

◆ WsNcInitializeFromRegistry()

INT WSAAPI WsNcInitializeFromRegistry ( IN PNSCATALOG  Catalog,
IN HKEY  ParentKey,
IN HANDLE  CatalogEvent 
)

Definition at line 211 of file nscatalo.c.

214 {
216 
217  /* Open the catalog */
218  if (WsNcOpen(Catalog, ParentKey))
219  {
220  /* Refresh it */
221  ErrorCode = WsNcRefreshFromRegistry(Catalog, CatalogEvent);
222  }
223 
224  /* Return the status */
225  return ErrorCode;
226 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
int32_t INT
Definition: typedefs.h:58
BOOLEAN WSAAPI WsNcOpen(IN PNSCATALOG Catalog, IN HKEY ParentKey)
Definition: nscatalo.c:38
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
INT WSAAPI WsNcRefreshFromRegistry(IN PNSCATALOG Catalog, IN HANDLE CatalogEvent)
Definition: nscatalo.c:230

Referenced by WsProcInitialize().

◆ WsNcLoadProvider()

INT WSAAPI WsNcLoadProvider ( IN PNSCATALOG  Catalog,
IN PNSCATALOG_ENTRY  CatalogEntry 
)

Definition at line 400 of file nscatalo.c.

402 {
405 
406  /* Lock the catalog */
407  WsNcLock();
408 
409  /* Check if we have a provider already */
410  if (!CatalogEntry->Provider)
411  {
412  /* Allocate a provider */
413  if ((Provider = WsNpAllocate()))
414  {
415  /* Initialize it */
417  CatalogEntry->DllPath,
418  &CatalogEntry->ProviderId);
419 
420  /* Ensure success */
421  if (ErrorCode == ERROR_SUCCESS)
422  {
423  /* Set the provider */
424  WsNcEntrySetProvider(CatalogEntry, Provider);
425  }
426 
427  /* Dereference it */
429  }
430  else
431  {
432  /* No memory */
434  }
435  }
436 
437  /* Release the lock and return */
438  WsNcUnlock();
439  return ErrorCode;
440 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WSAAPI WsNpInitialize(IN PNS_PROVIDER Provider, IN LPWSTR DllPath, IN LPGUID ProviderGuid)
Definition: nsprovid.c:82
int32_t INT
Definition: typedefs.h:58
#define WsNcUnlock()
Definition: nscatalo.c:19
#define WsNcLock()
Definition: nscatalo.c:18
VOID WSAAPI WsNpDereference(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:180
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:593
VOID WSAAPI WsNcEntrySetProvider(IN PNSCATALOG_ENTRY Entry, IN PNS_PROVIDER Provider)
Definition: nscatent.c:175
PNS_PROVIDER WSAAPI WsNpAllocate(VOID)
Definition: nsprovid.c:63

Referenced by WsNcGetCatalogFromProviderId(), and WsNqBeginEnumerationProc().

◆ WsNcMatchProtocols()

BOOL WSAAPI WsNcMatchProtocols ( IN DWORD  NameSpace,
IN LONG  AddressFamily,
IN LPWSAQUERYSETW  QuerySet 
)

Definition at line 561 of file nscatalo.c.

564 {
565  DWORD ProtocolCount = QuerySet->dwNumberOfProtocols;
566  LPAFPROTOCOLS AfpProtocols = QuerySet->lpafpProtocols;
567  LONG Family;
568 
569  /* Check for valid family */
570  if (AddressFamily != -1)
571  {
572  /* Check if it's the magic */
573  if (AddressFamily == AF_UNSPEC) return TRUE;
575  }
576  else
577  {
578  /* No family given, check for namespace */
579  if (NameSpace == NS_SAP)
580  {
581  /* Use IPX family */
582  Family = AF_IPX;
583  }
584  else
585  {
586  /* Other namespace, it's valid */
587  return TRUE;
588  }
589  }
590 
591  /* Now try to get a match */
592  while (ProtocolCount--)
593  {
594  /* Check this protocol entry */
595  if ((AfpProtocols->iAddressFamily == AF_UNSPEC) ||
596  (AfpProtocols->iAddressFamily == Family))
597  {
598  /* Match found */
599  return TRUE;
600  }
601 
602  /* Move to the next one */
603  AfpProtocols++;
604  }
605 
606  /* No match */
607  return FALSE;
608 }
IN PCO_ADDRESS_FAMILY AddressFamily
Definition: ndis.h:1906
#define TRUE
Definition: types.h:120
static int Family
Definition: ping.c:62
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define AF_UNSPEC
Definition: winsock.h:344
unsigned long DWORD
Definition: ntddk_ex.h:95
#define AF_IPX
Definition: winsock.h:350
INT iAddressFamily
Definition: winsock2.h:787
#define NS_SAP
Definition: nspapi.h:10

Referenced by WsNqBeginEnumerationProc().

◆ WsNcOpen()

BOOLEAN WSAAPI WsNcOpen ( IN PNSCATALOG  Catalog,
IN HKEY  ParentKey 
)

Definition at line 38 of file nscatalo.c.

40 {
43  HKEY CatalogKey, NewKey;
44  DWORD RegType = REG_DWORD;
45  DWORD RegSize = sizeof(DWORD);
46  DWORD UniqueId = 0;
47  DWORD NewData = 0;
48  CHAR* CatalogKeyName;
49 
50  /* Initialize the catalog lock and namespace list */
51  InitializeCriticalSection(&Catalog->Lock);
52  InitializeListHead(&Catalog->CatalogList);
53 
54  /* Read the catalog name */
56  "Current_NameSpace_Catalog",
57  0,
58  &RegType,
59  NULL,
60  &RegSize);
62  {
63  static const CHAR DefaultCatalogName[] = "NameSpace_Catalog5";
64  RegSize = sizeof(DefaultCatalogName);
65  CatalogKeyName = HeapAlloc(WsSockHeap, 0, RegSize);
66  memcpy(CatalogKeyName, DefaultCatalogName, RegSize);
67  }
68  else
69  {
70  if (ErrorCode != ERROR_SUCCESS)
71  {
72  DPRINT1("Failed to get namespace catalog name: %d.\n", ErrorCode);
73  return FALSE;
74  }
75 
76  if (RegType != REG_SZ)
77  {
78  DPRINT1("Namespace catalog name is not a string (Type %d).\n", RegType);
79  return FALSE;
80  }
81 
82  CatalogKeyName = HeapAlloc(WsSockHeap, 0, RegSize);
83 
84  /* Read the catalog name */
86  "Current_NameSpace_Catalog",
87  0,
88  &RegType,
89  (LPBYTE)CatalogKeyName,
90  &RegSize);
91 
92  /* Open the Catalog Key */
94  CatalogKeyName,
95  0,
97  &CatalogKey);
98  }
99 
100  /* If we didn't find the key, create it */
101  if (ErrorCode == ERROR_SUCCESS)
102  {
103  /* Fake that we opened an existing key */
105  }
106  else if (ErrorCode == ERROR_FILE_NOT_FOUND)
107  {
108  /* Create the Catalog Name */
110  CatalogKeyName,
111  0,
112  NULL,
115  NULL,
116  &CatalogKey,
118  }
119 
120  HeapFree(WsSockHeap, 0, CatalogKeyName);
121  RegType = REG_DWORD;
122  RegSize = sizeof(DWORD);
123 
124  /* Fail if that didn't work */
125  if (ErrorCode != ERROR_SUCCESS) return FALSE;
126 
127  /* Check if we had to create the key */
129  {
130  /* Write the count of entries (0 now) */
131  ErrorCode = RegSetValueEx(CatalogKey,
132  "Num_Catalog_Entries",
133  0,
134  REG_DWORD,
135  (LPBYTE)&NewData,
136  sizeof(NewData));
137  if (ErrorCode != ERROR_SUCCESS)
138  {
139  /* Close the key and fail */
140  RegCloseKey(CatalogKey);
141  return FALSE;
142  }
143 
144  /* Write the first catalog entry Uniqe ID */
145  NewData = 1;
146  ErrorCode = RegSetValueEx(CatalogKey,
147  "Serial_Access_Num",
148  0,
149  REG_DWORD,
150  (LPBYTE)&NewData,
151  sizeof(NewData));
152  if (ErrorCode != ERROR_SUCCESS)
153  {
154  /* Close the key and fail */
155  RegCloseKey(CatalogKey);
156  return FALSE;
157  }
158 
159  /* Create a key for this entry */
160  ErrorCode = RegCreateKeyEx(CatalogKey,
161  "Catalog_Entries",
162  0,
163  NULL,
166  NULL,
167  &NewKey,
169  if (ErrorCode != ERROR_SUCCESS)
170  {
171  /* Close the key and fail */
172  RegCloseKey(CatalogKey);
173  return FALSE;
174  }
175 
176  /* Close the key since we don't need it */
177  RegCloseKey(NewKey);
178  }
179  else
180  {
181  RegSize = sizeof(UniqueId);
182  /* Read the serial number */
183  ErrorCode = RegQueryValueEx(CatalogKey,
184  "Serial_Access_Num",
185  0,
186  &RegType,
187  (LPBYTE)&UniqueId,
188  &RegSize);
189 
190  /* Check if it's missing for some reason */
191  if (ErrorCode != ERROR_SUCCESS)
192  {
193  /* Write the first catalog entry Unique ID */
194  NewData = 1;
195  ErrorCode = RegSetValueEx(CatalogKey,
196  "Serial_Access_Num",
197  0,
198  REG_DWORD,
199  (LPBYTE)&NewData,
200  sizeof(NewData));
201  }
202  }
203 
204  /* Set the Catalog Key */
205  Catalog->CatalogKey = CatalogKey;
206  return TRUE;
207 }
#define RegQueryValueEx
Definition: winreg.h:524
#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 TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define DWORD
Definition: nt_native.h:44
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#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
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:112
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define RegOpenKeyEx
Definition: winreg.h:520
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define REG_DWORD
Definition: sdbapi.c:596
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:594
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define REG_SZ
Definition: layer.c:22

Referenced by WsNcInitializeFromRegistry().

◆ WsNcRefreshFromRegistry()

INT WSAAPI WsNcRefreshFromRegistry ( IN PNSCATALOG  Catalog,
IN HANDLE  CatalogEvent 
)

Definition at line 230 of file nscatalo.c.

232 {
233  INT ErrorCode;
234  BOOLEAN LocalEvent = FALSE;
235  LIST_ENTRY LocalList;
236  DWORD UniqueId;
237  HKEY EntriesKey;
238  DWORD CatalogEntries;
239  PNSCATALOG_ENTRY CatalogEntry;
240  BOOL NewChangesMade;
242  DWORD RegType = REG_DWORD;
243  DWORD RegSize = sizeof(DWORD);
244  DWORD i;
245 
246  /* Check if we got an event */
247  if (!CatalogEvent)
248  {
249  /* Create an event ourselves */
250  CatalogEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
251  if (!CatalogEvent) return WSASYSCALLFAILURE;
252  LocalEvent = TRUE;
253  }
254 
255  /* Lock the catalog */
256  WsNcLock();
257 
258  /* Initialize our local list for the loop */
259  InitializeListHead(&LocalList);
260 
261  /* Start looping */
262  do
263  {
264  /* Setup notifications for the catalog entry */
265  ErrorCode = WsSetupCatalogProtection(Catalog->CatalogKey,
266  CatalogEvent,
267  &UniqueId);
268  if (ErrorCode != ERROR_SUCCESS) break;
269 
270  /* Check if we've changed till now */
271  if (UniqueId == Catalog->UniqueId)
272  {
273  /* We haven't, so return */
275  break;
276  }
277 
278  /* Now Open the Entries */
279  ErrorCode = RegOpenKeyEx(Catalog->CatalogKey,
280  "Catalog_Entries",
281  0,
283  &EntriesKey);
284  if (ErrorCode != ERROR_SUCCESS)
285  {
286  /* Critical failure */
288  break;
289  }
290 
291  /* Find out how many there are */
292  ErrorCode = RegQueryValueEx(Catalog->CatalogKey,
293  "Num_Catalog_Entries",
294  0,
295  &RegType,
296  (LPBYTE)&CatalogEntries,
297  &RegSize);
298  if (ErrorCode != ERROR_SUCCESS)
299  {
300  /* Critical failure */
302  break;
303  }
304 
305  /* Initialize them all */
306  for (i = 1; i <= CatalogEntries; i++)
307  {
308  /* Allocate a Catalog Entry Structure */
309  CatalogEntry = WsNcEntryAllocate();
310  if (!CatalogEntry)
311  {
312  /* Not enough memory, fail */
314  break;
315  }
316 
317  /* Initialize it from the Registry Key */
319  EntriesKey,
320  i);
321  if (ErrorCode != ERROR_SUCCESS)
322  {
323  /* We failed to get it, dereference the entry and leave */
324  WsNcEntryDereference(CatalogEntry);
325  break;
326  }
327 
328  /* Insert it to our List */
329  InsertTailList(&LocalList, &CatalogEntry->CatalogLink);
330  }
331 
332  /* Close the catalog key */
333  RegCloseKey(EntriesKey);
334 
335  /* Check if we changed during our read and if we have success */
336  NewChangesMade = WsCheckCatalogState(CatalogEvent);
337  if (!NewChangesMade && ErrorCode == ERROR_SUCCESS)
338  {
339  /* All is good, update the protocol list */
340  WsNcUpdateNamespaceList(Catalog, &LocalList);
341 
342  /* Update and return */
343  Catalog->UniqueId = UniqueId;
344  break;
345  }
346 
347  /* We failed and/or catalog data changed, free what we did till now */
348  while (!IsListEmpty(&LocalList))
349  {
350  /* Get the LP Catalog Item */
351  Entry = RemoveHeadList(&LocalList);
352  CatalogEntry = CONTAINING_RECORD(Entry, NSCATALOG_ENTRY, CatalogLink);
353 
354  /* Dereference it */
355  WsNcEntryDereference(CatalogEntry);
356  }
357  } while (NewChangesMade);
358 
359  /* Release the lock */
360  WsNcUnlock();
361 
362  /* Close the event, if any was created by us */
363  if (LocalEvent) CloseHandle(CatalogEvent);
364 
365  /* All Done */
366  return ErrorCode;
367 }
#define CreateEvent
Definition: winbase.h:3604
#define RegQueryValueEx
Definition: winreg.h:524
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define CloseHandle
Definition: compat.h:598
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
VOID WSAAPI WsNcEntryDereference(IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatent.c:53
INT WSAAPI WsNcEntryInitializeFromRegistry(IN PNSCATALOG_ENTRY CatalogEntry, IN HKEY ParentKey, IN ULONG UniqueId)
Definition: nscatent.c:65
#define InsertTailList(ListHead, Entry)
LIST_ENTRY CatalogLink
Definition: ws2_32p.h:123
Definition: ws2_32p.h:121
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define WsNcUnlock()
Definition: nscatalo.c:19
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
#define WsNcLock()
Definition: nscatalo.c:18
unsigned int BOOL
Definition: ntddk_ex.h:94
INT WSAAPI WsSetupCatalogProtection(IN HKEY CatalogKey, IN HANDLE CatalogEvent, OUT LPDWORD UniqueId)
Definition: wsautil.c:142
unsigned char BOOLEAN
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID WSAAPI WsNcUpdateNamespaceList(IN PNSCATALOG Catalog, IN PLIST_ENTRY List)
Definition: nscatalo.c:455
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:593
BOOL WSAAPI WsCheckCatalogState(IN HANDLE Event)
Definition: wsautil.c:75
Definition: typedefs.h:119
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define RegOpenKeyEx
Definition: winreg.h:520
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
PNSCATALOG_ENTRY WSAAPI WsNcEntryAllocate(VOID)
Definition: nscatent.c:17
#define NULL
Definition: types.h:112
#define REG_DWORD
Definition: sdbapi.c:596
base of all file and directory entries
Definition: entries.h:82

Referenced by WsNcInitializeFromRegistry(), and WsProcGetNsCatalog().

◆ WsNcRemoveCatalogItem()

VOID WSAAPI WsNcRemoveCatalogItem ( IN PNSCATALOG  Catalog,
IN PNSCATALOG_ENTRY  Entry 
)

Definition at line 612 of file nscatalo.c.

614 {
615  /* Remove the entry from the list */
616  RemoveEntryList(&Entry->CatalogLink);
617 
618  /* Decrease our count */
619  Catalog->ItemCount--;
620 }
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
base of all file and directory entries
Definition: entries.h:82

Referenced by WsNcDelete().

◆ WsNcUpdateNamespaceList()

VOID WSAAPI WsNcUpdateNamespaceList ( IN PNSCATALOG  Catalog,
IN PLIST_ENTRY  List 
)

Definition at line 455 of file nscatalo.c.

457 {
458  LIST_ENTRY TempList;
459  PNSCATALOG_ENTRY CatalogEntry, OldCatalogEntry;
461 
462  /* First move from our list to the old one */
463  InsertHeadList(&Catalog->CatalogList, &TempList);
464  RemoveEntryList(&Catalog->CatalogList);
465  InitializeListHead(&Catalog->CatalogList);
466 
467  /* Loop every item on the list */
468  while (!IsListEmpty(List))
469  {
470  /* Get the catalog entry */
472  CatalogEntry = CONTAINING_RECORD(Entry, NSCATALOG_ENTRY, CatalogLink);
473 
474  /* Check if this item is already on our list */
475  Entry = TempList.Flink;
476  while (Entry != &TempList)
477  {
478  /* Get the catalog entry */
479  OldCatalogEntry = CONTAINING_RECORD(Entry, NSCATALOG_ENTRY, CatalogLink);
480  Entry = Entry->Flink;
481 
482  /* Check if they match */
483  if (IsEqualGUID(&CatalogEntry->ProviderId,
484  &OldCatalogEntry->ProviderId))
485  {
486  /* We have a match, use the old item instead */
487  WsNcEntryDereference(CatalogEntry);
488  CatalogEntry = OldCatalogEntry;
489  RemoveEntryList(&CatalogEntry->CatalogLink);
490 
491  /* Decrease the number of protocols we have */
492  Catalog->ItemCount--;
493  break;
494  }
495  }
496 
497  /* Add this item */
498  InsertTailList(&Catalog->CatalogList, &CatalogEntry->CatalogLink);
499  Catalog->ItemCount++;
500  }
501 
502  /* If there's anything left on the temporary list */
503  while (!IsListEmpty(&TempList))
504  {
505  /* Get the entry */
506  Entry = RemoveHeadList(&TempList);
507  CatalogEntry = CONTAINING_RECORD(Entry, NSCATALOG_ENTRY, CatalogLink);
508 
509  /* Remove it */
510  Catalog->ItemCount--;
511  WsNcEntryDereference(CatalogEntry);
512  }
513 }
struct _Entry Entry
Definition: kefuncs.h:627
VOID WSAAPI WsNcEntryDereference(IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatent.c:53
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define InsertTailList(ListHead, Entry)
LIST_ENTRY CatalogLink
Definition: ws2_32p.h:123
Definition: ws2_32p.h:121
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
Definition: typedefs.h:119
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
GUID ProviderId
Definition: ws2_32p.h:132
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
base of all file and directory entries
Definition: entries.h:82

Referenced by WsNcRefreshFromRegistry().