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

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