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.

350 lines
9.0 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. #if 0
  116. //////////////////////////////////////////////////////////////////////////
  117. // Function: BInitOEMExtraData
  118. //
  119. // Description: Initializes OEM Extra data.
  120. //
  121. //
  122. // Parameters:
  123. //
  124. // pOEMExtra Pointer to a OEM Extra data.
  125. //
  126. // dwSize Size of OEM extra data.
  127. //
  128. //
  129. // Returns: TRUE if successful; FALSE otherwise.
  130. //
  131. //
  132. // Comments:
  133. //
  134. //
  135. // History:
  136. // 02/11/97 APresley Created.
  137. //
  138. //////////////////////////////////////////////////////////////////////////
  139. static BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  140. {
  141. // Initialize OEM Extra data.
  142. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  143. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  144. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  145. memcpy(pOEMExtra->cbTestString, TESTSTRING, sizeof(TESTSTRING));
  146. return TRUE;
  147. }
  148. //////////////////////////////////////////////////////////////////////////
  149. // Function: BMergeOEMExtraData
  150. //
  151. // Description: Validates and merges OEM Extra data.
  152. //
  153. //
  154. // Parameters:
  155. //
  156. // pdmIn pointer to an input OEM private devmode containing the settings
  157. // to be validated and merged. Its size is current.
  158. //
  159. // pdmOut pointer to the output OEM private devmode containing the
  160. // default settings.
  161. //
  162. //
  163. // Returns: TRUE if valid; FALSE otherwise.
  164. //
  165. //
  166. // Comments:
  167. //
  168. //
  169. // History:
  170. // 02/11/97 APresley Created.
  171. // 04/08/97 ZhanW Modified the interface
  172. //
  173. //////////////////////////////////////////////////////////////////////////
  174. static BOOL BMergeOEMExtraData(
  175. POEMUD_EXTRADATA pdmIn,
  176. POEMUD_EXTRADATA pdmOut
  177. )
  178. {
  179. if(pdmIn)
  180. {
  181. //
  182. // copy over the private fields, if they are valid
  183. //
  184. memcmp(pdmOut->cbTestString, pdmIn->cbTestString, sizeof(TESTSTRING));
  185. }
  186. return TRUE;
  187. }
  188. #endif
  189. //////////////////////////////////////////////////////////////////////////
  190. // Function: BIsValidOEMDevModeParam
  191. //
  192. // Description: Validates OEM_DEVMODEPARAM structure.
  193. //
  194. //
  195. // Parameters:
  196. //
  197. // dwMode calling mode
  198. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  199. //
  200. //
  201. // Returns: TRUE if valid; FALSE otherwise.
  202. //
  203. //
  204. // Comments:
  205. //
  206. //
  207. // History:
  208. // 02/11/97 APresley Created.
  209. //
  210. //////////////////////////////////////////////////////////////////////////
  211. static BOOL BIsValidOEMDevModeParam(
  212. DWORD dwMode,
  213. POEMDMPARAM pOEMDevModeParam)
  214. {
  215. BOOL bValid = TRUE;
  216. if(NULL == pOEMDevModeParam)
  217. {
  218. ERR(("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\n"));
  219. return FALSE;
  220. }
  221. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  222. {
  223. ERR(("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\n"));
  224. bValid = FALSE;
  225. }
  226. if(NULL == pOEMDevModeParam->hPrinter)
  227. {
  228. ERR(("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\n"));
  229. bValid = FALSE;
  230. }
  231. if(NULL == pOEMDevModeParam->hModule)
  232. {
  233. ERR(("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\n"));
  234. bValid = FALSE;
  235. }
  236. if( (0 != pOEMDevModeParam->cbBufSize) &&
  237. (NULL == pOEMDevModeParam->pOEMDMOut)
  238. )
  239. {
  240. ERR(("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\n"));
  241. bValid = FALSE;
  242. }
  243. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  244. {
  245. ERR(("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\n"));
  246. bValid = FALSE;
  247. }
  248. return bValid;
  249. }
  250. //////////////////////////////////////////////////////////////////////////
  251. // Function: VDumpOEMDevModeParam
  252. //
  253. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  254. //
  255. //
  256. // Parameters:
  257. //
  258. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  259. //
  260. //
  261. // Returns: N/A.
  262. //
  263. //
  264. // Comments:
  265. //
  266. //
  267. // History:
  268. // 02/18/97 APresley Created.
  269. //
  270. //////////////////////////////////////////////////////////////////////////
  271. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  272. {
  273. // Can't dump if pOEMDevModeParam NULL.
  274. if(NULL != pOEMDevModeParam)
  275. {
  276. VERBOSE(("\n\tOEM_DEVMODEPARAM dump:\n\n"));
  277. VERBOSE(("\tcbSize = %d.\n", pOEMDevModeParam->cbSize));
  278. VERBOSE(("\thPrinter = %#lx.\n", pOEMDevModeParam->hPrinter));
  279. VERBOSE(("\thModule = %#lx.\n", pOEMDevModeParam->hModule));
  280. VERBOSE(("\tpPublicDMIn = %#lx.\n", pOEMDevModeParam->pPublicDMIn));
  281. VERBOSE(("\tpPublicDMOut = %#lx.\n", pOEMDevModeParam->pPublicDMOut));
  282. VERBOSE(("\tpOEMDMIn = %#lx.\n", pOEMDevModeParam->pOEMDMIn));
  283. VERBOSE(("\tpOEMDMOut = %#lx.\n", pOEMDevModeParam->pOEMDMOut));
  284. VERBOSE(("\tcbBufSize = %d.\n", pOEMDevModeParam->cbBufSize));
  285. }
  286. }