[Kimchi-devel] [PATCH] Forbid non-root users to start kimchi

Ramon Medeiros ramonn at linux.vnet.ibm.com
Tue Feb 18 12:58:11 UTC 2014


Only root users can use kimchi. If a non-root user tries to start, some
error messages to access data files and libvirt features will be
displayed.

Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
 src/kimchi/server.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/server.py b/src/kimchi/server.py
index 6dd0404..f48b2f8 100644
--- a/src/kimchi/server.py
+++ b/src/kimchi/server.py
@@ -38,7 +38,7 @@ from kimchi.control import sub_nodes
 from kimchi.root import KimchiRoot
 from kimchi.utils import get_enabled_plugins, import_class
 
-
+NOT_ROOT_USER = "You need root privileges to run this script.\nExiting."
 LOGGING_LEVEL = {"debug": logging.DEBUG,
                  "info": logging.INFO,
                  "warning": logging.WARNING,
@@ -269,7 +269,21 @@ class Server(object):
     def stop(self):
         cherrypy.engine.exit()
 
+def checkRootUser():
+    """
+    Checks if the running user is root
+
+    @rtype: None
+    @returns: Nothing
+    """
+    if os.geteuid() != 0:
+        exit(NOT_ROOT_USER)
 
 def main(options):
+    
+    # check if user is root
+    checkRootUser()
+
+    # user is root: start kimchi
     srv = Server(options)
     srv.start()
-- 
1.8.3.1




More information about the Kimchi-devel mailing list