Skip to content

Commit

Permalink
Replace the 'W' function by auto select between ANSI or unicode funct…
Browse files Browse the repository at this point in the history
…ion for win api.
  • Loading branch information
herve-er committed Apr 24, 2024
1 parent 60be97d commit a0bb606
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libcommonserver/utility/utility_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ static bool initTrusteeWithUserSID() {
// Get user name
DWORD userNameSize = 0;
WCHAR *szUserName = NULL;
GetUserNameExW(NameSamCompatible, szUserName, &userNameSize);
GetUserNameEx(NameSamCompatible, szUserName, &userNameSize);
WORD dwError = GetLastError();
if (dwError == ERROR_MORE_DATA) {
// Normal case as szUserName is NULL
szUserName = (WCHAR *)malloc(userNameSize * sizeof(WCHAR));
if (!GetUserNameExW(NameSamCompatible, szUserName, &userNameSize)) {
if (!GetUserNameEx(NameSamCompatible, szUserName, &userNameSize)) {
dwError = GetLastError();
LOGW_WARN(Log::instance()->getLogger(), "Error in GetUserNameExW - err=" << dwError);
free(szUserName);
Expand All @@ -80,7 +80,7 @@ static bool initTrusteeWithUserSID() {
DWORD sidsize = 0;
DWORD dlen = 0;
SID_NAME_USE stype;
if (!LookupAccountNameW(NULL, szUserName, Utility::_psid, &sidsize, NULL, &dlen, &stype)) {
if (!LookupAccountName(NULL, szUserName, Utility::_psid, &sidsize, NULL, &dlen, &stype)) {
dwError = GetLastError();
if (dwError == ERROR_INSUFFICIENT_BUFFER) {
// Normal case as Utility::_psid is NULL
Expand Down Expand Up @@ -114,7 +114,7 @@ static bool initTrusteeWithUserSID() {
return false;
}

if (!LookupAccountNameW(NULL, szUserName, Utility::_psid, &sidsize, pdomain, &dlen, &stype)) {
if (!LookupAccountName(NULL, szUserName, Utility::_psid, &sidsize, pdomain, &dlen, &stype)) {
WORD dwError = GetLastError();
LOGW_WARN(Log::instance()->getLogger(), "Error in LookupAccountNameW 2 - err=" << dwError);
LocalFree(Utility::_psid);
Expand All @@ -131,7 +131,7 @@ static bool initTrusteeWithUserSID() {
LocalFree(pdomain);

// Build trustee structure
BuildTrusteeWithSidW(&Utility::_trustee, Utility::_psid);
BuildTrusteeWithSid(&Utility::_trustee, Utility::_psid);

// NB: Don't free _psid as it is referenced in _trustee
std::cout << "TestIo::testCheckSetAndGetRights: trustee set" << std::endl;
Expand Down

0 comments on commit a0bb606

Please sign in to comment.