Beispiel #1
0
 def _create_user(self, user=None):
     if user is not None:
         call_args = []
         if self._has_rootcmd:
             call_args = get_callargs_rootcmd(call_args)
         if os.path.exists("/usr/sbin/useradd"):
             call_args.append("/usr/sbin/useradd")
             if 'username' in user:
                 call_args.append("-m")
                 call_args.append("--home")
                 call_args.append("/home/%s" % user["username"])
                 call_args.append("--shell")
                 call_args.append("/bin/bash")
                 if 'uid' in user and str(user["uid"]) != "-1":
                     call_args.append("-u")
                     call_args.append("%s" % user["uid"])
                 if 'gid' in user and str(user["gid"]) != "-1":
                     call_args.append("-g")
                     call_args.append("%s" % user["gid"])
                 if ('realname' in user and
                         user["realname"] != "" and
                         user["realname"] is not None):
                     call_args.append("-c")
                     call_args.append("%s" % user["realname"])
                 if ('cryptpw' in user and
                         user["cryptpw"] != "" and
                         user["cryptpw"] is not None):
                     call_args.append("-p")
                     call_args.append('%s' % user["cryptpw"])
                 call_args.append('%s' % user["username"])
                 subprocess.call(call_args)
                 if 'is_admin' in user and user["is_admin"] == "1":
                     admingroups =\
                         self._proxy.dc2.configuration.systemgroups.list(
                             {"is_admin_group": "1"})
                     if len(admingroups) > 0:
                         for i in admingroups:
                             call_args = []
                             if self._has_rootcmd:
                                 call_args = get_callargs_rootcmd(
                                     call_args)
                             call_args.append("/usr/sbin/adduser")
                             call_args.append(user["username"])
                             call_args.append(i["groupname"])
                             subprocess.call(call_args)
Beispiel #2
0
    def _check_user(self, user=None):
        if user is not None:
            call_args = []
            if self._has_rootcmd:
                call_args = get_callargs_rootcmd(call_args)

            call_args.append("id")
            if 'username' in user:
                call_args.append(user["username"])
            if subprocess.call(call_args) == 0:
                return True
            else:
                return False
        return None
Beispiel #3
0
 def _check_groupid(self, group=None):
     if group is not None:
         call_args = []
         if self._has_rootcmd:
             call_args = get_callargs_rootcmd(call_args)
         call_args.append("/usr/bin/getent")
         call_args.append("group")
         if "gid" in group:
             call_args.append(group["gid"])
             return_code = subprocess.call(call_args, stdout=None)
             if return_code > 0:
                 return True
             else:
                 return False
     return None
Beispiel #4
0
 def _change_user_password(self, user=None):
     if user is not None:
         call_args = []
         if self._has_rootcmd:
             call_args = get_callargs_rootcmd(call_args)
         if os.path.exists("/usr/sbin/usermod"):
             call_args.append("/usr/sbin/usermod")
             if 'cryptpw' in user and 'username' in user:
                 call_args.append("-p")
                 call_args.append(user["cryptpw"])
                 call_args.append(user["username"])
                 if subprocess.call(call_args) == 0:
                     return True
                 else:
                     return False
     return None
Beispiel #5
0
 def create_all_groups(self):
     grouplist = self._proxy.dc2.configuration.systemgroups.list()
     if len(grouplist) > 0:
         for i in grouplist:
             if 'groupname' in i:
                 if self._check_groupname(i):
                     call_args = []
                     if self._has_rootcmd:
                         call_args = get_callargs_rootcmd(call_args)
                     call_args.append("/usr/sbin/addgroup")
                     if ('is_system_group' in i and
                             i["is_system_group"] == "1"):
                         call_args.append("--system")
                     if 'gid' in i and i["gid"] != "-1":
                         call_args.append("--gid")
                         call_args.append(i["gid"])
                     call_args.append(i["groupname"])
                     subprocess.call(call_args)