]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] gh-92007: Handle elevation errors in NTEventLogHandler more grace… (GH-96322...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 27 Aug 2022 11:37:55 +0000 (04:37 -0700)
committerGitHub <noreply@github.com>
Sat, 27 Aug 2022 11:37:55 +0000 (12:37 +0100)
Lib/logging/handlers.py

index 32c04202c5aaa36d88fa43194d86157058c7f23c..f0fdedae5ebb5cf5061ad7f9ca57a87c1dfd9a9f 100644 (file)
@@ -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,