From: Sven Dietricht Date: Sun, 19 Nov 2000 09:02:12 +0000 (-0000) Subject: nt_clockstuff.c: X-Git-Tag: NTP_4_0_99_M~151 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd35bf8914d330dbf7a135116ea365184d481668;p=thirdparty%2Fntp.git nt_clockstuff.c: From: Ron Thornton [rthornto@pictel.com] Sent: Thu 11/16/00 8:51 AM On Windows 2000 it requires a privilege on the current process token that is disabled by default on Windows 2000. I set the token by adding the following code at the beginning of the init_winnt_time() function in nt_clockstuff.c. bk: 3a179714pLLqsGs5A68hxtyPOJFv7Q --- diff --git a/ports/winnt/ntpd/nt_clockstuff.c b/ports/winnt/ntpd/nt_clockstuff.c index ee71175981..2982b9d9e7 100644 --- a/ports/winnt/ntpd/nt_clockstuff.c +++ b/ports/winnt/ntpd/nt_clockstuff.c @@ -3,6 +3,15 @@ * * Revision History: * $Log$ + * Revision 1.9 2000/11/19 09:02:12 dietrich + * From: Ron Thornton [rthornto@pictel.com] + * Sent: Thu 11/16/00 8:51 AM + * On Windows 2000 it requires a privilege on the current process token + * that is disabled by default on Windows 2000. + * + * I set the token by adding the following code at the beginning of the + * init_winnt_time() function in nt_clockstuff.c. + * * Revision 1.8 2000/11/19 08:03:20 dietrich * From: "Colin Dancer" * To: @@ -133,12 +142,41 @@ adj_systime( void init_winnt_time(void) { BOOL noslew; - - /* Reset the Clock to a reasonable increment */ - if (!GetSystemTimeAdjustment(&initial_units_per_tick, &every, &noslew)) { + HANDLE hToken; + TOKEN_PRIVILEGES tkp; + /* + * Get privileges needed for fiddling with the clock + */ + + /* get the current process token handle */ + if (!OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { + msyslog(LOG_ERR, "OpenProcessToken failed: %m"); + exit(-1); + } + /* get the LUID for system-time privilege. */ + LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid); + tkp.PrivilegeCount = 1; /* one privilege to set */ + tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + + /* get set-time privilege for this process. */ + AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, + (PTOKEN_PRIVILEGES) NULL, 0); + + /* cannot use return value of AdjustTokenPrivileges. */ + /* (success does not indicate all privileges were set) */ + if (GetLastError() != ERROR_SUCCESS) + { + msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m"); + /* later set time call will probably fail */ + } + + /* Reset the Clock to a reasonable increment */ + if (!GetSystemTimeAdjustment(&initial_units_per_tick, &every,&noslew)) + { msyslog(LOG_ERR, "GetSystemTimeAdjustment failed: %m\n"); exit (-1); - } + } units_per_tick = initial_units_per_tick;