def _update_webdev_user(self):
     passwd = PasswdFile()
     passwd.load()
     group = GroupFile()
     group.load()
     if "webdev" not in passwd:
         if "webdev" not in group:
             next_id = passwd.new_uid()
             while next_id in group:
                 next_id = passwd.new_uid(next_id)
             webdev = GroupEntry()
             webdev.group("webdev")
             webdev.crypt("*")
             webdev.gid(next_id)
             webdev.user_list((webdev.group(),))
             group[webdev.group()] = webdev
             group.save()
         gid = group["webdev"].gid()
         uid = passwd.new_uid(gid-1)
         while uid in passwd:
             uid = passwd.new_uid(uid)
         webdev = PasswdEntry()
         webdev.user(user="******", validate=False)
         webdev.crypt(_crypted_password("webdev", "webdev"))
         webdev.uid(uid)
         webdev.gid(gid)
         webdev.gecos("AKA=webdev")
         webdev.directory(properties.WWW_ROOT)
         webdev.shell(os.path.join(properties.ETC_DIR,"ftponly"))
         passwd[webdev.user()] = webdev
         passwd.save()
     return
    def _update_mpxadmin_user(self):
        #
        # Ensure the mpxadmin group exists.
        #
        passwd = PasswdFile()
        passwd.load()
        group = GroupFile()
        group.load()

        self.options.normal_message("Checking for mpxadmin group.")
        if "mpxadmin" not in group:
            self.options.normal_message("No mpxadmin group, adding.")
            mpxadmin = GroupEntry()
            mpxadmin.group("mpxadmin")
            mpxadmin.crypt("*")
            mpxadmin.gid(int(MPX_GID))
            mpxadmin.user_list((mpxadmin.group(), ))
            group[mpxadmin.group()] = mpxadmin
            group.save()
            self.options.normal_message("Added mpxadmin group(%d) in %s.",
                                        mpxadmin.gid(), group._file)
        else:
            self.options.normal_message("mpxadmin group already exists.")
        if int(MPX_GID):
            # Installing as regular user, presumably in penvironment.d, add
            # the required "root" group.
            self.options.normal_message("Checking for root group.")
            if "root" not in group:
                self.options.normal_message("No root group, adding.")
                root = GroupEntry()
                root.group("root")
                root.crypt("*")
                root.gid(int(MPX_GID))
                root.user_list((root.group(), ))
                group[root.group()] = root
                group.save()
                self.options.normal_message("Added root group(%d) in %s.",
                                            root.gid(), group._file)
            else:
                self.options.normal_message("root group already exists.")
        #
        # Ensure the mpxadmin user exists.
        #
        self.options.normal_message("Checking for mpxadmin user.")
        #if "mpxadmin" not in passwd:
        # if there is no mpxadmin type user, create a default
        if len(filter(lambda pw: pw.user_type() == 'mpxadmin', passwd)) == 0:
            self.options.normal_message(
                "No mpxadmin user, checking for mpxadmin group.")
            gid = group["mpxadmin"].gid()
            # @fixme This is not pretty, but it will work for now.
            #        A new UID would be uid = passwd.new_uid(gid-1)
            uid = int(MPX_UID)  # Hijacking root for superuser privelidges...
            mpxadmin = PasswdEntry()
            mpxadmin.user("mpxadmin")
            mpxadmin.directory(passwd.default_home(mpxadmin.user()))
            mpxadmin.crypt(_crypted_password("mpxadmin", "mpxadmin"))
            mpxadmin.uid(uid)
            mpxadmin.gid(gid)
            # @fixme Formalize the Mediator concept of meta-data associated
            #        with users.  Also consider moving the meta-data out of
            #        /etc/passwd and into a PDO...
            # META-DATA:
            #   AKA:  Allows us to track renames of key users (pppuser,
            #         mpxadmin, webdev, ...)
            #   CSIK:  Configuration Service Initial Key (used to calculate
            #          "classic" Configuration Service Security Keys.
            mpxadmin.gecos("AKA=mpxadmin,CSIK=%s,ROLE=administrator" %
                           (_csiked_password("mpxadmin"), ))
            mpxadmin.shell("/bin/bash")
            passwd[mpxadmin.user()] = mpxadmin
            passwd.save()
            self.options.normal_message("Added mpxadmin user(%d.%d) in %s.",
                                        mpxadmin.uid(), mpxadmin.gid(),
                                        passwd._file)
            # Create and update the mpxadmin user.
            self._force_target_directory(mpxadmin.directory())
            self.cwd.pushd(mpxadmin.directory())
            passwd = PasswdFile()
            passwd.load()
            group = GroupFile()
            group.load()
            os.system("chmod -R ug+Xrw .", **self._fatal_keywords())
            chown(".", "mpxadmin", "mpxadmin", recurse=1, ignore_errors=1)
            self.cwd.popd()
        else:
            self.options.normal_message("mpxadmin user already exists.")
        #
        # Ensure mpxadmin is a member of the root group.
        #
        group = GroupFile()
        group.load()
        root = group["root"]
        user_list = root.user_list()
        if "mpxadmin" not in user_list:
            self.options.normal_message(
                "Adding mpxadmin user to the root group.")
            user_list.append("mpxadmin")
            root.user_list(user_list)
            group["root"] = root
            group.save()
        return
