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.

454 lines
14 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. PrtJob.c
  5. Abstract:
  6. This module provides RpcXlate support for the DosPrint APIs.
  7. Author:
  8. John Rogers (JohnRo) 20-May-1991
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 20-May-1991 JohnRo
  14. Created.
  15. 21-May-1991 JohnRo
  16. Added RxPrintJobDel(). Added module header. Explicitly fail enum
  17. attempt for level 3.
  18. 21-May-1991 JohnRo
  19. Added RxPrintJobGetInfo support.
  20. 22-May-1991 JohnRo
  21. Added RxPrintJobPause and RxPrintJobContinue support.
  22. Moved RxPrintJobDel into its place in alphabetical order.
  23. Added IN, OUT, and OPTIONAL where applicable.
  24. 26-May-1991 JohnRo
  25. Minor parm list changes: use LPBYTE and LPTSTR where possible.
  26. 16-Jul-1991 JohnRo
  27. Added RxPrintJobSetInfo support.
  28. Added hex dump of job info in RxPrintJobGetInfo.
  29. 17-Jul-1991 JohnRo
  30. Extracted RxpDebug.h from Rxp.h.
  31. 21-Nov-1991 JohnRo
  32. Removed NT dependencies to reduce recompiles.
  33. --*/
  34. // These must be included first:
  35. #include <windef.h> // IN, LPTSTR, etc.
  36. #include <lmcons.h> // NET_API_STATUS, etc.
  37. // These may be included in any order:
  38. #include <apinums.h> // API_ equates.
  39. #include <lmerr.h> // NERR_ and ERROR_ equates.
  40. #include <netdebug.h> // DBGSTATIC, NetpAssert().
  41. #include <netlib.h> // NetpSetOptionalArg().
  42. #include <rap.h> // RapValueWouldBeTruncated().
  43. #include <remdef.h> // REM16_, REMSmb_, field index equates.
  44. #include <rx.h> // RxRemoteApi().
  45. #include <rxp.h> // RxpEstimatedBytesNeeded().
  46. #include <rxpdebug.h> // IF_DEBUG().
  47. #include <rxprint.h> // My prototypes.
  48. DBGSTATIC NET_API_STATUS
  49. RxpGetPrintJobInfoDescs(
  50. IN DWORD InfoLevel,
  51. IN BOOL SetInfoApi,
  52. OUT LPDESC * DataDesc16 OPTIONAL,
  53. OUT LPDESC * DataDesc32 OPTIONAL,
  54. OUT LPDESC * DataDescSmb OPTIONAL
  55. )
  56. {
  57. switch (InfoLevel) {
  58. case 0 :
  59. if (SetInfoApi == TRUE) {
  60. return (ERROR_INVALID_LEVEL);
  61. }
  62. NetpSetOptionalArg(DataDesc16, REM16_print_job_0);
  63. NetpSetOptionalArg(DataDesc32, REM32_print_job_0);
  64. NetpSetOptionalArg(DataDescSmb, REMSmb_print_job_0);
  65. return (NERR_Success);
  66. case 1 :
  67. NetpSetOptionalArg(DataDesc16, REM16_print_job_1);
  68. NetpSetOptionalArg(DataDesc32, REM32_print_job_1);
  69. NetpSetOptionalArg(DataDescSmb, REMSmb_print_job_1);
  70. return (NERR_Success);
  71. case 2 :
  72. if (SetInfoApi == TRUE) {
  73. return (ERROR_INVALID_LEVEL);
  74. }
  75. NetpSetOptionalArg(DataDesc16, REM16_print_job_2);
  76. NetpSetOptionalArg(DataDesc32, REM32_print_job_2);
  77. NetpSetOptionalArg(DataDescSmb, REMSmb_print_job_2);
  78. return (NERR_Success);
  79. case 3 :
  80. NetpSetOptionalArg(DataDesc16, REM16_print_job_3);
  81. NetpSetOptionalArg(DataDesc32, REM32_print_job_3);
  82. NetpSetOptionalArg(DataDescSmb, REMSmb_print_job_3);
  83. return (NERR_Success);
  84. default :
  85. return (ERROR_INVALID_LEVEL);
  86. }
  87. /* NOTREACHED */
  88. } // RxpGetPrintJobInfoDescs
  89. SPLERR SPLENTRY
  90. RxPrintJobContinue(
  91. IN LPTSTR pszServer,
  92. IN DWORD uJobId
  93. )
  94. {
  95. NET_API_STATUS Status;
  96. NetpAssert(pszServer != NULL);
  97. NetpAssert(*pszServer != '\0');
  98. Status = RxRemoteApi(
  99. API_WPrintJobContinue,
  100. pszServer,
  101. REMSmb_DosPrintJobContinue_P, // parm desc
  102. NULL, // no data desc (16-bit)
  103. NULL, // no data desc (32-bit)
  104. NULL, // no data desc (SMB version)
  105. NULL, // no aux data desc 16
  106. NULL, // no aux data desc 32
  107. NULL, // no aux data desc SMB
  108. FALSE, // not a null session API
  109. // rest of LM2.x API's arguments, in 32-bit format:
  110. uJobId);
  111. return (Status);
  112. } // RxPrintJobContinue
  113. SPLERR SPLENTRY
  114. RxPrintJobDel(
  115. IN LPTSTR pszServer,
  116. IN DWORD uJobId
  117. )
  118. {
  119. NET_API_STATUS Status;
  120. NetpAssert(pszServer != NULL);
  121. NetpAssert(*pszServer != '\0');
  122. Status = RxRemoteApi(
  123. API_WPrintJobDel,
  124. pszServer,
  125. REMSmb_DosPrintJobDel_P, // parm desc
  126. NULL, // no data desc (16-bit)
  127. NULL, // no data desc (32-bit)
  128. NULL, // no data desc (SMB version)
  129. NULL, // no aux data desc 16
  130. NULL, // no aux data desc 32
  131. NULL, // no aux data desc SMB
  132. FALSE, // not a null session API
  133. // rest of LM2.x API's arguments, in 32-bit format:
  134. uJobId);
  135. return (Status);
  136. } // RxPrintJobDel
  137. SPLERR SPLENTRY
  138. RxPrintJobEnum(
  139. IN LPTSTR pszServer,
  140. IN LPTSTR pszQueueName,
  141. IN DWORD uLevel,
  142. OUT LPBYTE pbBuf,
  143. IN DWORD cbBuf,
  144. OUT LPDWORD pcReturned,
  145. OUT LPDWORD TotalEntries
  146. )
  147. {
  148. LPDESC DataDesc16, DataDesc32, DataDescSmb;
  149. NET_API_STATUS Status;
  150. NetpAssert(pszServer != NULL);
  151. NetpAssert(*pszServer != '\0');
  152. Status = RxpGetPrintJobInfoDescs(
  153. uLevel,
  154. FALSE, // not a setinfo API.
  155. & DataDesc16,
  156. & DataDesc32,
  157. & DataDescSmb);
  158. if (Status != NERR_Success) {
  159. return (Status);
  160. }
  161. // DosPrintJobEnum does not support level 3, despite what Ralph Ryan's
  162. // book says. I (JohnRo) have tried it, and DaveSn has looked at the
  163. // source code. So, we might as well check for it here.
  164. if (uLevel == 3) {
  165. return (ERROR_INVALID_LEVEL);
  166. }
  167. Status = RxRemoteApi(
  168. API_WPrintJobEnum,
  169. pszServer,
  170. REMSmb_DosPrintJobEnum_P,
  171. DataDesc16,
  172. DataDesc32,
  173. DataDescSmb,
  174. NULL, // no aux desc 16
  175. NULL, // no aux desc 32
  176. NULL, // no aux desc SMB
  177. FALSE, // not a null session API.
  178. // rest of API's arguments, in 32-bit LM 2.x form:
  179. pszQueueName,
  180. uLevel,
  181. pbBuf,
  182. cbBuf,
  183. pcReturned,
  184. TotalEntries);
  185. return (Status);
  186. } // RxPrintJobEnum
  187. SPLERR SPLENTRY
  188. RxPrintJobGetInfo(
  189. IN LPTSTR pszServer,
  190. IN DWORD uJobId,
  191. IN DWORD uLevel,
  192. OUT LPBYTE pbBuf,
  193. IN DWORD cbBuf,
  194. OUT LPDWORD BytesNeeded // estimated (probably too large).
  195. )
  196. {
  197. DWORD BytesNeeded16;
  198. LPDESC DataDesc16, DataDesc32, DataDescSmb;
  199. NET_API_STATUS Status;
  200. NetpAssert(pszServer != NULL);
  201. NetpAssert(*pszServer != '\0');
  202. Status = RxpGetPrintJobInfoDescs(
  203. uLevel,
  204. FALSE, // not a setinfo API
  205. & DataDesc16,
  206. & DataDesc32,
  207. & DataDescSmb);
  208. if (Status != NERR_Success) {
  209. return (Status);
  210. }
  211. Status = RxRemoteApi(
  212. API_WPrintJobGetInfo,
  213. pszServer,
  214. REMSmb_DosPrintJobGetInfo_P,
  215. DataDesc16,
  216. DataDesc32,
  217. DataDescSmb,
  218. NULL, // no aux desc 16
  219. NULL, // no aux desc 32
  220. NULL, // no aux desc SMB
  221. FALSE, // not a null session API.
  222. // rest of API's arguments, in LM 2.x form (32-bit version):
  223. uJobId,
  224. uLevel,
  225. pbBuf,
  226. cbBuf,
  227. & BytesNeeded16); // downlevel buffer size needed.
  228. // If buffer too small, convert BytesNeeded to native num.
  229. if ( (Status == ERROR_MORE_DATA) || (Status == NERR_BufTooSmall) ) {
  230. *BytesNeeded = RxpEstimateBytesNeeded(BytesNeeded16);
  231. } else {
  232. *BytesNeeded = cbBuf;
  233. }
  234. IF_DEBUG(PRTJOB) {
  235. NetpKdPrint(( "RxPrintJobGetInfo: output (level " FORMAT_DWORD "):\n",
  236. uLevel ));
  237. NetpDbgHexDump( (LPVOID) pbBuf, *BytesNeeded );
  238. }
  239. return (Status);
  240. } // RxPrintJobGetInfo
  241. SPLERR SPLENTRY
  242. RxPrintJobPause(
  243. IN LPTSTR pszServer,
  244. IN DWORD uJobId
  245. )
  246. {
  247. NET_API_STATUS Status;
  248. NetpAssert(pszServer != NULL);
  249. NetpAssert(*pszServer != '\0');
  250. Status = RxRemoteApi(
  251. API_WPrintJobPause,
  252. pszServer,
  253. REMSmb_DosPrintJobPause_P, // parm desc
  254. NULL, // no data desc (16-bit)
  255. NULL, // no data desc (32-bit)
  256. NULL, // no data desc (SMB version)
  257. NULL, // no aux data desc 16
  258. NULL, // no aux data desc 32
  259. NULL, // no aux data desc SMB
  260. FALSE, // not a null session API
  261. // rest of LM2.x API's arguments, in 32-bit format:
  262. uJobId);
  263. return (Status);
  264. } // RxPrintJobPause
  265. SPLERR SPLENTRY
  266. RxPrintJobSetInfo(
  267. IN LPTSTR UncServerName,
  268. IN DWORD JobId,
  269. IN DWORD Level,
  270. IN LPBYTE Buffer,
  271. IN DWORD BufferSize,
  272. IN DWORD ParmNum
  273. )
  274. {
  275. LPDESC DataDesc16, DataDesc32, DataDescSmb;
  276. NET_API_STATUS Status;
  277. NetpAssert(UncServerName != NULL);
  278. NetpAssert(*UncServerName != '\0');
  279. Status = RxpGetPrintJobInfoDescs(
  280. Level,
  281. TRUE, // This is a setinfo API.
  282. & DataDesc16,
  283. & DataDesc32,
  284. & DataDescSmb);
  285. if (Status != NERR_Success) {
  286. return (Status);
  287. }
  288. if (ParmNum == PARMNUM_ALL) {
  289. Status = RxRemoteApi(
  290. API_WPrintJobSetInfo, // API number
  291. UncServerName,
  292. REMSmb_DosPrintJobSetInfo_P, // parm desc
  293. DataDesc16,
  294. DataDesc32,
  295. DataDescSmb,
  296. NULL, // no aux desc 16
  297. NULL, // no aux desc 32
  298. NULL, // no aux desc SMB
  299. FALSE, // not a null session API
  300. // rest of API's arguments, in 32-bit LM 2.x format:
  301. JobId,
  302. Level,
  303. Buffer,
  304. BufferSize,
  305. ParmNum);
  306. } else {
  307. WORD DownLevelJobId;
  308. DWORD FieldIndex;
  309. if (RapValueWouldBeTruncated(JobId)) {
  310. IF_DEBUG(PRTJOB) {
  311. NetpKdPrint(( "RxPrintJobSetInfo: invalid (ID trunc).\n" ));
  312. }
  313. return (ERROR_INVALID_PARAMETER);
  314. }
  315. // Compute field index from parmnum and level.
  316. NetpAssert( (Level==1) || (Level==3) ); // Already verified.
  317. switch (ParmNum) {
  318. case PRJ_NOTIFYNAME_PARMNUM :
  319. if (Level==1) {
  320. FieldIndex = PRJ_NOTIFYNAME_LVL1_FIELDINDEX;
  321. } else {
  322. FieldIndex = PRJ_NOTIFYNAME_LVL3_FIELDINDEX;
  323. }
  324. break;
  325. case PRJ_DATATYPE_PARMNUM :
  326. if (Level==1) {
  327. FieldIndex = PRJ_DATATYPE_LVL1_FIELDINDEX;
  328. } else {
  329. FieldIndex = PRJ_DATATYPE_LVL3_FIELDINDEX;
  330. }
  331. break;
  332. case PRJ_PARMS_PARMNUM :
  333. if (Level==1) {
  334. FieldIndex = PRJ_PARMS_LVL1_FIELDINDEX;
  335. } else {
  336. FieldIndex = PRJ_PARMS_LVL3_FIELDINDEX;
  337. }
  338. break;
  339. case PRJ_POSITION_PARMNUM :
  340. if (Level==1) {
  341. FieldIndex = PRJ_POSITION_LVL1_FIELDINDEX;
  342. } else {
  343. FieldIndex = PRJ_POSITION_LVL3_FIELDINDEX;
  344. }
  345. break;
  346. case PRJ_COMMENT_PARMNUM :
  347. if (Level==1) {
  348. FieldIndex = PRJ_COMMENT_LVL1_FIELDINDEX;
  349. } else {
  350. FieldIndex = PRJ_COMMENT_LVL3_FIELDINDEX;
  351. }
  352. break;
  353. case PRJ_DOCUMENT_PARMNUM :
  354. if (Level==1) {
  355. return (ERROR_INVALID_LEVEL);
  356. } else {
  357. FieldIndex = PRJ_DOCUMENT_LVL3_FIELDINDEX;
  358. }
  359. break;
  360. case PRJ_PRIORITY_PARMNUM :
  361. if (Level==1) {
  362. return (ERROR_INVALID_LEVEL);
  363. } else {
  364. FieldIndex = PRJ_PRIORITY_LVL3_FIELDINDEX;
  365. }
  366. break;
  367. case PRJ_PROCPARMS_PARMNUM :
  368. if (Level==1) {
  369. return (ERROR_INVALID_LEVEL);
  370. } else {
  371. FieldIndex = PRJ_PROCPARMS_LVL3_FIELDINDEX;
  372. }
  373. break;
  374. case PRJ_DRIVERDATA_PARMNUM :
  375. // Can't set driver data from NT
  376. /* FALLTHROUGH */
  377. default :
  378. IF_DEBUG(PRTJOB) {
  379. NetpKdPrint(( "RxPrintJobSetInfo: invalid (bad parmnum).\n" ));
  380. }
  381. return (ERROR_INVALID_PARAMETER);
  382. }
  383. DownLevelJobId = (WORD) JobId;
  384. Status = RxpSetField (
  385. API_WPrintJobSetInfo, // API number
  386. UncServerName,
  387. "w", // object's desc
  388. & DownLevelJobId, // object to set
  389. REMSmb_DosPrintJobSetInfo_P, // parm desc
  390. DataDesc16,
  391. DataDesc32,
  392. DataDescSmb,
  393. (LPVOID) Buffer, // native info buffer
  394. ParmNum, // parm num to send
  395. FieldIndex, // field index
  396. Level);
  397. }
  398. return (Status);
  399. } // RxPrintJobSetInfo