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.

275 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. NdsApi95.c
  5. Abstract:
  6. NdsApi32 routines specific for Win95. Routines will call into the Windows95
  7. NWAPI32.DLL directly.
  8. Author:
  9. Felix Wong [t-felixw] 23-Sept-1996
  10. --*/
  11. #include <procs.h>
  12. #include <nw95.h>
  13. #include <msnwapi.h>
  14. #include <utils95.h>
  15. #include <nwatch95.h>
  16. // Ported from WIN95
  17. void
  18. MadeDSTreeNameDisplayableHack(
  19. LPSTR lpszDSName
  20. )
  21. {
  22. int i;
  23. LPSTR lpszStartTail = NULL;
  24. if (!lpszDSName)
  25. return;
  26. // Tree name is padded by 0x5f looks rather ugly if displayed
  27. // So we cut off tail of underscores, but being careful with
  28. // DBCS characters
  29. i = MAX_NDS_TREE_CHARS;
  30. while (*lpszDSName && i--) {
  31. if (*lpszDSName == 0x5f) {
  32. if (!lpszStartTail) {
  33. lpszStartTail = lpszDSName;
  34. }
  35. }
  36. else {
  37. lpszStartTail = NULL;
  38. }
  39. lpszDSName = CharNextA(lpszDSName);
  40. }
  41. if (lpszStartTail) {
  42. *lpszStartTail = '\0';
  43. }
  44. }
  45. // Ported from WIN95
  46. BOOL GetCurrentTree(LPSTR szPrefTree)
  47. {
  48. NW_STATUS NWStatus;
  49. NWStatus = NetWGetPreferredName(NETW_DirectoryServer,szPrefTree);
  50. if (NWStatus != NWSC_SUCCESS)
  51. return FALSE;
  52. MadeDSTreeNameDisplayableHack(szPrefTree);
  53. return TRUE;
  54. };
  55. NTSTATUS
  56. NwNdsResolveNameWin95 (
  57. IN HANDLE hNdsTree,
  58. IN PUNICODE_STRING puObjectName,
  59. OUT DWORD *pdwObjectId,
  60. OUT HANDLE *pConn,
  61. OUT PBYTE pbRawResponse,
  62. IN DWORD dwResponseBufferLen
  63. )
  64. {
  65. NTSTATUS NtStatus = STATUS_UNSUCCESSFUL;
  66. LPSTR ParentName;
  67. ParentName = AllocateAnsiString((LPWSTR)(puObjectName->Buffer));
  68. if (ParentName) {
  69. NW_STATUS NwStatus;
  70. // puObjectName->Buffer is a wide string but might not be necessarily
  71. // terminating at the right place. So, we need the following to null
  72. // terminaite the string correctly.
  73. ParentName[(puObjectName->Length)/2] = '\0';
  74. NwStatus = ResolveNameA(ParentName,
  75. RSLV_DEREF_ALIASES|RSLV_WALK_TREE|RSLV_WRITABLE,
  76. pdwObjectId,
  77. pConn);
  78. NtStatus = MapNwToNtStatus(NwStatus);
  79. FreeAnsiString(ParentName);
  80. };
  81. return NtStatus;
  82. }
  83. NTSTATUS
  84. NwOpenHandleWithSupplementalCredentials(
  85. IN PUNICODE_STRING puResourceName,
  86. IN PUNICODE_STRING puUserName,
  87. IN PUNICODE_STRING puPassword,
  88. OUT LPDWORD lpdwHandleType,
  89. OUT PHANDLE phNwHandle
  90. ) {
  91. return NwNdsOpenTreeHandle( puResourceName,
  92. phNwHandle);
  93. }
  94. NTSTATUS
  95. NwNdsOpenTreeHandle(
  96. IN PUNICODE_STRING puNdsTree,
  97. OUT PHANDLE phNwRdrHandle
  98. ) {
  99. LPSTR szTree;
  100. NTSTATUS NtStatus = STATUS_UNSUCCESSFUL;
  101. CHAR szPrefTree[MAX_NDS_TREE_CHARS+1] = {'\0'};
  102. NWCONN_HANDLE handle;
  103. szTree = AllocateAnsiString((LPWSTR)(puNdsTree->Buffer));
  104. if (szTree) {
  105. NW_STATUS NwStatus;
  106. // puObjectName->Buffer is a wide string but might not be necessarily
  107. // terminating at the right place. So, we need the following to null
  108. // terminaite the string correctly.
  109. szTree[(puNdsTree->Length)/2] = '\0';
  110. if (GetCurrentTree(szPrefTree) &&
  111. (lstrcmpiA(szTree,szPrefTree) == 0 )) {
  112. NwStatus = NetWGetPreferredConnID(NETW_DirectoryServer,
  113. phNwRdrHandle);
  114. NtStatus = MapNwToNtStatus(NwStatus);
  115. }
  116. FreeAnsiString(szTree);
  117. }
  118. return NtStatus;
  119. }
  120. int
  121. _cdecl
  122. CalculateBuf(
  123. const char *format,
  124. va_list args
  125. );
  126. NTSTATUS
  127. _cdecl
  128. FragExWithWait(
  129. IN HANDLE hNdsServer,
  130. IN DWORD NdsVerb,
  131. IN BYTE *pReplyBuffer,
  132. IN DWORD ReplyBufferLen,
  133. IN OUT DWORD *pdwReplyLen,
  134. IN BYTE *NdsRequestStr,
  135. ...
  136. )
  137. /*
  138. Routine Description:
  139. Exchanges an NDS request in fragments and collects the fragments
  140. of the response and writes them to the reply buffer.
  141. Routine Arguments:
  142. hNdsServer - A handle to the server you want to talk to.
  143. NdsVerb - The verb for that indicates the request.
  144. pReplyBuffer - The reply buffer.
  145. ReplyBufferLen - The length of the reply buffer.
  146. NdsReqestStr - The format string for the arguments to this NDS request.
  147. Arguments - The arguments that satisfy the NDS format string.
  148. Return Value:
  149. NTSTATUS - Status of the exchange, but not the result code in the packet.
  150. */
  151. {
  152. NTSTATUS NtStatus;
  153. NW_STATUS NwStatus;
  154. BYTE *NdsRequestBuf;
  155. DWORD NdsRequestLen;
  156. PNWR_NDS_REQUEST_PACKET RawRequest;
  157. int bufferSize = 0;
  158. va_list Arguments;
  159. //
  160. // Allocate a request buffer.
  161. //
  162. //
  163. // Calculate needed buffer size . . .
  164. //
  165. if ( NdsRequestStr != NULL ) {
  166. va_start( Arguments, NdsRequestStr );
  167. bufferSize = CalculateBuf( NdsRequestStr, Arguments );
  168. va_end( Arguments );
  169. if ( bufferSize == 0 )
  170. {
  171. NtStatus = STATUS_INVALID_PARAMETER;
  172. goto ExitWithCleanup;
  173. }
  174. }
  175. bufferSize += sizeof( NWR_NDS_REQUEST_PACKET ) + 50;
  176. RawRequest = LocalAlloc( LMEM_ZEROINIT, bufferSize );
  177. if ( !RawRequest ) {
  178. return STATUS_INSUFFICIENT_RESOURCES;
  179. }
  180. //
  181. // Build the request in our local buffer. The first DWORD
  182. // is the verb and the rest is the formatted request.
  183. //
  184. NdsRequestBuf = &RawRequest->Parameters.RawRequest.Request[0];
  185. if ( NdsRequestStr != NULL ) {
  186. va_start( Arguments, NdsRequestStr );
  187. NdsRequestLen = FormatBuf( NdsRequestBuf,
  188. bufferSize - sizeof( NWR_NDS_REQUEST_PACKET ),
  189. NdsRequestStr,
  190. Arguments );
  191. if ( !NdsRequestLen ) {
  192. NtStatus = STATUS_INVALID_PARAMETER;
  193. goto ExitWithCleanup;
  194. }
  195. va_end( Arguments );
  196. } else {
  197. NdsRequestLen = 0;
  198. }
  199. *pdwReplyLen = ReplyBufferLen;
  200. NwStatus = NDSRequest(hNdsServer,
  201. NdsVerb,
  202. NdsRequestBuf,
  203. NdsRequestLen,
  204. pReplyBuffer,
  205. pdwReplyLen
  206. );
  207. NtStatus = MapNwToNtStatus(NwStatus);
  208. ExitWithCleanup:
  209. if ( RawRequest ) {
  210. LocalFree( RawRequest );
  211. }
  212. return NtStatus;
  213. }