Skip to content

Commit

Permalink
fix #1875: username return ERROR_NONE_MAPPED
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 14, 2020
1 parent b6699b4 commit 6e288e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ XXXX-XX-XX

- 1866_: [Windows] process exe(), cmdline(), environ() may raise "invalid
access to memory location" on Python 3.9.
- 1874_: [Solaris] wrong swap output given when encrypted column is present
- 1874_: [Solaris] wrong swap output given when encrypted column is present.
- 1875_: [Windows] process username() may raise ERROR_NONE_MAPPED if the SID
has no corresponding account name. In this case AccessDenied is now raised.
- 1877_: [Windows] OpenProcess may fail with ERROR_SUCCESS. Turn it into
AccessDenied or NoSuchProcess depending on whether the PID is alive.
- 1886_: [macOS] EIO error may be raised on cmdline() and environment(). Now
Expand Down
13 changes: 13 additions & 0 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,19 @@ psutil_proc_username(PyObject *self, PyObject *args) {
free(domainName);
continue;
}
else if (GetLastError() == ERROR_NONE_MAPPED) {
// From MS doc:
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/
// nf-winbase-lookupaccountsida
// If the function cannot find an account name for the SID,
// GetLastError returns ERROR_NONE_MAPPED. This can occur if
// a network time-out prevents the function from finding the
// name. It also occurs for SIDs that have no corresponding
// account name, such as a logon SID that identifies a logon
// session.
AccessDenied("LookupAccountSidW -> ERROR_NONE_MAPPED");
goto error;
}
else {
PyErr_SetFromOSErrnoWithSyscall("LookupAccountSidW");
goto error;
Expand Down

0 comments on commit 6e288e0

Please sign in to comment.