Skip to contentSkip to conversation

qga-win: fall back to hardcoded user and group names if LookupAccountSidW failed

PATCH In review Chen Hanxiao 3 participants 10 messages Sep 29, 2017 – Nov 3, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qga-win: fall back to hardcoded user and group names if LookupAccountSidW failed

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
qga/vss-win32/install.cpp +8 -2
index ba7c94eb25..dcf6299af9 100644
@@ -312,7 +312,10 @@ STDAPI COMRegister(void)
 
     /* Setup roles of the applicaion */
 
-    chk(getNameByStringSID(administratorsGroupSID, buffer, &bufferLen));
+    hr = getNameByStringSID(administratorsGroupSID, buffer, &bufferLen);
+    if (FAILED(hr)) {
+        wsprintfW(buffer, L"%ls", L"Administrators");
+    }
     chk(pApps->GetCollection(_bstr_t(L"Roles"), key,
                              (IDispatch **)pRoles.replace()));
     chk(pRoles->Populate());
@@ -333,7 +336,10 @@ STDAPI COMRegister(void)
     chk(put_Value(pObj, L"User", _bstr_t(".\\") + name));
 
     bufferLen = BUFFER_SIZE;
-    chk(getNameByStringSID(systemUserSID, buffer, &bufferLen));
+    hr = getNameByStringSID(systemUserSID, buffer, &bufferLen);
+    if (FAILED(hr)) {
+        wsprintfW(buffer, L"%ls", L"SYSTEM");
+    }
     chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
     chk(put_Value(pObj, L"User", buffer));
     chk(pUsersInRole->SaveChanges(&n));
Signature · 1 line
2.13.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Fri, 29 Sep 2017 17:11:22 +0800 Chen Hanxiao <[email protected]> wrote:

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

Quoted 8 lines

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

I wonder if it's caused by qga itself or a race/conflict with some other app. But still...

Signature · 1 line
Tomáš Golembiovský <[email protected]>
#2 lore raw

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 22 lines
Quoted 10 lines · On Fri, 29 Sep 2017 17:11:22 +0800 Chen Hanxiao <[email protected]> wrote:

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

Quoted 8 lines

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 5 lines

I wonder if it's caused by qga itself or a race/conflict with some other app. But still...

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

Does this fix the issue?

qga/vss-win32/install.cpp +4 -3
index ba7c94eb25..94c921e8de 100644
@@ -149,9 +149,10 @@ static HRESULT getNameByStringSID(
     wchar_t domainName[BUFFER_SIZE];
 
     chk(ConvertStringSidToSidW(sid, &psid));
-    LookupAccountSidW(NULL, psid, buffer, bufferLen,
-                domainName, &domainNameLen, &groupType);
-    hr = HRESULT_FROM_WIN32(GetLastError());
+    if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+                           domainName, &domainNameLen, &groupType)) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+    }
 
     LocalFree(psid);
 
Quoted 5 lines
Signature · 2 lines
-- 
Tomáš Golembiovský <[email protected]>
#3 lore raw
Quoted 27 lines · Michael Roth

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 26 lines
Quoted 10 lines · On Fri, 29 Sep 2017 17:11:22 +0800 Chen Hanxiao <[email protected]> wrote:

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

Quoted 8 lines

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

I wonder if it's caused by qga itself or a race/conflict with some other app. But still...

Quoted 6 lines
Quoted 1 line

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

Does this fix the issue?

Not exactly.
I tested your patch several times, it improved greatly. But failed only one time,
got another error 1722.

Build with my fallback patch and your suggestion,
installation work perfectly.

Regards,
- Chen

Quoted 25 lines
qga/vss-win32/install.cpp +4 -3
index ba7c94eb25..94c921e8de 100644
@@ -149,9 +149,10 @@ static HRESULT getNameByStringSID(
    wchar_t domainName[BUFFER_SIZE];
 
    chk(ConvertStringSidToSidW(sid, &psid));
-    LookupAccountSidW(NULL, psid, buffer, bufferLen,
-                domainName, &domainNameLen, &groupType);
-    hr = HRESULT_FROM_WIN32(GetLastError());
+    if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+                           domainName, &domainNameLen, &groupType)) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+    }
 
    LocalFree(psid);
 
