Source code of Windows XP (NT5)
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.

409 lines
18 KiB

  1. //--------------------------------------------------------------------
  2. // w32timep - interface
  3. //
  4. // Copyright (C) Microsoft Corporation, 2000
  5. //
  6. // Created by: Duncan Bryce (duncanb), 12-07-00
  7. //
  8. // Contains methods to configure or query the windows time service
  9. //
  10. #ifndef __W32TIMEP_H__
  11. #define __W32TIMEP_H__ 1
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. //-------------------------------------------------------------------------------------
  16. // Configurable / queryable properties for the windows time service:
  17. //
  18. #ifndef MIDL_PASS
  19. #define W32TIME_CONFIG_SPECIAL_POLL_INTERVAL 0
  20. #define W32TIME_CONFIG_MANUAL_PEER_LIST 1
  21. #endif // MIDL_PASS
  22. //-------------------------------------------------------------------------------------
  23. // W32TimeQueryConfig
  24. //
  25. // Queries configuration information for the windows time service. The semantics
  26. // of the parameters depend on which property is being query:
  27. //
  28. // dwProperty: W32TIME_CONFIG_SPECIAL_POLL_INTERVAL
  29. // pdwType: REG_DWORD
  30. // pbConfig: a DWORD-sized buffer, containing the special polling interval (in seconds).
  31. // The special polling interval can be specified as an alternative to
  32. // using the standard, automatically-computed polling intervals specified by
  33. // NTP. NOTE: The special polling interval applies only to microsoft time
  34. // providers.
  35. // pdwSize: sizeof(DWORD)
  36. //
  37. //
  38. // dwProperty: W32TIME_CONFIG_MANUAL_PEER_LIST
  39. // pdwType: REG_SZ
  40. // pbConfig: a space-delimited unicode string containing the list of time sources which the
  41. // microsoft time providers should sync from. Each is an IP address
  42. // or DNS name of an NTP server, optionally followed by a "flags" parameter.
  43. // For example:
  44. //
  45. // time.windows.com,0x3 gproxy,0x2 ntdsdc9
  46. //
  47. // The following flags are available:
  48. //
  49. // 0x1 -- use the special polling interval for this source, instead of the
  50. // standard NTP polling
  51. // 0x2 -- use this source only when no domain hierarchy sources are available
  52. //
  53. // pdwSize: sizeof(WCHAR) * (wcslen(pbConfig) + 1)
  54. //
  55. #ifndef MIDL_PASS
  56. HRESULT W32TimeQueryConfig(IN DWORD dwProperty,
  57. OUT DWORD *pdwType,
  58. IN OUT BYTE *pbConfig,
  59. IN OUT DWORD *pdwSize);
  60. #endif // MIDL_PASS
  61. //-------------------------------------------------------------------------------------
  62. // W32TimeSetConfig
  63. //
  64. // Sets configuration information for the windows time service. The semantics
  65. // of the parameters depend on which property is being query. For a description
  66. // of the properties, see W32TimeQueryConfig().
  67. //
  68. #ifndef MIDL_PASS
  69. HRESULT W32TimeSetConfig(IN DWORD dwProperty,
  70. IN DWORD dwType,
  71. IN BYTE *pbConfig,
  72. IN DWORD dwSize);
  73. #endif // MIDL_PASS
  74. //-------------------------------------------------------------------------------------
  75. //
  76. // Client-side wrappers for the w32time RPC interface
  77. //
  78. //-------------------------------------------------------------------------------------
  79. #ifndef MIDL_PASS
  80. #define TimeSyncFlag_SoftResync 0x00
  81. #define TimeSyncFlag_HardResync 0x01
  82. #define TimeSyncFlag_ReturnResult 0x02
  83. #define TimeSyncFlag_Rediscover 0x04
  84. #define TimeSyncFlag_UpdateAndResync 0x08
  85. #define ResyncResult_Success 0x00
  86. #define ResyncResult_NoData 0x01
  87. #define ResyncResult_StaleData 0x02
  88. #define ResyncResult_Shutdown 0x03
  89. #define ResyncResult_ChangeTooBig 0x04
  90. #endif // MIDL_PASS
  91. //-------------------------------------------------------------------------------------
  92. // W32TimeSyncNow
  93. //
  94. // Sends an RPC request to the windows time service to attempt to synchronize time with
  95. // its configured time sources.
  96. //
  97. // wszServer: The name of the computer which should resync.
  98. // ulWaitFlag: if 0 is specified, the call will be asynchronous. Passing non-zero value
  99. // causes the call to block until time synchronization completes, or fails.
  100. // ulFlags: One of the resync types, or'd with any of the other flags.
  101. // NOTE: these flags are ignored by the Windows 2000 time service. Only
  102. // Windows XP and later servers will use them.
  103. //
  104. // Resync Types:
  105. //
  106. // TimeSyncFlag_SoftResync -- the time service will synchronize the computer clock with
  107. // whatever time samples it currently has available. It will
  108. // not poll the network, or hardware providers, for more data.
  109. // TimeSyncFlag_HardResync -- tells the time service that a time slip has occured.
  110. // causing the time service will discard its time data.
  111. // Microsoft default providers will attempt to acquire more
  112. // network samples, if possible.
  113. // TimeSyncFlag_Rediscover -- tells the time service that it needs to re-resolve its
  114. // network sources, and attempt to acquire network time data.
  115. //
  116. //
  117. // Flags:
  118. //
  119. // TimeSyncFlag_ReturnResult -- used only for asynchronous calls, causes the function
  120. // to return one of its possible return status codes, or an error.
  121. // See "Return Values".
  122. //
  123. // Return Values:
  124. //
  125. // ResyncResult_Success -- indicates that the time synchronization has succeeded. For asynchronous
  126. // calls, this does not guarantee that the server has acquired more data,
  127. // merely that the request has been successfully dispatched.
  128. // ResyncResult_NoData -- Windows XP and later. For synchronous requests, or when the
  129. // TimeSyncFlag_ReturnResult is set, indicates that the time service couldn't
  130. // synchronize time because it failed to acquire time data.
  131. // ResyncResult_StaleData -- Windows XP and later. For synchronous requests, or when the
  132. // TimeSyncFlag_ReturnResult is set, indicates that the time service couldn't
  133. // synchronize time because the data it received was stale (time stamped
  134. // as received earlier than the last good sample)
  135. // ResyncResult_Shutdown -- Windows XP and later. For synchronous requests, or when the
  136. // TimeSyncFlag_ReturnResult is set, indicates that the time service couldn't
  137. // synchronize because the service was shutting down
  138. // ResyncResult_ChangeTooBig -- Windows XP and later. For synchronous requests, or when the
  139. // TimeSyncFlag_ReturnResult is set, indicates that the time service couldn't
  140. // synchronize because it would've required a change larger than that allowed
  141. // by the w32time policy
  142. //
  143. // Otherwise, the function returns a standard windows error.
  144. //
  145. #ifndef MIDL_PASS
  146. DWORD W32TimeSyncNow(IN const WCHAR *wszServer,
  147. IN unsigned long ulWaitFlag,
  148. IN unsigned long ulFlags);
  149. #endif // MIDL_PASS
  150. //-------------------------------------------------------------------------------------
  151. // W32TimeGetNetlogonServiceBits
  152. //
  153. // Queries the specified time service to determine what it advertises itself as in the
  154. // DS.
  155. //
  156. // wszServer: The name of the computer which should resync.
  157. // pulBits: A set of flags indicating what the specified time service is
  158. // advertised as. Can be the OR of the following values:
  159. //
  160. // DS_TIMESERV_FLAG: if the service is advertising as a time service
  161. // DS_GOOD_TIMESERV_FLAG: if the service is advertising as a reliable time service
  162. //
  163. // Return Values:
  164. //
  165. // ERROR_SUCCESS if the call succeeds, otherwise, the function returns a standard
  166. // windows error.
  167. //
  168. #ifndef MIDL_PASS
  169. DWORD W32TimeGetNetlogonServiceBits(IN const WCHAR *wszServer,
  170. OUT unsigned long *pulBits);
  171. #endif // MIDL_PASS
  172. //--------------------------------------------------------------------------------
  173. //
  174. // NTP provider information structures
  175. //
  176. //--------------------------------------------------------------------------------
  177. //
  178. // W32TIME_NTP_PEER_INFO
  179. //
  180. // Represents the current state of a network provider's peer.
  181. //
  182. // Fields:
  183. //
  184. // ulSize -- sizeof(W32TIME_NTP_PEER_INFO), used for versioning
  185. // ulResolveAttempts -- the number of times the NTP provider has attempted to
  186. // resolve this peer unsuccessfully. Setting this
  187. // value to 0 indicates that the peer has been successfully
  188. // resolved.
  189. // u64TimeRemaining -- the number of 100ns intervals until the provider will
  190. // poll this peer again
  191. // u64LastSuccessfulSync -- the number of 100ns intervals since (0h 1-Jan 1601) (in UTC).
  192. // ulLastSyncError -- S_OK if the last sync with this peer was successful, otherwise,
  193. // the error that occured attempting to sync
  194. // ulLastSyncErrorMsgId -- the resource identifier of a string representing the last
  195. // error that occured syncing from this peer. 0 if there is no
  196. // string associated with this error. The strings are stored in
  197. // the DLL in which this provider is implemented.
  198. // ulValidDataCount -- the number of valid samples from this peer the provider
  199. // currently has in its clock filter
  200. // ulAuthTypeMsgId -- the resource identifier of a string representing the
  201. // authentication mechanism used by the NTP provider to
  202. // secure communications with this peer. 0 if none.
  203. // The strings are stored in the DLL in which this
  204. // provider is implemented.
  205. // wszUniqueName -- a name uniquely identifying this peer (usually the peers
  206. // dns name).
  207. // ulMode -- one of the NTP modes specified in the NTPv3 spec:
  208. //
  209. // +------------------+---+
  210. // | Reserved | 0 |
  211. // | SymmetricActive | 1 |
  212. // | SymmetricPassive | 2 |
  213. // | Client | 3 |
  214. // | Server | 4 |
  215. // | Broadcast | 5 |
  216. // | Control | 6 |
  217. // | PrivateUse | 7 |
  218. // +------------------+---+
  219. //
  220. // ulStratum -- this peer's stratum
  221. // ulreachability -- this peer's 1-byte reachability register. Each bit represents
  222. // whether or not a poll attempt returned valid data (set == success,
  223. // unset == failure). The low bit indicates the most recent sync,
  224. // the second bit represents the previous sync, etc. When this register
  225. // is 0, the peer is assumed to be unreachable.
  226. // ulPeerPollInterval -- the poll interval which this peer returned to the NTP provider (in log (base 2) seconds).
  227. // ulHostPollInterval -- the interval at which the NTP provider is polling this peer (in log (base 2) seconds).
  228. //
  229. typedef struct _W32TIME_NTP_PEER_INFO {
  230. unsigned __int32 ulSize;
  231. unsigned __int32 ulResolveAttempts;
  232. unsigned __int64 u64TimeRemaining;
  233. unsigned __int64 u64LastSuccessfulSync;
  234. unsigned __int32 ulLastSyncError;
  235. unsigned __int32 ulLastSyncErrorMsgId;
  236. unsigned __int32 ulValidDataCounter;
  237. unsigned __int32 ulAuthTypeMsgId;
  238. #ifdef MIDL_PASS
  239. [string, unique]
  240. wchar_t *wszUniqueName;
  241. #else // MIDL_PASS
  242. LPWSTR wszUniqueName;
  243. #endif // MIDL_PASS
  244. unsigned char ulMode;
  245. unsigned char ulStratum;
  246. unsigned char ulReachability;
  247. unsigned char ulPeerPollInterval;
  248. unsigned char ulHostPollInterval;
  249. } W32TIME_NTP_PEER_INFO, *PW32TIME_NTP_PEER_INFO;
  250. //
  251. // W32TIME_NTP_PROVIDER_DATA
  252. //
  253. // Represents the state of an NTP provider.
  254. //
  255. // ulSize -- sizeof(W32TIME_NTP_PROVIDER_DATA), used for versioning
  256. // ulError -- S_OK if the provider is functioning correctly,
  257. // otherwise, the error which caused it to fail.
  258. // ulErrorMsgId -- the resource identifier of a string representing the
  259. // error that caused this provider to fail.
  260. // cPeerInfo -- the number of active peers used by this provider
  261. // pPeerInfo -- an array of W32TIME_NTP_PEER_INFO structures, representing
  262. // the active peers this provider is currently synchronizing with
  263. //
  264. typedef struct _W32TIME_NTP_PROVIDER_DATA {
  265. unsigned __int32 ulSize;
  266. unsigned __int32 ulError;
  267. unsigned __int32 ulErrorMsgId;
  268. unsigned __int32 cPeerInfo;
  269. #ifdef MIDL_PASS
  270. [size_is(cPeerInfo)]
  271. #endif // MIDL_PASS
  272. W32TIME_NTP_PEER_INFO *pPeerInfo;
  273. } W32TIME_NTP_PROVIDER_DATA, *PW32TIME_NTP_PROVIDER_DATA;
  274. //--------------------------------------------------------------------------------
  275. //
  276. // HARDWARE provider structures
  277. //
  278. //--------------------------------------------------------------------------------
  279. // W32TIME_HARDWARE_PROVIDER_DATA
  280. //
  281. // Represents the state of a HARDWARE provider.
  282. //
  283. // ulSize -- sizeof(W32TIME_HARDWARE_PROVIDER_DATA), used for versioning
  284. // ulError -- S_OK if the provider is functioning correctly,
  285. // otherwise, the error which caused it to fail.
  286. // ulErrorMsgId -- the resource identifier of a string representing the
  287. // error that caused this provider to fail.
  288. // wszReferenceIdentifier -- the synchronization source (usually, the provider's
  289. // suggested 4-byte reference ID).
  290. //
  291. typedef struct _W32TIME_HARDWARE_PROVIDER_DATA {
  292. unsigned __int32 ulSize;
  293. unsigned __int32 ulError;
  294. unsigned __int32 ulErrorMsgId;
  295. #ifdef MIDL_PASS
  296. [string, unique]
  297. wchar_t *wszReferenceIdentifier;
  298. #else // MIDL_PASS
  299. LPWSTR wszReferenceIdentifier;
  300. #endif // MIDL_PASS
  301. } W32TIME_HARDWARE_PROVIDER_DATA, *PW32TIME_HARDWARE_PROVIDER_DATA;
  302. //-------------------------------------------------------------------------------------
  303. // W32TimeQueryHardwareProviderStatus
  304. //
  305. // Queries the specified time service for information about one of its installed
  306. // time providers.
  307. //
  308. // wszServer: The name of the computer which should resync.
  309. // dwFlags: Reserved, must be 0.
  310. // pwszProvider: The name of the provider to query.
  311. // ppHardwareProviderData: A structure representing the current state of this hardware provider.
  312. // The returned buffer is allocated by the system, and should be
  313. // freed with W32TimeBufferFree().
  314. //
  315. // Return Values:
  316. //
  317. // ERROR_SUCCESS if the call succeeds, otherwise, the function returns a standard
  318. // windows error.
  319. //
  320. #ifndef MIDL_PASS
  321. DWORD W32TimeQueryHardwareProviderStatus(IN const WCHAR *wszServer,
  322. IN DWORD dwFlags,
  323. IN LPWSTR pwszProvider,
  324. OUT W32TIME_HARDWARE_PROVIDER_DATA **ppHardwareProviderData);
  325. #endif // MIDL_PASS
  326. //-------------------------------------------------------------------------------------
  327. // W32TimeQueryNTPProviderStatus
  328. //
  329. // Queries the specified time service for information about one of its installed
  330. // time providers.
  331. //
  332. // wszServer: The name of the computer which should resync.
  333. // dwFlags: Reserved, must be 0.
  334. // pwszProvider: The name of the provider to query.
  335. // ppNTPProviderData: A structure representing the current state of this hardware provider.
  336. // The returned buffer is allocated by the system, and should be
  337. // freed with W32TimeBufferFree().
  338. //
  339. // Return Values:
  340. //
  341. // ERROR_SUCCESS if the call succeeds, otherwise, the function returns a standard
  342. // windows error.
  343. //
  344. #ifndef MIDL_PASS
  345. DWORD W32TimeQueryNTPProviderStatus(IN LPCWSTR pwszServer,
  346. IN DWORD dwFlags,
  347. IN LPWSTR pwszProvider,
  348. OUT W32TIME_NTP_PROVIDER_DATA **ppNTPProviderData);
  349. #endif // MIDL_PASS
  350. //-------------------------------------------------------------------------------------
  351. // W32TimeBufferFree
  352. //
  353. // Frees a buffer allocated by the w32time client API.
  354. //
  355. // pvBuffer: the buffer to free.
  356. //
  357. #ifndef MIDL_PASS
  358. void W32TimeBufferFree(IN LPVOID pvBuffer);
  359. #endif // MIDL_PASS
  360. //
  361. //-------------------------------------------------------------------------------------
  362. //-------------------------------------------------------------------------------------
  363. //
  364. // W32Time named events.
  365. // These events are ACL'd such that LocalSystem has full access.
  366. //
  367. //-------------------------------------------------------------------------------------
  368. //
  369. // Signaling this event tells w32time that its time is off, causing the windows time
  370. // service to attempt resynchronization. This does not guarantee that the time service
  371. // will successfully adjust the system clock, or that resynchronization will occur
  372. // in a timely manner.
  373. //
  374. #define W32TIME_NAMED_EVENT_SYSTIME_NOT_CORRECT L"W32TIME_NAMED_EVENT_SYSTIME_NOT_CORRECT"
  375. #ifdef __cplusplus
  376. } // balance extern "C" {
  377. #endif
  378. #endif // #ifndef __W32TIMEP_H__