Esempio n. 1
0
    def make_libexec_openvps(self):

        libexec_dir = os.path.join(self.vpsroot, 'usr/libexec/openvps')

        print 'Making %s' % libexec_dir
        os.mkdir(libexec_dir)

        print 'Copying traceroute there'

        for path, short_name in [('bin/traceroute', 'traceroute'),]:

            # move the originals into libexec/oh
            dest_path = os.path.join(libexec_dir, short_name)
            shutil.move(os.path.join(self.vpsroot, path), dest_path)
            vsutil.set_file_immutable_unlink(dest_path)

            # now place our custom in their path
            dest_path = os.path.join(self.vpsroot, path)

            shutil.copy(os.path.join(cfg.OV_MISC, short_name), dest_path)

            # why can't I do setuid with os.chmod?
            cmd = 'chmod 04755 %s' % dest_path
            commands.getoutput(cmd)

            vsutil.set_file_immutable_unlink(dest_path)
Esempio n. 2
0
    def make_libexec_openvps(self):

        libexec_dir = os.path.join(self.vpsroot, 'usr/libexec/openvps')

        print 'Making %s' % libexec_dir
        os.mkdir(libexec_dir)

        print 'Copying traceroute there'

        for path, short_name in [
            ('bin/traceroute', 'traceroute'),
        ]:

            # move the originals into libexec/oh
            dest_path = os.path.join(libexec_dir, short_name)
            shutil.move(os.path.join(self.vpsroot, path), dest_path)
            vsutil.set_file_immutable_unlink(dest_path)

            # now place our custom in their path
            dest_path = os.path.join(self.vpsroot, path)

            shutil.copy(os.path.join(cfg.OV_MISC, short_name), dest_path)

            # why can't I do setuid with os.chmod?
            cmd = 'chmod 04755 %s' % dest_path
            commands.getoutput(cmd)

            vsutil.set_file_immutable_unlink(dest_path)
Esempio n. 3
0
    def fixup_libexec_openvps(self):

        # This sets the right permissions for the files in
        # usr/libexec/oh

        print 'Setting flags in usr/libexec/openvps'

        for file in ['traceroute',]:

            path = os.path.join(self.vpsroot, 'usr/libexec/openvps/', file)
            vsutil.set_file_immutable_unlink(path)
Esempio n. 4
0
    def fixup_libexec_openvps(self):

        # This sets the right permissions for the files in
        # usr/libexec/oh

        print 'Setting flags in usr/libexec/openvps'

        for file in [
                'traceroute',
        ]:

            path = os.path.join(self.vpsroot, 'usr/libexec/openvps/', file)
            vsutil.set_file_immutable_unlink(path)
Esempio n. 5
0
    def fixflags(self):

        # This routine sets immutable-unlink flags on all files,
        # except those that are marked as config (or mentioned at all)
        # in rpms

        print 'Fixing flags in %s ... (this will take a while)' % self.vpsroot

        # progress indicator
        prog_size = 60
        sys.stdout.write('[%s]' % (' '*prog_size)); sys.stdout.flush()
        p = 0

        # list all rpms
        # (rpmlint is a good place to look at Python code when it comes
        #  to completely undocumented rpm-python)

        ts = rpm.TransactionSet(self.vpsroot)
        rpms  = [item[1][rpm.RPMTAG_NAME] for item in ts.IDTXload()]

        # a stupid trick. makes the progress indicator move slow at first
        # then faster (probably because small rpms are towards the end).
        rpms.reverse()

        # this will prevent some warnings related to chroot
        os.chdir(cfg.VSERVERS_ROOT)

        for name in rpms:

            # list files in the rpm
            it = ts.dbMatch('name', name)

            hdr = it.next()

            # this creates a list of file in an rpm. the implementation
            # is borrowed from rpmlint package, i don't really understand
            # how it works, but it does.

            files = hdr[rpm.RPMTAG_OLDFILENAMES]
            if files == None:
                basenames = hdr[rpm.RPMTAG_BASENAMES]
                if basenames:
                    dirnames = hdr[rpm.RPMTAG_DIRNAMES]
                    dirindexes = hdr[rpm.RPMTAG_DIRINDEXES]
                    files=[]
                    if type(dirindexes) == types.IntType:
                        files.append(dirnames[dirindexes] + basenames[0])
                    else:
                        for idx in range(0, len(dirindexes)):
                            files.append(dirnames[dirindexes[idx]] + basenames[idx])

            # now step through those files

            for idx in xrange(len(files)):

                # do we need a pacing sleep?
                if p >= 1000:
                    # instead of writing a dot, write something meaningful
                    prog = int(rpms.index(name)/float(len(rpms))*prog_size)
                    sys.stdout.write('\b'*(prog_size+2))
                    sys.stdout.write('[%s%s]' % ('='*prog, ' '*(prog_size-prog)))
                    sys.stdout.flush()
                    p = 0
                else:
                    p += 1

                flags = hdr[rpm.RPMTAG_FILEFLAGS][idx]

                if not flags & rpm.RPMFILE_CONFIG:
                    # (if not a config file)

                    file = files[idx]

                    # check against our cloning rules
                    c, t, s = self.match_path(file)

                    if c or t or s:
                        # skip it
                        continue
                    else:
                        abspath = os.path.join(self.vpsroot, file[1:])

                        if (os.path.exists(abspath) 
                            and (not os.path.islink(abspath)) 
                            and (not os.path.isdir(abspath))):
                            # (do not make symlinks and dirs immutable)

                            vsutil.set_file_immutable_unlink(abspath)
                            vsutil.set_file_xid(abspath, 0)

                            # NOTE that under no circumstances we *unset* the flag. This
                            # is because e.g. usr/libexec/oh stuff must be iunlink, but
                            # is not in an rpm.
                            # reldst is the way it would look relative to self.vpsroot

        sys.stdout.write('\b'*(prog_size+2))
        sys.stdout.write('[%s]' % ('='*prog_size)); sys.stdout.flush()
        print 'Done.'
