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.

546 lines
15 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. opk.h
  5. Abstract:
  6. Common functions for OPK Tools.
  7. Author:
  8. Donald McNamara (donaldm) 02/08/2000
  9. Brian Ku (briank) 06/21/2000
  10. Revision History:
  11. --*/
  12. #ifndef OPKLIB_H
  13. #define OPKLIB_H
  14. #ifndef STRICT
  15. #define STRICT
  16. #endif
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <shlwapi.h>
  22. #include <regstr.h>
  23. #include <tchar.h>
  24. #include <lm.h>
  25. #include <devguid.h>
  26. #include <setupapi.h>
  27. #include <spsyslib.h>
  28. #include <sysprep_.h>
  29. // ============================================================================
  30. // JCOHEN.H - Brought over from Windows Millennium Edition
  31. // ============================================================================
  32. #ifdef NULLSTR
  33. #undef NULLSTR
  34. #endif // NULLSTR
  35. #define NULLSTR _T("\0")
  36. #ifdef NULLCHR
  37. #undef NULLCHR
  38. #endif // NULLCHR
  39. #define NULLCHR _T('\0')
  40. #ifdef CHR_BACKSLASH
  41. #undef CHR_BACKSLASH
  42. #endif // CHR_BACKSLASH
  43. #define CHR_BACKSLASH _T('\\')
  44. #ifdef CHR_SPACE
  45. #undef CHR_SPACE
  46. #endif // CHR_SPACE
  47. #define CHR_SPACE _T(' ')
  48. //
  49. // Macros.
  50. //
  51. // String macros.
  52. //
  53. #ifndef LSTRCMPI
  54. #define LSTRCMPI(x, y) ( ( CompareString( LOCALE_INVARIANT, NORM_IGNORECASE, x, -1, y, -1 ) - CSTR_EQUAL ) )
  55. #endif // LSTRCMPI
  56. // Memory managing macros.
  57. //
  58. #ifdef MALLOC
  59. #undef MALLOC
  60. #endif // MALLOC
  61. #define MALLOC(cb) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb)
  62. #ifdef REALLOC
  63. #undef REALLOC
  64. #endif // REALLOC
  65. #define REALLOC(lp, cb) HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lp, cb)
  66. #ifdef FREE
  67. #undef FREE
  68. #endif // FREE
  69. #define FREE(lp) ( (lp != NULL) ? ( (HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, (LPVOID) lp)) ? ((lp = NULL) == NULL) : (FALSE) ) : (FALSE) )
  70. #ifdef NETFREE
  71. #undef NETFREE
  72. #endif // NETFREE
  73. #define NETFREE(lp) ( (lp != NULL) ? ( (NetApiBufferFree((LPVOID) lp)) ? ((lp = NULL) == NULL) : (FALSE) ) : (FALSE) )
  74. // Misc. macros.
  75. //
  76. #ifdef EXIST
  77. #undef EXIST
  78. #endif // EXIST
  79. #define EXIST(lpFileName) ( (GetFileAttributes(lpFileName) == 0xFFFFFFFF) ? (FALSE) : (TRUE) )
  80. #ifdef ISNUM
  81. #undef ISNUM
  82. #endif // ISNUM
  83. #define ISNUM(cChar) ( ( ( cChar >= _T('0') ) && ( cChar <= _T('9') ) ) ? (TRUE) : (FALSE) )
  84. #ifdef ISLET
  85. #undef ISLET
  86. #endif // ISLET
  87. #define ISLET(cChar) ( ( ( ( cChar >= _T('a') ) && ( cChar <= _T('z') ) ) || ( ( cChar >= _T('A') ) && ( cChar <= _T('Z') ) ) ) ? (TRUE) : (FALSE) )
  88. #ifdef UPPER
  89. #undef UPPER
  90. #endif // UPPER
  91. #define UPPER(x) ( ( (x >= _T('a')) && (x <= _T('z')) ) ? (x + _T('A') - _T('a')) : (x) )
  92. #ifdef RANDOM
  93. #undef RANDOM
  94. #endif // RANDOM
  95. #define RANDOM(low, high) ( (high - low + 1) ? (rand() % (high - low + 1) + low) : (0) )
  96. #ifdef COMP
  97. #undef COMP
  98. #endif // COMP
  99. #define COMP(x, y) ( (UPPER(x) == UPPER(y)) ? (TRUE) : (FALSE) )
  100. #ifdef STRSIZE
  101. #undef STRSIZE
  102. #endif // STRSIZE
  103. #define STRSIZE(sz) ( sizeof(sz) / sizeof(TCHAR) )
  104. #ifdef ARRAYSIZE
  105. #undef ARRAYSIZE
  106. #endif // ARRAYSIZE
  107. #define ARRAYSIZE(a) ( sizeof(a) / sizeof(a[0]) )
  108. #ifdef AS
  109. #undef AS
  110. #endif // AS
  111. #define AS(a) ARRAYSIZE(a)
  112. #ifdef GETBIT
  113. #undef GETBIT
  114. #endif // GETBIT
  115. #define GETBIT(dw, b) ( dw & b )
  116. #ifdef SETBIT
  117. #undef SETBIT
  118. #endif // SETBIT
  119. #define SETBIT(dw, b, f) ( (f) ? (dw |= b) : (dw &= ~b) )
  120. #ifndef GET_FLAG
  121. #define GET_FLAG(f, b) ( f & b )
  122. #endif // GET_FLAG
  123. #ifndef SET_FLAG
  124. #define SET_FLAG(f, b) ( f |= b )
  125. #endif // SET_FLAG
  126. #ifndef RESET_FLAG
  127. #define RESET_FLAG(f, b) ( f &= ~b )
  128. #endif // RESET_FLAG
  129. //
  130. // Logging constants and definitions.
  131. //
  132. #define LOG_DEBUG 0x00000003 // Only log in debug builds if this is specified. (Debug Level for logging.)
  133. #define LOG_LEVEL_MASK 0x0000000F // Mask to only show the log level bits
  134. #define LOG_MSG_BOX 0x00000010 // Display the message boxes if this is enabled.
  135. #define LOG_ERR 0x00000020 // Prefix the logged string with "Error:" if the message is level 0,
  136. // or "WARNx" if the message is at level x > 0.
  137. #define LOG_TIME 0x00000040 // Display time if this is enabled
  138. #define LOG_NO_NL 0x00000080 // Don't add new Line to the end of log string if this is set.
  139. #define LOG_FLAG_QUIET_MODE 0x00000001 // Quiet mode - don't display message boxes.
  140. typedef struct _LOG_INFO
  141. {
  142. DWORD dwLogFlags;
  143. DWORD dwLogLevel;
  144. TCHAR szLogFile[MAX_PATH];
  145. LPTSTR lpAppName;
  146. } LOG_INFO, *PLOG_INFO;
  147. #define INI_SEC_LOGGING _T("Logging")
  148. #define INI_KEY_LOGGING INI_SEC_LOGGING
  149. #define INI_VAL_YES _T("Yes")
  150. #define INI_VAL_NO _T("No")
  151. #define INI_KEY_LOGLEVEL _T("LogLevel")
  152. #define INI_KEY_QUIET _T("QuietMode")
  153. #define INI_KEY_LOGFILE _T("LogFile")
  154. // ============================================================================
  155. // MISCAPI.H - Brought over from Windows Millennium Edition
  156. // ============================================================================
  157. //
  158. // Defined Value(s):
  159. //
  160. #define MB_ERRORBOX MB_ICONSTOP | MB_OK | MB_APPLMODAL
  161. //
  162. // Type Definition(s):
  163. //
  164. // Use this simple struture to create a table that
  165. // maps a constant string to a localizable resource id.
  166. //
  167. typedef struct _STRRES
  168. {
  169. LPTSTR lpStr;
  170. UINT uId;
  171. } STRRES, *PLSTRRES, *LPSTRRES;
  172. //
  173. // External Function Prototype(s):
  174. //
  175. LPTSTR AllocateString(HINSTANCE, UINT);
  176. LPTSTR AllocateExpand(LPTSTR lpszBuffer);
  177. LPTSTR AllocateStrRes(HINSTANCE hInstance, LPSTRRES lpsrTable, DWORD cbTable, LPTSTR lpString, LPTSTR * lplpReturn);
  178. int MsgBoxLst(HWND, LPTSTR, LPTSTR, UINT, va_list);
  179. int MsgBoxStr(HWND, LPTSTR, LPTSTR, UINT, ...);
  180. int MsgBox(HWND, UINT, UINT, UINT, ...);
  181. void CenterDialog(HWND hwnd);
  182. void CenterDialogEx(HWND hParent, HWND hChild);
  183. INT_PTR CALLBACK SimpleDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  184. INT_PTR SimpleDialogBox(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent);
  185. HFONT GetFont(HWND, LPTSTR, DWORD, LONG, BOOL);
  186. void ShowEnableWindow(HWND, BOOL);
  187. extern BOOL IsServer(VOID);
  188. extern BOOL IsIA64(VOID);
  189. BOOL ValidDosName(LPCTSTR);
  190. DWORD GetLineArgs(LPTSTR lpSrc, LPTSTR ** lplplpArgs, LPTSTR * lplpAllArgs);
  191. DWORD GetCommandLineArgs(LPTSTR ** lplplpArgs);
  192. //
  193. // Generic singularly linked list
  194. //
  195. typedef struct _GENERIC_LIST {
  196. void* pvItem; // points to your structure
  197. struct _GENERIC_LIST* pNext;
  198. }GENERIC_LIST, *PGENERIC_LIST;
  199. BOOL FAddListItem(PGENERIC_LIST*, PGENERIC_LIST**, PVOID pvItem);
  200. void FreeList(PGENERIC_LIST);
  201. // ============================================================================
  202. BOOL FGetFactoryPath(LPTSTR pszFactoryPath);
  203. BOOL FGetSysprepPath(LPTSTR pszSysprepPath);
  204. // ============================================================================
  205. // DISKAPI.H - Brought over from Windows Millennium Edition
  206. // ============================================================================
  207. BOOL DirectoryExists(LPCTSTR);
  208. BOOL FileExists(LPCTSTR);
  209. BOOL CopyResetFile(LPCTSTR, LPCTSTR);
  210. DWORD IfGetLongPathName(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer);
  211. BOOL CreatePath(LPCTSTR);
  212. BOOL DeletePath(LPCTSTR);
  213. BOOL DeleteFilesEx(LPCTSTR lpDirectory, LPCTSTR lpFileSpec);
  214. LPTSTR AddPathN(LPTSTR lpPath, LPCTSTR lpName, DWORD cbPath);
  215. LPTSTR AddPath(LPTSTR, LPCTSTR);
  216. DWORD ExpandFullPath(LPTSTR lpszPath, LPTSTR lpszReturn, DWORD cbReturn);
  217. BOOL CopyDirectory(LPCTSTR, LPCTSTR);
  218. BOOL CopyDirectoryProgress(HWND, LPCTSTR, LPCTSTR);
  219. BOOL CopyDirectoryProgressCancel(HWND hwnd, HANDLE hEvent, LPCTSTR lpSrc, LPCTSTR lpDst);
  220. DWORD FileCount(LPCTSTR);
  221. BOOL BrowseForFolder(HWND, INT, LPTSTR, DWORD);
  222. BOOL BrowseForFile(HWND hwnd, INT, INT, INT, LPTSTR, DWORD, LPTSTR, DWORD);
  223. ULONG CrcFile(LPCTSTR); // In CRC32.C
  224. BOOL CreateUnicodeFile(LPCTSTR);
  225. // ============================================================================
  226. // STRAPI.H - Brought over from Windows Millennium Edition
  227. // ============================================================================
  228. #ifndef _INC_SHLWAPI
  229. LPTSTR StrChr(LPCTSTR, TCHAR);
  230. LPTSTR StrRChr(LPCTSTR, TCHAR);
  231. #endif // _INC_SHLWAPI
  232. LPTSTR StrRem(LPTSTR, TCHAR);
  233. LPTSTR StrRTrm(LPTSTR, TCHAR);
  234. LPTSTR StrTrm(LPTSTR, TCHAR);
  235. LPTSTR StrMov(LPTSTR, LPTSTR, INT);
  236. // Exported Function(s) in LOG.C:
  237. //
  238. INT LogFileLst(LPCTSTR lpFileName, LPTSTR lpFormat, va_list lpArgs);
  239. INT LogFileStr(LPCTSTR lpFileName, LPTSTR lpFormat, ...);
  240. INT LogFile(LPCTSTR lpFileName, UINT uFormat, ...);
  241. DWORD OpkLogFileLst(PLOG_INFO pLogInfo, DWORD dwLogOpt, LPTSTR lpFormat, va_list lpArgs);
  242. DWORD OpkLogFile(DWORD dwLogOpt, UINT uFormat, ...);
  243. DWORD OpkLogFileStr(DWORD dwLogOpt, LPTSTR lpFormat, ...);
  244. BOOL OpkInitLogging(LPTSTR lpszIniPath, LPTSTR lpAppName);
  245. /****************************************************************************\
  246. From REGAPI.C
  247. Registry API function prototypes and defined values.
  248. \****************************************************************************/
  249. //
  250. // Defined Root Key(s):
  251. //
  252. #define HKCR HKEY_CLASSES_ROOT
  253. #define HKCU HKEY_CURRENT_USER
  254. #define HKLM HKEY_LOCAL_MACHINE
  255. #define HKU HKEY_USERS
  256. //
  257. // Type Definition(s):
  258. //
  259. typedef BOOL (CALLBACK * REGENUMKEYPROC) (HKEY, LPTSTR, LPARAM);
  260. typedef BOOL (CALLBACK * REGENUMVALPROC) (LPTSTR, LPTSTR, LPARAM);
  261. //
  262. // External Function Prototype(s):
  263. //
  264. BOOL RegExists(HKEY hKeyReg, LPTSTR lpKey, LPTSTR lpValue);
  265. BOOL RegDelete(HKEY hRootKey, LPTSTR lpSubKey, LPTSTR lpValue);
  266. LPTSTR RegGetStringEx(HKEY hKeyReg, LPTSTR lpKey, LPTSTR lpValue, BOOL bExpand);
  267. LPTSTR RegGetString(HKEY hKeyReg, LPTSTR lpKey, LPTSTR lpValue);
  268. LPTSTR RegGetExpand(HKEY hKeyReg, LPTSTR lpKey, LPTSTR lpValue);
  269. LPVOID RegGetBin(HKEY hKeyReg, LPTSTR lpKey, LPTSTR lpValue);
  270. DWORD RegGetDword(HKEY hKeyReg, LPTSTR lpKey, LPTSTR lpValue);
  271. BOOL RegSetStringEx(HKEY hRootKey, LPTSTR lpSubKey, LPTSTR lpValue, LPTSTR lpData, BOOL bExpand);
  272. BOOL RegSetString(HKEY hRootKey, LPTSTR lpSubKey, LPTSTR lpValue, LPTSTR lpData);
  273. BOOL RegSetExpand(HKEY hRootKey, LPTSTR lpSubKey, LPTSTR lpValue, LPTSTR lpData);
  274. BOOL RegSetDword(HKEY hRootKey, LPTSTR lpSubKey, LPTSTR lpValue, DWORD dwData);
  275. BOOL RegCheck(HKEY hKeyRoot, LPTSTR lpKey, LPTSTR lpValue);
  276. BOOL RegEnumKeys(HKEY hKey, LPTSTR lpRegKey, REGENUMKEYPROC hCallBack, LPARAM lParam, BOOL bDelKeys);
  277. BOOL RegEnumValues(HKEY hKey, LPTSTR lpRegKey, REGENUMVALPROC hCallBack, LPARAM lParam, BOOL bDelValues);
  278. /****************************************************************************\
  279. From INIAPI.C
  280. INI API function prototypes and defined values.
  281. \****************************************************************************/
  282. //
  283. // External Function Prototype(s):
  284. //
  285. LPTSTR IniGetExpand(LPTSTR lpszIniFile, LPTSTR lpszSection, LPTSTR lpszKey, LPTSTR lpszDefault);
  286. LPTSTR IniGetString(LPTSTR lpszIniFile, LPTSTR lpszSection, LPTSTR lpszKey, LPTSTR lpszDefault);
  287. LPTSTR IniGetSection(LPTSTR lpszIniFile, LPTSTR lpszSection);
  288. LPTSTR IniGetStringEx(LPTSTR lpszIniFile, LPTSTR lpszSection, LPTSTR lpszKey, LPTSTR lpszDefault, LPDWORD lpdwSize);
  289. LPTSTR IniGetSectionEx(LPTSTR lpszIniFile, LPTSTR lpszSection, LPDWORD lpdwSize);
  290. BOOL IniSettingExists(LPCTSTR lpszFile, LPCTSTR lpszSection, LPCTSTR lpszKey, LPCTSTR lpszValue);
  291. /****************************************************************************\
  292. From OPKFAC.C
  293. Factory API function prototypes and defined values.
  294. \****************************************************************************/
  295. //
  296. // Defined Value(s):
  297. //
  298. // Flags for LocateWinBom():
  299. //
  300. #define LOCATE_NORMAL 0x00000000
  301. #define LOCATE_AGAIN 0x00000001
  302. #define LOCATE_NONET 0x00000002
  303. //
  304. // External Function Prototype(s):
  305. //
  306. BOOL EnablePrivilege(IN PCTSTR,IN BOOL);
  307. extern BOOL GetCredentials(LPTSTR lpszUsername, DWORD dwUsernameSize, LPTSTR lpszPassword, DWORD dwPasswordSize, LPTSTR lpFileName, LPTSTR lpAlternateSection);
  308. extern NET_API_STATUS FactoryNetworkConnect(LPTSTR lpszPath, LPTSTR lpszWinBOMPath, LPTSTR lpAlternateSection, BOOL bState);
  309. extern BOOL LocateWinBom(LPTSTR lpWinBOMPath, DWORD cbWinbBOMPath, LPTSTR lpFactoryPath, LPTSTR lpFactoryMode, DWORD dwFlags);
  310. void CleanupRegistry(VOID);
  311. VOID GenUniqueName(OUT PWSTR GeneratedString, IN DWORD DesiredStrLen);
  312. NET_API_STATUS ConnectNetworkResource(LPTSTR, LPTSTR, LPTSTR, BOOL);
  313. BOOL GetUncShare(LPCTSTR lpszPath, LPTSTR lpszShare, DWORD cbShare);
  314. DWORD GetSkuType();
  315. BOOL SetFactoryStartup(LPCTSTR lpFactory);
  316. BOOL UpdateDevicePathEx(HKEY hKeyRoot, LPTSTR lpszSubKey, LPTSTR lpszNewPath, LPTSTR lpszRoot, BOOL bRecursive);
  317. BOOL UpdateDevicePath(LPTSTR lpszNewPath, LPTSTR lpszRoot, BOOL bRecursive);
  318. BOOL UpdateSourcePath(LPTSTR lpszSourcePath);
  319. VOID CleanupSourcesDir(LPTSTR lpszSourcesPath);
  320. BOOL SetDefaultOEMApps(LPCTSTR pszWinBOMPath);
  321. BOOL OpklibCheckVersion(DWORD dwMajorVersion, DWORD dwQFEVersion);
  322. // If app uses setDefaultOEMApps, it must implement the following function
  323. // which is used for error reporting.
  324. void ReportSetDefaultOEMAppsError(LPCTSTR pszMissingApp, LPCTSTR pszCategory);
  325. //
  326. // Sysprep_c.w
  327. //
  328. // ============================================================================
  329. // USEFUL STRINGS
  330. // ============================================================================
  331. #define SYSCLONE_PART2 "setupcl.exe"
  332. #define IDS_ADMINISTRATOR 1
  333. // ============================================================================
  334. // USEFUL CONSTANTS
  335. // ============================================================================
  336. #define SETUPTYPE 1 // from winlogon\setup.h
  337. #define SETUPTYPE_NOREBOOT 2
  338. #define REGISTRY_QUOTA_BUMP (10* (1024 * 1024))
  339. #define DEFAULT_REGISTRY_QUOTA (32 * (1024 * 1024))
  340. #define SFC_DISABLE_NOPOPUPS 4 // from sfc.h
  341. #define FILE_SRCLIENT_DLL L"SRCLIENT.DLL"
  342. // ============================================================================
  343. // FUNCTION DECLARATIONS
  344. // ============================================================================
  345. BOOL
  346. IsDomainMember(
  347. VOID
  348. );
  349. BOOL
  350. ResetRegistryKey(
  351. IN HKEY Rootkey,
  352. IN PCWSTR Subkey,
  353. IN PCWSTR Delkey
  354. );
  355. BOOL
  356. DeleteWinlogonDefaults(
  357. VOID
  358. );
  359. VOID
  360. FixDevicePaths(
  361. VOID
  362. );
  363. BOOL
  364. NukeMruList(
  365. VOID
  366. );
  367. BOOL
  368. RemoveNetworkSettings(
  369. LPTSTR lpszSysprepINFPath
  370. );
  371. VOID
  372. RunExternalUniqueness(
  373. VOID
  374. );
  375. BOOL
  376. IsSetupClPresent(
  377. VOID
  378. );
  379. //
  380. // from spapip.h
  381. //
  382. BOOL
  383. pSetupIsUserAdmin(
  384. VOID
  385. );
  386. BOOL
  387. pSetupDoesUserHavePrivilege(
  388. PCTSTR
  389. );
  390. BOOL
  391. EnablePrivilege(
  392. IN PCTSTR,
  393. IN BOOL
  394. );
  395. BOOL
  396. ValidateAndChecksumFile(
  397. IN PCTSTR Filename,
  398. OUT PBOOLEAN IsNtImage,
  399. OUT PULONG Checksum,
  400. OUT PBOOLEAN Valid
  401. );
  402. VOID
  403. LogRepairInfo(
  404. IN PWSTR Source,
  405. IN PWSTR Target,
  406. IN PWSTR DirectoryOnSourceDevice,
  407. IN PWSTR DiskDescription,
  408. IN PWSTR DiskTag
  409. );
  410. BOOL
  411. ChangeBootTimeout(
  412. IN UINT
  413. );
  414. VOID
  415. DisableSR(
  416. VOID
  417. );
  418. VOID
  419. EnableSR(
  420. VOID
  421. );
  422. #endif // OPKLIB_H