Skip to content

Commit

Permalink
Change to JackTools::GetUID() on Windows that fixes metadata
Browse files Browse the repository at this point in the history
creating a new BDB on every API call.

JackTools::GetUID() would return the PID of the calling process.
(I think this was a stub because there is no Windows equivalent).
The linux version appears to return a linux UID. This patch does
something similar on Windows so as to create/open the same DB
on Windows.
  • Loading branch information
idconsultants committed Nov 3, 2024
1 parent 43e1173 commit b8d5799
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions common/JackTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,19 @@ namespace Jack {
int JackTools::GetUID()
{
#ifdef WIN32
return _getpid();
//#error "No getuid function available"
HANDLE tokenHandle = nullptr;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle)) {
return 0;
}

TOKEN_STATISTICS tokenStats;
DWORD returnLength;
if (!GetTokenInformation(tokenHandle, TokenStatistics, &tokenStats, sizeof(tokenStats), &returnLength)) {
CloseHandle(tokenHandle);
return 0;
}

return(tokenStats.AuthenticationId.LowPart);
#else
return geteuid();
#endif
Expand Down

0 comments on commit b8d5799

Please sign in to comment.