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

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