- Timestamp:
- Apr 3, 2009 9:02:44 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp
r18634 r18673 116 116 static uint32_t g_TimeSyncMinAdjust = 1000; 117 117 #else 118 static uint32_t g_TimeSyncMinAdjust = 100; 118 #if RT_OS_WINDOWS 119 /** Process token. */ 120 static HANDLE g_hTokenProcess = NULL; 121 /* Old token privileges. */ 122 static TOKEN_PRIVILEGES g_tpOld; 123 static uint32_t g_TimeSyncMinAdjust = 100; 124 #else 125 static uint32_t g_TimeSyncMinAdjust = 100; 126 #endif 119 127 #endif 120 128 /** @see pg_vboxservice_timesync */ … … 125 133 /** The semaphore we're blocking on. */ 126 134 static RTSEMEVENTMULTI g_TimeSyncEvent = NIL_RTSEMEVENTMULTI; 127 128 135 129 136 /** @copydoc VBOXSERVICE::pfnPreInit */ … … 159 166 static DECLCALLBACK(int) VBoxServiceTimeSyncInit(void) 160 167 { 168 int rc = VINF_SUCCESS; 169 161 170 /* 162 171 * If not specified, find the right interval default. … … 168 177 g_TimeSyncInterval = 10 * 1000; 169 178 170 intrc = RTSemEventMultiCreate(&g_TimeSyncEvent);179 rc = RTSemEventMultiCreate(&g_TimeSyncEvent); 171 180 AssertRC(rc); 181 182 #if defined(RT_OS_WINDOWS) 183 /* Adjust priviledges of this process to adjust the time. */ 184 TOKEN_PRIVILEGES tp; /* Token provileges. */ 185 DWORD dwSize = sizeof (TOKEN_PRIVILEGES); 186 LUID luid = {0}; 187 188 if (!OpenProcessToken(GetCurrentProcess(), 189 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &g_hTokenProcess)) 190 { 191 VBoxServiceError("Opening process token (SE_SYSTEMTIME_NAME) failed with code %ld!\n", GetLastError()); 192 rc = VERR_PERMISSION_DENIED; 193 } 194 else 195 { 196 if(!::LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &luid)) 197 { 198 VBoxServiceError("Looking up token privileges (SE_SYSTEMTIME_NAME) failed with code %ld!\n", GetLastError()); 199 rc = VERR_PERMISSION_DENIED; 200 } 201 202 ZeroMemory (&tp, sizeof (tp)); 203 tp.PrivilegeCount = 1; 204 tp.Privileges[0].Luid = luid; 205 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 206 207 /* Adjust Token privileges. */ 208 if (!::AdjustTokenPrivileges(g_hTokenProcess, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), 209 &g_tpOld, &dwSize)) 210 { 211 VBoxServiceError("Adjusting token privileges (SE_SYSTEMTIME_NAME) failed with code %ld!\n", GetLastError()); 212 rc = VERR_PERMISSION_DENIED; 213 } 214 } 215 #else 216 /* Nothing to do here yet. */ 217 #endif 218 219 if (RT_FAILURE(rc)) 220 { 221 CloseHandle (g_hTokenProcess); 222 g_hTokenProcess = NULL; 223 } 224 172 225 return rc; 173 226 } … … 236 289 * *NIX systems have it. Fall back on settimeofday. 237 290 */ 238 #ifdef RT_OS_WINDOWS 291 #if defined(RT_OS_WINDOWS) 292 293 239 294 /* Just make sure it compiles for now, but later: 240 295 SetSystemTimeAdjustment and fall back on SetSystemTime. 241 296 */ 242 AssertFatalFailed();297 //AssertFatalFailed(); 243 298 #else 244 299 struct timeval tv; 245 # 300 #if !defined(RT_OS_OS2) /* PORTME */ 246 301 RTTimeSpecGetTimeval(&Drift, &tv); 247 302 if (adjtime(&tv, NULL) == 0) … … 252 307 } 253 308 else 254 # 309 #endif 255 310 { 256 311 errno = 0; … … 264 319 VBoxServiceVerbose(1, "settimeofday to %s\n", 265 320 RTTimeToString(RTTimeExplode(&Time, &Tmp), sz, sizeof(sz))); 266 # 321 #ifdef DEBUG 267 322 if (g_cVerbosity >= 3) 268 323 VBoxServiceVerbose(2, " new time %s\n", 269 324 RTTimeToString(RTTimeExplode(&Time, RTTimeNow(&Tmp)), sz, sizeof(sz))); 270 # 325 #endif 271 326 cErrors = 0; 272 327 } … … 320 375 static DECLCALLBACK(void) VBoxServiceTimeSyncTerm(void) 321 376 { 377 #if defined(RT_OS_WINDOWS) 378 /* Disable SE_SYSTEMTIME_NAME again. */ 379 DWORD dwSize = sizeof (TOKEN_PRIVILEGES); 380 if (g_hTokenProcess && !::AdjustTokenPrivileges(g_hTokenProcess, FALSE, &g_tpOld, dwSize, NULL, NULL)) 381 VBoxServiceError("Adjusting back token privileges (SE_SYSTEMTIME_NAME) failed with code %ld!\n", GetLastError()); 382 #endif 383 322 384 RTSemEventMultiDestroy(g_TimeSyncEvent); 323 385 g_TimeSyncEvent = NIL_RTSEMEVENTMULTI;
Note:
See TracChangeset
for help on using the changeset viewer.