[Python-checkins] [3.11] gh-92007: Handle elevation errors in NTEventLogHandler more grace… (GH-96322) (GH-96337)

vsajip webhook-mailer at python.org
Sat Aug 27 08:08:24 EDT 2022


https://github.com/python/cpython/commit/b7ea2b8358b2f50e1aad502bab29783bb40ed4d9
commit: b7ea2b8358b2f50e1aad502bab29783bb40ed4d9
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022-08-27T13:08:14+01:00
summary:

[3.11] gh-92007: Handle elevation errors in NTEventLogHandler more grace… (GH-96322) (GH-96337)

files:
M Lib/logging/handlers.py

diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 2bcab657ba4e..c6853e0513e0 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1111,7 +1111,16 @@ def __init__(self, appname, dllname=None, logtype="Application"):
                 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,



More information about the Python-checkins mailing list