Leaked source code of windows server 2003
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.

2485 lines
70 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. mpransi.cxx
  5. Abstract:
  6. Contains Ansi Entry points for the MPR api.
  7. Author:
  8. Dan Lafferty (danl) 20-Dec-1991
  9. Environment:
  10. User Mode -Win32
  11. Notes:
  12. I may want to add a buffer size parameter to ConvertToAnsi
  13. Revision History:
  14. 08-Aug-1996 anirudhs
  15. Major revision (simplification): Converted all remaining APIs to
  16. the smaller, faster interpreted scheme. Added ANSI_API_ macros.
  17. Eliminated helper functions used by the old scheme. These changes
  18. shrink this file by about 1400 lines.
  19. 16-Feb-1996 anirudhs
  20. Added InputParmsToUnicode, OutputBufferToAnsi and helper functions.
  21. These form a smaller, faster, interpreted scheme for writing the
  22. Ansi APIs. This scheme is smaller chiefly because it eliminates
  23. a very large amount of code duplication present in the previous
  24. scheme. This also makes the Ansi APIs less bug-prone. It is
  25. faster chiefly because intermediate storage is allocated with a
  26. single heap allocation per API, rather than several. Also, the
  27. number of passes to scan and copy data is minimized.
  28. 06-Oct-1995 anirudhs
  29. MprMakeUnicodeNetRes and related functions: Removed duplicated
  30. code for the string fields of the net resource; added code to
  31. iterate over the string fields instead. Fixed access violation
  32. and memory leaks.
  33. 24-Aug-1992 danl
  34. For WNetGetConnection & WNetGetUser, we allocate a buffer twice
  35. the size of the user buffer. The data is placed in this buffer.
  36. Then we check to see if the data will fit in the user buffer
  37. after it is translated to Ansi. The presence of DBSC characters
  38. may make it not fit. In which case, we return the required number
  39. of bytes. This number assumes worse-case where all characters are
  40. DBCS characters.
  41. 20-Dec-1991 danl
  42. created
  43. --*/
  44. //
  45. // INCLUDES
  46. //
  47. #include "precomp.hxx"
  48. #include <string.h> // strlen
  49. //
  50. // CONSTANTS
  51. //
  52. #define MAX_STRINGS_PER_API 6
  53. //
  54. // The following masks are used to indicate which fields in the NetResource
  55. // structure are used by an API.
  56. // The values must match the NRWField and NRAField arrays.
  57. //
  58. #define NETRESFIELD_LOCALNAME 0x00000001
  59. #define NETRESFIELD_REMOTENAME 0x00000002
  60. #define NETRESFIELD_COMMENT 0x00000004
  61. #define NETRESFIELD_PROVIDER 0x00000008
  62. #define NUMBER_OF_NETRESFIELD 4
  63. //
  64. // Combinations of the NETRESFIELD_ constants, for passing to InputParmsToUnicode.
  65. //
  66. #define NETRES_LRP "\xB" // local name, remote name, provider
  67. #define NETRES_RP "\xA" // remote name, provider
  68. //
  69. // Alignment macros
  70. // These macros assume that sizeof(WCHAR) and sizeof(DWORD) are powers of 2
  71. //
  72. #define ROUND_UP_TO_WCHAR(x) (((DWORD)(x) + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1))
  73. #define ROUND_UP_TO_DWORD(x) (((DWORD)(x) + sizeof(DWORD) - 1) & ~(sizeof(DWORD) - 1))
  74. #define IS_WCHAR_ALIGNED(x) (((ULONG_PTR)(x) & (sizeof(WCHAR) - 1)) == 0)
  75. #define IS_DWORD_ALIGNED(x) (((ULONG_PTR)(x) & (sizeof(DWORD) - 1)) == 0)
  76. //
  77. // Nearly every API ends this way
  78. //
  79. #define SET_AND_RETURN(status) \
  80. if (status != NO_ERROR) \
  81. { \
  82. SetLastError(status); \
  83. } \
  84. \
  85. return status;
  86. //
  87. // This is the general pattern of an Ansi wrapper for an API with no
  88. // output Ansi parameters. There are some exceptions.
  89. //
  90. #define ANSI_API_WITHOUT_ANSI_OUTPUT(NUMBER_OF_PARMS, \
  91. ANSI_PARM_ASSIGNMENT, \
  92. INSTRUCTION_STRING, \
  93. UNICODE_CALL) \
  94. \
  95. DWORD status; \
  96. LPBYTE tempBuffer = NULL; \
  97. ANSI_PARM AParm[NUMBER_OF_PARMS]; \
  98. UNICODE_PARM UParm[NUMBER_OF_PARMS]; \
  99. \
  100. ANSI_PARM_ASSIGNMENT \
  101. \
  102. status = InputParmsToUnicode(INSTRUCTION_STRING, AParm, UParm, &tempBuffer); \
  103. \
  104. if (status == WN_SUCCESS) \
  105. { \
  106. status = UNICODE_CALL \
  107. } \
  108. \
  109. LocalFree(tempBuffer); \
  110. \
  111. SET_AND_RETURN(status)
  112. //
  113. // This is the general pattern of an Ansi wrapper for an API that
  114. // has output Ansi parameters. There are some exceptions.
  115. //
  116. #define ANSI_API_WITH_ANSI_OUTPUT(NUMBER_OF_PARMS, \
  117. ANSI_PARM_ASSIGNMENT, \
  118. INSTRUCTION_STRING, \
  119. UNICODE_CALL, \
  120. OUTPUT_CALL) \
  121. \
  122. DWORD status; \
  123. LPBYTE tempBuffer = NULL; \
  124. ANSI_PARM AParm[NUMBER_OF_PARMS]; \
  125. UNICODE_PARM UParm[NUMBER_OF_PARMS]; \
  126. \
  127. ANSI_PARM_ASSIGNMENT \
  128. \
  129. status = InputParmsToUnicode(INSTRUCTION_STRING, AParm, UParm, &tempBuffer); \
  130. \
  131. if (status == WN_SUCCESS) \
  132. { \
  133. status = UNICODE_CALL \
  134. \
  135. if (status == WN_SUCCESS) \
  136. { \
  137. status = OUTPUT_CALL \
  138. } \
  139. } \
  140. \
  141. LocalFree(tempBuffer); \
  142. \
  143. SET_AND_RETURN(status)
  144. //
  145. // STRUCTURES
  146. //
  147. // These unions are defined so that parameters of various types can be passed
  148. // to the generic routine InputParmsToUnicode.
  149. // CODEWORK: By using these unions, we have lost type safety, and this could
  150. // cause some bugs to go undetected. To get back type safety, ANSI_PARM and
  151. // UNICODE_PARM could be made into "smart union" classes, with overloaded
  152. // assignment and cast operators that, in the checked build, remember the
  153. // type of the data that they are assigned, and assert if they are used as
  154. // any other type of data.
  155. // This would also make the code neater by allowing initializers like
  156. // ANSI_PARM AParm[] = { lpName, lpUserName, lpnLength };
  157. typedef union
  158. {
  159. DWORD dword;
  160. LPCSTR lpcstr;
  161. LPNETRESOURCEA lpNetResA;
  162. LPVOID lpvoid;
  163. LPDWORD lpdword;
  164. } ANSI_PARM;
  165. typedef union
  166. {
  167. DWORD dword;
  168. LPBYTE lpbyte;
  169. LPWSTR lpwstr;
  170. LPNETRESOURCEW lpNetResW;
  171. } UNICODE_PARM;
  172. class ANSI_OUT_BUFFER
  173. {
  174. private:
  175. const LPBYTE _Start; // Pointer to start of buffer
  176. const DWORD _Size; // Total number of bytes in buffer
  177. DWORD _Used; // Number of bytes used (may exceed Size)
  178. public:
  179. ANSI_OUT_BUFFER(LPBYTE Start, DWORD Size) :
  180. _Start(Start),
  181. _Size (Size),
  182. _Used (0)
  183. { }
  184. BYTE * Next() const
  185. { return _Start + _Used; }
  186. BOOL Overflow() const
  187. { return (_Used > _Size); }
  188. DWORD FreeSpace() const
  189. { return (Overflow() ? 0 : _Size - _Used); }
  190. BOOL HasRoomFor(DWORD Request) const
  191. { return (_Used + Request <= _Size); }
  192. void AddUsed(DWORD Request)
  193. { _Used += Request; }
  194. DWORD GetUsage() const
  195. { return _Used; }
  196. };
  197. //
  198. // STATIC DATA
  199. //
  200. //
  201. // These arrays of members are used to iterate through the string fields
  202. // of a net resource.
  203. // The order must match the NETRESFIELD_ definitions.
  204. //
  205. LPWSTR NETRESOURCEW::* const NRWField[NUMBER_OF_NETRESFIELD] =
  206. {
  207. &NETRESOURCEW::lpLocalName,
  208. &NETRESOURCEW::lpRemoteName,
  209. &NETRESOURCEW::lpComment,
  210. &NETRESOURCEW::lpProvider
  211. };
  212. LPSTR NETRESOURCEA::* const NRAField[NUMBER_OF_NETRESFIELD] =
  213. {
  214. &NETRESOURCEA::lpLocalName,
  215. &NETRESOURCEA::lpRemoteName,
  216. &NETRESOURCEA::lpComment,
  217. &NETRESOURCEA::lpProvider
  218. };
  219. //
  220. // Local Functions
  221. //
  222. DWORD
  223. InputParmsToUnicode(
  224. IN LPCSTR Instructions,
  225. IN const ANSI_PARM InputParms[],
  226. OUT UNICODE_PARM OutputParms[],
  227. OUT LPBYTE * ppBuffer
  228. );
  229. DWORD
  230. StringParmToUnicodePass1(
  231. IN LPCSTR StringParm,
  232. OUT PANSI_STRING AnsiString,
  233. OUT PUNICODE_STRING UnicodeString,
  234. IN OUT PULONG BufferOffset
  235. );
  236. DWORD
  237. StringParmToUnicodePass2(
  238. IN OUT PANSI_STRING AnsiString,
  239. OUT PUNICODE_STRING UnicodeString,
  240. IN const BYTE * BufferStart,
  241. OUT LPWSTR * Result
  242. );
  243. DWORD
  244. OutputBufferToAnsi(
  245. IN char BufferFormat,
  246. IN LPBYTE SourceBuffer,
  247. OUT LPVOID AnsiBuffer,
  248. IN OUT LPDWORD pcbBufferSize
  249. );
  250. DWORD
  251. OutputStringToAnsi(
  252. IN LPCWSTR UnicodeIn,
  253. IN OUT ANSI_OUT_BUFFER * Buf
  254. );
  255. DWORD
  256. OutputStringToAnsiInPlace(
  257. IN LPWSTR UnicodeIn
  258. );
  259. DWORD
  260. OutputNetResourceToAnsi(
  261. IN NETRESOURCEW * lpNetResW,
  262. IN OUT ANSI_OUT_BUFFER * Buf
  263. );
  264. DWORD
  265. InputParmsToUnicode(
  266. IN LPCSTR Instructions,
  267. IN const ANSI_PARM InputParms[],
  268. OUT UNICODE_PARM OutputParms[],
  269. OUT LPBYTE * ppBuffer
  270. )
  271. /*++
  272. Routine Description:
  273. This function converts the caller's input parameters to Unicode.
  274. If necessary, it allocates one temporary buffer in which it stores
  275. the intermediate Unicode parameters. This minimizes the cost of
  276. calls to LocalAlloc.
  277. Arguments:
  278. Instructions - A string of characters, roughly one for each member
  279. of the InputParms array, describing the action to be taken on each
  280. InputParms member. Recognized values for the characters are:
  281. 'S' (String) - InputParms member is an LPSTR to be converted to
  282. Unicode. Store a pointer to the Unicode string in the
  283. corresponding OutputParms member.
  284. 'N' (NetResource) - InputParms member is a LPNETRESOURCEA to be
  285. converted to a NETRESOURCEW. The next character in Instructions
  286. is a bitmask of the NETRESFIELD_ constants, indicating which
  287. fields of the NETRESOURCEA to convert. Store a pointer to the
  288. NETRESOURCEW in the corresponding OutputParms member.
  289. 'B' (Buffer) - InputParms member (say InputParms[i]) is a pointer to
  290. an output buffer. InputParms[i+1] is a pointer to a DWORD
  291. indicating the buffer size in bytes. Probe the buffer for write.
  292. Allocate an area of double the size (i.e. of size
  293. (*InputParms[i+1])*sizeof(WCHAR)) in the intermediate buffer.
  294. Store a pointer to this area of the buffer in OutputParms[i].
  295. Store the size of this area in OutputParms[i+1].
  296. If InputParms[i] is NULL, store NULL in OutputParms[i], and
  297. ignore InputParms[i+1]. (In other words, the buffer pointer
  298. is optional; the size pointer is required if the buffer pointer
  299. is present and ignored if the buffer pointer is absent.)
  300. 'Bs' (Buffer beginning with structure) - Same as 'B', but the first
  301. N bytes of the output buffer, where N is stored in InputParms[i+2],
  302. are supposed to hold a fixed-size structure, not strings.
  303. When calculating the size of the intermediate area, double the
  304. size of the rest of the buffer, but not the size of the structure.
  305. CODEWORK: Also verify that the buffer is DWORD-aligned?
  306. InputParms - An array of parameters to the Ansi API, described by the
  307. Instructions parameter.
  308. OutputParms - An array of the same size as InputParms, to hold the
  309. converted Unicode parameters.
  310. ppBuffer - A pointer to the intermediate buffer allocated by this
  311. function will be stored here. It must be freed by a single call
  312. to LocalFree, regardless of the return value from this function.
  313. Return Value:
  314. WN_SUCCESS
  315. WN_OUT_OF_MEMORY
  316. WN_BAD_POINTER
  317. History:
  318. 16-Feb-1996 anirudhs Created.
  319. Notes:
  320. The function works by making two passes through the Instructions string.
  321. In the first pass the string lengths are determined and saved, and the
  322. required size of the temporary buffer is calculated. In the second
  323. pass the parameters are actually converted to Unicode.
  324. --*/
  325. {
  326. ANSI_STRING AnsiStrings [MAX_STRINGS_PER_API] = {0};
  327. UNICODE_STRING UnicodeStrings[MAX_STRINGS_PER_API] = {0};
  328. ULONG Bytes = 0; // Size of buffer to allocate
  329. DWORD status = WN_SUCCESS;
  330. //
  331. // The caller must have initialized the buffer pointer to NULL, so
  332. // he can free the buffer even if this function fails.
  333. //
  334. ASSERT(*ppBuffer == NULL);
  335. __try
  336. {
  337. //
  338. // For two passes through Instructions
  339. //
  340. #define FIRST_PASS (iPass == 0)
  341. for (ULONG iPass = 0; iPass <= 1; iPass++)
  342. {
  343. ULONG iString = 0; // Index into AnsiStrings and UnicodeStrings
  344. //
  345. // For each character in Instructions
  346. //
  347. const CHAR * pInstruction; // Pointer into Instructions
  348. ULONG iParm; // Index into InputParms and OutputParms
  349. for (pInstruction = Instructions, iParm = 0;
  350. *pInstruction;
  351. pInstruction++, iParm++)
  352. {
  353. MPR_LOG(ANSI, "Processing instruction '%hc'\n", *pInstruction);
  354. switch (*pInstruction)
  355. {
  356. case 'B':
  357. //
  358. // The next 2 InputParms are a buffer pointer and size.
  359. // Note that this code could cause an exception.
  360. //
  361. if (InputParms[iParm].lpvoid == NULL)
  362. {
  363. // A NULL pointer stays NULL; the size pointer is ignored
  364. OutputParms[iParm].lpbyte = NULL;
  365. }
  366. else if (FIRST_PASS)
  367. {
  368. // Probe the original buffer
  369. if (IS_BAD_BYTE_BUFFER(InputParms[iParm].lpvoid,
  370. InputParms[iParm+1].lpdword))
  371. {
  372. status = WN_BAD_POINTER;
  373. __leave;
  374. }
  375. // Reserve the intermediate buffer area
  376. Bytes = ROUND_UP_TO_DWORD(Bytes);
  377. OutputParms[iParm].dword = Bytes;
  378. OutputParms[iParm+1].dword =
  379. (*InputParms[iParm+1].lpdword) * sizeof(WCHAR);
  380. // Check for an optional 's' in Instructions
  381. if (*(pInstruction+1) == 's')
  382. {
  383. // CODEWORK: Check for DWORD alignment on RISC?
  384. // if (!IS_DWORD_ALIGNED(InputParms[iParm].lpvoid))
  385. // { status = WN_BAD_POINTER; __leave; }
  386. // InputParms[iParm+2].dword holds the size of the
  387. // fixed-length structure that will go at the start
  388. // of the buffer. We don't want to multiply its
  389. // size by sizeof(WCHAR).
  390. if (OutputParms[iParm+1].dword/sizeof(WCHAR) <
  391. InputParms[iParm+2].dword)
  392. {
  393. OutputParms[iParm+1].dword /= sizeof(WCHAR);
  394. }
  395. else
  396. {
  397. OutputParms[iParm+1].dword -=
  398. InputParms[iParm+2].dword*(sizeof(WCHAR)-1);
  399. }
  400. }
  401. Bytes += OutputParms[iParm+1].dword;
  402. }
  403. else // Non-NULL pointer, second pass
  404. {
  405. // Convert the offset to a pointer
  406. OutputParms[iParm].lpbyte =
  407. *ppBuffer + OutputParms[iParm].dword;
  408. ASSERT(IS_DWORD_ALIGNED(OutputParms[iParm].lpbyte));
  409. }
  410. iParm++; // iParm+1 was for the buffer size
  411. if (*(pInstruction+1) == 's')
  412. {
  413. pInstruction++;
  414. iParm++; // iParm+2 was for the fixed structure size
  415. }
  416. break;
  417. case 'S':
  418. //
  419. // InputParm is a string to be converted.
  420. // A NULL string stays NULL.
  421. //
  422. if (FIRST_PASS)
  423. {
  424. ASSERT(iString < MAX_STRINGS_PER_API);
  425. Bytes = ROUND_UP_TO_WCHAR(Bytes);
  426. status = StringParmToUnicodePass1(
  427. InputParms[iParm].lpcstr,
  428. &AnsiStrings[iString],
  429. &UnicodeStrings[iString],
  430. &Bytes);
  431. }
  432. else
  433. {
  434. status = StringParmToUnicodePass2(
  435. &AnsiStrings[iString],
  436. &UnicodeStrings[iString],
  437. *ppBuffer,
  438. &OutputParms[iParm].lpwstr);
  439. }
  440. if (status != WN_SUCCESS)
  441. {
  442. __leave;
  443. }
  444. iString++;
  445. break;
  446. case 'N':
  447. //
  448. // InputParm is a NETRESOURCEA to be converted, and the
  449. // next character in Instructions tells which of its string
  450. // fields are to be converted.
  451. // NULL strings remain NULL; ignored fields are copied
  452. // unchanged.
  453. //
  454. pInstruction++;
  455. if (InputParms[iParm].lpNetResA == NULL)
  456. {
  457. // A null netresource stays null
  458. OutputParms[iParm].lpNetResW = NULL;
  459. break;
  460. }
  461. {
  462. // First deal with the fixed-size part of the structure.
  463. const NETRESOURCEA *pNetResA =
  464. InputParms[iParm].lpNetResA;
  465. NETRESOURCEW *pNetResW;
  466. if (FIRST_PASS)
  467. {
  468. // Reserve space for the NETRESOURCEW
  469. Bytes = ROUND_UP_TO_DWORD(Bytes);
  470. OutputParms[iParm].dword = Bytes;
  471. Bytes += sizeof(NETRESOURCEW);
  472. ASSERT(IS_WCHAR_ALIGNED(Bytes));
  473. }
  474. else
  475. {
  476. // Copy fixed-size fields and NULL pointers
  477. pNetResW = (NETRESOURCEW *)
  478. (*ppBuffer + OutputParms[iParm].dword);
  479. ASSERT(IS_DWORD_ALIGNED(pNetResW));
  480. RtlCopyMemory(pNetResW, pNetResA, sizeof(NETRESOURCEA));
  481. OutputParms[iParm].lpNetResW = pNetResW;
  482. }
  483. // Next add each non-null string specified in the
  484. // field mask.
  485. CHAR FieldMask = *pInstruction;
  486. ASSERT(FieldMask != 0);
  487. for (ULONG iField = 0;
  488. iField < NUMBER_OF_NETRESFIELD;
  489. iField++)
  490. {
  491. if ((FieldMask >> iField) & 1)
  492. {
  493. if (FIRST_PASS)
  494. {
  495. ASSERT(iString < MAX_STRINGS_PER_API);
  496. status = StringParmToUnicodePass1(
  497. pNetResA->*NRAField[iField],
  498. &AnsiStrings[iString],
  499. &UnicodeStrings[iString],
  500. &Bytes);
  501. }
  502. else
  503. {
  504. status = StringParmToUnicodePass2(
  505. &AnsiStrings[iString],
  506. &UnicodeStrings[iString],
  507. *ppBuffer,
  508. &(pNetResW->*NRWField[iField]));
  509. }
  510. if (status != WN_SUCCESS)
  511. {
  512. __leave;
  513. }
  514. iString++;
  515. }
  516. }
  517. }
  518. break;
  519. default:
  520. ASSERT(0);
  521. }
  522. }
  523. if (FIRST_PASS)
  524. {
  525. //
  526. // Actually allocate the space for the Unicode parameters
  527. //
  528. *ppBuffer = (LPBYTE) LocalAlloc(0, Bytes);
  529. if (*ppBuffer == NULL)
  530. {
  531. status = GetLastError();
  532. MPR_LOG2(ERROR,
  533. "InputParmsToUnicode: LocalAlloc for %lu bytes failed, %lu\n",
  534. Bytes, status);
  535. __leave;
  536. }
  537. }
  538. }
  539. }
  540. __except(MPR_EXCEPTION_FILTER)
  541. {
  542. #if DBG == 1
  543. status = GetExceptionCode();
  544. if (status != EXCEPTION_ACCESS_VIOLATION)
  545. {
  546. MPR_LOG(ERROR,"InputParmsToUnicode: Unexpected Exception %#lx\n",status);
  547. }
  548. #endif
  549. status = WN_BAD_POINTER;
  550. }
  551. return status;
  552. }
  553. DWORD
  554. StringParmToUnicodePass1 (
  555. IN LPCSTR StringParm,
  556. OUT PANSI_STRING AnsiString,
  557. OUT PUNICODE_STRING UnicodeString,
  558. IN OUT PULONG BufferOffset
  559. )
  560. /*++
  561. Routine Description:
  562. Helper function for InputParmsToUnicode.
  563. --*/
  564. {
  565. RtlInitAnsiString( AnsiString, StringParm );
  566. if (StringParm == NULL)
  567. {
  568. return WN_SUCCESS;
  569. }
  570. // Save the offset to the memory for this Unicode string, to be converted
  571. // to a pointer after the memory is allocated
  572. ULONG UnicodeLength = RtlAnsiStringToUnicodeSize( AnsiString );
  573. if (UnicodeLength > MAXUSHORT)
  574. {
  575. MPR_LOG(ERROR,
  576. "Unicode size of Ansi string parm is %lu, exceeds MAXUSHORT\n",
  577. UnicodeLength);
  578. return WN_BAD_VALUE;
  579. }
  580. UnicodeString->Buffer = (LPWSTR) UlongToPtr(*BufferOffset);
  581. UnicodeString->MaximumLength = (USHORT) UnicodeLength;
  582. *BufferOffset = ROUND_UP_TO_DWORD(*BufferOffset + UnicodeLength);
  583. return WN_SUCCESS;
  584. }
  585. DWORD
  586. StringParmToUnicodePass2 (
  587. IN OUT PANSI_STRING AnsiString,
  588. OUT PUNICODE_STRING UnicodeString,
  589. IN const BYTE * BufferStart,
  590. OUT LPWSTR * Result
  591. )
  592. /*++
  593. Routine Description:
  594. Helper function for InputParmsToUnicode.
  595. --*/
  596. {
  597. if (AnsiString->Buffer == NULL)
  598. {
  599. *Result = NULL;
  600. // NOTE: the UnicodeString is not initialized in this case
  601. return WN_SUCCESS;
  602. }
  603. // Convert the previously stored buffer offset into a pointer
  604. UnicodeString->Buffer = (LPWSTR)
  605. (BufferStart + (ULONG_PTR) UnicodeString->Buffer);
  606. ASSERT(IS_WCHAR_ALIGNED(UnicodeString->Buffer));
  607. // Convert the string to Unicode
  608. NTSTATUS ntstatus =
  609. RtlAnsiStringToUnicodeString(UnicodeString, AnsiString, FALSE);
  610. if (!NT_SUCCESS(ntstatus))
  611. {
  612. MPR_LOG(ERROR, "RtlAnsiStringToUnicodeString failed %#lx\n", ntstatus);
  613. return RtlNtStatusToDosError(ntstatus);
  614. }
  615. *Result = UnicodeString->Buffer;
  616. return WN_SUCCESS;
  617. }
  618. DWORD
  619. OutputBufferToAnsi(
  620. IN char BufferFormat,
  621. IN LPBYTE SourceBuffer,
  622. OUT LPVOID AnsiBuffer,
  623. IN OUT LPDWORD pcbBufferSize
  624. )
  625. /*++
  626. Routine Description:
  627. This function converts the data in the result buffer that was returned
  628. from a Unicode API into Ansi and stores it in the Ansi caller's result
  629. buffer. If the caller's buffer isn't large enough it saves the required
  630. size in *pcbBufferSize and returns WN_MORE_DATA.
  631. Nearly all the WNet APIs that have output buffers have only a single
  632. field in the output buffer, so this API takes only a single character,
  633. rather than a string, for the buffer format. APIs with more complicated
  634. output buffers should handle the complexity themselves, by directly
  635. calling the functions that this function calls.
  636. Arguments:
  637. BufferFormat - A character indicating the format of the SourceBuffer
  638. field. Recognized values are:
  639. 'S' - SourceBuffer contains a Unicode string. Convert it to Ansi
  640. and store the Ansi version in AnsiBuffer.
  641. 'N' - SourceBuffer contains a NETRESOURCEW with its associated
  642. strings. Convert it to Ansi and store the Ansi version in
  643. AnsiBuffer.
  644. SourceBuffer - The output buffer returned from a Unicode API.
  645. This must not be NULL.
  646. AnsiBuffer - The output buffer that the caller of the Ansi API supplied.
  647. This must not be NULL.
  648. pcbBufferSize - On entry, the size of AnsiBuffer in bytes. If the
  649. function returns WN_MORE_DATA, the required size is stored here;
  650. otherwise this is unmodified.
  651. This must not be NULL (must be a writeable DWORD pointer).
  652. Return Value:
  653. WN_SUCCESS - successful.
  654. WN_MORE_DATA - The buffer specified by AnsiBuffer and pcbBufferSize was
  655. not large enough to hold the converted data from SourceBuffer. In
  656. this case the required buffer size (in bytes) is written to
  657. *pcbBufferSize. The contents of AnsiBuffer are undefined (it will
  658. be partially filled).
  659. History:
  660. 16-Feb-1996 anirudhs Created.
  661. Notes:
  662. --*/
  663. {
  664. // Doesn't handle optional parameters for now
  665. ASSERT(SourceBuffer != NULL &&
  666. AnsiBuffer != NULL &&
  667. pcbBufferSize != NULL);
  668. ANSI_OUT_BUFFER Buf((LPBYTE) AnsiBuffer, *pcbBufferSize);
  669. DWORD status;
  670. switch (BufferFormat)
  671. {
  672. case 'S':
  673. status = OutputStringToAnsi((LPCWSTR) SourceBuffer, &Buf);
  674. break;
  675. case 'N':
  676. status = OutputNetResourceToAnsi((NETRESOURCEW *) SourceBuffer, &Buf);
  677. break;
  678. default:
  679. ASSERT(0);
  680. return ERROR_INVALID_LEVEL;
  681. }
  682. //
  683. // Map the results to the conventions followed by the WNet APIs
  684. //
  685. if (status == WN_SUCCESS)
  686. {
  687. if (Buf.Overflow())
  688. {
  689. *pcbBufferSize = Buf.GetUsage();
  690. status = WN_MORE_DATA;
  691. }
  692. }
  693. else
  694. {
  695. ASSERT(status != WN_MORE_DATA);
  696. }
  697. return status;
  698. }
  699. DWORD
  700. OutputStringToAnsi(
  701. IN LPCWSTR UnicodeIn,
  702. IN OUT ANSI_OUT_BUFFER * Buf
  703. )
  704. /*++
  705. Routine Description:
  706. This function converts a Unicode string to Ansi and calculates the number
  707. of bytes required to store it. If the caller passes a buffer that has
  708. enough remaining free space, it stores the Ansi data in the buffer.
  709. Otherwise it just increments the buffer's space usage by the number of
  710. bytes required.
  711. Arguments:
  712. UnicodeIn - A Unicode string to be converted to Ansi.
  713. This must not be NULL.
  714. Buf - A structure whose elements are interpreted as follows:
  715. _Start - Start address of a buffer to contain the Ansi data.
  716. This buffer must be writeable, or an exception will occur.
  717. _Size - The total size of the buffer for the Ansi data.
  718. _Used - On entry, the number of bytes in the buffer that have
  719. already been used. The function will begin writing data at
  720. _Start + _Used and will never write past the total size
  721. specified by _Size. If there is not enough room left
  722. in the buffer it will be partially filled or unmodified.
  723. On a successful return, _Used is incremented by the number
  724. of bytes that would be required to store the converted Ansi
  725. data, whether or not it was actually stored in the buffer.
  726. (This is done because the WNet APIs need to return the
  727. required buffer size if the caller's buffer was too small.)
  728. The use of this structure simplifies the writing of routines that
  729. use this function and need to convert multiple fields of Unicode
  730. data. Callers that need to convert only a single field can use
  731. OutputBufferToAnsi.
  732. Return Value:
  733. WN_SUCCESS - successful. The Ansi data was written to the buffer if
  734. Buf->_Used <= Buf->_Size. Otherwise, Buf->_Used was incremented
  735. without completely writing the data.
  736. Note that WN_MORE_DATA is never returned.
  737. History:
  738. 16-Feb-1996 anirudhs Created.
  739. Notes:
  740. --*/
  741. {
  742. NTSTATUS ntStatus;
  743. UNICODE_STRING unicodeString;
  744. ANSI_STRING ansiString;
  745. ASSERT(UnicodeIn != NULL); // Doesn't handle optional parameters for now
  746. //
  747. // Initialize the string structures
  748. //
  749. RtlInitUnicodeString(&unicodeString, UnicodeIn);
  750. ansiString.Buffer = (PCHAR) Buf->Next();
  751. ansiString.MaximumLength = (Buf->FreeSpace() > MAXUSHORT ?
  752. MAXUSHORT :
  753. (USHORT) Buf->FreeSpace()
  754. );
  755. //
  756. // Call the conversion function
  757. //
  758. ntStatus = RtlUnicodeStringToAnsiString (
  759. &ansiString, // Destination
  760. &unicodeString, // Source
  761. (BOOLEAN)FALSE); // Don't allocate the destination
  762. if (NT_SUCCESS(ntStatus))
  763. {
  764. // Add on the buffer space we used
  765. Buf->AddUsed(ansiString.Length + 1);
  766. ASSERT(! Buf->Overflow());
  767. return WN_SUCCESS;
  768. }
  769. else if (ntStatus == STATUS_BUFFER_OVERFLOW)
  770. {
  771. // We couldn't fit the string in the buffer, but still figure out
  772. // how much buffer space we would have used if we could
  773. Buf->AddUsed(RtlUnicodeStringToAnsiSize(&unicodeString));
  774. ASSERT(Buf->Overflow());
  775. return WN_SUCCESS;
  776. }
  777. else
  778. {
  779. MPR_LOG(ERROR, "RtlUnicodeStringToAnsiString failed %#lx\n", ntStatus);
  780. DWORD status = RtlNtStatusToDosError(ntStatus);
  781. ASSERT(status != WN_MORE_DATA);
  782. return status;
  783. }
  784. }
  785. DWORD
  786. OutputNetResourceToAnsi(
  787. IN NETRESOURCEW * lpNetResW,
  788. IN OUT ANSI_OUT_BUFFER * Buf
  789. )
  790. /*++
  791. Routine Description:
  792. This function converts a NETRESOURCEW and its associated Unicode strings
  793. to Ansi and returns the number of bytes required to store them. If the
  794. caller passes a buffer that has enough remaining free space, it stores
  795. the Ansi data in the buffer.
  796. Arguments:
  797. lpNetResW - A Unicode net resource to be converted to Ansi.
  798. This must not be NULL.
  799. Buf - same as OutputStringToAnsi.
  800. Return Value:
  801. Same as OutputStringToAnsi.
  802. History:
  803. 16-Feb-1996 anirudhs Created.
  804. Notes:
  805. --*/
  806. {
  807. //
  808. // Copy the fixed-size part of the structure, including NULL pointers,
  809. // and/or add on the buffer space it would take
  810. //
  811. LPNETRESOURCEA lpNetResA = (LPNETRESOURCEA) Buf->Next();
  812. if (Buf->HasRoomFor(sizeof(NETRESOURCEA)))
  813. {
  814. RtlCopyMemory(lpNetResA, lpNetResW, sizeof(NETRESOURCEA));
  815. }
  816. Buf->AddUsed(sizeof(NETRESOURCEA));
  817. //
  818. // Copy each non-NULL string field,
  819. // and/or add on the buffer space it would take
  820. //
  821. for (DWORD iField = 0;
  822. iField < NUMBER_OF_NETRESFIELD;
  823. iField++)
  824. {
  825. if (lpNetResW->*NRWField[iField] != NULL)
  826. {
  827. // Save a pointer to the Ansi string we are about to create
  828. // in the Ansi net resource
  829. lpNetResA->*NRAField[iField] = (LPSTR) Buf->Next();
  830. // Convert the string
  831. DWORD status = OutputStringToAnsi(lpNetResW->*NRWField[iField], Buf);
  832. if (status != WN_SUCCESS)
  833. {
  834. ASSERT(status != WN_MORE_DATA);
  835. return status;
  836. }
  837. }
  838. }
  839. return WN_SUCCESS;
  840. }
  841. DWORD
  842. OutputStringToAnsiInPlace(
  843. IN LPWSTR UnicodeIn
  844. )
  845. /*++
  846. Routine Description:
  847. This function converts a Unicode string to Ansi in place.
  848. This is the same as OutputStringToAnsi, optimized for in-place conversions.
  849. Arguments:
  850. UnicodeIn - A Unicode string to be converted to Ansi.
  851. This may be NULL, in which case the function does nothing.
  852. Return Value:
  853. WN_SUCCESS - successful.
  854. Note that WN_MORE_DATA is never returned.
  855. History:
  856. 08-Aug-1996 anirudhs Created.
  857. Notes:
  858. --*/
  859. {
  860. NTSTATUS ntStatus;
  861. UNICODE_STRING unicodeString;
  862. ANSI_STRING ansiString;
  863. if (UnicodeIn == NULL)
  864. {
  865. return WN_SUCCESS;
  866. }
  867. //
  868. // Initialize the string structures
  869. //
  870. RtlInitUnicodeString(&unicodeString, UnicodeIn);
  871. ansiString.Buffer = (PCHAR) UnicodeIn;
  872. ansiString.MaximumLength = unicodeString.MaximumLength;
  873. //
  874. // Call the conversion function
  875. //
  876. ntStatus = RtlUnicodeStringToAnsiString (
  877. &ansiString, // Destination
  878. &unicodeString, // Source
  879. (BOOLEAN)FALSE); // Don't allocate the destination
  880. ASSERT(ntStatus != STATUS_BUFFER_OVERFLOW);
  881. if (NT_SUCCESS(ntStatus))
  882. {
  883. return WN_SUCCESS;
  884. }
  885. else
  886. {
  887. MPR_LOG(ERROR, "RtlUnicodeStringToAnsiString failed %#lx\n", ntStatus);
  888. DWORD status = RtlNtStatusToDosError(ntStatus);
  889. ASSERT(status != WN_MORE_DATA);
  890. return status;
  891. }
  892. }
  893. //////////////////////////////////////////////////////////////////////////
  894. //////////////////////////////////////////////////////////////////////////
  895. DWORD APIENTRY
  896. WNetGetNetworkInformationA(
  897. IN LPCSTR lpProvider,
  898. IN OUT LPNETINFOSTRUCT lpNetInfoStruct
  899. )
  900. /*++
  901. Routine Description:
  902. Arguments:
  903. Return Value:
  904. --*/
  905. {
  906. ANSI_API_WITHOUT_ANSI_OUTPUT(
  907. 1,
  908. AParm[0].lpcstr = lpProvider; ,
  909. "S",
  910. WNetGetNetworkInformationW(UParm[0].lpwstr, lpNetInfoStruct);
  911. )
  912. }
  913. DWORD APIENTRY
  914. WNetGetProviderNameA(
  915. IN DWORD dwNetType,
  916. OUT LPSTR lpProviderName,
  917. IN OUT LPDWORD lpBufferSize
  918. )
  919. /*++
  920. Routine Description:
  921. Arguments:
  922. Return Value:
  923. --*/
  924. {
  925. ANSI_API_WITH_ANSI_OUTPUT(
  926. 2,
  927. AParm[0].lpvoid = lpProviderName;
  928. AParm[1].lpdword = lpBufferSize; ,
  929. "B",
  930. WNetGetProviderNameW(dwNetType, UParm[0].lpwstr, lpBufferSize); ,
  931. OutputBufferToAnsi('S', UParm[0].lpbyte, lpProviderName, lpBufferSize);
  932. )
  933. }
  934. DWORD
  935. WNetGetProviderTypeA(
  936. IN LPCSTR lpProvider,
  937. OUT LPDWORD lpdwNetType
  938. )
  939. /*++
  940. Routine Description:
  941. Arguments:
  942. Return Value:
  943. --*/
  944. {
  945. ANSI_API_WITHOUT_ANSI_OUTPUT(
  946. 1,
  947. AParm[0].lpcstr = lpProvider; ,
  948. "S",
  949. WNetGetProviderTypeW(UParm[0].lpwstr, lpdwNetType);
  950. )
  951. }
  952. DWORD APIENTRY
  953. WNetAddConnectionA (
  954. IN LPCSTR lpRemoteName,
  955. IN LPCSTR lpPassword,
  956. IN LPCSTR lpLocalName
  957. )
  958. /*++
  959. Routine Description:
  960. Arguments:
  961. Return Value:
  962. --*/
  963. {
  964. DWORD status;
  965. LPBYTE tempBuffer = NULL;
  966. ANSI_PARM AParm[3];
  967. UNICODE_PARM UParm[3];
  968. AParm[0].lpcstr = lpRemoteName;
  969. AParm[1].lpcstr = lpPassword;
  970. AParm[2].lpcstr = lpLocalName;
  971. UParm[1].lpwstr = NULL;
  972. status = InputParmsToUnicode("SSS", AParm, UParm, &tempBuffer);
  973. if (status == WN_SUCCESS)
  974. {
  975. status = WNetAddConnectionW(
  976. UParm[0].lpwstr,
  977. UParm[1].lpwstr,
  978. UParm[2].lpwstr
  979. );
  980. }
  981. MprClearString(UParm[1].lpwstr);
  982. LocalFree(tempBuffer);
  983. SET_AND_RETURN(status)
  984. }
  985. DWORD APIENTRY
  986. WNetAddConnection2A (
  987. IN LPNETRESOURCEA lpNetResource,
  988. IN LPCSTR lpPassword,
  989. IN LPCSTR lpUserName,
  990. IN DWORD dwFlags
  991. )
  992. /*++
  993. Routine Description:
  994. Arguments:
  995. Return Value:
  996. --*/
  997. {
  998. return (WNetUseConnectionA(
  999. NULL,
  1000. lpNetResource,
  1001. lpPassword,
  1002. lpUserName,
  1003. dwFlags,
  1004. NULL,
  1005. NULL,
  1006. NULL
  1007. ));
  1008. }
  1009. DWORD APIENTRY
  1010. WNetAddConnection3A (
  1011. IN HWND hwndOwner,
  1012. IN LPNETRESOURCEA lpNetResource,
  1013. IN LPCSTR lpPassword,
  1014. IN LPCSTR lpUserName,
  1015. IN DWORD dwFlags
  1016. )
  1017. /*++
  1018. Routine Description:
  1019. Arguments:
  1020. Return Value:
  1021. --*/
  1022. {
  1023. return (WNetUseConnectionA(
  1024. hwndOwner,
  1025. lpNetResource,
  1026. lpPassword,
  1027. lpUserName,
  1028. dwFlags,
  1029. NULL,
  1030. NULL,
  1031. NULL
  1032. ));
  1033. }
  1034. DWORD APIENTRY
  1035. WNetUseConnectionA(
  1036. IN HWND hwndOwner,
  1037. IN LPNETRESOURCEA lpNetResource,
  1038. IN LPCSTR lpPassword,
  1039. IN LPCSTR lpUserID,
  1040. IN DWORD dwFlags,
  1041. OUT LPSTR lpAccessName OPTIONAL,
  1042. IN OUT LPDWORD lpBufferSize OPTIONAL, // Optional only if lpAccessName absent
  1043. OUT LPDWORD lpResult
  1044. )
  1045. /*++
  1046. Routine Description:
  1047. Arguments:
  1048. Return Value:
  1049. --*/
  1050. {
  1051. DWORD status;
  1052. LPBYTE tempBuffer = NULL;
  1053. ANSI_PARM AParm[5];
  1054. UNICODE_PARM UParm[5];
  1055. AParm[0].lpNetResA = lpNetResource;
  1056. AParm[1].lpcstr = lpPassword;
  1057. AParm[2].lpcstr = lpUserID;
  1058. AParm[3].lpvoid = lpAccessName;
  1059. AParm[4].lpdword = lpBufferSize;
  1060. UParm[1].lpwstr = NULL;
  1061. status = InputParmsToUnicode("N" NETRES_LRP "SSB", AParm, UParm, &tempBuffer);
  1062. if (status == WN_SUCCESS)
  1063. {
  1064. status = WNetUseConnectionW(
  1065. hwndOwner,
  1066. UParm[0].lpNetResW,
  1067. UParm[1].lpwstr,
  1068. UParm[2].lpwstr,
  1069. dwFlags,
  1070. UParm[3].lpwstr,
  1071. lpBufferSize,
  1072. lpResult
  1073. );
  1074. if (status == WN_SUCCESS)
  1075. {
  1076. if (ARGUMENT_PRESENT(lpAccessName))
  1077. {
  1078. //
  1079. // Note: At this point, we know that lpBufferSize is writeable.
  1080. //
  1081. status = OutputBufferToAnsi(
  1082. 'S', UParm[3].lpbyte, lpAccessName, lpBufferSize);
  1083. }
  1084. }
  1085. }
  1086. MprClearString(UParm[1].lpwstr);
  1087. LocalFree(tempBuffer);
  1088. SET_AND_RETURN(status)
  1089. }
  1090. DWORD APIENTRY
  1091. WNetCancelConnection2A (
  1092. IN LPCSTR lpName,
  1093. IN DWORD dwFlags,
  1094. IN BOOL fForce
  1095. )
  1096. /*++
  1097. Routine Description:
  1098. Arguments:
  1099. Return Value:
  1100. --*/
  1101. {
  1102. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1103. 1,
  1104. AParm[0].lpcstr = lpName; ,
  1105. "S",
  1106. WNetCancelConnection2W(UParm[0].lpwstr, dwFlags, fForce);
  1107. )
  1108. }
  1109. DWORD APIENTRY
  1110. WNetCancelConnectionA (
  1111. IN LPCSTR lpName,
  1112. IN BOOL fForce
  1113. )
  1114. /*++
  1115. Routine Description:
  1116. This routine is provided for Win 3.1 compatibility.
  1117. Arguments:
  1118. Return Value:
  1119. --*/
  1120. {
  1121. return WNetCancelConnection2A( lpName, CONNECT_UPDATE_PROFILE, fForce ) ;
  1122. }
  1123. DWORD APIENTRY
  1124. WNetGetConnectionA (
  1125. IN LPCSTR lpLocalName,
  1126. OUT LPSTR lpRemoteName,
  1127. IN OUT LPDWORD lpnLength
  1128. )
  1129. /*++
  1130. Routine Description:
  1131. This function returns the RemoteName that is associated with a
  1132. LocalName (or drive letter).
  1133. Arguments:
  1134. lpLocalName - This is a pointer to the string that contains the LocalName.
  1135. lpRemoteName - This is a pointer to the buffer that will contain the
  1136. RemoteName string upon exit.
  1137. lpnLength - This is a pointer to the size (in characters) of the buffer
  1138. that is to be filled in with the RemoteName string. It is assumed
  1139. upon entry, that characters are all single byte characters.
  1140. If the buffer is too small and WN_MORE_DATA is returned, the data
  1141. at this location contains buffer size information - in number of
  1142. characters (bytes). This information indicates how large the buffer
  1143. should be (in bytes) to obtain the remote name. It is assumed that
  1144. all Unicode characteres translate into DBCS characters.
  1145. Return Value:
  1146. --*/
  1147. {
  1148. DWORD status;
  1149. LPBYTE tempBuffer = NULL;
  1150. ANSI_PARM AParm[3];
  1151. UNICODE_PARM UParm[3];
  1152. AParm[0].lpcstr = lpLocalName;
  1153. AParm[1].lpvoid = lpRemoteName;
  1154. AParm[2].lpdword = lpnLength;
  1155. status = InputParmsToUnicode("SB", AParm, UParm, &tempBuffer);
  1156. if (status == WN_SUCCESS)
  1157. {
  1158. status = WNetGetConnectionW(UParm[0].lpwstr, UParm[1].lpwstr, lpnLength);
  1159. if (status == WN_SUCCESS || status == WN_CONNECTION_CLOSED)
  1160. {
  1161. DWORD tempStatus =
  1162. OutputBufferToAnsi('S', UParm[1].lpbyte, lpRemoteName, lpnLength);
  1163. if (tempStatus != WN_SUCCESS)
  1164. {
  1165. status = tempStatus;
  1166. }
  1167. }
  1168. }
  1169. LocalFree(tempBuffer);
  1170. SET_AND_RETURN(status)
  1171. }
  1172. DWORD APIENTRY
  1173. WNetGetConnection2A (
  1174. IN LPSTR lpLocalName,
  1175. OUT LPVOID lpBuffer,
  1176. IN OUT LPDWORD lpnLength
  1177. )
  1178. /*++
  1179. Routine Description:
  1180. This function returns the RemoteName that is associated with a
  1181. LocalName (or drive letter) and the provider name that made the
  1182. connection.
  1183. Arguments:
  1184. lpLocalName - This is a pointer to the string that contains the LocalName.
  1185. lpBuffer - This is a pointer to the buffer that will contain the
  1186. WNET_CONNECTIONINFO structure upon exit.
  1187. lpnLength - This is a pointer to the size (in characters) of the buffer
  1188. that is to be filled in with the RemoteName string. It is assumed
  1189. upon entry, that characters are all single byte characters.
  1190. If the buffer is too small and WN_MORE_DATA is returned, the data
  1191. at this location contains buffer size information - in number of
  1192. characters (bytes). This information indicates how large the buffer
  1193. should be (in bytes) to obtain the remote name. It is assumed that
  1194. all Unicode characters translate into DBCS characters.
  1195. Return Value:
  1196. --*/
  1197. {
  1198. DWORD status;
  1199. LPBYTE tempBuffer = NULL;
  1200. ANSI_PARM AParm[4];
  1201. UNICODE_PARM UParm[4];
  1202. AParm[0].lpcstr = lpLocalName;
  1203. AParm[1].lpvoid = lpBuffer;
  1204. AParm[2].lpdword = lpnLength;
  1205. AParm[3].dword = sizeof(WNET_CONNECTIONINFO);
  1206. status = InputParmsToUnicode("SBs", AParm, UParm, &tempBuffer);
  1207. if (status == WN_SUCCESS)
  1208. {
  1209. status = WNetGetConnection2W(
  1210. UParm[0].lpwstr,
  1211. UParm[1].lpbyte,
  1212. &UParm[2].dword
  1213. );
  1214. if (status == WN_SUCCESS || status == WN_CONNECTION_CLOSED)
  1215. {
  1216. ANSI_OUT_BUFFER Buf((LPBYTE) lpBuffer, *lpnLength);
  1217. //
  1218. // Copy the fixed-size part of the structure, including NULL pointers,
  1219. // and/or add on the buffer space it would take
  1220. //
  1221. WNET_CONNECTIONINFOW * pconninfow = (WNET_CONNECTIONINFOW *) UParm[1].lpbyte;
  1222. WNET_CONNECTIONINFOA * pconninfoa = (WNET_CONNECTIONINFOA *) Buf.Next();
  1223. ASSERT(Buf.HasRoomFor(sizeof(WNET_CONNECTIONINFOA)));
  1224. RtlCopyMemory(pconninfoa, pconninfow, sizeof(WNET_CONNECTIONINFOA));
  1225. Buf.AddUsed(sizeof(WNET_CONNECTIONINFOA));
  1226. //
  1227. // Copy each non-NULL string field,
  1228. // and/or add on the buffer space it would take
  1229. //
  1230. DWORD tempStatus = WN_SUCCESS;
  1231. if (pconninfow->lpRemoteName != NULL)
  1232. {
  1233. pconninfoa->lpRemoteName = (LPSTR) Buf.Next();
  1234. tempStatus = OutputStringToAnsi(pconninfow->lpRemoteName, &Buf);
  1235. }
  1236. if (tempStatus == WN_SUCCESS &&
  1237. pconninfow->lpProvider != NULL)
  1238. {
  1239. pconninfoa->lpProvider = (LPSTR) Buf.Next();
  1240. tempStatus = OutputStringToAnsi(pconninfow->lpProvider, &Buf);
  1241. }
  1242. //
  1243. // Map the results to WNet API conventions
  1244. //
  1245. if (tempStatus != WN_SUCCESS)
  1246. {
  1247. status = tempStatus;
  1248. }
  1249. else if (Buf.Overflow())
  1250. {
  1251. *lpnLength = Buf.GetUsage();
  1252. status = WN_MORE_DATA;
  1253. }
  1254. }
  1255. else if (status == WN_MORE_DATA)
  1256. {
  1257. //
  1258. // Adjust the required buffer size for ansi/DBCS.
  1259. //
  1260. // We don't know how many characters will be required so we have to
  1261. // assume the worst case (all characters are DBCS characters).
  1262. //
  1263. *lpnLength = UParm[2].dword;
  1264. }
  1265. }
  1266. LocalFree(tempBuffer);
  1267. SET_AND_RETURN(status)
  1268. }
  1269. DWORD APIENTRY
  1270. WNetGetConnection3A(
  1271. IN LPCSTR lpLocalName,
  1272. IN LPCSTR lpProviderName OPTIONAL,
  1273. IN DWORD dwLevel,
  1274. OUT LPVOID lpBuffer,
  1275. IN OUT LPDWORD lpBufferSize // in bytes
  1276. )
  1277. /*++
  1278. Routine Description:
  1279. Arguments:
  1280. Return Value:
  1281. --*/
  1282. {
  1283. // For the only supported level, the output buffer is a DWORD, so no
  1284. // conversion of the output buffer is necessary
  1285. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1286. 2,
  1287. AParm[0].lpcstr = lpLocalName;
  1288. AParm[1].lpcstr = lpProviderName; ,
  1289. "SS",
  1290. WNetGetConnection3W(
  1291. UParm[0].lpwstr,
  1292. UParm[1].lpwstr,
  1293. dwLevel,
  1294. lpBuffer,
  1295. lpBufferSize
  1296. );
  1297. )
  1298. }
  1299. DWORD
  1300. WNetGetUniversalNameA (
  1301. IN LPCSTR lpLocalPath,
  1302. IN DWORD dwInfoLevel,
  1303. OUT LPVOID lpBuffer,
  1304. IN OUT LPDWORD lpBufferSize
  1305. )
  1306. /*++
  1307. Routine Description:
  1308. Arguments:
  1309. Return Value:
  1310. --*/
  1311. {
  1312. DWORD status;
  1313. LPBYTE tempBuffer = NULL;
  1314. ANSI_PARM AParm[4];
  1315. UNICODE_PARM UParm[4];
  1316. DWORD dwStructSize =
  1317. (dwInfoLevel == UNIVERSAL_NAME_INFO_LEVEL) ? sizeof(UNIVERSAL_NAME_INFO) :
  1318. (dwInfoLevel == REMOTE_NAME_INFO_LEVEL) ? sizeof(REMOTE_NAME_INFO) :
  1319. 0;
  1320. AParm[0].lpcstr = lpLocalPath;
  1321. AParm[1].lpvoid = lpBuffer;
  1322. AParm[2].lpdword = lpBufferSize;
  1323. AParm[3].dword = dwStructSize;
  1324. status = InputParmsToUnicode("SBs", AParm, UParm, &tempBuffer);
  1325. if (status == WN_SUCCESS)
  1326. {
  1327. status = WNetGetUniversalNameW(
  1328. UParm[0].lpwstr,
  1329. dwInfoLevel,
  1330. UParm[1].lpbyte,
  1331. &UParm[2].dword
  1332. );
  1333. if (status == WN_SUCCESS || status == WN_CONNECTION_CLOSED)
  1334. {
  1335. DWORD tempStatus = WN_SUCCESS;
  1336. ANSI_OUT_BUFFER Buf((LPBYTE) lpBuffer, *lpBufferSize);
  1337. //
  1338. // Copy the fixed-size part of the structure, including NULL pointers,
  1339. // and/or add on the buffer space it would take
  1340. //
  1341. ASSERT(Buf.HasRoomFor(dwStructSize));
  1342. RtlCopyMemory(Buf.Next(), UParm[1].lpbyte, dwStructSize);
  1343. if (dwInfoLevel == REMOTE_NAME_INFO_LEVEL)
  1344. {
  1345. // -----------------------------------
  1346. // REMOTE_NAME_INFO_LEVEL
  1347. // -----------------------------------
  1348. LPREMOTE_NAME_INFOW pRemoteNameInfoW =
  1349. (LPREMOTE_NAME_INFOW) UParm[1].lpbyte;
  1350. LPREMOTE_NAME_INFOA pRemoteNameInfoA =
  1351. (LPREMOTE_NAME_INFOA) Buf.Next();
  1352. Buf.AddUsed(dwStructSize);
  1353. //
  1354. // Convert the returned Unicode string and string size back to
  1355. // ansi.
  1356. //
  1357. if (pRemoteNameInfoW->lpUniversalName != NULL)
  1358. {
  1359. pRemoteNameInfoA->lpUniversalName = (LPSTR) Buf.Next();
  1360. tempStatus = OutputStringToAnsi(pRemoteNameInfoW->lpUniversalName, &Buf);
  1361. }
  1362. if (tempStatus == WN_SUCCESS && pRemoteNameInfoW->lpConnectionName != NULL)
  1363. {
  1364. pRemoteNameInfoA->lpConnectionName = (LPSTR) Buf.Next();
  1365. tempStatus = OutputStringToAnsi(pRemoteNameInfoW->lpConnectionName, &Buf);
  1366. }
  1367. if (tempStatus == WN_SUCCESS && pRemoteNameInfoW->lpRemainingPath != NULL)
  1368. {
  1369. pRemoteNameInfoA->lpRemainingPath = (LPSTR) Buf.Next();
  1370. tempStatus = OutputStringToAnsi(pRemoteNameInfoW->lpRemainingPath, &Buf);
  1371. }
  1372. }
  1373. else
  1374. {
  1375. // -----------------------------------
  1376. // Must be UNIVERSAL_NAME_INFO_LEVEL
  1377. // -----------------------------------
  1378. ASSERT(dwInfoLevel == UNIVERSAL_NAME_INFO_LEVEL);
  1379. LPUNIVERSAL_NAME_INFOW pUniNameInfoW =
  1380. (LPUNIVERSAL_NAME_INFOW) UParm[1].lpbyte;
  1381. LPUNIVERSAL_NAME_INFOA pUniNameInfoA =
  1382. (LPUNIVERSAL_NAME_INFOA) Buf.Next();
  1383. Buf.AddUsed(dwStructSize);
  1384. //
  1385. // Convert the returned Unicode string and string size back to
  1386. // ansi.
  1387. //
  1388. if (pUniNameInfoW->lpUniversalName != NULL)
  1389. {
  1390. pUniNameInfoA->lpUniversalName = (LPSTR) Buf.Next();
  1391. tempStatus = OutputStringToAnsi(pUniNameInfoW->lpUniversalName, &Buf);
  1392. }
  1393. }
  1394. //
  1395. // Map the results to WNet API conventions
  1396. //
  1397. if (tempStatus != WN_SUCCESS)
  1398. {
  1399. status = tempStatus;
  1400. }
  1401. else if (Buf.Overflow())
  1402. {
  1403. *lpBufferSize = Buf.GetUsage();
  1404. status = WN_MORE_DATA;
  1405. }
  1406. }
  1407. else if (status == WN_MORE_DATA)
  1408. {
  1409. //
  1410. // Adjust the required buffer size for ansi/DBCS.
  1411. //
  1412. // We don't know how many characters will be required so we have to
  1413. // assume the worst case (all characters are DBCS characters).
  1414. //
  1415. *lpBufferSize = UParm[2].dword;
  1416. }
  1417. }
  1418. LocalFree(tempBuffer);
  1419. SET_AND_RETURN(status)
  1420. }
  1421. DWORD APIENTRY
  1422. WNetSetConnectionA(
  1423. IN LPCSTR lpName,
  1424. IN DWORD dwProperties,
  1425. IN OUT LPVOID pvValues
  1426. )
  1427. /*++
  1428. Routine Description:
  1429. Arguments:
  1430. Return Value:
  1431. --*/
  1432. {
  1433. //
  1434. // pvValues points to various types of structures depending on the value
  1435. // of dwProperties.
  1436. // Currently there is only one valid value for dwProperties, and its
  1437. // corresponding pvValues points to a DWORD, so we don't need to worry
  1438. // about converting pvValues to Unicode.
  1439. //
  1440. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1441. 1,
  1442. AParm[0].lpcstr = lpName; ,
  1443. "S",
  1444. WNetSetConnectionW(UParm[0].lpwstr, dwProperties, pvValues);
  1445. )
  1446. }
  1447. DWORD APIENTRY
  1448. MultinetGetConnectionPerformanceA(
  1449. IN LPNETRESOURCEA lpNetResource,
  1450. OUT LPNETCONNECTINFOSTRUCT lpNetConnectInfoStruct
  1451. )
  1452. /*++
  1453. Routine Description:
  1454. Arguments:
  1455. Return Value:
  1456. --*/
  1457. {
  1458. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1459. 1,
  1460. AParm[0].lpNetResA = lpNetResource; ,
  1461. "N" NETRES_LRP,
  1462. MultinetGetConnectionPerformanceW(
  1463. UParm[0].lpNetResW,
  1464. lpNetConnectInfoStruct);
  1465. )
  1466. }
  1467. DWORD APIENTRY
  1468. WNetOpenEnumA (
  1469. IN DWORD dwScope,
  1470. IN DWORD dwType,
  1471. IN DWORD dwUsage,
  1472. IN LPNETRESOURCEA lpNetResource,
  1473. OUT LPHANDLE lphEnum
  1474. )
  1475. /*++
  1476. Routine Description:
  1477. Arguments:
  1478. Return Value:
  1479. --*/
  1480. {
  1481. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1482. 1,
  1483. AParm[0].lpNetResA = lpNetResource; ,
  1484. "N" NETRES_RP,
  1485. WNetOpenEnumW(dwScope, dwType, dwUsage, UParm[0].lpNetResW, lphEnum);
  1486. )
  1487. }
  1488. DWORD APIENTRY
  1489. WNetEnumResourceA (
  1490. IN HANDLE hEnum,
  1491. IN OUT LPDWORD lpcCount,
  1492. OUT LPVOID lpBuffer,
  1493. IN OUT LPDWORD lpBufferSize
  1494. )
  1495. /*++
  1496. Routine Description:
  1497. This function calls the unicode version of WNetEnumResource and
  1498. then converts the strings that are returned into ansi strings.
  1499. Since the user provided buffer is used to contain the unicode strings,
  1500. that buffer should be allocated with the size of unicode strings
  1501. in mind.
  1502. Arguments:
  1503. Return Value:
  1504. --*/
  1505. {
  1506. DWORD status = WNetEnumResourceW(
  1507. hEnum,
  1508. lpcCount,
  1509. lpBuffer,
  1510. lpBufferSize);
  1511. if (status == WN_SUCCESS)
  1512. {
  1513. //
  1514. // The output buffer contains an array of NETRESOURCEWs, plus strings.
  1515. // Convert the Unicode strings pointed to by these NETRESOURCEWs
  1516. // to Ansi strings, in place.
  1517. //
  1518. LPNETRESOURCEW lpNetResW = (LPNETRESOURCEW) lpBuffer;
  1519. for (DWORD i=0; i<*lpcCount; i++, lpNetResW++)
  1520. {
  1521. for (UINT iField = 0;
  1522. iField < NUMBER_OF_NETRESFIELD;
  1523. iField++)
  1524. {
  1525. if (lpNetResW->*NRWField[iField] != NULL)
  1526. {
  1527. status = OutputStringToAnsiInPlace(
  1528. lpNetResW->*NRWField[iField]);
  1529. if (status != WN_SUCCESS)
  1530. {
  1531. MPR_LOG0(ERROR,"WNetEnumResourceA: Couldn't convert all structs\n");
  1532. status = WN_SUCCESS;
  1533. *lpcCount = i;
  1534. break; // breaks out of both loops
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. SET_AND_RETURN(status)
  1541. }
  1542. DWORD APIENTRY
  1543. WNetGetResourceInformationA(
  1544. IN LPNETRESOURCEA lpNetResource,
  1545. OUT LPVOID lpBuffer,
  1546. IN OUT LPDWORD lpBufferSize,
  1547. OUT LPSTR * lplpSystem
  1548. )
  1549. {
  1550. DWORD status;
  1551. LPBYTE tempBuffer = NULL;
  1552. ANSI_PARM AParm[4];
  1553. UNICODE_PARM UParm[4];
  1554. AParm[0].lpNetResA = lpNetResource;
  1555. AParm[1].lpvoid = lpBuffer;
  1556. AParm[2].lpdword = lpBufferSize;
  1557. AParm[3].dword = sizeof(NETRESOURCE);
  1558. status = InputParmsToUnicode("N" NETRES_RP "Bs", AParm, UParm, &tempBuffer);
  1559. if (status == WN_SUCCESS)
  1560. {
  1561. status = WNetGetResourceInformationW(
  1562. UParm[0].lpNetResW,
  1563. UParm[1].lpbyte,
  1564. &UParm[2].dword,
  1565. (LPWSTR *) lplpSystem
  1566. );
  1567. if (status == WN_SUCCESS)
  1568. {
  1569. ANSI_OUT_BUFFER Buf((LPBYTE) lpBuffer, *lpBufferSize);
  1570. //
  1571. // Convert the Unicode netresource returned to Ansi
  1572. //
  1573. status = OutputNetResourceToAnsi(UParm[1].lpNetResW, &Buf);
  1574. if (status == WN_SUCCESS)
  1575. {
  1576. //
  1577. // Convert the Unicode string (*lplpSystem) returned to Ansi
  1578. //
  1579. LPWSTR lpSystemW = * (LPWSTR *) lplpSystem;
  1580. if (lpSystemW != NULL)
  1581. {
  1582. *lplpSystem = (LPSTR) Buf.Next();
  1583. status = OutputStringToAnsi(lpSystemW, &Buf);
  1584. }
  1585. }
  1586. //
  1587. // Map the results to WNet API conventions
  1588. //
  1589. if (status == WN_SUCCESS && Buf.Overflow())
  1590. {
  1591. *lpBufferSize = Buf.GetUsage();
  1592. status = WN_MORE_DATA;
  1593. }
  1594. }
  1595. else if (status == WN_MORE_DATA)
  1596. {
  1597. //
  1598. // Adjust the required buffer size for ansi/DBCS.
  1599. //
  1600. // We don't know how many characters will be required so we have to
  1601. // assume the worst case (all characters are DBCS characters).
  1602. //
  1603. *lpBufferSize = UParm[2].dword;
  1604. }
  1605. }
  1606. LocalFree(tempBuffer);
  1607. SET_AND_RETURN(status)
  1608. }
  1609. DWORD APIENTRY
  1610. WNetGetResourceParentA(
  1611. IN LPNETRESOURCEA lpNetResource,
  1612. OUT LPVOID lpBuffer,
  1613. IN OUT LPDWORD lpBufferSize
  1614. )
  1615. {
  1616. DWORD status;
  1617. LPBYTE tempBuffer = NULL;
  1618. ANSI_PARM AParm[4];
  1619. UNICODE_PARM UParm[4];
  1620. AParm[0].lpNetResA = lpNetResource;
  1621. AParm[1].lpvoid = lpBuffer;
  1622. AParm[2].lpdword = lpBufferSize;
  1623. AParm[3].dword = sizeof(NETRESOURCE);
  1624. status = InputParmsToUnicode("N" NETRES_RP "Bs", AParm, UParm, &tempBuffer);
  1625. if (status == WN_SUCCESS)
  1626. {
  1627. status = WNetGetResourceParentW(
  1628. UParm[0].lpNetResW,
  1629. UParm[1].lpbyte,
  1630. &UParm[2].dword
  1631. );
  1632. if (status == WN_SUCCESS)
  1633. {
  1634. //
  1635. // Convert the Unicode netresource returned to Ansi
  1636. //
  1637. status = OutputBufferToAnsi('N', UParm[1].lpbyte, lpBuffer, lpBufferSize);
  1638. }
  1639. else if (status == WN_MORE_DATA)
  1640. {
  1641. //
  1642. // Adjust the required buffer size for ansi/DBCS.
  1643. //
  1644. // We don't know how many characters will be required so we have to
  1645. // assume the worst case (all characters are DBCS characters).
  1646. //
  1647. *lpBufferSize = UParm[2].dword;
  1648. }
  1649. }
  1650. LocalFree(tempBuffer);
  1651. SET_AND_RETURN(status)
  1652. }
  1653. DWORD APIENTRY
  1654. WNetGetUserA (
  1655. IN LPCSTR lpName,
  1656. OUT LPSTR lpUserName,
  1657. IN OUT LPDWORD lpnLength
  1658. )
  1659. /*++
  1660. Routine Description:
  1661. This function retreives the current default user name or the username
  1662. used to establish a network connection.
  1663. Arguments:
  1664. lpName - Points to a null-terminated string that specifies either the
  1665. name or the local device to return the user name for, or a network
  1666. name that the user has made a connection to. If the pointer is
  1667. NULL, the name of the current user is returned.
  1668. lpUserName - Points to a buffer to receive the null-terminated
  1669. user name.
  1670. lpnLength - Specifies the size (in characters) of the buffer pointed
  1671. to by the lpUserName parameter. If the call fails because the
  1672. buffer is not big enough, this location is used to return the
  1673. required buffer size.
  1674. Return Value:
  1675. --*/
  1676. {
  1677. ANSI_API_WITH_ANSI_OUTPUT(
  1678. 3,
  1679. AParm[0].lpcstr = lpName;
  1680. AParm[1].lpvoid = lpUserName;
  1681. AParm[2].lpdword = lpnLength; ,
  1682. "SB",
  1683. WNetGetUserW(UParm[0].lpwstr, UParm[1].lpwstr, lpnLength); ,
  1684. OutputBufferToAnsi('S', UParm[1].lpbyte, lpUserName, lpnLength);
  1685. )
  1686. }
  1687. DWORD
  1688. RestoreConnectionA0 (
  1689. IN HWND hwnd,
  1690. IN LPSTR lpDevice
  1691. )
  1692. /*++
  1693. Routine Description:
  1694. Arguments:
  1695. Return Value:
  1696. --*/
  1697. {
  1698. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1699. 1,
  1700. AParm[0].lpcstr = lpDevice; ,
  1701. "S",
  1702. WNetRestoreConnectionW(hwnd, UParm[0].lpwstr);
  1703. )
  1704. }
  1705. DWORD
  1706. WNetGetDirectoryTypeA (
  1707. IN LPSTR lpName,
  1708. OUT LPINT lpType,
  1709. IN BOOL bFlushCache
  1710. )
  1711. /*++
  1712. Routine Description:
  1713. Arguments:
  1714. Return Value:
  1715. --*/
  1716. {
  1717. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1718. 1,
  1719. AParm[0].lpcstr = lpName; ,
  1720. "S",
  1721. WNetGetDirectoryTypeW(UParm[0].lpwstr, lpType, bFlushCache);
  1722. )
  1723. }
  1724. DWORD
  1725. WNetDirectoryNotifyA (
  1726. IN HWND hwnd,
  1727. IN LPSTR lpDir,
  1728. IN DWORD dwOper
  1729. )
  1730. /*++
  1731. Routine Description:
  1732. Arguments:
  1733. Return Value:
  1734. --*/
  1735. {
  1736. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1737. 1,
  1738. AParm[0].lpcstr = lpDir; ,
  1739. "S",
  1740. WNetDirectoryNotifyW(hwnd, UParm[0].lpwstr, dwOper);
  1741. )
  1742. }
  1743. DWORD APIENTRY
  1744. WNetGetLastErrorA (
  1745. OUT LPDWORD lpError,
  1746. OUT LPSTR lpErrorBuf,
  1747. IN DWORD nErrorBufSize,
  1748. OUT LPSTR lpNameBuf,
  1749. IN DWORD nNameBufSize
  1750. )
  1751. /*++
  1752. Routine Description:
  1753. Arguments:
  1754. Return Value:
  1755. --*/
  1756. {
  1757. DWORD status;
  1758. //
  1759. // We re-use the Ansi buffers for the Unicode API.
  1760. // There are no input Ansi parameters to convert to Unicode.
  1761. //
  1762. // Call the Unicode version of the function.
  1763. // Note: The sizes for the buffers that are passed in assume that
  1764. // the returned unicode strings will return DBCS characters.
  1765. //
  1766. status = WNetGetLastErrorW(
  1767. lpError,
  1768. (LPWSTR) lpErrorBuf,
  1769. nErrorBufSize / sizeof(WCHAR),
  1770. (LPWSTR) lpNameBuf,
  1771. nNameBufSize / sizeof(WCHAR)
  1772. );
  1773. //
  1774. // Convert the returned strings to Ansi, in place.
  1775. // There should be no buffer overflow.
  1776. //
  1777. if (status == WN_SUCCESS)
  1778. {
  1779. status = OutputStringToAnsiInPlace((LPWSTR) lpErrorBuf);
  1780. if (status == WN_SUCCESS)
  1781. {
  1782. status = OutputStringToAnsiInPlace((LPWSTR) lpNameBuf);
  1783. }
  1784. }
  1785. SET_AND_RETURN(status)
  1786. }
  1787. VOID
  1788. WNetSetLastErrorA(
  1789. IN DWORD err,
  1790. IN LPSTR lpError,
  1791. IN LPSTR lpProviders
  1792. )
  1793. /*++
  1794. Routine Description:
  1795. Arguments:
  1796. Return Value:
  1797. --*/
  1798. {
  1799. DWORD status;
  1800. LPBYTE tempBuffer = NULL;
  1801. ANSI_PARM AParm[2];
  1802. UNICODE_PARM UParm[2];
  1803. AParm[0].lpcstr = lpError;
  1804. AParm[1].lpcstr = lpProviders;
  1805. status = InputParmsToUnicode("SS", AParm, UParm, &tempBuffer);
  1806. if (status != WN_SUCCESS)
  1807. {
  1808. UParm[0].lpwstr = NULL;
  1809. UParm[1].lpwstr = NULL;
  1810. }
  1811. WNetSetLastErrorW(err, UParm[0].lpwstr, UParm[1].lpwstr);
  1812. LocalFree(tempBuffer);
  1813. return;
  1814. }
  1815. DWORD APIENTRY
  1816. MultinetGetErrorTextA(
  1817. OUT LPSTR lpErrorTextBuf OPTIONAL,
  1818. IN OUT LPDWORD lpnErrorBufSize OPTIONAL,
  1819. OUT LPSTR lpProviderNameBuf OPTIONAL,
  1820. IN OUT LPDWORD lpnNameBufSize OPTIONAL
  1821. )
  1822. /*++
  1823. Routine Description:
  1824. Arguments:
  1825. Return Value:
  1826. --*/
  1827. {
  1828. // CODEWORK: This could be simplified by re-using the Unicode buffers,
  1829. // like WNetGetLastErrorA.
  1830. DWORD status;
  1831. LPBYTE tempBuffer = NULL;
  1832. ANSI_PARM AParm[4];
  1833. UNICODE_PARM UParm[4];
  1834. AParm[0].lpvoid = lpErrorTextBuf;
  1835. AParm[1].lpdword = lpnErrorBufSize;
  1836. AParm[2].lpvoid = lpProviderNameBuf;
  1837. AParm[3].lpdword = lpnNameBufSize;
  1838. status = InputParmsToUnicode("BB", AParm, UParm, &tempBuffer);
  1839. if (status == WN_SUCCESS)
  1840. {
  1841. // Remember the sizes before calling the function
  1842. DWORD nErrorBufSize;
  1843. DWORD nNameBufSize;
  1844. if (ARGUMENT_PRESENT(lpErrorTextBuf))
  1845. {
  1846. nErrorBufSize = *lpnErrorBufSize;
  1847. }
  1848. if (ARGUMENT_PRESENT(lpProviderNameBuf))
  1849. {
  1850. nNameBufSize = *lpnNameBufSize;
  1851. }
  1852. status = MultinetGetErrorTextW(
  1853. UParm[0].lpwstr,
  1854. lpnErrorBufSize,
  1855. UParm[2].lpwstr,
  1856. lpnNameBufSize
  1857. );
  1858. if (status == WN_SUCCESS || status == WN_MORE_DATA)
  1859. {
  1860. if (ARGUMENT_PRESENT(lpErrorTextBuf) &&
  1861. nErrorBufSize == *lpnErrorBufSize)
  1862. {
  1863. // The Unicode API must have written the error text buffer
  1864. DWORD status2 = OutputBufferToAnsi(
  1865. 'S',
  1866. UParm[0].lpbyte,
  1867. lpErrorTextBuf,
  1868. lpnErrorBufSize);
  1869. if (status2 != WN_SUCCESS)
  1870. {
  1871. status = status2;
  1872. }
  1873. }
  1874. }
  1875. if (status == WN_SUCCESS || status == WN_MORE_DATA)
  1876. {
  1877. if (ARGUMENT_PRESENT(lpProviderNameBuf) &&
  1878. nNameBufSize == *lpnNameBufSize)
  1879. {
  1880. // The Unicode API must have written the provider name buffer
  1881. DWORD status2 = OutputBufferToAnsi(
  1882. 'S',
  1883. UParm[2].lpbyte,
  1884. lpProviderNameBuf,
  1885. lpnNameBufSize);
  1886. if (status2 != WN_SUCCESS)
  1887. {
  1888. status = status2;
  1889. }
  1890. }
  1891. }
  1892. }
  1893. LocalFree(tempBuffer);
  1894. SET_AND_RETURN(status)
  1895. }
  1896. DWORD
  1897. WNetPropertyDialogA (
  1898. HWND hwndParent,
  1899. DWORD iButton,
  1900. DWORD nPropSel,
  1901. LPSTR lpszName,
  1902. DWORD nType
  1903. )
  1904. /*++
  1905. Routine Description:
  1906. Arguments:
  1907. Return Value:
  1908. --*/
  1909. {
  1910. ANSI_API_WITHOUT_ANSI_OUTPUT(
  1911. 1,
  1912. AParm[0].lpcstr = lpszName; ,
  1913. "S",
  1914. WNetPropertyDialogW(hwndParent, iButton, nPropSel, UParm[0].lpwstr, nType);
  1915. )
  1916. }
  1917. DWORD
  1918. WNetGetPropertyTextA (
  1919. IN DWORD iButton,
  1920. IN DWORD nPropSel,
  1921. IN LPSTR lpszName,
  1922. OUT LPSTR lpszButtonName,
  1923. IN DWORD nButtonNameLen,
  1924. IN DWORD nType
  1925. )
  1926. /*++
  1927. Routine Description:
  1928. Arguments:
  1929. Return Value:
  1930. --*/
  1931. {
  1932. ANSI_API_WITH_ANSI_OUTPUT(
  1933. 3,
  1934. AParm[0].lpcstr = lpszName;
  1935. AParm[1].lpvoid = lpszButtonName;
  1936. AParm[2].lpdword = &nButtonNameLen; ,
  1937. "SB",
  1938. WNetGetPropertyTextW(iButton, nPropSel, UParm[0].lpwstr,
  1939. UParm[1].lpwstr, nButtonNameLen, nType); ,
  1940. OutputBufferToAnsi('S', UParm[1].lpbyte, lpszButtonName, &nButtonNameLen);
  1941. )
  1942. }
  1943. DWORD APIENTRY
  1944. WNetFormatNetworkNameA(
  1945. IN LPCSTR lpProvider,
  1946. IN LPCSTR lpRemoteName,
  1947. OUT LPSTR lpFormattedName,
  1948. IN OUT LPDWORD lpnLength, // In characters!
  1949. IN DWORD dwFlags,
  1950. IN DWORD dwAveCharPerLine
  1951. )
  1952. /*++
  1953. Routine Description:
  1954. Arguments:
  1955. Return Value:
  1956. --*/
  1957. {
  1958. ANSI_API_WITH_ANSI_OUTPUT(
  1959. 4,
  1960. AParm[0].lpcstr = lpProvider;
  1961. AParm[1].lpcstr = lpRemoteName;
  1962. AParm[2].lpvoid = lpFormattedName;
  1963. AParm[3].lpdword = lpnLength; ,
  1964. "SSB",
  1965. WNetFormatNetworkNameW(
  1966. UParm[0].lpwstr,
  1967. UParm[1].lpwstr,
  1968. UParm[2].lpwstr,
  1969. lpnLength,
  1970. dwFlags,
  1971. dwAveCharPerLine
  1972. ); ,
  1973. OutputBufferToAnsi('S', UParm[2].lpbyte, lpFormattedName, lpnLength);
  1974. )
  1975. }