andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0009-Issue-49157-ds-logpipe.py-crashes-for-non-existing-u.patch

74ca47
From e33f58d5a9984fd5d5533425fb420d05e6484d7f Mon Sep 17 00:00:00 2001
74ca47
From: Mark Reynolds <mreynolds@redhat.com>
74ca47
Date: Mon, 20 Mar 2017 15:29:48 -0400
74ca47
Subject: [PATCH] Issue 49157 - ds-logpipe.py crashes for non-existing users
74ca47
74ca47
Description:  Added try/except's for various OS function calls, as the tool
74ca47
              should gracefully exit when there is a problem and not crash
74ca47
74ca47
https://pagure.io/389-ds-base/issue/49157
74ca47
74ca47
Reviewed by: firstyear(Thanks!)
74ca47
---
74ca47
 ldap/admin/src/scripts/ds-logpipe.py | 25 ++++++++++++++++++-------
74ca47
 1 file changed, 18 insertions(+), 7 deletions(-)
74ca47
74ca47
diff --git a/ldap/admin/src/scripts/ds-logpipe.py b/ldap/admin/src/scripts/ds-logpipe.py
74ca47
index 4ba4d1b..dc1856a 100644
74ca47
--- a/ldap/admin/src/scripts/ds-logpipe.py
74ca47
+++ b/ldap/admin/src/scripts/ds-logpipe.py
74ca47
@@ -262,7 +262,8 @@ def parse_options():
74ca47
 
74ca47
 options, logfname = parse_options()
74ca47
 
74ca47
-if options.debug: debug = True
74ca47
+if options.debug:
74ca47
+    debug = True
74ca47
 
74ca47
 if len(plgfuncs) == 0:
74ca47
     plgfuncs.append(defaultplugin)
74ca47
@@ -270,9 +271,15 @@ if len(plgpostfuncs) == 0:
74ca47
     plgpostfuncs.append(defaultpost)
74ca47
 
74ca47
 if options.user:
74ca47
-    try: userid = int(options.user)
74ca47
-    except ValueError: # not a numeric userid - look it up
74ca47
-        userid = pwd.getpwnam(options.user)[2]
74ca47
+    try:
74ca47
+        userid = int(options.user)
74ca47
+    except ValueError:  # not a numeric userid - look it up
74ca47
+        try:
74ca47
+            userid = pwd.getpwnam(options.user)[2]
74ca47
+        except Exception as e:
74ca47
+            print("Failed to lookup name (%s) error: %s" %
74ca47
+                  (options.user, str(e)))
74ca47
+            sys.exit(1)
74ca47
     os.seteuid(userid)
74ca47
 
74ca47
 if options.scriptpidfile:
74ca47
@@ -298,8 +305,12 @@ except OSError as e:
74ca47
     if e.errno == errno.ENOENT:
74ca47
         if debug:
74ca47
             print("Creating log pipe", logfname)
74ca47
-        os.mkfifo(logfname)
74ca47
-        os.chmod(logfname, 0o600)
74ca47
+        try:
74ca47
+            os.mkfifo(logfname)
74ca47
+            os.chmod(logfname, 0o600)
74ca47
+        except Exception as e:
74ca47
+            print("Failed to create log pipe: " + str(e))
74ca47
+            sys.exit(1)
74ca47
     else:
74ca47
         raise Exception("%s [%d]" % (e.strerror, e.errno))
74ca47
 
74ca47
@@ -393,7 +404,7 @@ while not done:
74ca47
         else: # we read something
74ca47
             # pipe closed - usually when server shuts down
74ca47
             done = True
74ca47
-            
74ca47
+
74ca47
     if not done and debug:
74ca47
         print("log pipe", logfname, "closed - reopening - read", totallines, "total lines")
74ca47
 
74ca47
-- 
74ca47
2.9.3
74ca47