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

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