Quoted 5 lines
Signature · 2 lines
-- 
Tomáš Golembiovský <[email protected]>
#4 lore raw

Quoting Chen Hanxiao (2017-10-26 04:27:40)

Quoted 35 lines
Quoted 32 lines · Michael Roth

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 22 lines
Quoted 10 lines · On Fri, 29 Sep 2017 17:11:22 +0800 Chen Hanxiao <[email protected]> wrote:

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

Quoted 8 lines

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 5 lines

I wonder if it's caused by qga itself or a race/conflict with some other app. But still...

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

Quoted 6 lines
Quoted 1 line

Does this fix the issue?

Not exactly.
I tested your patch several times, it improved greatly. But failed only one time,
got another error 1722.

Hmm, was that error also from the getNameByStringSID() call?

Quoted 3 lines

Build with my fallback patch and your suggestion,
installation work perfectly.

Thanks for testing.

Quoted 29 lines

Regards,
- Chen

Quoted 25 lines
qga/vss-win32/install.cpp +4 -3
index ba7c94eb25..94c921e8de 100644
@@ -149,9 +149,10 @@ static HRESULT getNameByStringSID(
    wchar_t domainName[BUFFER_SIZE];
 
    chk(ConvertStringSidToSidW(sid, &psid));
-    LookupAccountSidW(NULL, psid, buffer, bufferLen,
-                domainName, &domainNameLen, &groupType);
-    hr = HRESULT_FROM_WIN32(GetLastError());
+    if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+                           domainName, &domainNameLen, &groupType)) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+    }
 
    LocalFree(psid);
 
Quoted 5 lines
Signature · 2 lines
-- 
Tomáš Golembiovský <[email protected]>
#5 lore raw
Quoted 36 lines · Michael Roth

Quoting Chen Hanxiao (2017-10-26 04:27:40)

Quoted 35 lines
Quoted 32 lines · Michael Roth

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 22 lines
Quoted 10 lines · On Fri, 29 Sep 2017 17:11:22 +0800 Chen Hanxiao <[email protected]> wrote:

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

Quoted 8 lines

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 5 lines

I wonder if it's caused by qga itself or a race/conflict with some other app. But still...

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Does this fix the issue?

Not exactly.
I tested your patch several times, it improved greatly. But failed only one time,
got another error 1722.

Hmm, was that error also from the getNameByStringSID() call?

I don't know how to trace qemu-ga-win,
but added some fprintf(stdout).

+ hr = getNameByStringSID(administratorsGroupSID, buffer, &bufferLen);
+ if (FAILED(hr)) {

I saw my logs inside if (FAILED(hr)) {

But it looks weird, as your patch already dealing with this senario.

Regards,
- Chen

Quoted 8 lines
Quoted 4 lines

Build with my fallback patch and your suggestion,
installation work perfectly.

Thanks for testing.

Quoted 1 line
#6 lore raw
In reply to Michael Roth
Quoted 23 lines · On Wed, 25 Oct 2017 16:58:07 -0500 Michael Roth <[email protected]>…

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 22 lines
Quoted 18 lines · On Fri, 29 Sep 2017 17:11:22 +0800 Chen Hanxiao <[email protected]> wrote:

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 9 lines
Quoted 5 lines

I wonder if it's caused by qga itself or a race/conflict with some other app. But still...

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

I suppose you're right! Taking a closer look there's one more issue with getNameByStringSID(). The call ConvertStringSidToSidW() does not return HRESULT so using chk() makes no sense.

I propose slightly modified version of your fix:

qga/vss-win32/install.cpp +9 -4
index ba7c94eb25..65f68f94a3 100644
@@ -148,10 +148,15 @@ static HRESULT getNameByStringSID(
     DWORD domainNameLen = BUFFER_SIZE;
     wchar_t domainName[BUFFER_SIZE];
 
-    chk(ConvertStringSidToSidW(sid, &psid));
-    LookupAccountSidW(NULL, psid, buffer, bufferLen,
-                domainName, &domainNameLen, &groupType);
-    hr = HRESULT_FROM_WIN32(GetLastError());
+    if (!ConvertStringSidToSidW(sid, &psid) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        goto out;
+    }
+    if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+                           domainName, &domainNameLen, &groupType)) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        /* Fall through and free psid */
+    }
 
     LocalFree(psid);
 
