aboutsummaryrefslogtreecommitdiff
path: root/rhodecode/lib
diff options
context:
space:
mode:
authorStevan Radaković <stevan.radakovic@linaro.org>2013-03-27 13:05:46 +0100
committerStevan Radaković <stevan.radakovic@linaro.org>2013-03-27 13:05:46 +0100
commite06e946525e259b9aa1a117344438b7f2c92eab5 (patch)
tree5dece603b9171f3127e24f8a7bf91906e8f291e6 /rhodecode/lib
parentf6e9d7be791b269967311ba281b5705361112669 (diff)
Introduce LDAP system based acl.
Diffstat (limited to 'rhodecode/lib')
-rw-r--r--rhodecode/lib/helpers.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py
index 2183ae69..0852f44a 100644
--- a/rhodecode/lib/helpers.py
+++ b/rhodecode/lib/helpers.py
@@ -1170,3 +1170,70 @@ def ip_range(ip_addr):
from rhodecode.model.db import UserIpMap
s, e = UserIpMap._get_ip_range(ip_addr)
return '%s - %s' % (s, e)
+
+
+class SystemCommand():
+
+ @classmethod
+ def execute(cls, cmd_args, with_sudo=True):
+ """Runs the command passed."""
+ if not isinstance(cmd_args, list):
+ cmd_args = list(cmd_args)
+ if with_sudo:
+ cmd_args.insert(0, "sudo")
+
+ with open(os.devnull, 'w') as tempf:
+ process = subprocess.Popen(cmd_args, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (stdout, stderr) = process.communicate()
+
+ if process.returncode != 0:
+ log.warn("Error executing command: '%s'. Reason: %s." %
+ (" ".join(cmd_args), stderr))
+ else:
+ log.debug("Sucess executing command %s. Output: %s" % (cmd_args,
+ stdout))
+
+ return stdout
+
+ @classmethod
+ def add_group(cls, groupname):
+ cmd_args = ["groupadd", groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def rename_group(cls, groupname, newgroupname):
+ cmd_args = ["groupmod", "-n", newgroupname, groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def delete_group(cls, groupname):
+ cmd_args = ["groupdel", groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def add_user(cls, username):
+ cmd_args = ["adduser", "--disabled-password", "--force-badname",
+ "--quiet", "--gecos", "''", username]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def add_user_to_group(cls, groupname, username):
+ cmd_args = ["gpasswd", "-a", username, groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def remove_user_from_group(cls, groupname, username):
+ cmd_args = ["gpasswd", "-d", username, groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def get_group_members(cls, groupname):
+ cmd_args = ["members", "--all", groupname]
+ try:
+ output = cls.execute(cmd_args)
+ users = set(output.split())
+ return users
+ except:
+ return {}
+