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.

331 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1996-1998 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. Implementation of OEMGetInfo and OEMDevMode.
  7. Shared by all Unidrv OEM test dll's.
  8. Environment:
  9. Windows NT Unidrv driver
  10. Revision History:
  11. 04/07/97 -zhanw-
  12. Created it.
  13. --*/
  14. #include "PDEV.H" // defined in sub-directory such as DDICMDCB, FONTCB, etc.
  15. #include "strsafe.h" // Security-Code 2002.3.6
  16. DWORD gdwDrvMemPoolTag = 'meoD'; // lib.h requires this global var, for debugging
  17. ////////////////////////////////////////////////////////
  18. // INTERNAL PROTOTYPES
  19. ////////////////////////////////////////////////////////
  20. //static BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra);
  21. //static BOOL BMergeOEMExtraData(POEMUD_EXTRADATA pdmIn, POEMUD_EXTRADATA pdmOut);
  22. static BOOL BIsValidOEMDevModeParam(DWORD dwMode, POEMDMPARAM pOEMDevModeParam);
  23. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam);
  24. BOOL APIENTRY OEMGetInfo(DWORD dwInfo, PVOID pBuffer, DWORD cbSize, PDWORD pcbNeeded)
  25. {
  26. LPCSTR OEM_INFO[] = { "Bad Index",
  27. "OEMGI_GETSIGNATURE",
  28. "OEMGI_GETINTERFACEVERSION",
  29. "OEMGI_GETVERSION",
  30. };
  31. VERBOSE(("OEMGetInfo(%s) entry.\n", OEM_INFO[dwInfo]));
  32. // Validate parameters.
  33. if( ( (OEMGI_GETSIGNATURE != dwInfo) &&
  34. (OEMGI_GETINTERFACEVERSION != dwInfo) &&
  35. (OEMGI_GETVERSION != dwInfo) ) ||
  36. (NULL == pcbNeeded)
  37. )
  38. {
  39. ERR(("OEMGetInfo() ERROR_INVALID_PARAMETER.\n"));
  40. // Did not write any bytes.
  41. if(NULL != pcbNeeded)
  42. *pcbNeeded = 0;
  43. return FALSE;
  44. }
  45. // Need/wrote 4 bytes.
  46. *pcbNeeded = 4;
  47. // Validate buffer size. Minimum size is four bytes.
  48. if( (NULL == pBuffer) || (4 > cbSize) )
  49. {
  50. ERR(("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\n"));
  51. return FALSE;
  52. }
  53. // Write information to buffer.
  54. switch(dwInfo)
  55. {
  56. case OEMGI_GETSIGNATURE:
  57. *(LPDWORD)pBuffer = OEM_SIGNATURE;
  58. break;
  59. case OEMGI_GETINTERFACEVERSION:
  60. *(LPDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  61. break;
  62. case OEMGI_GETVERSION:
  63. *(LPDWORD)pBuffer = OEM_VERSION;
  64. break;
  65. }
  66. return TRUE;
  67. }
  68. BOOL APIENTRY OEMDevMode(
  69. DWORD dwMode,
  70. POEMDMPARAM pOEMDevModeParam)
  71. {
  72. LPCSTR OEMDevMode_fMode[] = { "NULL",
  73. "OEMDM_SIZE",
  74. "OEMDM_DEFAULT",
  75. "OEMDM_CONVERT",
  76. "OEMDM_MERGE",
  77. };
  78. VERBOSE(("OEMDevMode(%s) entry.\n", OEMDevMode_fMode[dwMode]));
  79. // Validate parameters.
  80. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  81. {
  82. ERR(("OEMDevMode() ERROR_INVALID_PARAMETER.\n"));
  83. VDumpOEMDevModeParam(pOEMDevModeParam);
  84. return FALSE;
  85. }
  86. // Verify OEM extra data size.
  87. if( (dwMode != OEMDM_SIZE) &&
  88. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  89. {
  90. ERR(("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\n"));
  91. return FALSE;
  92. }
  93. // Handle dwMode.
  94. switch(dwMode)
  95. {
  96. case OEMDM_SIZE:
  97. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  98. break;
  99. case OEMDM_DEFAULT:
  100. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  101. case OEMDM_CONVERT:
  102. // nothing to convert for this private devmode. So just initialize it.
  103. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  104. case OEMDM_MERGE:
  105. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  106. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  107. {
  108. ERR(("OEMUD OEMDevMode(): not valid OEM Extra Data.\n"));
  109. return FALSE;
  110. }
  111. break;
  112. }
  113. return TRUE;
  114. }
  115. //////////////////////////////////////////////////////////////////////////
  116. // Function: BInitOEMExtraData
  117. //
  118. // Description: Initializes OEM Extra data.
  119. //
  120. //
  121. // Parameters:
  122. //
  123. // pOEMExtra Pointer to a OEM Extra data.
  124. //
  125. // dwSize Size of OEM extra data.
  126. //
  127. //
  128. // Returns: TRUE if successful; FALSE otherwise.
  129. //
  130. //
  131. // Comments:
  132. //
  133. //
  134. // History:
  135. // 02/11/97 APresley Created.
  136. //
  137. //////////////////////////////////////////////////////////////////////////
  138. BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  139. {
  140. // Initialize OEM Extra data.
  141. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  142. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  143. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  144. return TRUE;
  145. }
  146. //////////////////////////////////////////////////////////////////////////
  147. // Function: BMergeOEMExtraData
  148. //
  149. // Description: Validates and merges OEM Extra data.
  150. //
  151. //
  152. // Parameters:
  153. //
  154. // pdmIn pointer to an input OEM private devmode containing the settings
  155. // to be validated and merged. Its size is current.
  156. //
  157. // pdmOut pointer to the output OEM private devmode containing the
  158. // default settings.
  159. //
  160. //
  161. // Returns: TRUE if valid; FALSE otherwise.
  162. //
  163. //
  164. // Comments:
  165. //
  166. //
  167. // History:
  168. // 02/11/97 APresley Created.
  169. // 04/08/97 ZhanW Modified the interface
  170. //
  171. //////////////////////////////////////////////////////////////////////////
  172. BOOL BMergeOEMExtraData(
  173. POEMUD_EXTRADATA pdmIn,
  174. POEMUD_EXTRADATA pdmOut
  175. )
  176. {
  177. return TRUE;
  178. }
  179. //////////////////////////////////////////////////////////////////////////
  180. // Function: BIsValidOEMDevModeParam
  181. //
  182. // Description: Validates OEM_DEVMODEPARAM structure.
  183. //
  184. //
  185. // Parameters:
  186. //
  187. // dwMode calling mode
  188. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  189. //
  190. //
  191. // Returns: TRUE if valid; FALSE otherwise.
  192. //
  193. //
  194. // Comments:
  195. //
  196. //
  197. // History:
  198. // 02/11/97 APresley Created.
  199. //
  200. //////////////////////////////////////////////////////////////////////////
  201. static BOOL BIsValidOEMDevModeParam(
  202. DWORD dwMode,
  203. POEMDMPARAM pOEMDevModeParam)
  204. {
  205. BOOL bValid = TRUE;
  206. if(NULL == pOEMDevModeParam)
  207. {
  208. ERR(("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\n"));
  209. return FALSE;
  210. }
  211. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  212. {
  213. ERR(("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\n"));
  214. bValid = FALSE;
  215. }
  216. if(NULL == pOEMDevModeParam->hPrinter)
  217. {
  218. ERR(("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\n"));
  219. bValid = FALSE;
  220. }
  221. if(NULL == pOEMDevModeParam->hModule)
  222. {
  223. ERR(("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\n"));
  224. bValid = FALSE;
  225. }
  226. if( (0 != pOEMDevModeParam->cbBufSize) &&
  227. (NULL == pOEMDevModeParam->pOEMDMOut)
  228. )
  229. {
  230. ERR(("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\n"));
  231. bValid = FALSE;
  232. }
  233. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  234. {
  235. ERR(("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\n"));
  236. bValid = FALSE;
  237. }
  238. return bValid;
  239. }
  240. //////////////////////////////////////////////////////////////////////////
  241. // Function: VDumpOEMDevModeParam
  242. //
  243. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  244. //
  245. //
  246. // Parameters:
  247. //
  248. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  249. //
  250. //
  251. // Returns: N/A.
  252. //
  253. //
  254. // Comments:
  255. //
  256. //
  257. // History:
  258. // 02/18/97 APresley Created.
  259. //
  260. //////////////////////////////////////////////////////////////////////////
  261. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  262. {
  263. // Can't dump if pOEMDevModeParam NULL.
  264. if(NULL != pOEMDevModeParam)
  265. {
  266. VERBOSE(("\n\tOEM_DEVMODEPARAM dump:\n\n"));
  267. VERBOSE(("\tcbSize = %d.\n", pOEMDevModeParam->cbSize));
  268. VERBOSE(("\thPrinter = %#lx.\n", pOEMDevModeParam->hPrinter));
  269. VERBOSE(("\thModule = %#lx.\n", pOEMDevModeParam->hModule));
  270. VERBOSE(("\tpPublicDMIn = %#lx.\n", pOEMDevModeParam->pPublicDMIn));
  271. VERBOSE(("\tpPublicDMOut = %#lx.\n", pOEMDevModeParam->pPublicDMOut));
  272. VERBOSE(("\tpOEMDMIn = %#lx.\n", pOEMDevModeParam->pOEMDMIn));
  273. VERBOSE(("\tpOEMDMOut = %#lx.\n", pOEMDevModeParam->pOEMDMOut));
  274. VERBOSE(("\tcbBufSize = %d.\n", pOEMDevModeParam->cbBufSize));
  275. }
  276. }