Signature · 1 line
Tomáš Golembiovský <[email protected]>
#7 lore raw

Quoting Tomáš Golembiovský (2017-10-26 08:54:37)

Quoted 55 lines
Quoted 23 lines · On Wed, 25 Oct 2017 16:58:07 -0500 Michael Roth <[email protected]>…

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 22 lines
Quoted 18 lines · On Fri, 29 Sep 2017 17:11:22 +0800 Chen Hanxiao <[email protected]> wrote:

From: Chen Hanxiao <[email protected]>

On some of windows (win08 sp2),
it doesn't work by calling LookupAccountSidW with well-known SIDs,
We got an error:
error 997 overlapped I/O operation is in progress

But hardcoded names work.

This patch introduces a workaroud for this issue:
if LookupAccountSidW failed, try hardcoded one.

---
 qga/vss-win32/install.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 9 lines
Quoted 5 lines

I wonder if it's caused by qga itself or a race/conflict with some other app. But still...

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

I suppose you're right! Taking a closer look there's one more issue with getNameByStringSID(). The call ConvertStringSidToSidW() does not return HRESULT so using chk() makes no sense.

I propose slightly modified version of your fix:

qga/vss-win32/install.cpp +1 -4
index ba7c94eb25..65f68f94a3 100644
@@ -148,10 +148,15 @@ static HRESULT getNameByStringSID(
     DWORD domainNameLen = BUFFER_SIZE;
     wchar_t domainName[BUFFER_SIZE];
 
-    chk(ConvertStringSidToSidW(sid, &psid));
-    LookupAccountSidW(NULL, psid, buffer, bufferLen,
-                domainName, &domainNameLen, &groupType);
-    hr = HRESULT_FROM_WIN32(GetLastError());
+    if (!ConvertStringSidToSidW(sid, &psid) {

qga/vss-win32/install.cpp static HRESULT getNameByStringSID( · line 161

Quoted 10 lines
qga/vss-win32/install.cpp +8 -0
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        goto out;
+    }
+    if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+                           domainName, &domainNameLen, &groupType)) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        /* Fall through and free psid */
+    }
 
     LocalFree(psid);

Thanks! It's not yet clear if this fixes the issue completely (though it seems likely), but it's clearly a bug either way so I've gone ahead and applied it to the qga tree:

https://github.com/mdroth/qemu/commit/8cedc80555e5a395a4fda7130b0115015e775c48

Chen, if there's still an issue with the updated patch please let me know.

Quoted 5 lines
qga/vss-win32/install.cpp +0 -1
-- 

Tomáš Golembiovský <[email protected]>

#8 lore raw
Quoted 49 lines · Michael Roth

Quoting Tomáš Golembiovský (2017-10-26 08:54:37)

Quoted 32 lines
Quoted 9 lines · On Wed, 25 Oct 2017 16:58:07 -0500 Michael Roth <[email protected]>…

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 4 lines

On Fri, 29 Sep 2017 17:11:22 +0800
Chen Hanxiao <[email protected]> wrote:

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

I suppose you're right! Taking a closer look there's one more issue with getNameByStringSID(). The call ConvertStringSidToSidW() does not return HRESULT so using chk() makes no sense.

I propose slightly modified version of your fix:

