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.

427 lines
17 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: GETMACH.HXX
  7. //
  8. // Contents: GetMachineList API
  9. //
  10. // History: 30-Aug-95 XimingZ Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #ifndef __GETMACH_HXX__
  14. #define __GETMACH_HXX__
  15. #include <dg.hxx>
  16. #define GM_ALLMACHINES 9999 // number of machines
  17. #define GU_ALLUSERS 9999 // number of users
  18. #define GU_ADMIN 0x01
  19. #define GU_POWERUSER 0x02
  20. #define GU_ORDINARYUSER 0x04
  21. #define GU_SERVICEUSER 0x08
  22. #define GU_LOGINPRIV 0x10
  23. #define GU_DOMAINUSER 0x20
  24. #define GU_LOCALUSER 0x40
  25. #define GU_BATCHUSER 0x80
  26. #define GU_ANYUSER 0 // users properties
  27. // Bit flags for machine name forms
  28. #define GM_SHORT_UNC 0x1 // form of Serverfoo
  29. #define GM_LONG_UNC 0x2 // form of \\ServerFoo
  30. #define GM_SHORT_DNS 0x4 // form of ServerFoo.com
  31. #define GM_LONG_DNS 0x8 // form of ServerFoo.microsoft.com
  32. #define GM_NUMERICAL_DNS 0x10 // form of 157.45.34.230
  33. // Bit flags for operating systems
  34. #define GM_NONE 0x0
  35. #define GM_NT 0x1
  36. #define GM_WIN9X 0x2
  37. #define GM_MACINTOSH 0x4
  38. #define GM_DEFAULT GM_NT // The default OS
  39. #define GM_OS_ANY (GM_NT | GM_WIN9X | GM_MACINTOSH)
  40. #define GM_PROTO_TCP 0x10000
  41. #define GM_PROTO_IPX 0x20000
  42. #define GM_PROTO_NETB 0x40000
  43. #define GM_PROTO_ANY (GM_PROTO_TCP | GM_PROTO_IPX | GM_PROTO_NETB)
  44. #define GM_OS_WORD(a) (a & 0xffff)
  45. #define GM_PROTO_WORD(a) (a >> 16)
  46. #define CT_OS_KEY _TN("os") // Key for operating system
  47. #define CT_LOGONUSER_KEY _TN("logonuser") // Key for logon user
  48. #define CT_NT_STR _TN("nt") // String for NT
  49. #define CT_WIN9X_STR _TN("win9x") // String for Win9X
  50. #define CT_MACINTOSH_STR _TN("mac") // String for Macintosh
  51. #define GM_MACHINE_SECTION _TN("Machines") // Section name in ini file
  52. #define CT_ARCH_KEY _TN("arch") // Key for architecture
  53. #define CT_OS_BUILD_KEY _TN("OSbuild") // Key for OS build no.
  54. #define CT_OLE_BUILD_KEY _TN("OLEbuild") // Key for OLE build no.
  55. #define CT_IE_BUILD_KEY _TN("IEbuild") // Key for IE build no.
  56. #define CT_SP_BUILD_KEY _TN("SPbuild") // Key for SP build no.
  57. #define CT_INIFILE _TN("ctdata.ini") // Default ini file name
  58. typedef struct
  59. {
  60. LPNSTR pwszAccount;
  61. LPNSTR pwszDomain;
  62. LPNSTR pwszPassword;
  63. DWORD dwProperties;
  64. }USERINFO, *LPUSERINFO;
  65. typedef struct _MACHINFO
  66. {
  67. DWORD dwOS;
  68. LPNSTR pnszLogonUser;
  69. DWORD dwProtocols;
  70. DWORD dwArch;
  71. } MACHINFO, *PMACHINFO;
  72. //+-------------------------------------------------------------------------
  73. //
  74. // Function: GetMachineListEx
  75. //
  76. // Synopsis: Get a list of machine names from an ini file.
  77. //
  78. // Arguments: [pnszFile] -- Ini file name.
  79. // [pcMach] -- Pointer to a variable which gives the number
  80. // of requested machines. GM_ALLMACHINES
  81. // means as many machines as possible.
  82. // When the function returns, the variable
  83. // contains the number of machines actually
  84. // returned.
  85. // [papnszMach] -- Array of returned machine names.
  86. // The caller should release memory using
  87. // FreeMachineList.
  88. // [pdgint] -- Pointer to a caller supplied DG_INTERGER
  89. // instance which is used to randomize
  90. // the machine and form selections.
  91. // If the value is NULL, machines will always
  92. // be picked from the top of the list in the
  93. // ini file and be in UNC form (e.g. server1) only.
  94. // But if the ini file contains the fixedmach
  95. // key in options section, machines will be
  96. // picked from the top of the list in the ini
  97. // file.
  98. // [fLocalIncluded] -- Do we allow local machine included?
  99. // [dwForm] -- Specifies desired form of machine names.
  100. // The value should be 0 or any union of flags
  101. // GM_SHORT_UNC, GM_LONG_UNC, GM_LONG_DNS,
  102. // GM_SHORT_DNS and GM_NUMERICAL_DNS.
  103. // If the value is 0, only the short UNC form
  104. // is used; else if only one form is specified,
  105. // it is used for all machine names; else the
  106. // form of each machine name is randomly
  107. // selected among the specfied forms. The
  108. // value of pdgint may not be NULL if multiple
  109. // forms are specified.
  110. // See getmach.hxx for meaning of the flags.
  111. //
  112. // [pMachInfo] -- Points to a struct specifying the
  113. // attributes of machines to be selected.
  114. //
  115. // The dwOS field specfies the operating
  116. // system of the machines to be selected
  117. // It is a union of zero or more of flags
  118. // GM_NT and GM_WIN9X. If its value is 0,
  119. // it defaults to GM_NT.
  120. //
  121. // If flag GM_NT is specfied, machines that
  122. // have line "os=nt" or have no os= line in
  123. // the ini will be selected. If flag
  124. // GM_WIN9X is specified, those that
  125. // have line "os=win9x" in the ini file
  126. // will be selected. When both flags
  127. // are present, any machine is qualified.
  128. //
  129. // The pnszLogonUser field specfies the
  130. // logon user of the machines to be selected.
  131. // If its value is NULL or a pointer to an
  132. // empty string, no restrictions on logon
  133. // user is imposed. Otherwise, only the
  134. // machines with the specifed logon user
  135. // will be selected. The logon user is
  136. // specifed in the ini file as a line
  137. // logonuser=<LogonUser> in the corresponding
  138. // machine's section.
  139. //
  140. // Fields dwProtocols and dwReserved are
  141. // not used for now and must be set to 0.
  142. //
  143. // Returns: S_OK if some machine names are returned with the desired forms;
  144. // S_FALSE if an attempt to get a DNS name has failed and the UNC
  145. // name is returned instead.
  146. // E_FAIL if DNS name is explictly requested but can not be
  147. // obtained.
  148. // An error code for any other error.
  149. //
  150. // History: 30-Aug-95 XimingZ Created
  151. // 06-Mar-96 XimingZ Added dwForm parameter for DNS names
  152. // 01-Aug-96 XimingZ Added pMacnInfo parameter
  153. //
  154. // Notes: The ini file should be in the %SystemRoot% directory and its
  155. // contents should look like:
  156. // [Machines]
  157. // ctolex861=
  158. // ctolemips2=
  159. // ctoleaxp1=
  160. // [options]
  161. // fixedmach=1 ; optional
  162. // [ctolex861]
  163. // os=win9x
  164. // logonuser=oleuser1
  165. //
  166. // where the '=' following each machine name is required.
  167. //
  168. // An example for using this API would be:
  169. //
  170. // ULONG cMach = 5;
  171. // PNSTR *apnszMach = NULL;
  172. // DG_INTEGER dgint(ulSeed);
  173. //
  174. // // Specify Win9x machine with oleuser1 as logon user
  175. // MACHINFO mi = {GM_WIN9X, _TN("oleuser1", 0, 0};
  176. //
  177. // hr = GetMachineListEx(
  178. // pnszIniFile,
  179. // &cMach,
  180. // &apnszMach,
  181. // &dgint, // Non-NULL required for multiple forms/attributes
  182. // FALSE, // Exclude local machine
  183. // GM_SHORT_UNC | GM_LONG_UNC, // both UNC forms are used
  184. // &mi);
  185. // // Code to use the machine list:
  186. // // ......
  187. //
  188. // FreeMachineList(cMach, apnszMach);
  189. //
  190. //--------------------------------------------------------------------------
  191. HRESULT GetMachineListEx(
  192. LPCNSTR pnszFile,
  193. ULONG *pcMach,
  194. LPNSTR **papnszMach,
  195. DG_INTEGER *pdgint,
  196. BOOL fLocalIncluded,
  197. DWORD dwForm,
  198. PMACHINFO pMachInfo);
  199. // Overloaded version using GU_SHORT_UNC as the default value of dwForm:
  200. HRESULT GetMachineListEx(
  201. LPCNSTR pnszFile,
  202. ULONG *pcMach,
  203. LPNSTR **papnszMach,
  204. DG_INTEGER *pdgint,
  205. BOOL fLocalIncluded);
  206. // Function using %SystemRoot%\ctdata.ini as the default ini file.
  207. HRESULT GetMachineList(
  208. ULONG *pcMach,
  209. LPNSTR **papnszMach,
  210. DG_INTEGER *pdgint,
  211. BOOL fLocalIncluded);
  212. VOID FreeMachineList(
  213. ULONG cMach,
  214. LPNSTR* apnszMach);
  215. HRESULT RemoveMachineFromListEx(
  216. LPCNSTR pnszFile,
  217. LPCNSTR pnszMach);
  218. HRESULT RemoveMachineFromList(
  219. LPCNSTR pnszMach);
  220. //+-------------------------------------------------------------------------
  221. //
  222. // Function: GetUserList
  223. //
  224. // Synopsis: Get a list of users names from an ini file. The list will
  225. // contain only the users that held ALL the properties
  226. // specified by the 'dwProperties' flag AND belong to the
  227. // local group specified by [pnszLocalGroup] parameter. If
  228. // pnszLocalGroup=NULL then all the users will be returned
  229. // regardless to the local group they belong to.
  230. //
  231. // Arguments: [pnszFile] -- name of the .ini file.
  232. // [pcUser] -- number of the users requested, will
  233. // contain the actual number after call.
  234. // [paUserInfo] -- array with users information.
  235. // [dwProperties] -- user properties
  236. // [pnszLocalGroup] -- user local group
  237. //
  238. // Return: HRESULT
  239. //
  240. // Notes: The ini file should be in the %SystemRoot% directory and its
  241. // contents should look like:
  242. //
  243. // [users]
  244. // ctuser=
  245. // ctadmin=
  246. //
  247. // [ctuser]
  248. // domain=redmond
  249. // password=apassword
  250. // group=admin|poweruser|ordinary
  251. // service=1
  252. // loginpriv=1
  253. // batch=1
  254. //
  255. // [groups]
  256. // group1=
  257. // group2=
  258. //
  259. // [group1]
  260. // ctuser=
  261. //
  262. // [group2]
  263. // ctadmin=
  264. //
  265. // Some of the properties can not be held by the same user in the
  266. // same time (e.g. GU_DOMAINUSER | GU_LOCALUSER so, if we specify
  267. // both these properties you'll get an empty list)
  268. //
  269. // History: 15-Jan-96 GigelA Created
  270. //
  271. //--------------------------------------------------------------------------
  272. HRESULT GetUserList(
  273. LPCNSTR pnszFile,
  274. ULONG *pcUser,
  275. LPUSERINFO *paUserInfo,
  276. DWORD dwProperties = GU_ANYUSER,
  277. LPCNSTR pnszLocalGroup = NULL );
  278. HRESULT FreeUserList (
  279. ULONG cUser,
  280. LPUSERINFO aUserInfo );
  281. //+-------------------------------------------------------------------------
  282. //
  283. // Function: GetGroupList
  284. //
  285. // Synopsis: Get a list of group names from an ini file.
  286. //
  287. // Arguments: [pnszFile] -- Ini file name.
  288. // [pcGroup] -- Pointer to a variable which gives the number
  289. // of requested machines. GM_ALLGROUPS
  290. // means as many groups as possible.
  291. // When the function returns, the variable
  292. // contains the number of groups actually
  293. // returned.
  294. // [papnszGroup] -- Array of returned machine names.
  295. // The caller should release memory using
  296. // FreeGroupList.
  297. // Returns: S_OK or An error code.
  298. //
  299. // History: 05-Aug-96 GigelA Created
  300. //
  301. // Notes: The ini file should be in the %SystemRoot% directory and its
  302. // contents should look like:
  303. // [groups]
  304. // group1=
  305. // group2=
  306. //
  307. // [group1]
  308. // ctuser=
  309. //
  310. // [group2]
  311. // ctadmin=
  312. //
  313. //--------------------------------------------------------------------------
  314. HRESULT GetGroupList(
  315. LPCNSTR pnszFile,
  316. ULONG *pcMach,
  317. LPNSTR **papnszMach);
  318. VOID FreeGroupList(
  319. ULONG cGroup,
  320. LPNSTR* apnszGroup);
  321. HRESULT GetDNSNameCt(
  322. LPCNSTR pnszMachName,
  323. DWORD dwForm,
  324. DG_INTEGER *pdgint,
  325. LPNSTR *ppnszDNSName);
  326. class CMachData {
  327. public:
  328. LPNSTR pwszMachName; // The mach name as is in ctdata.ini
  329. LPNSTR pwszMachAddr; // UNC/DNS short/long munged name
  330. DWORD dwOS; // OS type
  331. LPNSTR pwszLoginUser; // logged on user
  332. DWORD dwProtocols; // bitmask of supported protocols.
  333. DWORD dwArch;
  334. CMachData();
  335. CMachData(LPNSTR pnszMachNameVal,
  336. LPNSTR pnszMachAddrVal = NULL,
  337. DWORD dwOSVal = GM_NONE,
  338. LPNSTR pnszLoginUserVal = NULL,
  339. DWORD dwProtocolsVal = GM_PROTO_ANY,
  340. DWORD dwArchVal = PROCESSOR_ARCHITECTURE_UNKNOWN);
  341. ~CMachData();
  342. HRESULT GetMachAttributes(LPNSTR pnszIniFile);
  343. BOOL IsValid();
  344. };
  345. class CMachineList {
  346. protected:
  347. BOOL m_bHaveList; // Have already read a list
  348. DWORD m_dwMachCount; // Number of machines in array
  349. CMachData *m_aMachines; // Array of machines
  350. DWORD m_dwFiltCount; // Count of filter matches
  351. CMachData **m_ppMachArray; // Array of filtered machines
  352. DWORD m_dwFiltOSandProto; // Find mach with this OS and Proto
  353. LPNSTR m_pnszFiltLoginUser; // Find mach. w/this login user
  354. DWORD m_dwFiltDisk; // Find machine with this drive format
  355. BOOL m_bLocalIncluded; // Include local machine in list
  356. DG_INTEGER *m_pdgInt; // Random number data generator
  357. DWORD m_dwForm; // Output Format
  358. NCHAR m_pnszFile[MAX_PATH]; // Ini file name
  359. DWORD m_dwFiltArch;
  360. protected:
  361. HRESULT SetFilter(DWORD dwFiltOSandProto,
  362. LPNSTR pnszFiltLoginUser,
  363. DWORD dwFiltDisk,
  364. DWORD dwFiltArch );
  365. BOOL IsQualified(CMachData *pMach);
  366. public:
  367. CMachineList(BOOL bLocalInc = FALSE,
  368. DG_INTEGER *pdgInt = NULL,
  369. LPNSTR pnszFile = NULL,
  370. DWORD dwForm = GM_SHORT_UNC);
  371. ~CMachineList();
  372. HRESULT FilterList(DWORD dwFiltOSandProto,
  373. LPNSTR pnszFiltLoginUser = NULL,
  374. DWORD dwFiltDisk = 0,
  375. DWORD dwFIltArch = PROCESSOR_ARCHITECTURE_UNKNOWN );
  376. HRESULT Randomize();
  377. HRESULT GetAt(CMachData **ppMach, DWORD idx);
  378. DWORD GetCount() { return m_dwFiltCount; }
  379. CMachData & operator[] (DWORD idx);
  380. };
  381. HRESULT GetMachInfo( DWORD* pdwOS,
  382. DWORD* pdwArch,
  383. DWORD* pdwOSBuild,
  384. DWORD* pdwOLEBuild,
  385. DWORD* pdwIEBuild,
  386. LPWSTR pwszSPBuild,
  387. DWORD cchSPBuildSize );
  388. #endif // __GETMACH_HXX__