Esempio n. 1
0
    def fixxids(self, xid, pace=cfg.PACE[0]):

        # walk the root, and set all non-iunlink files to xid xid.  this
        # means that when a non iunlink file is deleted, the proper amount
        # of space is freed.

        xid = int(xid)

        print 'Fixing xids in %s for xid %d... (this may take a while)' % (
            self.vpsroot, xid)

        p = 0
        t, x = 0, 0

        for root, dirs, files in os.walk(self.vpsroot):

            for file in files + dirs:

                path = os.path.join(root, file)

                if pace and p >= pace:
                    sys.stdout.write('.')
                    sys.stdout.flush()
                    time.sleep(cfg.PACE[1])
                    p = 0
                else:
                    p += 1

                t += 1  # total file count

                if os.path.isdir(path) or path.endswith('dev/null') or \
                       path.endswith('etc/protocols') or path.endswith('etc/resolv.conf'):

                    # do not set xid on directories, as this breaks the ohd
                    # thing which would get permission denied trying to run
                    # stuff from another context. since space (not security) is
                    # the prime motivator for this, and dirs are tiny, this is ok
                    # XXX and of course the dev/null and etc/protocols is a total
                    # dirty hack to make traceroute work

                    # XXX or is it?

                    vsutil.set_file_xid(path, 0)

                elif (not vsutil.is_file_immutable_unlink(path)
                      and not os.path.islink(path)
                      and os.stat(path).st_nlink == 1):

                    vsutil.set_file_xid(path, xid)

                    x += 1  # setxid file count

                elif not os.path.islink(path):

                    # default to 0
                    vsutil.set_file_xid(path, 0)

        print 'Done.\n%d xids of a total of %d has been set to %d' % (x, t,
                                                                      xid)
Esempio n. 2
0
    def fixxids(self, xid, pace=cfg.PACE[0]):

        # walk the root, and set all non-iunlink files to xid xid.  this
        # means that when a non iunlink file is deleted, the proper amount
        # of space is freed.

        xid = int(xid)

        print 'Fixing xids in %s for xid %d... (this may take a while)' % (self.vpsroot, xid)

        p = 0
        t, x = 0, 0

        for root, dirs, files in os.walk(self.vpsroot):

            for file in files + dirs:

                path = os.path.join(root, file)

                if pace and p >= pace:
                    sys.stdout.write('.'); sys.stdout.flush()
                    time.sleep(cfg.PACE[1])
                    p = 0
                else:
                    p += 1

                t += 1  # total file count

                if os.path.isdir(path) or path.endswith('dev/null') or \
                       path.endswith('etc/protocols') or path.endswith('etc/resolv.conf'):

                    # do not set xid on directories, as this breaks the ohd
                    # thing which would get permission denied trying to run
                    # stuff from another context. since space (not security) is
                    # the prime motivator for this, and dirs are tiny, this is ok
                    # XXX and of course the dev/null and etc/protocols is a total
                    # dirty hack to make traceroute work

                    # XXX or is it?

                    vsutil.set_file_xid(path, 0)

                elif (not vsutil.is_file_immutable_unlink(path) and
                      not os.path.islink(path) and
                      os.stat(path).st_nlink == 1):

                    vsutil.set_file_xid(path, xid)

                    x += 1 # setxid file count

                elif not os.path.islink(path):

                    # default to 0
                    vsutil.set_file_xid(path, 0)
                    

        print 'Done.\n%d xids of a total of %d has been set to %d' % (x, t, xid)
Esempio n. 3
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. 4
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.'