def subprocess_setup():
     os.environ['HOME'] = '/root'
     os.environ['LC_COLLATE'] = 'C'
     for key, value in env.iteritems():
         os.environ[key] = value
     # Python installs a SIGPIPE handler by default. This is bad for
     # non-Python subprocesses, which need SIGPIPE set to the default
     # action.
     signal.signal(signal.SIGPIPE, signal.SIG_DFL)
     # Regain root.
     misc.regain_privileges()
 def subprocess_setup():
     os.environ['HOME'] = '/root'
     os.environ['LC_COLLATE'] = 'C'
     for key, value in env.items():
         os.environ[key] = value
     # Python installs a SIGPIPE handler by default. This is bad for
     # non-Python subprocesses, which need SIGPIPE set to the default
     # action.
     signal.signal(signal.SIGPIPE, signal.SIG_DFL)
     # Regain root.
     misc.regain_privileges()
Example #3
0
    def openURL(self, url):
        from PyQt5.QtGui import QDesktopServices
        from PyQt5.QtCore import QUrl
        import shutil
        import os

        # this nonsense is needed because kde doesn't want to be root
        misc.drop_privileges()
        misc.drop_privileges_save()
        # copy over gtkrc-2.0 to get the themeing right
        if os.path.exists("/usr/share/kubuntu-default-settings"):
            shutil.copy(
                "/usr/share/kubuntu-default-settings/" + "dot-gtkrc-2.0-kde4",
                os.getenv("HOME") + "/.gtkrc-2.0")
        QDesktopServices.openUrl(QUrl(url))
        misc.regain_privileges()
        misc.regain_privileges_save()
Example #4
0
    def openURL(self, url):
        from PyQt4.QtGui import QDesktopServices
        from PyQt4.QtCore import QUrl
        import shutil
        import os

        # this nonsense is needed because kde doesn't want to be root
        misc.drop_privileges()
        misc.drop_privileges_save()
        # copy over gtkrc-2.0 to get the themeing right
        if os.path.exists("/usr/share/netrunner-default-settings"):
            shutil.copy("/usr/share/netrunner-default-settings/" +
                        "dot-gtkrc-2.0-kde4",
                        os.getenv("HOME") + "/.gtkrc-2.0")
        QDesktopServices.openUrl(QUrl(url))
        misc.regain_privileges()
        misc.regain_privileges_save()
Example #5
0
 def subprocess_setup():
     os.environ['DEBIAN_HAS_FRONTEND'] = '1'
     if 'DEBCONF_USE_CDEBCONF' in os.environ:
         # cdebconf expects to be able to redirect standard output to fd
         # 5. Make this stderr to match debconf.
         os.dup2(2, 5)
     else:
         os.environ['PERL_DL_NONLAZY'] = '1'
     os.environ['HOME'] = '/root'
     os.environ['LC_COLLATE'] = 'C'
     for key, value in extra_env.iteritems():
         os.environ[key] = value
     # Python installs a SIGPIPE handler by default. This is bad for
     # non-Python subprocesses, which need SIGPIPE set to the default
     # action or else they won't notice if the debconffilter dies.
     signal.signal(signal.SIGPIPE, signal.SIG_DFL)
     # Regain root.
     misc.regain_privileges()
Example #6
0
    def prepare(self):
        self.preseed('console-setup/ask_detect', 'false')

        # We need to get rid of /etc/default/console-setup, or console-setup
        # will think it's already configured and behave differently. Try to
        # save the old file for interest's sake, but it's not a big deal if
        # we can't.
        misc.regain_privileges()
        try:
            os.unlink('/etc/default/console-setup.pre-ubiquity')
        except OSError:
            pass
        try:
            os.rename('/etc/default/console-setup',
                      '/etc/default/console-setup.pre-ubiquity')
        except OSError:
            try:
                os.unlink('/etc/default/console-setup')
            except OSError:
                pass
        misc.drop_privileges()
        # Make sure debconf doesn't do anything with crazy "preseeded"
        # answers to these questions. If you want to preseed these, use the
        # *code variants.
        self.db.fset('console-setup/layout', 'seen', 'false')
        self.db.fset('console-setup/variant', 'seen', 'false')
        self.db.fset('console-setup/model', 'seen', 'false')
        self.db.fset('console-setup/codeset', 'seen', 'false')

        # Technically we should provide a version as the second argument,
        # but that isn't currently needed and it would require querying
        # apt/dpkg for the current version, which would be slow, so we don't
        # bother for now.
        return (['/usr/lib/ubiquity/console-setup/console-setup.postinst',
                 'configure'],
                ['^console-setup/layout', '^console-setup/variant'],
                {'OVERRIDE_ALLOW_PRESEEDING': '1'})
