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
9.8 KiB

  1. /*************************************************************************
  2. *
  3. * NTCAP.C
  4. *
  5. * NT NetWare routines
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\NTCAP.C $
  10. *
  11. * Rev 1.2 10 Apr 1996 14:23:04 terryt
  12. * Hotfix for 21181hq
  13. *
  14. * Rev 1.2 12 Mar 1996 19:54:36 terryt
  15. * Relative NDS names and merge
  16. *
  17. * Rev 1.1 22 Dec 1995 14:25:20 terryt
  18. * Add Microsoft headers
  19. *
  20. * Rev 1.0 15 Nov 1995 18:07:20 terryt
  21. * Initial revision.
  22. *
  23. * Rev 1.0 25 Aug 1995 15:41:14 terryt
  24. * Initial revision.
  25. *
  26. *
  27. *************************************************************************/
  28. #include "common.h"
  29. #include <ntddnwfs.h>
  30. #include <nwapi.h>
  31. #include <npapi.h>
  32. #include "ntnw.h"
  33. extern unsigned char NW_PROVIDERA[];
  34. /********************************************************************
  35. EndCapture
  36. Routine Description:
  37. Remove the local printer redirection
  38. Arguments:
  39. LPTDevice - IN
  40. 1, 2, or 3 - the local printer #
  41. Return Value:
  42. Error
  43. *******************************************************************/
  44. unsigned int
  45. EndCapture(
  46. unsigned char LPTDevice
  47. )
  48. {
  49. char LPTname[] = "LPT1";
  50. unsigned int dwRes;
  51. LPTname[3] = '1' + LPTDevice - 1;
  52. /*
  53. * Should we check for non-NetWare printers?
  54. */
  55. dwRes = WNetCancelConnection2A( LPTname, 0, TRUE );
  56. if ( dwRes != NO_ERROR )
  57. dwRes = GetLastError();
  58. if ( dwRes == ERROR_EXTENDED_ERROR )
  59. NTPrintExtendedError();
  60. return dwRes;
  61. }
  62. /********************************************************************
  63. GetCaptureFlags
  64. Routine Description:
  65. Return info about the printer capture status. Note that the only
  66. options set on NT are on a per-user basis and can be changed with
  67. the control panel.
  68. Arguments:
  69. LPTDevice - IN
  70. LPT device 1, 2 or 3
  71. pCaptureFlagsRW - OUT
  72. Capture options
  73. pCaptureFlagsRO - OUT
  74. Capture options
  75. Return Value:
  76. *******************************************************************/
  77. unsigned int
  78. GetCaptureFlags(
  79. unsigned char LPTDevice,
  80. PNETWARE_CAPTURE_FLAGS_RW pCaptureFlagsRW,
  81. PNETWARE_CAPTURE_FLAGS_RO pCaptureFlagsRO
  82. )
  83. {
  84. LPBYTE Buffer ;
  85. DWORD dwErr ;
  86. HANDLE EnumHandle ;
  87. DWORD Count ;
  88. char LPTName[10];
  89. DWORD BufferSize = 4096;
  90. char *remotename;
  91. char *p;
  92. DWORD dwPrintOptions ;
  93. LPTSTR pszPreferred ;
  94. strcpy( LPTName, "LPT1" );
  95. LPTName[3] = '1' + LPTDevice - 1;
  96. pCaptureFlagsRO->LPTCaptureFlag = 0;
  97. //
  98. // allocate memory and open the enumeration
  99. //
  100. if (!(Buffer = LocalAlloc( LPTR, BufferSize ))) {
  101. DisplayMessage(IDR_NOT_ENOUGH_MEMORY);
  102. return 0xFFFF;
  103. }
  104. dwErr = WNetOpenEnum(RESOURCE_CONNECTED, 0, 0, NULL, &EnumHandle) ;
  105. if (dwErr != WN_SUCCESS) {
  106. dwErr = GetLastError();
  107. if ( dwErr == ERROR_EXTENDED_ERROR )
  108. NTPrintExtendedError();
  109. (void) LocalFree((HLOCAL) Buffer) ;
  110. return 0xFFFF;
  111. }
  112. do {
  113. Count = 0xFFFFFFFF ;
  114. BufferSize = 4096;
  115. dwErr = WNetEnumResourceA(EnumHandle, &Count, Buffer, &BufferSize) ;
  116. if ((dwErr == WN_SUCCESS || dwErr == WN_NO_MORE_ENTRIES)
  117. && ( Count != 0xFFFFFFFF) )
  118. {
  119. LPNETRESOURCEA lpNetResource ;
  120. DWORD i ;
  121. lpNetResource = (LPNETRESOURCEA) Buffer ;
  122. //
  123. // search for our printer
  124. //
  125. for ( i = 0; i < Count; lpNetResource++, i++ )
  126. {
  127. if ( lpNetResource->lpLocalName )
  128. {
  129. if ( !_strcmpi(lpNetResource->lpLocalName, LPTName ))
  130. {
  131. if ( lpNetResource->lpProvider )
  132. {
  133. if ( _strcmpi( lpNetResource->lpProvider,
  134. NW_PROVIDERA ) )
  135. {
  136. pCaptureFlagsRO->LPTCaptureFlag = 0;
  137. }
  138. else
  139. {
  140. remotename = lpNetResource->lpRemoteName;
  141. p = strchr (remotename + 2, '\\');
  142. if ( !p )
  143. return 0xffffffff;
  144. *p++ = '\0';
  145. _strupr( remotename+2 );
  146. _strupr( p );
  147. strcpy( pCaptureFlagsRO->ServerName, remotename+2 );
  148. strcpy( pCaptureFlagsRO->QueueName, p );
  149. pCaptureFlagsRO->LPTCaptureFlag = 1;
  150. pCaptureFlagsRW->JobControlFlags = 0;
  151. pCaptureFlagsRW->TabSize = 8;
  152. pCaptureFlagsRW->NumCopies = 1;
  153. //
  154. // query NW wksta for print options
  155. // & preferred server
  156. //
  157. if ( NwQueryInfo(&dwPrintOptions,
  158. &pszPreferred)) {
  159. pCaptureFlagsRW->PrintFlags =
  160. CAPTURE_FLAG_NOTIFY |
  161. CAPTURE_FLAG_PRINT_BANNER ;
  162. }
  163. else {
  164. pCaptureFlagsRW->PrintFlags = 0;
  165. if ( dwPrintOptions & NW_PRINT_PRINT_NOTIFY )
  166. pCaptureFlagsRW->PrintFlags |=
  167. CAPTURE_FLAG_NOTIFY;
  168. if ( dwPrintOptions & NW_PRINT_SUPPRESS_FORMFEED)
  169. pCaptureFlagsRW->PrintFlags |=
  170. CAPTURE_FLAG_NO_FORMFEED;
  171. if ( dwPrintOptions & NW_PRINT_PRINT_BANNER )
  172. pCaptureFlagsRW->PrintFlags |=
  173. CAPTURE_FLAG_PRINT_BANNER;
  174. }
  175. pCaptureFlagsRW->FormName[0] = 0;
  176. pCaptureFlagsRW->FormType = 0;
  177. pCaptureFlagsRW->BannerText[0] = 0;
  178. pCaptureFlagsRW->FlushCaptureTimeout = 0;
  179. pCaptureFlagsRW->FlushCaptureOnClose = 1;
  180. }
  181. }
  182. else
  183. {
  184. pCaptureFlagsRO->LPTCaptureFlag = 0;
  185. }
  186. (void) WNetCloseEnum(EnumHandle) ;
  187. (void) LocalFree((HLOCAL) Buffer) ;
  188. return 0;
  189. }
  190. }
  191. }
  192. }
  193. } while (dwErr == WN_SUCCESS) ;
  194. if ( ( dwErr != WN_SUCCESS ) && ( dwErr != WN_NO_MORE_ENTRIES ) )
  195. {
  196. dwErr = GetLastError();
  197. if ( dwErr == ERROR_EXTENDED_ERROR )
  198. NTPrintExtendedError();
  199. }
  200. (void ) WNetCloseEnum(EnumHandle) ;
  201. (void) LocalFree((HLOCAL) Buffer) ;
  202. return 0;
  203. }
  204. /********************************************************************
  205. StartQueueCapture
  206. Routine Description:
  207. Attach local name to the queue.
  208. Arguments:
  209. ConnectionHandle - IN
  210. Handle to file server
  211. LPTDevice - IN
  212. LPT 1, 2 or 3
  213. pServerName - IN
  214. Server name
  215. pQueueName - IN
  216. Printer queue name
  217. Return Value:
  218. *******************************************************************/
  219. unsigned int
  220. StartQueueCapture(
  221. unsigned int ConnectionHandle,
  222. unsigned char LPTDevice,
  223. unsigned char *pServerName,
  224. unsigned char *pQueueName
  225. )
  226. {
  227. NETRESOURCEA NetResource;
  228. DWORD dwRes, dwSize;
  229. unsigned char * pszRemoteName = NULL;
  230. unsigned char pszLocalName[10];
  231. char * p;
  232. //
  233. // validate parameters
  234. //
  235. if (!pServerName || !pQueueName || !LPTDevice) {
  236. DisplayMessage(IDR_ERROR_DURING, "StartQueueCapture");
  237. return 0xffffffff ;
  238. }
  239. //
  240. // allocate memory for string
  241. //
  242. dwSize = strlen(pServerName) + strlen(pQueueName) + 5 ;
  243. if (!(pszRemoteName = (unsigned char *)LocalAlloc(
  244. LPTR,
  245. dwSize)))
  246. {
  247. DisplayMessage(IDR_NOT_ENOUGH_MEMORY);
  248. dwRes = 0xffffffff;
  249. goto ExitPoint ;
  250. }
  251. sprintf(pszRemoteName, "\\\\%s\\%s", pServerName, pQueueName);
  252. sprintf(pszLocalName, "LPT%d", LPTDevice );
  253. NetResource.dwScope = 0 ;
  254. NetResource.dwUsage = 0 ;
  255. NetResource.dwType = RESOURCETYPE_PRINT;
  256. NetResource.lpLocalName = pszLocalName;
  257. NetResource.lpRemoteName = pszRemoteName;
  258. NetResource.lpComment = NULL;
  259. // NetResource.lpProvider = NW_PROVIDERA ;
  260. // Allow OS to select provider in case localized name doesn't map to OEM code page
  261. NetResource.lpProvider = NULL;
  262. //
  263. // make the connection
  264. //
  265. dwRes=WNetAddConnection2A ( &NetResource, NULL, NULL, 0 );
  266. if ( dwRes != NO_ERROR )
  267. dwRes = GetLastError();
  268. ExitPoint:
  269. if (pszRemoteName)
  270. (void) LocalFree((HLOCAL) pszRemoteName) ;
  271. return( dwRes );
  272. }