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.

234 lines
6.9 KiB

  1. // logui.cpp : Implementation of CLoguiApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "logui.h"
  4. #include <iiscnfg.h>
  5. #include <iiscnfgp.h>
  6. #include <inetinfo.h>
  7. #include "initguid.h"
  8. #include <logtype.h>
  9. #include <ilogobj.hxx>
  10. #include "uincsa.h"
  11. #include "uiextnd.h"
  12. #include "uimsft.h"
  13. #include "uiodbc.h"
  14. // the global factory objects
  15. CFacNcsaLogUI facNcsa;
  16. CFacMsftLogUI facMsft;
  17. CFacOdbcLogUI facOdbc;
  18. CFacExtndLogUI facExtnd;
  19. const WORD _wVerMajor = 1;
  20. const WORD _wVerMinor = 0;
  21. // the key type strings for the metabaes keys
  22. #define SZ_LOGGING_MAIN_TYPE _T("IIsLogModules")
  23. #define SZ_LOGGING_TYPE _T("IIsLogModule")
  24. static HRESULT RegisterInMetabase();
  25. //int SetInfoAdminACL(CMetaKey& mk, LPCTSTR szSubKeyPath);
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. CLoguiApp NEAR theApp;
  32. HINSTANCE g_hInstance = NULL;
  33. void CLoguiApp::PrepHelp( OLECHAR* pocMetabasePath )
  34. {
  35. CString szMetaPath = pocMetabasePath;
  36. szMetaPath.MakeLower();
  37. UINT iHelp = IDS_HELPLOC_W3SVCHELP;
  38. if ( szMetaPath.Find(_T("msftpsvc")) >= 0 )
  39. iHelp = IDS_HELPLOC_FTPHELP;
  40. CString sz;
  41. CString szHelpLocation;
  42. sz.LoadString( iHelp );
  43. ExpandEnvironmentStrings(sz, szHelpLocation.GetBuffer(MAX_PATH + 1), MAX_PATH);
  44. szHelpLocation.ReleaseBuffer();
  45. if ( m_pszHelpFilePath )
  46. free((void*)m_pszHelpFilePath);
  47. m_pszHelpFilePath = _tcsdup(szHelpLocation);
  48. }
  49. ////////////////////////////////////////////////////////////////////////////
  50. // CLoguiApp::InitInstance - DLL initialization
  51. BOOL CLoguiApp::InitInstance()
  52. {
  53. g_hInstance = m_hInstance;
  54. BOOL bInit = COleControlModule::InitInstance();
  55. InitCommonDll();
  56. if (bInit)
  57. {
  58. CString sz;
  59. sz.LoadString( IDS_LOGUI_ERR_TITLE );
  60. // Never free this string because now MF...kingC
  61. // uses it internally BEFORE call to this function
  62. //free((void*)m_pszAppName);
  63. m_pszAppName = _tcsdup(sz);
  64. // Get debug flag
  65. GetOutputDebugFlag();
  66. }
  67. return bInit;
  68. }
  69. ////////////////////////////////////////////////////////////////////////////
  70. // CLoguiApp::ExitInstance - DLL termination
  71. int CLoguiApp::ExitInstance()
  72. {
  73. return COleControlModule::ExitInstance();
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // DllRegisterServer - Adds entries to the system registry
  77. STDAPI DllRegisterServer(void)
  78. {
  79. AFX_MANAGE_STATE(_afxModuleAddrThis);
  80. if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
  81. return ResultFromScode(SELFREG_E_CLASS);
  82. return RegisterInMetabase();
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // DllUnregisterServer - Removes entries from the system registry
  86. STDAPI DllUnregisterServer(void)
  87. {
  88. AFX_MANAGE_STATE(_afxModuleAddrThis);
  89. if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
  90. return ResultFromScode(SELFREG_E_CLASS);
  91. return NOERROR;
  92. }
  93. // add all the base logging info to the /LM portion of the tree Also, add in
  94. // the ftp and w3 service logging load strings
  95. static HRESULT
  96. RegisterInMetabase()
  97. {
  98. CString sz;
  99. DWORD dw;
  100. BOOL fService_Exist_W3SVC = FALSE;
  101. BOOL fService_Exist_MSFTPSVC = FALSE;
  102. BOOL fODBCW3 = FALSE;
  103. BOOL fODBCFTP = FALSE;
  104. CString szAvail, path;
  105. CError err;
  106. do
  107. {
  108. // This function is getting called only during registration -- locally.
  109. // Therefore we don't need any names, passwords, etc here
  110. CComAuthInfo auth;
  111. CMetaKey mk(&auth, SZ_MBN_MACHINE, METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE);
  112. err = mk.QueryResult();
  113. BREAK_ON_ERR_FAILURE(err);
  114. // test to see if we can do odbc logging
  115. err = mk.QueryValue(MD_SERVER_CAPABILITIES, dw, NULL, _T("/W3SVC/Info"));
  116. // This key may not even exist (since this service might not even be installed)
  117. if (SUCCEEDED(err))
  118. {
  119. fService_Exist_W3SVC = TRUE;
  120. fODBCW3 = (dw & IIS_CAP1_ODBC_LOGGING) != 0;
  121. }
  122. err = mk.QueryValue(MD_SERVER_CAPABILITIES, dw, NULL, _T("/MSFTPSVC/Info"));
  123. // This key may not even exist (since this service might not even be installed)
  124. if (SUCCEEDED(err))
  125. {
  126. fService_Exist_MSFTPSVC = TRUE;
  127. fODBCFTP = (dw & IIS_CAP1_ODBC_LOGGING) != 0;
  128. }
  129. // open the logging object
  130. path = _T("logging");
  131. err = mk.AddKey(path);
  132. if (err.Win32Error() == ERROR_ALREADY_EXISTS)
  133. {
  134. err.Reset();
  135. }
  136. BREAK_ON_ERR_FAILURE(err);
  137. err = mk.SetValue(MD_KEY_TYPE, CString(SZ_LOGGING_MAIN_TYPE), NULL, path);
  138. BREAK_ON_ERR_FAILURE(err);
  139. #define SETUP_LOG_KEY(id,x,y)\
  140. VERIFY(sz.LoadString((id)));\
  141. sz = CMetabasePath(FALSE, path, sz);\
  142. err = mk.AddKey(sz);\
  143. if (err.Win32Error() == ERROR_ALREADY_EXISTS)\
  144. {\
  145. err.Reset();\
  146. }\
  147. BREAK_ON_ERR_FAILURE(err);\
  148. err = mk.SetValue(MD_KEY_TYPE, CString(SZ_LOGGING_TYPE), NULL, sz);\
  149. BREAK_ON_ERR_FAILURE(err);\
  150. err = mk.SetValue(MD_LOG_PLUGIN_MOD_ID, CString((x)), NULL, sz);\
  151. BREAK_ON_ERR_FAILURE(err);\
  152. err = mk.SetValue(MD_LOG_PLUGIN_UI_ID, CString((y)), NULL, sz);\
  153. BREAK_ON_ERR_FAILURE(err)\
  154. SETUP_LOG_KEY(IDS_MTITLE_NCSA, NCSALOG_CLSID, NCSALOGUI_CLSID);
  155. SETUP_LOG_KEY(IDS_MTITLE_ODBC, ODBCLOG_CLSID, ODBCLOGUI_CLSID);
  156. SETUP_LOG_KEY(IDS_MTITLE_MSFT, ASCLOG_CLSID, ASCLOGUI_CLSID);
  157. SETUP_LOG_KEY(IDS_MTITLE_XTND, EXTLOG_CLSID, EXTLOGUI_CLSID);
  158. // prepare the available logging extensions string
  159. // start with w3svc
  160. if (fService_Exist_W3SVC)
  161. {
  162. szAvail.LoadString(IDS_MTITLE_NCSA);
  163. sz.LoadString(IDS_MTITLE_MSFT);
  164. szAvail += _T(',') + sz;
  165. sz.LoadString(IDS_MTITLE_XTND);
  166. szAvail += _T(',') + sz;
  167. if (fODBCW3)
  168. {
  169. sz.LoadString(IDS_MTITLE_ODBC);
  170. szAvail += _T(',') + sz;
  171. }
  172. // This key may not even exist (since this service might not even be installed) so don't break on err
  173. err = mk.SetValue(MD_LOG_PLUGINS_AVAILABLE, szAvail, NULL, _T("W3SVC/info"));
  174. }
  175. if (fService_Exist_MSFTPSVC)
  176. {
  177. // now ftp - no ncsa
  178. szAvail.LoadString(IDS_MTITLE_MSFT);
  179. sz.LoadString(IDS_MTITLE_XTND);
  180. szAvail += _T(',') + sz;
  181. if (fODBCFTP)
  182. {
  183. sz.LoadString(IDS_MTITLE_ODBC);
  184. szAvail += _T(',') + sz;
  185. }
  186. // This key may not even exist (since this service might not even be installed) so don't break on err
  187. err = mk.SetValue(MD_LOG_PLUGINS_AVAILABLE, szAvail, NULL, _T("MSFTPSVC/info"));
  188. }
  189. } while(FALSE);
  190. return err;
  191. }