Example #7
0
 def subprocess_setup():
     misc.regain_privileges()
Example #8
0
 def test_regain_privileges(self, *args):
     self.test_drop_privileges()
     misc.regain_privileges()
     os.seteuid.assert_called_once_with(0)
     os.setegid.assert_called_once_with(0)
     os.setgroups.assert_called_once_with([])
Example #9
0
 def test_regain_privileges(self, *args):
     self.test_drop_privileges()
     misc.regain_privileges()
     os.seteuid.assert_called_once_with(0)
     os.setegid.assert_called_once_with(0)
     os.setgroups.assert_called_once_with([])
Example #10
0
    def cleanup(self):
        # TODO cjwatson 2006-09-07: I'd use dexconf, but it seems reasonable
        # for somebody to edit /etc/X11/xorg.conf on the live CD and expect
        # that to be carried over to the installed system (indeed, we've
        # always supported that up to now). So we get this horrible mess
        # instead ...

        model = self.db.get('console-setup/modelcode')
        layout = self.db.get('console-setup/layoutcode')
        variant = self.db.get('console-setup/variantcode')
        options = self.db.get('console-setup/optionscode')
        self.apply_real_keyboard(model, layout, variant, options.split(','))

        if layout == '':
            return

        misc.regain_privileges()
        oldconfigfile = '/etc/X11/xorg.conf'
        newconfigfile = '/etc/X11/xorg.conf.new'
        try:
            oldconfig = open(oldconfigfile)
        except IOError:
            # Did they remove /etc/X11/xorg.conf or something? Oh well,
            # better to carry on than to crash.
            return
        newconfig = open(newconfigfile, 'w')

        re_section_inputdevice = re.compile(r'\s*Section\s+"InputDevice"\s*$')
        re_driver_kbd = re.compile(r'\s*Driver\s+"kbd"\s*$')
        re_endsection = re.compile(r'\s*EndSection\s*$')
        re_option_xkbmodel = re.compile(r'(\s*Option\s*"XkbModel"\s*).*')
        re_option_xkblayout = re.compile(r'(\s*Option\s*"XkbLayout"\s*).*')
        re_option_xkbvariant = re.compile(r'(\s*Option\s*"XkbVariant"\s*).*')
        re_option_xkboptions = re.compile(r'(\s*Option\s*"XkbOptions"\s*).*')
        in_inputdevice = False
        in_inputdevice_kbd = False
        done = {'model': model == '', 'layout': False,
                'variant': variant == '', 'options': options == ''}

        for line in oldconfig:
            line = line.rstrip('\n')
            if re_section_inputdevice.match(line) is not None:
                in_inputdevice = True
            elif in_inputdevice and re_driver_kbd.match(line) is not None:
                in_inputdevice_kbd = True
            elif re_endsection.match(line) is not None:
                if in_inputdevice_kbd:
                    if not done['model']:
                        print >>newconfig, ('\tOption\t\t"XkbModel"\t"%s"' %
                                            model)
                    if not done['layout']:
                        print >>newconfig, ('\tOption\t\t"XkbLayout"\t"%s"' %
                                            layout)
                    if not done['variant']:
                        print >>newconfig, ('\tOption\t\t"XkbVariant"\t"%s"' %
                                            variant)
                    if not done['options']:
                        print >>newconfig, ('\tOption\t\t"XkbOptions"\t"%s"' %
                                            options)
                in_inputdevice = False
                in_inputdevice_kbd = False
                done = {'model': model == '', 'layout': False,
                        'variant': variant == '', 'options': options == ''}
            elif in_inputdevice_kbd:
                match = re_option_xkbmodel.match(line)
                if match is not None:
                    if model == '':
                        # hmm, not quite sure what to do here; guessing that
                        # forcing to pc105 will be reasonable
                        line = match.group(1) + '"pc105"'
                    else:
                        line = match.group(1) + '"%s"' % model
                    done['model'] = True
                else:
                    match = re_option_xkblayout.match(line)
                    if match is not None:
                        line = match.group(1) + '"%s"' % layout
                        done['layout'] = True
                    else:
                        match = re_option_xkbvariant.match(line)
                        if match is not None:
                            if variant == '':
                                continue # delete this line
                            else:
                                line = match.group(1) + '"%s"' % variant
                            done['variant'] = True
                        else:
                            match = re_option_xkboptions.match(line)
                            if match is not None:
                                if options == '':
                                    continue # delete this line
                                else:
                                    line = match.group(1) + '"%s"' % options
                                done['options'] = True
            print >>newconfig, line

        newconfig.close()
        oldconfig.close()
        os.rename(newconfigfile, oldconfigfile)
        misc.drop_privileges()