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.

472 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 1994-1999 Microsoft Corporation
  3. Module Name :
  4. utcls.cpp
  5. Abstract:
  6. Internet Properties base classes
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "common.h"
  18. #include "idlg.h"
  19. #include "mmc.h"
  20. extern "C"
  21. {
  22. #include <lm.h>
  23. }
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char BASED_CODE THIS_FILE[] = __FILE__;
  27. #endif
  28. #define new DEBUG_NEW
  29. #define SZ_REG_KEY_BASE _T("Software\\Microsoft\\%s")
  30. BOOL
  31. IsServerLocal(
  32. IN LPCTSTR lpszServer
  33. )
  34. /*++
  35. Routine Description:
  36. Check to see if the given name refers to the local machine
  37. Arguments:
  38. LPCTSTR lpszServer : Server name
  39. Return Value:
  40. TRUE if the given name refers to the local computer, FALSE otherwise
  41. Note:
  42. Doesn't work if the server is an ip address
  43. --*/
  44. {
  45. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  46. DWORD dwSize = sizeof(szComputerName) / sizeof(TCHAR);
  47. //
  48. // CODEWORK(?): we're not checking for all the ip addresses
  49. // on the local box or full dns names.
  50. //
  51. // Try GetComputerNameEx when we're building with NT5
  52. // settings.
  53. //
  54. return (!_tcsicmp(_T("localhost"), PURE_COMPUTER_NAME(lpszServer))
  55. || !_tcscmp( _T("127.0.0.1"), PURE_COMPUTER_NAME(lpszServer)))
  56. || (GetComputerName(szComputerName, &dwSize)
  57. && !_tcsicmp(szComputerName, PURE_COMPUTER_NAME(lpszServer)));
  58. }
  59. BOOL
  60. GetVolumeInformationSystemFlags(
  61. IN LPCTSTR lpszPath,
  62. OUT DWORD * pdwSystemFlags
  63. )
  64. /*++
  65. Routine Description:
  66. Get the system flags for the path in question
  67. Arguments:
  68. LPCTSTR lpszPath : Path
  69. DWORD * pdwSystemFlags : Returns system flags
  70. Return Value:
  71. TRUE for success, FALSE for failure.
  72. --*/
  73. {
  74. ASSERT_WRITE_PTR(pdwSystemFlags);
  75. TRACEEOLID("Getting system flags for " << lpszPath);
  76. DWORD dwMaxComponentLength;
  77. TCHAR szRoot[MAX_PATH + 1];
  78. TCHAR szFileSystem[MAX_PATH + 1];
  79. //
  80. // Generating root path
  81. //
  82. if (IsUNCName(lpszPath))
  83. {
  84. //
  85. // Root path of a UNC path is \\foo\bar\
  86. //
  87. ASSERT(lstrlen(lpszPath) < MAX_PATH);
  88. int cSlashes = 0;
  89. LPCTSTR lpszSrc = lpszPath;
  90. LPTSTR lpszDst = szRoot;
  91. while (cSlashes < 4 && *lpszSrc)
  92. {
  93. if ((*lpszDst++ = *lpszSrc++) == '\\')
  94. {
  95. ++cSlashes;
  96. }
  97. }
  98. if (!*lpszSrc)
  99. {
  100. *lpszDst++ = '\\';
  101. }
  102. *lpszDst = '\0';
  103. }
  104. else
  105. {
  106. ::wsprintf(szRoot, _T("%c:\\"), *lpszPath);
  107. }
  108. TRACEEOLID("Root path is " << szRoot);
  109. return ::GetVolumeInformation(
  110. szRoot,
  111. NULL,
  112. 0,
  113. NULL,
  114. &dwMaxComponentLength,
  115. pdwSystemFlags,
  116. szFileSystem,
  117. STRSIZE(szFileSystem)
  118. );
  119. }
  120. LPCTSTR
  121. GenerateRegistryKey(
  122. OUT CString & strBuffer,
  123. IN LPCTSTR lpszSubKey OPTIONAL
  124. )
  125. /*++
  126. Routine Description:
  127. Generate a registry key name based on the current app, and a
  128. provided subkey (optional)
  129. Arguments:
  130. CString & strBuffer : Buffer to create registry key name into.
  131. LPCTSTR lpszSubKey : Subkey name or NULL
  132. Return Value:
  133. Pointer to the registry key value
  134. --*/
  135. {
  136. try
  137. {
  138. //
  139. // Use the app name as the primary registry name
  140. //
  141. CWinApp * pApp = ::AfxGetApp();
  142. if (!pApp)
  143. {
  144. ASSERT_MSG("No app object -- can't generate registry key name");
  145. return NULL;
  146. }
  147. strBuffer.Format(SZ_REG_KEY_BASE, pApp->m_pszAppName);
  148. if (lpszSubKey)
  149. {
  150. strBuffer += _T("\\");
  151. strBuffer += lpszSubKey;
  152. }
  153. TRACEEOLID("Registry key is " << strBuffer);
  154. }
  155. catch(CMemoryException * e)
  156. {
  157. TRACEEOLID("!!!exception building regkey");
  158. e->ReportError();
  159. e->Delete();
  160. return NULL;
  161. }
  162. return strBuffer;
  163. }
  164. //
  165. // CBlob Implementation
  166. //
  167. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  168. CBlob::CBlob()
  169. /*++
  170. Routine Description:
  171. NULL constructor
  172. Arguments:
  173. None
  174. Return Value:
  175. N/A
  176. --*/
  177. : m_pbItem(NULL),
  178. m_dwSize(0L)
  179. {
  180. }
  181. CBlob::CBlob(
  182. IN DWORD dwSize,
  183. IN PBYTE pbItem,
  184. IN BOOL fMakeCopy
  185. )
  186. /*++
  187. Routine Description:
  188. Constructor
  189. Arguments:
  190. DWORD dwSize : Size of memory block
  191. PBYTE pbItem : Pointer to memory block
  192. BOOL fMakeCopy : If TRUE, makes a copy of the memory block.
  193. If FALSE, takes ownership of the pointer.
  194. Return Value:
  195. N/A
  196. --*/
  197. : m_pbItem(NULL),
  198. m_dwSize(0L)
  199. {
  200. SetValue(dwSize, pbItem, fMakeCopy);
  201. }
  202. CBlob::CBlob(
  203. IN const CBlob & blob
  204. )
  205. /*++
  206. Routine Description:
  207. Copy constructor
  208. Arguments:
  209. const CBlob & blob : Source blob
  210. Return Value:
  211. N/A
  212. Notes:
  213. This contructor makes a copy of the memory block in question.
  214. --*/
  215. : m_pbItem(NULL),
  216. m_dwSize(0L)
  217. {
  218. SetValue(blob.GetSize(), blob.m_pbItem, TRUE);
  219. }
  220. void
  221. CBlob::SetValue(
  222. IN DWORD dwSize,
  223. IN PBYTE pbItem,
  224. IN BOOL fMakeCopy OPTIONAL
  225. )
  226. /*++
  227. Routine Description:
  228. Assign the value to this binary object. If fMakeCopy is FALSE,
  229. the blob will take ownership of the pointer, otherwise a copy
  230. will be made.
  231. Arguments:
  232. DWORD dwSize : Size in bytes
  233. PBYTE pbItem : Byte streadm
  234. BOOL fMakeCopy : If true, make a copy, else assign pointer
  235. Return Value:
  236. None
  237. --*/
  238. {
  239. //ASSERT_READ_PTR2(pbItem, dwSize);
  240. if (!IsEmpty())
  241. {
  242. TRACEEOLID("Assigning value to non-empty blob. Cleaning up");
  243. CleanUp();
  244. }
  245. if (dwSize > 0L)
  246. {
  247. //
  248. // Make private copy
  249. //
  250. m_dwSize = dwSize;
  251. if (fMakeCopy)
  252. {
  253. m_pbItem = (PBYTE)AllocMem(m_dwSize);
  254. if (NULL != m_pbItem)
  255. {
  256. CopyMemory(m_pbItem, pbItem, dwSize);
  257. }
  258. }
  259. else
  260. {
  261. m_pbItem = pbItem;
  262. }
  263. }
  264. }
  265. void
  266. CBlob::CleanUp()
  267. /*++
  268. Routine Description:
  269. Delete data pointer, and reset pointer and size.
  270. Arguments:
  271. None
  272. Return Value:
  273. None
  274. --*/
  275. {
  276. if (m_pbItem)
  277. {
  278. FreeMem(m_pbItem);
  279. }
  280. m_pbItem = NULL;
  281. m_dwSize = 0L;
  282. }
  283. CBlob &
  284. CBlob::operator =(
  285. IN const CBlob & blob
  286. )
  287. /*++
  288. Routine Description:
  289. Assign values from another CBlob.
  290. Arguments:
  291. const CBlob & blob : Source blob
  292. Return Value:
  293. Reference to this object
  294. --*/
  295. {
  296. //
  297. // Make copy of data
  298. //
  299. SetValue(blob.GetSize(), blob.m_pbItem, TRUE);
  300. return *this;
  301. }
  302. BOOL
  303. CBlob::operator ==(
  304. IN const CBlob & blob
  305. ) const
  306. /*++
  307. Routine Description:
  308. Compare two binary large objects. In order to match, the objects
  309. must be the same size, and byte identical.
  310. Arguments:
  311. const CBlob & blob : Blob to compare against.
  312. Return Value:
  313. TRUE if the objects match, FALSE otherwise.
  314. --*/
  315. {
  316. if (GetSize() != blob.GetSize())
  317. {
  318. return FALSE;
  319. }
  320. return memcmp(m_pbItem, blob.m_pbItem, GetSize()) == 0;
  321. }