-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change to JackTools::GetUID() on Windows that fixes metadata #991
base: develop
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things should be fixed. For completeness' sake here's my suggestion:
int JackTools::GetUID()
{
#ifdef WIN32
int id = 0;
HANDLE tokenHandle = nullptr;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle)) {
TOKEN_STATISTICS tokenStats{};
DWORD len = sizeof tokenStats;
if (GetTokenInformation(tokenHandle, TokenStatistics,
&tokenStats, sizeof tokenStats, &len)) {
id = static_cast<int>(tokenStats.AuthenticationId.LowPart);
}
CloseHandle(tokenHandle);
}
return id;
#else
return geteuid();
#endif
}
} | ||
|
||
TOKEN_STATISTICS tokenStats; | ||
DWORD returnLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize tokenStats
and returnLength
:
TOKEN_STATISTICS tokenStats{};
DWORD returnLength = sizeof tokenStats;
TOKEN_STATISTICS tokenStats; | ||
DWORD returnLength; | ||
if (!GetTokenInformation(tokenHandle, TokenStatistics, &tokenStats, sizeof(tokenStats), &returnLength)) { | ||
CloseHandle(tokenHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're only closing the handle if GetTokenInformation()
succeeds, it should be closed every time.
return 0; | ||
} | ||
|
||
return(tokenStats.AuthenticationId.LowPart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: return
is not a function call, don't make it look like one.
Change to JackTools::GetUID() on Windows that fixes metadata 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 and metadata now works correctly.