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.

354 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ccfapi.cpp
  5. Abstract:
  6. Implementation of CCcfApiApp, the MFC application object for CCFAPI32.DLL.
  7. Author:
  8. Jeff Parham (jeffparh) 13-Dec-1995
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include <lmerr.h>
  13. #include "ccfapi.h"
  14. #include "source.h"
  15. #include "imagelst.h"
  16. #include "remdlg.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. CCcfApiApp theApp; // The one and only CCcfApiApp object
  23. BEGIN_MESSAGE_MAP(CCcfApiApp, CWinApp)
  24. //{{AFX_MSG_MAP(CCcfApiApp)
  25. // NOTE - the ClassWizard will add and remove mapping macros here.
  26. // DO NOT EDIT what you see in these blocks of generated code!
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. CCcfApiApp::CCcfApiApp()
  30. /*++
  31. Routine Description:
  32. Constructor for CCF API application.
  33. Arguments:
  34. None.
  35. Return Values:
  36. None.
  37. --*/
  38. {
  39. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  40. m_LastError = 0;
  41. m_LastLlsError = 0;
  42. LPTSTR pszHelpFileName = m_strHelpFileName.GetBuffer( MAX_PATH );
  43. if ( NULL != pszHelpFileName )
  44. {
  45. BOOL ok = GetSystemDirectory( pszHelpFileName, MAX_PATH );
  46. m_strHelpFileName.ReleaseBuffer();
  47. if ( ok )
  48. {
  49. m_strHelpFileName += TEXT( "\\" );
  50. }
  51. m_strHelpFileName += TEXT( "ccfapi.hlp" );
  52. }
  53. }
  54. void CCcfApiApp::DisplayLastError()
  55. /*++
  56. Routine Description:
  57. Displays a message corresponding to the last error encountered.
  58. Arguments:
  59. None.
  60. Return Values:
  61. None.
  62. --*/
  63. {
  64. CString strLastError;
  65. CString strErrorCaption;
  66. strLastError = GetLastErrorString();
  67. AfxMessageBox( strLastError, MB_ICONSTOP | MB_OK );
  68. }
  69. CString CCcfApiApp::GetLastErrorString()
  70. /*++
  71. Routine Description:
  72. Retrieves string for last error.
  73. (Routine stolen from winsadmn...).
  74. (And that routine stolen from LlsMgr...).
  75. Arguments:
  76. None.
  77. Return Values:
  78. CString.
  79. --*/
  80. {
  81. CString strLastError;
  82. DWORD nId = m_LastError;
  83. const int cchLastErrorSize = 512;
  84. LPTSTR pszLastError;
  85. DWORD cchLastError;
  86. if (((long)nId == RPC_S_CALL_FAILED) ||
  87. ((long)nId == RPC_NT_SS_CONTEXT_MISMATCH))
  88. {
  89. strLastError.LoadString(IDS_ERROR_DROPPED_LINK);
  90. }
  91. else if (((long)nId == RPC_S_SERVER_UNAVAILABLE) ||
  92. ((long)nId == RPC_NT_SERVER_UNAVAILABLE))
  93. {
  94. strLastError.LoadString(IDS_ERROR_NO_RPC_SERVER);
  95. }
  96. else if ((long)nId == STATUS_INVALID_LEVEL)
  97. {
  98. strLastError.LoadString(IDS_ERROR_DOWNLEVEL_SERVER);
  99. }
  100. else if (((long)nId == ERROR_ACCESS_DENIED) ||
  101. ((long)nId == STATUS_ACCESS_DENIED))
  102. {
  103. strLastError.LoadString(IDS_ERROR_ACCESS_DENIED);
  104. }
  105. else if ((long)nId == STATUS_ACCOUNT_EXPIRED)
  106. {
  107. strLastError.LoadString(IDS_ERROR_CERTIFICATE_EXPIRED);
  108. }
  109. else
  110. {
  111. HINSTANCE hinstDll = NULL;
  112. if ((nId >= NERR_BASE) && (nId <= MAX_NERR))
  113. {
  114. hinstDll = ::LoadLibrary( _T( "netmsg.dll" ) );
  115. }
  116. else if (nId >= 0x4000000)
  117. {
  118. hinstDll = ::LoadLibrary( _T( "ntdll.dll" ) );
  119. }
  120. cchLastError = 0;
  121. pszLastError = strLastError.GetBuffer( cchLastErrorSize );
  122. if ( NULL != pszLastError )
  123. {
  124. DWORD dwFlags = FORMAT_MESSAGE_IGNORE_INSERTS
  125. | FORMAT_MESSAGE_MAX_WIDTH_MASK
  126. | ( hinstDll ? FORMAT_MESSAGE_FROM_HMODULE
  127. : FORMAT_MESSAGE_FROM_SYSTEM );
  128. cchLastError = ::FormatMessage( dwFlags,
  129. hinstDll,
  130. nId,
  131. 0,
  132. pszLastError,
  133. cchLastErrorSize,
  134. NULL );
  135. strLastError.ReleaseBuffer();
  136. }
  137. if ( hinstDll )
  138. {
  139. ::FreeLibrary( hinstDll );
  140. }
  141. if ( 0 == cchLastError )
  142. {
  143. strLastError.LoadString( IDS_ERROR_UNSUCCESSFUL );
  144. }
  145. }
  146. return strLastError;
  147. }
  148. //////////////////////////////////////////////////////////////////////////////
  149. // CCF API //
  150. ///////////////
  151. DWORD CCcfApiApp::CertificateEnter( HWND hWndParent, LPCSTR pszServerName, LPCSTR pszProductName, LPCSTR pszVendor, DWORD dwFlags, LPCSTR pszSourceToUse )
  152. /*++
  153. Routine Description:
  154. Display a dialog allowing the user to enter a license certificate
  155. into the system.
  156. Arguments:
  157. hWndParent (HWND)
  158. HWND to the client's main window, for use as the parent window to any
  159. opened dialogs. May be NULL.
  160. pszServerName (LPCSTR)
  161. Name of the server for which licenses are to be installed. Note that
  162. this may not be the same as the server on which licenses are actually
  163. installed, as, for example, per seat licenses are always installed on
  164. the enterprise server. A NULL value indicates the local server.
  165. pszProductName (LPCSTR)
  166. Product for which licenses are to be installed. A NULL value indicates
  167. that the user should be allowed to choose.
  168. pszVendor (LPCSTR)
  169. Name of the vendor of the product. This value should be NULL if
  170. pszProductName is NULL, and should be non-NULL if pszProductName is
  171. non-NULL.
  172. dwFlags (DWORD)
  173. A bitfield containing one or more of the following:
  174. CCF_ENTER_FLAG_PER_SEAT_ONLY
  175. Allow the user to enter only per seat licenses. Not valid in
  176. combination with CCF_ENTER_FLAG_PER_SERVER_ONLY.
  177. CCF_ENTER_FLAG_PER_SERVER_ONLY
  178. Allow the user to enter only per server licenses. Not valid in
  179. combination with CCF_ENTER_FLAG_PER_SEAT_ONLY.
  180. pszSourceToUse (LPCSTR)
  181. Name of the secure certificate source to use to install the certificate,
  182. e.g., "Paper". A NULL value indicates that the user should be allowed
  183. to choose.
  184. Return Value:
  185. ERROR_SUCCESS (A certificate was successfully entered into the system.)
  186. ERROR_CANCELLED (The user cancelled without installing a certificate.)
  187. other Win error
  188. --*/
  189. {
  190. CCertSourceSelectDlg srcDlg( CWnd::FromHandle( hWndParent ) );
  191. LPCSTR pszNetServerName = NULL;
  192. CHAR szNetServerName[ 2 + MAX_PATH ] = "\\\\";
  193. // make sure server name, if specified, is in the form \\server
  194. if ( NULL != pszServerName )
  195. {
  196. if ( ( pszServerName[0] != '\\' ) || ( pszServerName[1] != '\\' ) )
  197. {
  198. // is not prefixed with backslashes
  199. lstrcpynA( szNetServerName + 2, pszServerName, sizeof( szNetServerName ) - 3 );
  200. pszNetServerName = szNetServerName;
  201. }
  202. else
  203. {
  204. // is prefixed with backslashes
  205. pszNetServerName = pszServerName;
  206. }
  207. }
  208. return srcDlg.CertificateEnter( hWndParent, pszNetServerName, pszProductName, pszVendor, dwFlags, pszSourceToUse );
  209. }
  210. DWORD CCcfApiApp::CertificateRemove( HWND hWndParent, LPCSTR pszServerName, LPCSTR pszProductName, LPCSTR pszVendor, DWORD dwFlags, LPCSTR pszSourceToUse )
  211. /*++
  212. Routine Description:
  213. Display a dialog allowing the user to remove one or more license
  214. certificates from the system.
  215. Arguments:
  216. hWndParent (HWND)
  217. HWND to the client's main window, for use as the parent window to any
  218. opened dialogs. May be NULL.
  219. pszServerName (LPCSTR)
  220. Name of the server on which licenses are to be removed. A NULL value
  221. indicates the local server.
  222. pszProductName (LPCSTR)
  223. Product for which licenses are to be removed. A NULL value indicates
  224. that the user should be allowed to remove licenses from any product.
  225. pszVendor (LPCSTR)
  226. Name of the vendor of the product. This value should be NULL if
  227. pszProductName is NULL, and should be non-NULL if pszProductName is
  228. non-NULL.
  229. dwFlags (DWORD)
  230. Certificate removal options. As of this writing, no flags are
  231. supported.
  232. pszSourceToUse (LPCSTR)
  233. Name of the secure certificate source by which licenses are to be
  234. removed, e.g., "Paper". A NULL value indicates that the user should
  235. be allowed to remove licenses that were installed with any source.
  236. Return Value:
  237. ERROR_SUCCESS
  238. Win error
  239. --*/
  240. {
  241. CCertRemoveSelectDlg remDlg( CWnd::FromHandle( hWndParent ) );
  242. LPCSTR pszNetServerName = NULL;
  243. CHAR szNetServerName[ 2 + MAX_PATH ] = "\\\\";
  244. // make sure server name, if specified, is in the form \\server
  245. if ( NULL != pszServerName )
  246. {
  247. if ( ( pszServerName[0] != '\\' ) || ( pszServerName[1] != '\\' ) )
  248. {
  249. // is not prefixed with backslashes
  250. lstrcpynA( szNetServerName + 2, pszServerName, sizeof( szNetServerName ) - 3 );
  251. pszNetServerName = szNetServerName;
  252. }
  253. else
  254. {
  255. // is prefixed with backslashes
  256. pszNetServerName = pszServerName;
  257. }
  258. }
  259. return remDlg.CertificateRemove( pszNetServerName, pszProductName, pszVendor, dwFlags, pszSourceToUse );
  260. }