summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-08-27 04:37:55 -0700
committerGitHub <noreply@github.com>2022-08-27 12:37:55 +0100
commita2cf98449c8e176e8534eb961043f6eac918ce2b (patch)
treea07ddf9b0ad71a583a97a9f7e1430405a1057d28
parent91b6ca4e76f4d753780469054877e9eea7cf5e81 (diff)
downloadcpython-git-a2cf98449c8e176e8534eb961043f6eac918ce2b.tar.gz
[3.10] gh-92007: Handle elevation errors in NTEventLogHandler more grace… (GH-96322) (GH-96338)
-rw-r--r--Lib/logging/handlers.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 32c04202c5..f0fdedae5e 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1098,7 +1098,16 @@ class NTEventLogHandler(logging.Handler):
dllname = os.path.join(dllname[0], r'win32service.pyd')
self.dllname = dllname
self.logtype = logtype
- self._welu.AddSourceToRegistry(appname, dllname, logtype)
+ # Administrative privileges are required to add a source to the registry.
+ # This may not be available for a user that just wants to add to an
+ # existing source - handle this specific case.
+ try:
+ self._welu.AddSourceToRegistry(appname, dllname, logtype)
+ except Exception as e:
+ # This will probably be a pywintypes.error. Only raise if it's not
+ # an "access denied" error, else let it pass
+ if getattr(e, 'winerror', None) != 5: # not access denied
+ raise
self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
self.typemap = {
logging.DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,