def set_password(self, password, encrypted=False):
     '''Set the password, encrypting it unless this function
     is explicitly called with encrypted=True
     
     '''
     if password is None:
         self._password = None
         self.passlen = 0
         return
     
     if not encrypted:
         self._password = encrypt_password(password)
         self.passlen = len(password)
     else:
         self._password = password
         self.passlen = 16
Esempio n. 2
0
    def set_password(self, password, encrypted=False):
        '''Set the password, encrypting it unless this function
        is explicitly called with encrypted=True
        
        '''
        if password is None:
            self._password = None
            self.passlen = 0
            return

        if not encrypted:
            self._password = encrypt_password(password)
            self.passlen = len(password)
        else:
            self._password = password
            self.passlen = 16
    def set_password(self):
        """ class method to set the root password
        """
        self.logger.debug("root password is: " + self.root_password)
        self.logger.debug("is root password plaintext: " +
                          str(self.is_plaintext))

        if self.is_plaintext.capitalize() == "True":
            encrypted_pw = encrypt_password(self.root_password,
                                            alt_root=self.pkg_img_path)
        else:
            encrypted_pw = self.root_password

        self.logger.debug("encrypted root password is: " + encrypted_pw)

        pfile = PasswordFile(self.pkg_img_path)
        root_entry = pfile.getuser("root")
        root_entry["password"] = encrypted_pw
        pfile.setvalue(root_entry)
        pfile.writefile()
Esempio n. 4
0
    def set_password(self):
        """ class method to set the root password
        """
        self.logger.debug("root password is: " + self.root_password)
        self.logger.debug("is root password plaintext: " +
                          str(self.is_plaintext))

        if self.is_plaintext.capitalize() == "True":
            encrypted_pw = encrypt_password(self.root_password,
                                            alt_root=self.pkg_img_path)
        else:
            encrypted_pw = self.root_password

        self.logger.debug("encrypted root password is: " + encrypted_pw)

        pfile = PasswordFile(self.pkg_img_path)
        root_entry = pfile.getuser("root")
        root_entry["password"] = encrypted_pw
        pfile.setvalue(root_entry)
        pfile.writefile()
Esempio n. 5
0
    mfest_socket = sys.argv[1]  # Manifest reader socket
    pkg_img_path = sys.argv[2]  # package image area mountpoint

    # get the manifest reader object from the socket
    manifest_reader_obj = ManifestRead(mfest_socket)

    # Get the password for the root user from the manifest
    root_passwd_text = get_manifest_value(manifest_reader_obj, ROOT_PASSWD)
    is_plaintext = get_manifest_boolean(manifest_reader_obj,
                                        ROOT_PASSWD_PLAINTEXT)

    print "root_passwd_text = " + root_passwd_text
    print "is_plaintext = " + str(is_plaintext)

    if is_plaintext:
        encrypted_root_passwd = encrypt_password(root_passwd_text,
                                                 alt_root=pkg_img_path)
    else:
        encrypted_root_passwd = root_passwd_text

    print "Encrypted root password: "******"root")
        root_entry["password"] = encrypted_root_passwd
        pfile.setvalue(root_entry)
        pfile.writefile()
    except StandardError:
        print >> sys.stderr, "Failed to modify image with user" \
                             + "specified root password"
        sys.exit(1)
Esempio n. 6
0
    def customize_config_files(self):
        """ class method to save and/or tune various configuration files
        """

        #
        # Save the original /boot/grub/menu.lst file if it exists. It will not
        # exist on GRUB2 based images so it is silently ignored if not present.
        # Specific to i386 platform.
        #
        if platform.processor() == "i386":
            save_list = ["boot/grub/menu.lst"]
            if os.path.exists(os.path.join(self.pkg_img_path, save_list[0])):
                self.save_files_directories(save_list)

        #
        # Save pristine /etc/inet/hosts file, since it is modified by
        # identity:node smf service during media boot.
        #
        self.save_files_directories(["etc/inet/hosts"], preserve=True)

        #
        # Modify /etc/system to make ZFS consume less memory.
        # Save original system(4) file.
        #
        self.save_files_directories(["etc/system"], preserve=True)

        etc_system = os.path.join(self.pkg_img_path, "etc/system")
        with open(etc_system, "a+") as fh:
            fh.write("set zfs:zfs_arc_max=0x4002000\n")
            fh.write("set zfs:zfs_vdev_cache_size=0\n")

        # Configure the root password. Save original shadow(4) file.
        self.save_files_directories(["etc/shadow"], preserve=True)

        self.logger.debug("root password is: " + self.root_password)
        self.logger.debug("is root password plaintext: " +
                          str(self.is_plaintext))

        if self.is_plaintext.capitalize() == "True":
            encrypted_pw = encrypt_password(self.root_password,
                                            alt_root=self.pkg_img_path)
        else:
            encrypted_pw = self.root_password

        self.logger.debug("encrypted root password is: " + encrypted_pw)

        pfile = PasswordFile(self.pkg_img_path)
        root_entry = pfile.getuser("root")
        root_entry["password"] = encrypted_pw
        pfile.setvalue(root_entry)
        pfile.writefile()

        #
        # Modify /etc/default/dhcpagent to include the Rootpath
        # bootp-dhcp-parameter for finding iSCSI information from the DHCP
        # server.
        #
        # This method can be removed if/when CR 7129888 is addressed.
        #

        # verify /etc/default/dhcpagent exists
        dhcpagent = os.path.join(self.pkg_img_path, "etc/default/dhcpagent")
        if not os.path.exists(dhcpagent):
            self.logger.debug("skipping modification of "
                              "/etc/default/dhcpagent, file does not exist")
        else:
            # Save pristine dhcpagent file.
            self.save_files_directories(["etc/default/dhcpagent"],
                                        preserve=True)

            # open the file and read it into memory
            with open(dhcpagent, "r") as fh:
                contents = fh.read()

            new_file = list()
            for line in contents.splitlines():
                if line.startswith("PARAM_REQUEST_LIST") and "17" not in line:
                    # append the parameter to enable rootpath
                    new_file.append(line + ",17")
                else:
                    new_file.append(line)

            # rewrite the file
            with open(dhcpagent, "w+") as fh:
                fh.write("\n".join(new_file))
                fh.write("\n")