Пример #3
0
    def _update_mpxadmin_user(self):
        #
        # Ensure the mpxadmin group exists.
        #
        passwd = PasswdFile()
        passwd.load()
        group = GroupFile()
        group.load()

        self.options.normal_message("Checking for mpxadmin group.")
        if "mpxadmin" not in group:
            self.options.normal_message("No mpxadmin group, adding.")
            mpxadmin = GroupEntry()
            mpxadmin.group("mpxadmin")
            mpxadmin.crypt("*")
            mpxadmin.gid(int(MPX_GID))
            mpxadmin.user_list((mpxadmin.group(),))
            group[mpxadmin.group()] = mpxadmin
            group.save()
            self.options.normal_message("Added mpxadmin group(%d) in %s.", mpxadmin.gid(), group._file)
        else:
            self.options.normal_message("mpxadmin group already exists.")
        if int(MPX_GID):
            # Installing as regular user, presumably in penvironment.d, add
            # the required "root" group.
            self.options.normal_message("Checking for root group.")
            if "root" not in group:
                self.options.normal_message("No root group, adding.")
                root = GroupEntry()
                root.group("root")
                root.crypt("*")
                root.gid(int(MPX_GID))
                root.user_list((root.group(),))
                group[root.group()] = root
                group.save()
                self.options.normal_message("Added root group(%d) in %s.", root.gid(), group._file)
            else:
                self.options.normal_message("root group already exists.")
        #
        # Ensure the mpxadmin user exists.
        #
        self.options.normal_message("Checking for mpxadmin user.")
        # if "mpxadmin" not in passwd:
        # if there is no mpxadmin type user, create a default
        if len(filter(lambda pw: pw.user_type() == "mpxadmin", passwd)) == 0:
            self.options.normal_message("No mpxadmin user, checking for mpxadmin group.")
            gid = group["mpxadmin"].gid()
            # @fixme This is not pretty, but it will work for now.
            #        A new UID would be uid = passwd.new_uid(gid-1)
            uid = int(MPX_UID)  # Hijacking root for superuser privelidges...
            mpxadmin = PasswdEntry()
            mpxadmin.user("mpxadmin")
            mpxadmin.directory(passwd.default_home(mpxadmin.user()))
            mpxadmin.crypt(_crypted_password("mpxadmin", "mpxadmin"))
            mpxadmin.uid(uid)
            mpxadmin.gid(gid)
            # @fixme Formalize the Mediator concept of meta-data associated
            #        with users.  Also consider moving the meta-data out of
            #        /etc/passwd and into a PDO...
            # META-DATA:
            #   AKA:  Allows us to track renames of key users (pppuser,
            #         mpxadmin, webdev, ...)
            #   CSIK:  Configuration Service Initial Key (used to calculate
            #          "classic" Configuration Service Security Keys.
            mpxadmin.gecos("AKA=mpxadmin,CSIK=%s,ROLE=administrator" % (_csiked_password("mpxadmin"),))
            mpxadmin.shell("/bin/bash")
            passwd[mpxadmin.user()] = mpxadmin
            passwd.save()
            self.options.normal_message(
                "Added mpxadmin user(%d.%d) in %s.", mpxadmin.uid(), mpxadmin.gid(), passwd._file
            )
            # Create and update the mpxadmin user.
            self._force_target_directory(mpxadmin.directory())
            self.cwd.pushd(mpxadmin.directory())
            passwd = PasswdFile()
            passwd.load()
            group = GroupFile()
            group.load()
            os.system("chmod -R ug+Xrw .", **self._fatal_keywords())
            chown(".", "mpxadmin", "mpxadmin", recurse=1, ignore_errors=1)
            self.cwd.popd()
        else:
            self.options.normal_message("mpxadmin user already exists.")
        #
        # Ensure mpxadmin is a member of the root group.
        #
        group = GroupFile()
        group.load()
        root = group["root"]
        user_list = root.user_list()
        if "mpxadmin" not in user_list:
            self.options.normal_message("Adding mpxadmin user to the root group.")
            user_list.append("mpxadmin")
            root.user_list(user_list)
            group["root"] = root
            group.save()
        return