Esempio n. 6
0
    def fixflags(self):

        # This routine sets immutable-unlink flags on all files,
        # except those that are marked as config (or mentioned at all)
        # in rpms

        print 'Fixing flags in %s ... (this will take a while)' % self.vpsroot

        # progress indicator
        prog_size = 60
        sys.stdout.write('[%s]' % (' ' * prog_size))
        sys.stdout.flush()
        p = 0

        # list all rpms
        # (rpmlint is a good place to look at Python code when it comes
        #  to completely undocumented rpm-python)

        ts = rpm.TransactionSet(self.vpsroot)
        rpms = [item[1][rpm.RPMTAG_NAME] for item in ts.IDTXload()]

        # a stupid trick. makes the progress indicator move slow at first
        # then faster (probably because small rpms are towards the end).
        rpms.reverse()

        # this will prevent some warnings related to chroot
        os.chdir(cfg.VSERVERS_ROOT)

        for name in rpms:

            # list files in the rpm
            it = ts.dbMatch('name', name)

            hdr = it.next()

            # this creates a list of file in an rpm. the implementation
            # is borrowed from rpmlint package, i don't really understand
            # how it works, but it does.

            files = hdr[rpm.RPMTAG_OLDFILENAMES]
            if files == None:
                basenames = hdr[rpm.RPMTAG_BASENAMES]
                if basenames:
                    dirnames = hdr[rpm.RPMTAG_DIRNAMES]
                    dirindexes = hdr[rpm.RPMTAG_DIRINDEXES]
                    files = []
                    if type(dirindexes) == types.IntType:
                        files.append(dirnames[dirindexes] + basenames[0])
                    else:
                        for idx in range(0, len(dirindexes)):
                            files.append(dirnames[dirindexes[idx]] +
                                         basenames[idx])

            # now step through those files

            for idx in xrange(len(files)):

                # do we need a pacing sleep?
                if p >= 1000:
                    # instead of writing a dot, write something meaningful
                    prog = int(rpms.index(name) / float(len(rpms)) * prog_size)
                    sys.stdout.write('\b' * (prog_size + 2))
                    sys.stdout.write('[%s%s]' % ('=' * prog, ' ' *
                                                 (prog_size - prog)))
                    sys.stdout.flush()
                    p = 0
                else:
                    p += 1

                flags = hdr[rpm.RPMTAG_FILEFLAGS][idx]

                if not flags & rpm.RPMFILE_CONFIG:
                    # (if not a config file)

                    file = files[idx]

                    # check against our cloning rules
                    c, t, s = self.match_path(file)

                    if c or t or s:
                        # skip it
                        continue
                    else:
                        abspath = os.path.join(self.vpsroot, file[1:])

                        if (os.path.exists(abspath)
                                and (not os.path.islink(abspath))
                                and (not os.path.isdir(abspath))):
                            # (do not make symlinks and dirs immutable)

                            vsutil.set_file_immutable_unlink(abspath)
                            vsutil.set_file_xid(abspath, 0)

                            # NOTE that under no circumstances we *unset* the flag. This
                            # is because e.g. usr/libexec/oh stuff must be iunlink, but
                            # is not in an rpm.
                            # reldst is the way it would look relative to self.vpsroot

        sys.stdout.write('\b' * (prog_size + 2))
        sys.stdout.write('[%s]' % ('=' * prog_size))
        sys.stdout.flush()
        print 'Done.'