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.

214 lines
5.3 KiB

  1. /*****************************************************************************\
  2. * MODULE: ppport.c
  3. *
  4. * This module contains the routines which handle port related calls.
  5. *
  6. *
  7. * Copyright (C) 1996-1997 Microsoft Corporation
  8. * Copyright (C) 1996-1997 Hewlett Packard
  9. *
  10. * History:
  11. * 18-Nov-1996 HWP-Guys Initiated port from win95 to winNT
  12. *
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #include "priv.h"
  16. /*****************************************************************************\
  17. * _ppport_validate_enumport (Local Routine)
  18. *
  19. * Validate the servername and level of EnumPorts.
  20. *
  21. \*****************************************************************************/
  22. _inline BOOL _ppport_validate_enumport(
  23. LPCTSTR lpszServerName,
  24. DWORD dwLevel)
  25. {
  26. if (MyName (lpszServerName) ) {
  27. if (dwLevel <= PRINT_LEVEL_2) {
  28. return TRUE;
  29. } else {
  30. SetLastError(ERROR_INVALID_LEVEL);
  31. }
  32. } else {
  33. SetLastError(ERROR_INVALID_NAME);
  34. }
  35. return FALSE;
  36. }
  37. /*****************************************************************************\
  38. * _ppport_validate_portname (Local Routine)
  39. *
  40. * Validates the portname string.
  41. *
  42. \*****************************************************************************/
  43. _inline BOOL _ppport_validate_portname(
  44. LPCTSTR lpszPortName)
  45. {
  46. if (lpszPortName == NULL) {
  47. SetLastError(ERROR_INVALID_NAME);
  48. return FALSE;
  49. }
  50. return TRUE;
  51. }
  52. /*****************************************************************************\
  53. * PPEnumPorts
  54. *
  55. * Enumerates the ports available through the print-provider.
  56. *
  57. *
  58. \*****************************************************************************/
  59. BOOL PPEnumPorts(
  60. LPTSTR lpszServerName,
  61. DWORD dwLevel,
  62. LPBYTE pbPorts,
  63. DWORD cbBuf,
  64. LPDWORD pcbNeed,
  65. LPDWORD pcbRet)
  66. {
  67. BOOL bRet = FALSE;
  68. DBG_MSG(DBG_LEV_CALLTREE, (TEXT("Call: PPEnumPorts")));
  69. semEnterCrit();
  70. if (_ppport_validate_enumport(lpszServerName, dwLevel))
  71. bRet = gpInetMon->InetmonEnumPorts(lpszServerName, dwLevel, pbPorts, cbBuf, pcbNeed, pcbRet);
  72. semLeaveCrit();
  73. return bRet;
  74. }
  75. /*****************************************************************************\
  76. * PPDeletePort
  77. *
  78. * Deletes a port from the list.
  79. *
  80. * The following is not true anymore -- weihaic
  81. *
  82. * For internal use only. THIS IS NOT EXPORTED to the spooler.
  83. * HTTP Provider cannot remotely delete a port on the server.
  84. *
  85. \*****************************************************************************/
  86. BOOL PPDeletePort(
  87. LPTSTR lpszServerName,
  88. HWND hWnd,
  89. LPTSTR lpszPortName)
  90. {
  91. BOOL bRet = FALSE;
  92. DBG_MSG(DBG_LEV_CALLTREE, (TEXT("Call: PPDeletePort")));
  93. semEnterCrit();
  94. if (_ppport_validate_portname(lpszPortName)) {
  95. DWORD dwReturned;
  96. DWORD dwNeeded;
  97. DWORD i;
  98. PPRINTER_INFO_5 pPrinters = NULL;
  99. BOOL bFound = FALSE;
  100. // Leave critical section to call enum printers
  101. semLeaveCrit();
  102. if (!EnumPrinters( PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &dwNeeded, &dwReturned) &&
  103. GetLastError () == ERROR_INSUFFICIENT_BUFFER) {
  104. pPrinters = ( PPRINTER_INFO_5) LocalAlloc (LPTR, dwNeeded);
  105. if (pPrinters) {
  106. if (EnumPrinters( PRINTER_ENUM_LOCAL, NULL, 5, (PBYTE) pPrinters,
  107. dwNeeded, &dwNeeded, &dwReturned)) {
  108. for (i = 0; i< dwReturned; i++) {
  109. if (!lstrcmpi (pPrinters[i].pPortName, lpszPortName)) {
  110. bFound = TRUE;
  111. break;
  112. }
  113. }
  114. if (bFound) {
  115. SetLastError (ERROR_BUSY);
  116. }
  117. }
  118. LocalFree (pPrinters);
  119. }
  120. }
  121. semEnterCrit();
  122. if (!bFound && _ppport_validate_portname(lpszPortName)) {
  123. bRet = gpInetMon->InetmonDeletePort(lpszPortName, hWnd, NULL);
  124. }
  125. }
  126. semLeaveCrit();
  127. return bRet;
  128. }
  129. /*****************************************************************************\
  130. * PPAddPort
  131. *
  132. * Adds a port to the list.
  133. *
  134. * For internal use only. THIS IS NOT EXPORTED to the spooler.
  135. * HTTP Provider cannot remotely add a port to the server.
  136. *
  137. \*****************************************************************************/
  138. BOOL PPAddPort(
  139. LPTSTR lpszPortName,
  140. HWND hWnd,
  141. LPTSTR lpszMonitorName)
  142. {
  143. BOOL bRet = FALSE;
  144. DBG_MSG(DBG_LEV_CALLTREE, (TEXT("Call: PPAddPort")));
  145. semEnterCrit();
  146. if (_ppport_validate_portname(lpszPortName))
  147. bRet = gpInetMon->InetmonAddPort(lpszPortName, lpszMonitorName);
  148. semLeaveCrit();
  149. return bRet;
  150. }
  151. /*****************************************************************************\
  152. * PPConfigurePort
  153. *
  154. *
  155. \*****************************************************************************/
  156. BOOL PPConfigurePort(
  157. LPTSTR lpszServerName,
  158. HWND hWnd,
  159. LPTSTR lpszPortName)
  160. {
  161. return stubConfigurePort(lpszServerName, hWnd, lpszPortName);
  162. }