Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
6.4 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1995, Microsoft Corporation
  4. //
  5. // File: jnpt.cxx
  6. //
  7. // Contents: Junction point creation/deletion/modification related
  8. // functions
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 8-2-95 Sudk Created
  15. // 12-27-95 Milans Modified for NT/SUR
  16. //
  17. //-----------------------------------------------------------------------------
  18. #include "headers.hxx"
  19. #pragma hdrstop
  20. extern "C" {
  21. #include <string.h>
  22. #include <nodetype.h>
  23. #include <fsctrl.h>
  24. #include <dfsmrshl.h>
  25. #include <upkt.h>
  26. #include <ntddnfs.h>
  27. #include <dfsgluon.h>
  28. #include <dfserr.h>
  29. }
  30. #include "service.hxx"
  31. //+----------------------------------------------------------------------------
  32. //
  33. // Function: IsValidWin32Path
  34. //
  35. // Synopsis: Given a prefix, determines if it is a valid win32 path. This
  36. // routine checks for invalid names in win32, like com1 etc. It
  37. // also checks to see if the prefix, canonicalized for spaces,
  38. // ., and .. is still a valid prefix.
  39. //
  40. // Arguments: [pwszPrefix] -- The prefix to check
  41. //
  42. // Returns: TRUE if valid win32 path, FALSE otherwise
  43. //
  44. //-----------------------------------------------------------------------------
  45. BOOLEAN
  46. IsValidWin32Path(
  47. IN LPWSTR pwszPrefix)
  48. {
  49. BOOLEAN fIsValid = FALSE;
  50. UNICODE_STRING ustrWin32, ustrRoot;
  51. ULONG cwPrefix;
  52. WCHAR wszWin32Path[MAX_PATH];
  53. LPWSTR wszRoot = L"C:\\";
  54. LPWSTR wszRootAndPrefix;
  55. cwPrefix = wcslen( pwszPrefix );
  56. //
  57. // We don't allow the last character to be a backslash
  58. //
  59. if (cwPrefix == 0 || pwszPrefix[cwPrefix-1] == UNICODE_PATH_SEP) {
  60. return( FALSE );
  61. }
  62. //
  63. // Form a dummy path that looks like "c:\<pwszPrefix>"
  64. //
  65. if (cwPrefix < (MAX_PATH - 3)) {
  66. wszRootAndPrefix = wszWin32Path;
  67. } else {
  68. wszRootAndPrefix = new WCHAR[ 3 + cwPrefix + 1 ];
  69. if (wszRootAndPrefix == NULL) {
  70. return( FALSE );
  71. }
  72. }
  73. wcscpy( wszRootAndPrefix, wszRoot );
  74. if (pwszPrefix[0] == UNICODE_PATH_SEP)
  75. wcscat( wszRootAndPrefix, &pwszPrefix[1] );
  76. else
  77. wcscat( wszRootAndPrefix, pwszPrefix );
  78. //
  79. // Convert the dummy path to an NT path and compare against the root
  80. //
  81. if (RtlDosPathNameToNtPathName_U(wszRootAndPrefix, &ustrWin32, 0, 0)) {
  82. if (RtlDosPathNameToNtPathName_U(wszRoot, &ustrRoot, 0, 0)) {
  83. fIsValid = !RtlEqualUnicodeString(&ustrRoot, &ustrWin32, TRUE);
  84. RtlFreeUnicodeString( &ustrRoot );
  85. }
  86. RtlFreeUnicodeString( &ustrWin32 );
  87. }
  88. if (wszRootAndPrefix != wszWin32Path)
  89. delete [] wszRootAndPrefix;
  90. return( fIsValid );
  91. }
  92. //+-------------------------------------------------------------------------
  93. //
  94. // Function: DfsGetDSMachine
  95. //
  96. // Synopsis: This function sets DS_MACHINE property on machine object
  97. //
  98. // Arguments: [pwszServer] -- NetBIOS name of server for which DS_MACHINE
  99. // is required.
  100. //
  101. // [ppMachine] -- On successful return, contains pointer to
  102. // allocated DS_MACHINE.
  103. //
  104. //
  105. // History: 8-2-94 SudK Created
  106. // 12-27-95 Milans Modified for NT/SUR.
  107. //
  108. //--------------------------------------------------------------------------
  109. #define SIZE_OF_DS_MACHINE_WITH_1_ADDR \
  110. (sizeof(DS_MACHINE) + sizeof(LPWSTR) + sizeof(DS_TRANSPORT) + sizeof(TDI_ADDRESS_NETBIOS))
  111. DWORD
  112. DfsGetDSMachine(
  113. LPWSTR pwszServer,
  114. PDS_MACHINE *ppMachine
  115. )
  116. {
  117. DWORD dwErr;
  118. PDS_MACHINE pdsMachine;
  119. PDS_TRANSPORT pdsTransport;
  120. PTDI_ADDRESS_NETBIOS ptdiNB;
  121. LPWSTR wszPrincipalName;
  122. LPWSTR pwszNetBIOSName;
  123. IDfsVolInlineDebOut((DEB_TRACE, "DfsGetDSMachine(%ws)\n", pwszServer));
  124. ASSERT( pwszServer != NULL );
  125. pwszNetBIOSName = pwszServer;
  126. pdsMachine = (PDS_MACHINE) MarshalBufferAllocate(
  127. SIZE_OF_DS_MACHINE_WITH_1_ADDR +
  128. wcslen(pwszServer) * sizeof(WCHAR) +
  129. sizeof(UNICODE_NULL));
  130. if (pdsMachine != NULL) {
  131. ZeroMemory( pdsMachine, sizeof(DS_MACHINE) );
  132. //
  133. // Insert the principal name - simply domain\machine
  134. //
  135. pdsMachine->cPrincipals = 1;
  136. wszPrincipalName = (LPWSTR) (((PCHAR) pdsMachine) +
  137. SIZE_OF_DS_MACHINE_WITH_1_ADDR);
  138. wcscpy( wszPrincipalName, pwszServer );
  139. pdsMachine->prgpwszPrincipals = (LPWSTR *) (pdsMachine + 1);
  140. pdsMachine->prgpwszPrincipals[0] = wszPrincipalName;
  141. //
  142. // Build the NetBIOS DS_TRANSPORT structure
  143. //
  144. pdsMachine->cTransports = 1;
  145. pdsTransport = (PDS_TRANSPORT) (pdsMachine + 1);
  146. pdsTransport = (PDS_TRANSPORT)
  147. (((PUCHAR) pdsTransport) + sizeof(LPWSTR));
  148. pdsMachine->rpTrans[0] = pdsTransport;
  149. pdsTransport->usFileProtocol = FSP_SMB;
  150. pdsTransport->iPrincipal = 0;
  151. pdsTransport->grfModifiers = 0;
  152. //
  153. // Build the TA_ADDRESS_NETBIOS
  154. //
  155. pdsTransport->taddr.AddressLength = sizeof(TDI_ADDRESS_NETBIOS);
  156. pdsTransport->taddr.AddressType = TDI_ADDRESS_TYPE_NETBIOS;
  157. ptdiNB = (PTDI_ADDRESS_NETBIOS) &pdsTransport->taddr.Address[0];
  158. ptdiNB->NetbiosNameType = TDI_ADDRESS_NETBIOS_TYPE_UNIQUE;
  159. FillMemory( &ptdiNB->NetbiosName[0], 16, ' ' );
  160. wcstombs(
  161. (PCHAR) &ptdiNB->NetbiosName[0],
  162. pwszNetBIOSName,
  163. wcslen(pwszNetBIOSName));
  164. *ppMachine = pdsMachine;
  165. dwErr = ERROR_SUCCESS;
  166. } else {
  167. dwErr = ERROR_OUTOFMEMORY;
  168. }
  169. IDfsVolInlineDebOut((DEB_TRACE, "DfsGetDSMachine() exit\n"));
  170. return( dwErr );
  171. }
  172. //+----------------------------------------------------------------------------
  173. //
  174. // Function: DfsMachineFree
  175. //
  176. // Synopsis: Deallocates a DS_MACHINE allocated by DfsGetDSMachine.
  177. //
  178. // Arguments: [pMachine] -- Pointer to DS_MACHINE returned by
  179. // DfsGetDSMachine.
  180. //
  181. // Returns: Nothing
  182. //
  183. //-----------------------------------------------------------------------------
  184. VOID
  185. DfsMachineFree(
  186. PDS_MACHINE pMachine)
  187. {
  188. ULONG i;
  189. MarshalBufferFree(pMachine);
  190. return;
  191. }