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.

1203 lines
31 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. dosprint.c
  5. Abstract:
  6. This module provides the ANSI mapping layer from the old DosPrint APIs to
  7. the new all singing all dancing beautiful Print APIs. (The UNICODE mapping
  8. layer is in DosPrtW.c in this directory.)
  9. Author:
  10. Dave Snipp (DaveSn) 26-Apr-1991
  11. Revision History:
  12. 09-Jul-1992 JohnRo
  13. RAID 10324: net print vs. UNICODE.
  14. Fixed many wrong error codes.
  15. Use PREFIX_ equates.
  16. Use offsetof() as provided by implmentation, not our own (nonportable).
  17. Made changes suggested by PC-LINT, including one bug fix.
  18. 03-Oct-1992 JohnRo
  19. RAID 3556: DosPrintQGetInfo(from downlevel) level 3, rc=124. (4&5 too.)
  20. RAID 8333: view printer queues hangs DOS LM enh client.
  21. Make sure data type in job level 1 is null terminated.
  22. Fixed job submitted times.
  23. Fixed DosPrintQEnumA level 5 array bug.
  24. Fixed DosPrintJobEnumA levels 2 and 3.
  25. Also implemented DosPrintJobGetInfo levels 0, 1, and 3.
  26. Fixed bug calling OpenPrinter with wrong char set here and there.
  27. Fixed job comment field (was set to document by mistake).
  28. Fixed error code if GlobalAlloc fails.
  29. Avoid compiler warnings due to new winspool.h.
  30. 04-Dec-1992 JohnRo
  31. RAID 1661: downlevel to NT DosPrintDestEnum not supported.
  32. Added code to track down empty queue name.
  33. Quiet normal debug output.
  34. Avoid const vs. volatile compiler warnings.
  35. Avoid new compiler warnings.
  36. Made changes suggested by PC-LINT 5.0
  37. 08-Feb-1993 JohnRo
  38. RAID 10164: Data misalignment error during XsDosPrintQGetInfo().
  39. 22-Mar-1993 JohnRo
  40. RAID 2974: NET PRINT says NT printer is held when it isn't.
  41. DosPrint API cleanup: reduced this file to just ANSI wrappers.
  42. Made more changes suggested by PC-LINT 5.0
  43. Added some IN and OUT keywords.
  44. Clarified many debug messages.
  45. 07-Apr-1993 JohnRo
  46. RAID 5670: "NET PRINT \\server\share" gives err 124 (bad level) on NT.
  47. 11-May-1993 JohnRo
  48. RAID 9942: workaround Windows For Workgroups (WFW) bug in DosPrintQEnum.
  49. Also fixed "NET PRINT \\server\share" and "NET SHARE printshare /DEL"
  50. GP faults.
  51. --*/
  52. #define NOMINMAX
  53. #define NOSERVICE // Avoid <winsvc.h> vs. <lmsvc.h> conflicts.
  54. #include <windows.h>
  55. #include <lmcons.h>
  56. #include <dosprint.h> // My prototypes.
  57. #include <dosprtp.h> // My prototypes.
  58. #include <lmapibuf.h> // NetApiBufferFree(), etc.
  59. #include <netdebug.h> // DBGSTATIC, NetpKdPrint(()), etc.
  60. #include <prefix.h> // PREFIX_ equates.
  61. #include <stddef.h> // offsetof().
  62. #include <string.h> // memcpy(), strncpy().
  63. #include <tstring.h> // NetpAlloc{type}From{type}.
  64. #include <winerror.h> // NO_ERROR, ERROR_ equates.
  65. #include "convprt.h" // Netp* print helpers
  66. #define MAX_WORD ( (WORD) (~0) )
  67. SPLERR SPLENTRY DosPrintQGetInfoA(
  68. IN LPSTR pszServer OPTIONAL,
  69. IN LPSTR pszQueueName,
  70. IN WORD uLevel,
  71. OUT PBYTE pbBuf,
  72. IN WORD cbBuf,
  73. OUT PUSHORT pcbNeeded
  74. )
  75. {
  76. DWORD cbBufW;
  77. DWORD rc;
  78. USHORT cbNeeded;
  79. LPWSTR QueueNameW = NULL;
  80. LPWSTR ServerNameW = NULL;
  81. LPVOID TempBufferW = NULL;
  82. QueueNameW = NetpAllocWStrFromStr( pszQueueName );
  83. if (QueueNameW == NULL) {
  84. rc = ERROR_NOT_ENOUGH_MEMORY;
  85. goto Cleanup;
  86. }
  87. if (pszServer && *pszServer) {
  88. ServerNameW = NetpAllocWStrFromStr( pszServer );
  89. if (ServerNameW == NULL) {
  90. rc = ERROR_NOT_ENOUGH_MEMORY;
  91. goto Cleanup;
  92. }
  93. }
  94. // Compute wide buff size.
  95. cbBufW = cbBuf * sizeof(WCHAR);
  96. if ( cbBufW > (DWORD) MAX_WORD ) {
  97. cbBufW = (DWORD) MAX_WORD;
  98. }
  99. rc = NetApiBufferAllocate(
  100. cbBuf * sizeof(WCHAR),
  101. (LPVOID *) (LPVOID) &TempBufferW );
  102. if (rc != NO_ERROR) {
  103. goto Cleanup;
  104. }
  105. //
  106. // Process the API (locally or remotely) and get results (with
  107. // UNICODE strings).
  108. //
  109. rc = DosPrintQGetInfoW(
  110. ServerNameW,
  111. QueueNameW,
  112. uLevel,
  113. TempBufferW,
  114. (WORD) cbBufW,
  115. (PUSHORT) &cbNeeded);
  116. *pcbNeeded = cbNeeded;
  117. //
  118. // Convert results back from UNICODE.
  119. //
  120. if (rc == NO_ERROR) {
  121. LPBYTE StringAreaA = (LPBYTE)pbBuf + cbBuf;
  122. // Translate UNICODE strings back to ANSI.
  123. rc = NetpConvertPrintQCharSet(
  124. uLevel,
  125. FALSE, // not add or setinfo API
  126. TempBufferW, // from info
  127. pbBuf, // to info
  128. FALSE, // no, don't convert to UNICODE.
  129. & StringAreaA ); // conv strings and update ptr
  130. if (rc == ERROR_MORE_DATA)
  131. {
  132. *pcbNeeded = (USHORT)cbBufW ; // Unicode call succeeded but no room to go
  133. // Ansi. we know the Unicode buffer size is
  134. // definitely good enough. This is temporary
  135. // fix.
  136. }
  137. }
  138. Cleanup:
  139. if (QueueNameW != NULL) {
  140. (VOID) NetApiBufferFree( QueueNameW );
  141. }
  142. if (ServerNameW != NULL) {
  143. (VOID) NetApiBufferFree( ServerNameW );
  144. }
  145. if (TempBufferW != NULL) {
  146. (VOID) NetApiBufferFree( TempBufferW );
  147. }
  148. return rc;
  149. }
  150. SPLERR SPLENTRY DosPrintJobGetInfoA(
  151. IN LPSTR pszServer OPTIONAL,
  152. IN BOOL bRemote,
  153. IN WORD uJobId,
  154. IN WORD uLevel,
  155. OUT PBYTE pbBuf,
  156. IN WORD cbBuf,
  157. OUT PUSHORT pcbNeeded
  158. )
  159. {
  160. DWORD cbBufW;
  161. DWORD rc;
  162. USHORT cbNeeded;
  163. LPWSTR ServerNameW = NULL;
  164. LPVOID TempBufferW = NULL;
  165. if (pszServer && *pszServer) {
  166. ServerNameW = NetpAllocWStrFromStr( pszServer );
  167. if (ServerNameW == NULL) {
  168. rc = ERROR_NOT_ENOUGH_MEMORY;
  169. goto Cleanup;
  170. }
  171. }
  172. // Compute wide buff size.
  173. cbBufW = cbBuf * sizeof(WCHAR);
  174. if ( cbBufW > (DWORD) MAX_WORD ) {
  175. cbBufW = (DWORD) MAX_WORD;
  176. }
  177. rc = NetApiBufferAllocate(
  178. cbBufW,
  179. (LPVOID *) (LPVOID) &TempBufferW );
  180. if (rc != NO_ERROR) {
  181. goto Cleanup;
  182. }
  183. // Process the API (local or remote) and get results (with UNICODE strings).
  184. rc = DosPrintJobGetInfoW(
  185. ServerNameW,
  186. bRemote,
  187. uJobId,
  188. uLevel,
  189. TempBufferW,
  190. (WORD) cbBufW,
  191. &cbNeeded);
  192. *pcbNeeded = cbNeeded;
  193. if (rc == NO_ERROR) {
  194. LPBYTE StringAreaA = (LPBYTE)pbBuf + cbBuf;
  195. // Translate UNICODE strings back to ANSI.
  196. rc = NetpConvertPrintJobCharSet(
  197. uLevel,
  198. FALSE, // not add or setinfo API
  199. TempBufferW, // from info
  200. pbBuf, // to info
  201. FALSE, // no, don't convert to UNICODE.
  202. & StringAreaA ); // conv strings and update ptr
  203. }
  204. Cleanup:
  205. if (ServerNameW != NULL) {
  206. (VOID) NetApiBufferFree( ServerNameW );
  207. }
  208. if (TempBufferW != NULL) {
  209. (VOID) NetApiBufferFree( TempBufferW );
  210. }
  211. return (rc);
  212. }
  213. SPLERR SPLENTRY DosPrintJobDelA(
  214. LPSTR pszServer,
  215. BOOL bRemote,
  216. WORD uJobId
  217. )
  218. {
  219. DWORD rc;
  220. LPWSTR ServerNameW = NULL;
  221. if (pszServer && *pszServer) {
  222. ServerNameW = NetpAllocWStrFromStr( pszServer );
  223. if (ServerNameW == NULL) {
  224. rc = ERROR_NOT_ENOUGH_MEMORY;
  225. goto Cleanup;
  226. }
  227. }
  228. rc = DosPrintJobDelW( ServerNameW, bRemote, uJobId );
  229. Cleanup:
  230. if (ServerNameW != NULL) {
  231. (VOID) NetApiBufferFree( ServerNameW );
  232. }
  233. return (rc);
  234. }
  235. SPLERR SPLENTRY DosPrintJobContinueA(
  236. LPSTR pszServer,
  237. BOOL bRemote,
  238. WORD uJobId
  239. )
  240. {
  241. DWORD rc;
  242. LPWSTR ServerNameW = NULL;
  243. if (pszServer && *pszServer) {
  244. ServerNameW = NetpAllocWStrFromStr( pszServer );
  245. if (ServerNameW == NULL) {
  246. rc = ERROR_NOT_ENOUGH_MEMORY;
  247. goto Cleanup;
  248. }
  249. }
  250. rc = DosPrintJobContinueW( ServerNameW, bRemote, uJobId );
  251. Cleanup:
  252. if (ServerNameW != NULL) {
  253. (VOID) NetApiBufferFree( ServerNameW );
  254. }
  255. return (rc);
  256. }
  257. SPLERR SPLENTRY DosPrintJobPauseA(
  258. IN LPSTR pszServer,
  259. IN BOOL bRemote,
  260. IN WORD uJobId
  261. )
  262. {
  263. DWORD rc;
  264. LPWSTR ServerNameW = NULL;
  265. if (pszServer && *pszServer) {
  266. ServerNameW = NetpAllocWStrFromStr( pszServer );
  267. if (ServerNameW == NULL) {
  268. rc = ERROR_NOT_ENOUGH_MEMORY;
  269. goto Cleanup;
  270. }
  271. }
  272. rc = DosPrintJobPauseW( ServerNameW, bRemote, uJobId );
  273. Cleanup:
  274. if (ServerNameW != NULL) {
  275. (VOID) NetApiBufferFree( ServerNameW );
  276. }
  277. return rc;
  278. }
  279. SPLERR SPLENTRY DosPrintJobEnumA(
  280. IN LPSTR pszServer OPTIONAL,
  281. IN LPSTR pszQueueName,
  282. IN WORD uLevel,
  283. OUT PBYTE pbBuf,
  284. IN WORD cbBuf,
  285. OUT PWORD pcReturned,
  286. OUT PWORD pcTotal
  287. )
  288. {
  289. DWORD cbBufW;
  290. DWORD rc;
  291. LPWSTR QueueNameW = NULL;
  292. LPWSTR ServerNameW = NULL;
  293. LPVOID TempBufferW = NULL;
  294. QueueNameW = NetpAllocWStrFromStr( pszQueueName );
  295. if (QueueNameW == NULL) {
  296. rc = ERROR_NOT_ENOUGH_MEMORY;
  297. goto Cleanup;
  298. }
  299. if (pszServer && *pszServer) {
  300. ServerNameW = NetpAllocWStrFromStr( pszServer );
  301. if (ServerNameW == NULL) {
  302. rc = ERROR_NOT_ENOUGH_MEMORY;
  303. goto Cleanup;
  304. }
  305. }
  306. // Compute wide buff size.
  307. cbBufW = cbBuf * sizeof(WCHAR);
  308. if ( cbBufW > (DWORD) MAX_WORD ) {
  309. cbBufW = (DWORD) MAX_WORD;
  310. }
  311. rc = NetApiBufferAllocate(
  312. cbBufW,
  313. (LPVOID *) (LPVOID) &TempBufferW );
  314. if (rc != NO_ERROR) {
  315. goto Cleanup;
  316. }
  317. // Process API (local/remote), get UNICODE results.
  318. rc = DosPrintJobEnumW(
  319. ServerNameW,
  320. QueueNameW,
  321. uLevel,
  322. TempBufferW,
  323. (WORD) cbBufW,
  324. pcReturned,
  325. pcTotal);
  326. if (rc == NO_ERROR) {
  327. LPBYTE StringAreaA = (LPBYTE)pbBuf + cbBuf;
  328. // Translate UNICODE strings back to ANSI.
  329. rc = NetpConvertPrintJobArrayCharSet(
  330. uLevel,
  331. FALSE, // not add or setinfo API
  332. TempBufferW, // from info
  333. pbBuf, // to info
  334. FALSE, // no, don't convert to UNICODE.
  335. & StringAreaA, // conv strings and update ptr
  336. (DWORD) (*pcTotal) );
  337. }
  338. Cleanup:
  339. if (QueueNameW != NULL) {
  340. (VOID) NetApiBufferFree( QueueNameW );
  341. }
  342. if (ServerNameW != NULL) {
  343. (VOID) NetApiBufferFree( ServerNameW );
  344. }
  345. if (TempBufferW != NULL) {
  346. (VOID) NetApiBufferFree( TempBufferW );
  347. }
  348. return (rc);
  349. }
  350. SPLERR SPLENTRY
  351. DosPrintDestEnumA(
  352. IN LPSTR pszServer OPTIONAL,
  353. IN WORD uLevel,
  354. OUT PBYTE pbBuf,
  355. IN WORD cbBuf,
  356. OUT PUSHORT pcReturned,
  357. OUT PUSHORT pcTotal
  358. )
  359. {
  360. DWORD cbBufW;
  361. WORD cReturned, cTotal;
  362. DWORD rc;
  363. LPWSTR ServerNameW = NULL;
  364. LPVOID TempBufferW = NULL;
  365. if (pszServer && *pszServer) {
  366. ServerNameW = NetpAllocWStrFromStr( pszServer );
  367. if (ServerNameW == NULL) {
  368. rc = ERROR_NOT_ENOUGH_MEMORY;
  369. goto Cleanup;
  370. }
  371. }
  372. // Compute wide buff size.
  373. cbBufW = cbBuf * sizeof(WCHAR);
  374. if ( cbBufW > (DWORD) MAX_WORD ) {
  375. cbBufW = (DWORD) MAX_WORD;
  376. }
  377. rc = NetApiBufferAllocate(
  378. cbBufW,
  379. (LPVOID *) (LPVOID) &TempBufferW );
  380. if (rc != NO_ERROR) {
  381. goto Cleanup;
  382. }
  383. // Invoke wide-char version of API, which will do local or downlevel for us.
  384. rc = DosPrintDestEnumW(
  385. ServerNameW,
  386. uLevel,
  387. TempBufferW,
  388. (WORD) cbBufW,
  389. &cReturned,
  390. &cTotal);
  391. *pcReturned = (USHORT)cReturned;
  392. *pcTotal = (USHORT)cTotal;
  393. // Convert from wide chars for caller.
  394. if (rc == NO_ERROR) {
  395. LPBYTE StringAreaA = (LPBYTE)pbBuf + cbBuf;
  396. // Translate UNICODE strings back to ANSI.
  397. rc = NetpConvertPrintDestArrayCharSet(
  398. uLevel,
  399. FALSE, // not add or setinfo API
  400. TempBufferW, // from info
  401. pbBuf, // to info
  402. FALSE, // no, don't convert to UNICODE.
  403. & StringAreaA, // conv strings and update ptr
  404. cTotal );
  405. }
  406. Cleanup:
  407. if (ServerNameW != NULL) {
  408. (VOID) NetApiBufferFree( ServerNameW );
  409. }
  410. if (TempBufferW != NULL) {
  411. (VOID) NetApiBufferFree( TempBufferW );
  412. }
  413. return (rc);
  414. }
  415. SPLERR SPLENTRY DosPrintDestControlA(
  416. IN LPSTR pszServer OPTIONAL,
  417. IN LPSTR pszDevName,
  418. IN WORD uControl
  419. )
  420. {
  421. LPWSTR DestNameW = NULL;
  422. DWORD rc;
  423. LPWSTR ServerNameW = NULL;
  424. if (pszServer && *pszServer) {
  425. ServerNameW = NetpAllocWStrFromStr( pszServer );
  426. if (ServerNameW == NULL) {
  427. rc = ERROR_NOT_ENOUGH_MEMORY;
  428. goto Cleanup;
  429. }
  430. }
  431. DestNameW = NetpAllocWStrFromStr( pszDevName );
  432. if (DestNameW == NULL) {
  433. rc = ERROR_NOT_ENOUGH_MEMORY;
  434. goto Cleanup;
  435. }
  436. rc = DosPrintDestControlW(ServerNameW, DestNameW, uControl);
  437. Cleanup:
  438. if (DestNameW != NULL) {
  439. (VOID) NetApiBufferFree( DestNameW );
  440. }
  441. if (ServerNameW != NULL) {
  442. (VOID) NetApiBufferFree( ServerNameW );
  443. }
  444. return (rc);
  445. } // DosPrintDestControlA
  446. SPLERR SPLENTRY DosPrintDestGetInfoA(
  447. IN LPSTR pszServer OPTIONAL,
  448. IN LPSTR pszName,
  449. IN WORD uLevel,
  450. OUT PBYTE pbBuf,
  451. IN WORD cbBuf,
  452. OUT PUSHORT pcbNeeded
  453. )
  454. {
  455. DWORD cbBufW;
  456. DWORD rc;
  457. LPWSTR DestNameW = NULL;
  458. LPWSTR ServerNameW = NULL;
  459. LPVOID TempBufferW = NULL;
  460. if (pszServer && *pszServer) {
  461. ServerNameW = NetpAllocWStrFromStr( pszServer );
  462. if (ServerNameW == NULL) {
  463. rc = ERROR_NOT_ENOUGH_MEMORY;
  464. goto Cleanup;
  465. }
  466. }
  467. DestNameW = NetpAllocWStrFromStr( pszName );
  468. if (DestNameW == NULL) {
  469. rc = ERROR_NOT_ENOUGH_MEMORY;
  470. goto Cleanup;
  471. }
  472. // Compute wide buff size.
  473. cbBufW = cbBuf * sizeof(WCHAR);
  474. if ( cbBufW > (DWORD) MAX_WORD ) {
  475. cbBufW = (DWORD) MAX_WORD;
  476. }
  477. rc = NetApiBufferAllocate(
  478. cbBufW,
  479. (LPVOID *) (LPVOID) &TempBufferW );
  480. if (rc != NO_ERROR) {
  481. goto Cleanup;
  482. }
  483. // Process the API (local or remote) and get results (with UNICODE strings).
  484. rc = DosPrintDestGetInfoW(
  485. ServerNameW,
  486. DestNameW,
  487. uLevel,
  488. TempBufferW,
  489. (WORD) cbBufW,
  490. pcbNeeded);
  491. if (rc == NO_ERROR) {
  492. LPBYTE StringAreaA = (LPBYTE)pbBuf + cbBuf;
  493. // Translate UNICODE strings back to ANSI.
  494. rc = NetpConvertPrintDestCharSet(
  495. uLevel,
  496. FALSE, // not add or setinfo API
  497. TempBufferW, // from info
  498. pbBuf, // to info
  499. FALSE, // no, don't convert to UNICODE.
  500. & StringAreaA ); // conv strings and update ptr
  501. }
  502. Cleanup:
  503. if (DestNameW != NULL) {
  504. (VOID) NetApiBufferFree( DestNameW );
  505. }
  506. if (ServerNameW != NULL) {
  507. (VOID) NetApiBufferFree( ServerNameW );
  508. }
  509. if (TempBufferW != NULL) {
  510. (VOID) NetApiBufferFree( TempBufferW );
  511. }
  512. return (rc);
  513. }
  514. SPLERR SPLENTRY DosPrintDestAddA(
  515. IN LPSTR pszServer OPTIONAL,
  516. IN WORD uLevel,
  517. IN PBYTE pbBuf,
  518. IN WORD cbBuf
  519. )
  520. {
  521. DWORD cbBufW;
  522. DWORD rc;
  523. LPWSTR ServerNameW = NULL;
  524. LPBYTE StringAreaW;
  525. LPVOID TempBufferW = NULL;
  526. if (pszServer && *pszServer) {
  527. ServerNameW = NetpAllocWStrFromStr( pszServer );
  528. if (ServerNameW == NULL) {
  529. rc = ERROR_NOT_ENOUGH_MEMORY;
  530. goto Cleanup;
  531. }
  532. }
  533. // Compute wide buff size.
  534. cbBufW = cbBuf * sizeof(WCHAR);
  535. if ( cbBufW > (DWORD) MAX_WORD ) {
  536. cbBufW = (DWORD) MAX_WORD;
  537. }
  538. rc = NetApiBufferAllocate(
  539. cbBufW,
  540. (LPVOID *) (LPVOID) &TempBufferW );
  541. if (rc != NO_ERROR) {
  542. goto Cleanup;
  543. }
  544. StringAreaW = (LPBYTE)TempBufferW + cbBufW;
  545. rc = NetpConvertPrintDestCharSet(
  546. uLevel,
  547. TRUE, // yes, is add or setinfo API
  548. pbBuf, // from info
  549. TempBufferW, // to info
  550. TRUE, // yes, convert to UNICODE.
  551. & StringAreaW ); // conv strings and update ptr
  552. if (rc != NO_ERROR) {
  553. goto Cleanup;
  554. }
  555. rc = DosPrintDestAddW(
  556. ServerNameW,
  557. uLevel,
  558. TempBufferW,
  559. (WORD) cbBufW);
  560. Cleanup:
  561. if (ServerNameW != NULL) {
  562. (VOID) NetApiBufferFree( ServerNameW );
  563. }
  564. if (TempBufferW != NULL) {
  565. (VOID) NetApiBufferFree( TempBufferW );
  566. }
  567. return (rc);
  568. }
  569. SPLERR SPLENTRY DosPrintDestSetInfoA(
  570. IN LPSTR pszServer OPTIONAL,
  571. IN LPSTR pszName,
  572. IN WORD uLevel,
  573. IN PBYTE pbBuf,
  574. IN WORD cbBuf,
  575. IN WORD uParmNum
  576. )
  577. {
  578. DWORD cbBufW;
  579. LPWSTR DestNameW = NULL;
  580. DWORD rc;
  581. LPWSTR ServerNameW = NULL;
  582. LPBYTE StringAreaW;
  583. LPVOID TempBufferW = NULL;
  584. if (pszServer && *pszServer) {
  585. ServerNameW = NetpAllocWStrFromStr( pszServer );
  586. if (ServerNameW == NULL) {
  587. rc = ERROR_NOT_ENOUGH_MEMORY;
  588. goto Cleanup;
  589. }
  590. }
  591. DestNameW = NetpAllocWStrFromStr( pszName );
  592. if (DestNameW == NULL) {
  593. rc = ERROR_NOT_ENOUGH_MEMORY;
  594. goto Cleanup;
  595. }
  596. // Compute wide buff size.
  597. cbBufW = cbBuf * sizeof(WCHAR);
  598. if ( cbBufW > (DWORD) MAX_WORD ) {
  599. cbBufW = (DWORD) MAX_WORD;
  600. }
  601. rc = NetApiBufferAllocate(
  602. cbBufW,
  603. (LPVOID *) (LPVOID) &TempBufferW );
  604. if (rc != NO_ERROR) {
  605. goto Cleanup;
  606. }
  607. StringAreaW = (LPBYTE)TempBufferW + cbBufW;
  608. rc = NetpConvertPrintDestCharSet(
  609. uLevel,
  610. TRUE, // yes, is add or setinfo API
  611. pbBuf, // from info
  612. TempBufferW, // to info
  613. TRUE, // yes, convert to UNICODE.
  614. & StringAreaW ); // conv strings and update ptr
  615. if (rc != NO_ERROR) {
  616. goto Cleanup;
  617. }
  618. rc = DosPrintDestSetInfoW(
  619. ServerNameW,
  620. DestNameW,
  621. uLevel,
  622. TempBufferW,
  623. (WORD) cbBufW,
  624. uParmNum);
  625. Cleanup:
  626. if (DestNameW != NULL) {
  627. (VOID) NetApiBufferFree( DestNameW );
  628. }
  629. if (ServerNameW != NULL) {
  630. (VOID) NetApiBufferFree( ServerNameW );
  631. }
  632. if (TempBufferW != NULL) {
  633. (VOID) NetApiBufferFree( TempBufferW );
  634. }
  635. return (rc);
  636. }
  637. SPLERR SPLENTRY DosPrintDestDelA(
  638. IN LPSTR pszServer OPTIONAL,
  639. IN LPSTR pszPrinterName
  640. )
  641. {
  642. LPWSTR PrinterNameW = NULL;
  643. DWORD rc;
  644. LPWSTR ServerNameW = NULL;
  645. if (pszServer && *pszServer) {
  646. ServerNameW = NetpAllocWStrFromStr( pszServer );
  647. if (ServerNameW == NULL) {
  648. rc = ERROR_NOT_ENOUGH_MEMORY;
  649. goto Cleanup;
  650. }
  651. }
  652. PrinterNameW = NetpAllocWStrFromStr( pszPrinterName );
  653. if (PrinterNameW == NULL) {
  654. rc = ERROR_NOT_ENOUGH_MEMORY;
  655. goto Cleanup;
  656. }
  657. rc = DosPrintDestDelW(
  658. ServerNameW,
  659. PrinterNameW);
  660. Cleanup:
  661. if (PrinterNameW != NULL) {
  662. (VOID) NetApiBufferFree( PrinterNameW );
  663. }
  664. if (ServerNameW != NULL) {
  665. (VOID) NetApiBufferFree( ServerNameW );
  666. }
  667. return (rc);
  668. }
  669. SPLERR SPLENTRY DosPrintQEnumA(
  670. IN LPSTR pszServer OPTIONAL,
  671. IN WORD uLevel,
  672. OUT PBYTE pbBuf,
  673. IN WORD cbBuf,
  674. OUT PUSHORT pcReturned,
  675. OUT PUSHORT pcTotal
  676. )
  677. {
  678. DWORD cbBufW;
  679. DWORD rc;
  680. LPWSTR ServerNameW = NULL;
  681. LPVOID TempBufferW = NULL; // queue structure with UNICODE strings.
  682. if (pszServer && *pszServer) {
  683. ServerNameW = NetpAllocWStrFromStr( pszServer );
  684. if (ServerNameW == NULL) {
  685. rc = ERROR_NOT_ENOUGH_MEMORY;
  686. goto Cleanup;
  687. }
  688. }
  689. // Compute wide buff size.
  690. cbBufW = cbBuf * sizeof(WCHAR);
  691. if ( cbBufW > (DWORD) MAX_WORD ) {
  692. cbBufW = (DWORD) MAX_WORD;
  693. }
  694. rc = NetApiBufferAllocate(
  695. cbBufW,
  696. (LPVOID *) (LPVOID) &TempBufferW );
  697. if (rc != NO_ERROR) {
  698. goto Cleanup;
  699. }
  700. // Process local/remote, get UNICODE results.
  701. rc = DosPrintQEnumW(
  702. ServerNameW,
  703. uLevel,
  704. TempBufferW,
  705. (WORD) cbBufW,
  706. pcReturned,
  707. pcTotal);
  708. // Convert back to UNICODE.
  709. if (rc == NO_ERROR) {
  710. LPBYTE StringAreaA = (LPBYTE)pbBuf + cbBuf;
  711. rc = (DWORD) NetpConvertPrintQArrayCharSet(
  712. uLevel,
  713. FALSE, // not add or setinfo API
  714. TempBufferW, // from info
  715. pbBuf, // to info
  716. FALSE, // no, not converting to UNICODE
  717. &StringAreaA, // string area; update ptr
  718. *pcReturned ); // Q count
  719. }
  720. Cleanup:
  721. if (ServerNameW != NULL) {
  722. (VOID) NetApiBufferFree( ServerNameW );
  723. }
  724. if (TempBufferW != NULL) {
  725. (VOID) NetApiBufferFree( TempBufferW );
  726. }
  727. return (rc);
  728. }
  729. SPLERR SPLENTRY DosPrintQSetInfoA(
  730. IN LPSTR pszServer OPTIONAL,
  731. IN LPSTR pszQueueName,
  732. IN WORD uLevel,
  733. IN PBYTE pbBuf,
  734. IN WORD cbBuf,
  735. IN WORD uParmNum
  736. )
  737. {
  738. DWORD cbBufW;
  739. LPWSTR QueueNameW = NULL;
  740. DWORD rc;
  741. LPWSTR ServerNameW = NULL;
  742. LPBYTE StringAreaW;
  743. LPVOID TempBufferW = NULL;
  744. if (pszServer && *pszServer) {
  745. ServerNameW = NetpAllocWStrFromStr( pszServer );
  746. if (ServerNameW == NULL) {
  747. rc = ERROR_NOT_ENOUGH_MEMORY;
  748. goto Cleanup;
  749. }
  750. }
  751. QueueNameW = NetpAllocWStrFromStr( pszQueueName );
  752. if (QueueNameW == NULL) {
  753. rc = ERROR_NOT_ENOUGH_MEMORY;
  754. goto Cleanup;
  755. }
  756. // Compute wide buff size.
  757. cbBufW = cbBuf * sizeof(WCHAR);
  758. if ( cbBufW > (DWORD) MAX_WORD ) {
  759. cbBufW = (DWORD) MAX_WORD;
  760. }
  761. rc = NetApiBufferAllocate(
  762. cbBufW,
  763. (LPVOID *) (LPVOID) &TempBufferW );
  764. if (rc != NO_ERROR) {
  765. goto Cleanup;
  766. }
  767. StringAreaW = (LPBYTE)TempBufferW + cbBufW;
  768. rc = NetpConvertPrintQCharSet(
  769. uLevel,
  770. TRUE, // yes, is add or setinfo API
  771. pbBuf, // from info
  772. TempBufferW, // to info
  773. TRUE, // yes, convert to UNICODE.
  774. & StringAreaW ); // conv strings and update ptr
  775. if (rc != NO_ERROR) {
  776. goto Cleanup;
  777. }
  778. rc = DosPrintQSetInfoW(
  779. ServerNameW,
  780. QueueNameW,
  781. uLevel,
  782. TempBufferW,
  783. (WORD) cbBufW,
  784. uParmNum);
  785. Cleanup:
  786. if (QueueNameW != NULL) {
  787. (VOID) NetApiBufferFree( QueueNameW );
  788. }
  789. if (ServerNameW != NULL) {
  790. (VOID) NetApiBufferFree( ServerNameW );
  791. }
  792. if (TempBufferW != NULL) {
  793. (VOID) NetApiBufferFree( TempBufferW );
  794. }
  795. return (rc);
  796. }
  797. SPLERR SPLENTRY DosPrintQPauseA(
  798. IN LPSTR pszServer OPTIONAL,
  799. IN LPSTR pszQueueName
  800. )
  801. {
  802. LPWSTR QueueNameW = NULL;
  803. DWORD rc;
  804. LPWSTR ServerNameW = NULL;
  805. if (pszServer && *pszServer) {
  806. ServerNameW = NetpAllocWStrFromStr( pszServer );
  807. if (ServerNameW == NULL) {
  808. rc = ERROR_NOT_ENOUGH_MEMORY;
  809. goto Cleanup;
  810. }
  811. }
  812. QueueNameW = NetpAllocWStrFromStr( pszQueueName );
  813. if (QueueNameW == NULL) {
  814. rc = ERROR_NOT_ENOUGH_MEMORY;
  815. goto Cleanup;
  816. }
  817. rc = DosPrintQPauseW(ServerNameW, QueueNameW);
  818. Cleanup:
  819. if (QueueNameW != NULL) {
  820. (VOID) NetApiBufferFree( QueueNameW );
  821. }
  822. if (ServerNameW != NULL) {
  823. (VOID) NetApiBufferFree( ServerNameW );
  824. }
  825. return (rc);
  826. }
  827. SPLERR SPLENTRY DosPrintQContinueA(
  828. IN LPSTR pszServer OPTIONAL,
  829. IN LPSTR pszQueueName
  830. )
  831. {
  832. LPWSTR QueueNameW = NULL;
  833. DWORD rc;
  834. LPWSTR ServerNameW = NULL;
  835. if (pszServer && *pszServer) {
  836. ServerNameW = NetpAllocWStrFromStr( pszServer );
  837. if (ServerNameW == NULL) {
  838. rc = ERROR_NOT_ENOUGH_MEMORY;
  839. goto Cleanup;
  840. }
  841. }
  842. QueueNameW = NetpAllocWStrFromStr( pszQueueName );
  843. if (QueueNameW == NULL) {
  844. rc = ERROR_NOT_ENOUGH_MEMORY;
  845. goto Cleanup;
  846. }
  847. rc = DosPrintQContinueW( ServerNameW, QueueNameW );
  848. Cleanup:
  849. if (QueueNameW != NULL) {
  850. (VOID) NetApiBufferFree( QueueNameW );
  851. }
  852. if (ServerNameW != NULL) {
  853. (VOID) NetApiBufferFree( ServerNameW );
  854. }
  855. return (rc);
  856. }
  857. SPLERR SPLENTRY DosPrintQPurgeA(
  858. IN LPSTR pszServer OPTIONAL,
  859. IN LPSTR pszQueueName
  860. )
  861. {
  862. LPWSTR QueueNameW = NULL;
  863. DWORD rc;
  864. LPWSTR ServerNameW = NULL;
  865. if (pszServer && *pszServer) {
  866. ServerNameW = NetpAllocWStrFromStr( pszServer );
  867. if (ServerNameW == NULL) {
  868. rc = ERROR_NOT_ENOUGH_MEMORY;
  869. goto Cleanup;
  870. }
  871. }
  872. QueueNameW = NetpAllocWStrFromStr( pszQueueName );
  873. if (QueueNameW == NULL) {
  874. rc = ERROR_NOT_ENOUGH_MEMORY;
  875. goto Cleanup;
  876. }
  877. rc = DosPrintQPurgeW(ServerNameW, QueueNameW);
  878. Cleanup:
  879. if (QueueNameW != NULL) {
  880. (VOID) NetApiBufferFree( QueueNameW );
  881. }
  882. if (ServerNameW != NULL) {
  883. (VOID) NetApiBufferFree( ServerNameW );
  884. }
  885. return (rc);
  886. }
  887. SPLERR SPLENTRY DosPrintQAddA(
  888. IN LPSTR pszServer OPTIONAL,
  889. IN WORD uLevel,
  890. IN PBYTE pbBuf,
  891. IN WORD cbBuf
  892. )
  893. {
  894. DWORD cbBufW;
  895. DWORD rc;
  896. LPWSTR ServerNameW = NULL;
  897. LPBYTE StringAreaW;
  898. LPVOID TempBufferW = NULL;
  899. if (pszServer && *pszServer) {
  900. ServerNameW = NetpAllocWStrFromStr( pszServer );
  901. if (ServerNameW == NULL) {
  902. rc = ERROR_NOT_ENOUGH_MEMORY;
  903. goto Cleanup;
  904. }
  905. }
  906. // Compute wide buff size.
  907. cbBufW = cbBuf * sizeof(WCHAR);
  908. if ( cbBufW > (DWORD) MAX_WORD ) {
  909. cbBufW = (DWORD) MAX_WORD;
  910. }
  911. rc = NetApiBufferAllocate(
  912. cbBufW,
  913. (LPVOID *) (LPVOID) &TempBufferW );
  914. if (rc != NO_ERROR) {
  915. goto Cleanup;
  916. }
  917. StringAreaW = (LPBYTE)TempBufferW + cbBufW;
  918. rc = NetpConvertPrintQCharSet(
  919. uLevel,
  920. TRUE, // yes, is add or setinfo API
  921. pbBuf, // from info
  922. TempBufferW, // to info
  923. TRUE, // yes, convert to UNICODE.
  924. & StringAreaW ); // conv strings and update ptr
  925. if (rc != NO_ERROR) {
  926. goto Cleanup;
  927. }
  928. rc = DosPrintQAddW(
  929. ServerNameW,
  930. uLevel,
  931. TempBufferW,
  932. (WORD) cbBufW );
  933. Cleanup:
  934. if (ServerNameW != NULL) {
  935. (VOID) NetApiBufferFree( ServerNameW );
  936. }
  937. if (TempBufferW != NULL) {
  938. (VOID) NetApiBufferFree( TempBufferW );
  939. }
  940. return (rc);
  941. }
  942. SPLERR SPLENTRY DosPrintQDelA(
  943. IN LPSTR pszServer OPTIONAL,
  944. IN LPSTR pszQueueName
  945. )
  946. {
  947. LPWSTR QueueNameW = NULL;
  948. DWORD rc;
  949. LPWSTR ServerNameW = NULL;
  950. if (pszServer && *pszServer) {
  951. ServerNameW = NetpAllocWStrFromStr( pszServer );
  952. if (ServerNameW == NULL) {
  953. rc = ERROR_NOT_ENOUGH_MEMORY;
  954. goto Cleanup;
  955. }
  956. }
  957. QueueNameW = NetpAllocWStrFromStr( pszQueueName );
  958. if (QueueNameW == NULL) {
  959. rc = ERROR_NOT_ENOUGH_MEMORY;
  960. goto Cleanup;
  961. }
  962. rc = DosPrintQDelW(ServerNameW, QueueNameW);
  963. Cleanup:
  964. if (QueueNameW != NULL) {
  965. (VOID) NetApiBufferFree( QueueNameW );
  966. }
  967. if (ServerNameW != NULL) {
  968. (VOID) NetApiBufferFree( ServerNameW );
  969. }
  970. return (rc);
  971. }
  972. SPLERR SPLENTRY DosPrintJobSetInfoA(
  973. IN LPSTR pszServer OPTIONAL,
  974. IN BOOL bRemote,
  975. IN WORD uJobId,
  976. IN WORD uLevel,
  977. IN PBYTE pbBuf,
  978. IN WORD cbBuf,
  979. IN WORD uParmNum
  980. )
  981. {
  982. DWORD cbBufW;
  983. DWORD rc;
  984. LPWSTR ServerNameW = NULL;
  985. LPBYTE StringAreaW;
  986. LPVOID TempBufferW = NULL; // job structure with UNICODE strings.
  987. if (pszServer && *pszServer) {
  988. ServerNameW = NetpAllocWStrFromStr( pszServer );
  989. if (ServerNameW == NULL) {
  990. rc = ERROR_NOT_ENOUGH_MEMORY;
  991. goto Cleanup;
  992. }
  993. }
  994. // Compute wide buff size.
  995. cbBufW = cbBuf * sizeof(WCHAR);
  996. if ( cbBufW > (DWORD) MAX_WORD ) {
  997. cbBufW = (DWORD) MAX_WORD;
  998. }
  999. rc = NetApiBufferAllocate(
  1000. cbBufW,
  1001. (LPVOID *) (LPVOID) &TempBufferW );
  1002. if (rc != NO_ERROR) {
  1003. goto Cleanup;
  1004. }
  1005. StringAreaW = (LPBYTE)TempBufferW + cbBufW;
  1006. // Translate ANSI strings to UNICODE.
  1007. rc = NetpConvertPrintJobCharSet(
  1008. uLevel,
  1009. TRUE, // yes, is add or setinfo API
  1010. TempBufferW, // from info
  1011. pbBuf, // to info
  1012. TRUE, // yes, convert to UNICODE.
  1013. & StringAreaW ); // conv strings and update ptr
  1014. if (rc != NO_ERROR) {
  1015. goto Cleanup;
  1016. }
  1017. // Process the actual API.
  1018. rc = DosPrintJobSetInfoW(
  1019. ServerNameW,
  1020. bRemote,
  1021. uJobId,
  1022. uLevel,
  1023. TempBufferW,
  1024. (WORD) cbBufW,
  1025. uParmNum);
  1026. Cleanup:
  1027. if (ServerNameW != NULL) {
  1028. (VOID) NetApiBufferFree( ServerNameW );
  1029. }
  1030. if (TempBufferW != NULL) {
  1031. (VOID) NetApiBufferFree( TempBufferW );
  1032. }
  1033. return (rc);
  1034. }