qga/vss-win32/install.cpp +1 -4
index ba7c94eb25..65f68f94a3 100644
@@ -148,10 +148,15 @@ static HRESULT getNameByStringSID(
     DWORD domainNameLen = BUFFER_SIZE;
     wchar_t domainName[BUFFER_SIZE];
 
-    chk(ConvertStringSidToSidW(sid, &psid));
-    LookupAccountSidW(NULL, psid, buffer, bufferLen,
-                domainName, &domainNameLen, &groupType);
-    hr = HRESULT_FROM_WIN32(GetLastError());
+    if (!ConvertStringSidToSidW(sid, &psid) {

qga/vss-win32/install.cpp static HRESULT getNameByStringSID( · line 161

Quoted 10 lines
qga/vss-win32/install.cpp +8 -0
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        goto out;
+    }
+    if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+                           domainName, &domainNameLen, &groupType)) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        /* Fall through and free psid */
+    }
 
     LocalFree(psid);

Thanks! It's not yet clear if this fixes the issue completely (though it seems likely), but it's clearly a bug either way so I've gone ahead and applied it to the qga tree:

Quoted 3 lines

https://github.com/mdroth/qemu/commit/8cedc80555e5a395a4fda7130b0115015e775c48

Chen, if there's still an issue with the updated patch please let me know.

Sorry for the late reply.

I tested the upstream qga-win on that windows VM for several times. It works fine by my limit tests.

Regards,
- Chen

Quoted 7 lines
Quoted 6 lines
qga/vss-win32/install.cpp +0 -1
-- 

Tomáš Golembiovský <[email protected]>

#9 lore raw
Quoted 50 lines · On Thu, 2 Nov 2017 18:58:49 +0800 (CST) "Chen Hanxiao" <[email protected]>…
Quoted 49 lines · Michael Roth

Quoting Tomáš Golembiovský (2017-10-26 08:54:37)

Quoted 32 lines
Quoted 9 lines · On Wed, 25 Oct 2017 16:58:07 -0500 Michael Roth <[email protected]>…

Quoting Tomáš Golembiovský (2017-09-29 16:31:02)

Quoted 4 lines

On Fri, 29 Sep 2017 17:11:22 +0800
Chen Hanxiao <[email protected]> wrote:

I think it might be getNameByStringSID()/LookupAccountSidW() reporting a stale GetLastError() value.

I suppose you're right! Taking a closer look there's one more issue with getNameByStringSID(). The call ConvertStringSidToSidW() does not return HRESULT so using chk() makes no sense.

I propose slightly modified version of your fix:

qga/vss-win32/install.cpp +1 -4
index ba7c94eb25..65f68f94a3 100644
@@ -148,10 +148,15 @@ static HRESULT getNameByStringSID(
     DWORD domainNameLen = BUFFER_SIZE;
     wchar_t domainName[BUFFER_SIZE];
 
-    chk(ConvertStringSidToSidW(sid, &psid));
-    LookupAccountSidW(NULL, psid, buffer, bufferLen,
-                domainName, &domainNameLen, &groupType);
-    hr = HRESULT_FROM_WIN32(GetLastError());
+    if (!ConvertStringSidToSidW(sid, &psid) {

qga/vss-win32/install.cpp static HRESULT getNameByStringSID( · line 161

Quoted 10 lines
qga/vss-win32/install.cpp +8 -0
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        goto out;
+    }
+    if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+                           domainName, &domainNameLen, &groupType)) {
+        hr = HRESULT_FROM_WIN32(GetLastError());
+        /* Fall through and free psid */
+    }
 
     LocalFree(psid);  

Thanks! It's not yet clear if this fixes the issue completely (though it seems likely), but it's clearly a bug either way so I've gone ahead and applied it to the qga tree:

Quoted 9 lines
Quoted 3 lines

https://github.com/mdroth/qemu/commit/8cedc80555e5a395a4fda7130b0115015e775c48

Chen, if there's still an issue with the updated patch please let me know.

Sorry for the late reply.

I tested the upstream qga-win on that windows VM for several times. It works fine by my limit tests.

I'm glad to hear that.

Tomas

Quoted 12 lines

Regards,
- Chen

Quoted 7 lines
Quoted 6 lines
qga/vss-win32/install.cpp +0 -1
-- 

Tomáš Golembiovský <[email protected]>

Signature · 1 line
Tomáš Golembiovský <[email protected]>