~gilir/+junk/ubiquity-lxdm-autologin

« back to all changes in this revision

Viewing changes to ubiquity/misc.py

  • Committer: Julien Lavergne
  • Date: 2010-09-30 17:38:28 UTC
  • mfrom: (331.1.35 maverick)
  • Revision ID: gilir@ubuntu.com-20100930173828-9g1k2kwixmrfrxyf
Merge with upstream.

* manually update indicators ABI in panel source.
* pixmaps/cd_in_tray.png has moved back to ubiquity-frontend-gtk.  Remove
  it from ubiquity.
[ Jonathon Riddell ]
* gui/qt/stepLanguage.ui: nicer icons and better layout on
  language page (LP: #628808)
[ Mario Limonciello ]
* Set the LANG before running oem-config-remove.
* Prevent a crash of debconf-communicate when removing oem-config.
  (LP: #641478)
* Raise privileges when running the language page in only-installable
  mode. (LP: #647792)
* Automatic update of included source packages: flash-kernel
  2.28ubuntu10.
[ Evan Dandrea ]
* Don't let Jockey's automatic driver installation failing cause the
  entire prepare page to fail.
* Make sure $LANGUAGE gets set in the parallel debconf child process,
  so that we get translated descriptions (LP: #646109).
* Set the effective UID in regain_privileges_save so we don't try to
  setgroups([]) as a regular user (LP: #646827).
[ Didier Roche ]
* depends on latest libindicator-dev for ABI change (LP: #637692, #647739)
[ Evan Dandrea ]
* Fix the installer window growing and shrinking when typing in the
  boxes on the user setup page.
* Do not show the prepare page by means of hiding the language page
  before the former is ready.
* Fix a crash in the KDE partitioning page when no partitions are
  available for resizing (LP: #644407).
* Call setgroups() when raising and dropping privileges.  Thanks Colin
  Watson!
* Also tail syslog in the installer details pane, since that's where
  the action is.
* Correctly use the plugin_translate hook in the KDE frontend
  (LP: #645092).
* Update translations from Launchpad.
* Automatic update of included source packages: base-installer
  1.107ubuntu2.
[ Jonathan Riddell ]
* In gui/qt/app.ui remove unnecessary margin, (LP: #628883)
* KDE UI, Change button next between 'install now' and 'next'
  depending on partition mode, (LP: #628882)
[ Sebastian Heinlein ]
* Rework oem-config-gtk to use a mainloop (LP: #637517)
[ Evan Dandrea ]
* Call gconftool-2 --set with --config-source.
* Better lock down the installer environment when past partitioning.
* Lock down the installer environment when at partitioning commit,
  rather than just after automatic partitioning (and not manual
  partitioning) (LP: #640604, LP: #641897).
* Do not show the quit button in OEM mode.
* Depend on aptdaemon (LP: #641051).
* Fix the skip download button (LP: #628311).
* Make the '[type here to change]' string translatable (LP: #642989).
* Disable the non-free software option if multiverse and restricted
  are disabled via preseed (LP: #641676).
* Install kubuntu-restricted-addons, not kubuntu-restricted-extras
  (LP: #643614).
* Clear hostname error when fixed (LP: #640661).
* Deal with broken /cdrom symlinks (LP: #642274).
* Disable locking the screen and switching users in the installer
  session (LP: #644016).
* Update translations from Launchpad.
[ Colin Watson ]
* Stop ubiquity and oem-config when stopping display managers.  This
  should guarantee that X has exited by the time we try to start plymouth
  on shutdown (LP: #628630).
* Make sure /var/lib/ubiquity/langpacks gets generated (LP: #630924).
* Fall back to root if the regular user cannot be found in
  ubiquity-dm (LP: #640386).
* Properly handle dmimodel() returning the null string.
* Fix bootloader installation test (LP: #640341).
* Set a the respective timezone, both internally and visually, when an
  entry is selected from the geonames autocompletion.
[ Evan Dandrea ]
* Improve the text on the prepare page, based on input from Matthew
  Paul Thomas, Amanda Brock, and Andrew Sinclair
  (LP: #635269, LP: #635260).
* Translate latitude and longitude from the Geonames service to its
  respective Olsen timezone database entry.
* Add back the hostname entry (LP: #628087).
* Use a block device icon for cases where we cannot detect the
  operating system on a partition.
* Set the amount of used space on a partition that we presume contains
  no operating system (LP: #626299).
* Make requiring a password to log in the default again, matching the
  behavior in the previous version of Ubuntu.
* Use the correct string for the resize partition option.
* Set the size of the disk on the automatic partitioning page
  (LP: #626299).
* Use dmidecode to get a more unique suffix for the hostname
  (LP: #628087).
* Also generate a sample hostname when generating a sample username
  (LP: #634279).
* Only set the next button to 'Install Now' when not on the first
  partitioning page (LP: #636392).
* Fix transposed latitude and longitude in geonames lookup.
* Provide a version parameter to the geoname lookup.
* Show the number of partitions that will be deleted when in 'use
  entire disk' mode.
* Remove Pango markup from the debconf templates where possible.
* Properly set the partition widget description label.
* Use a GtkMenuBar rather than a GtkMenu as the source of the dark
  styling to match recent changes to the default theme.
* Properly start a ConsoleKit session (LP: #631538).
* Fix the spacing on the automatic partitioning page.
  gui/gtk/stepPartAuto.ui
* Correct layout based on suggestions from Matthew Paul Thomas.
* Correct layout on keyboard guesser.
* Run the Jockey backend with an in-memory debconf database, and run
  the frontend asynchronously (LP: #627822).
* Don't show the GTK frontend until it's done constructing the UI.
* Show a spinning cursor on the X root window in addition to the
  ubiquity window, so it's clear that the installer is loading the
  next page even when the cursor is off the main window.
* Make return_to_partitioning work with parallel debconf instances
  (LP: #637706).
* Added a Windows icon for the resize widget.  Thanks Otto Greenslade!
* Disable the alpha warning, albeit late.
* Add a command line option to not install a bootloader
  (-b, --no-bootloader) (LP: #615033).
* Do not show 'free space' partitions in the bootloader target
  combobox (LP: #615033).
* Meet the Geonames.org CC license requirements by adding 'Geonames.org'
  to the map.
* Install the restricted package independent of the apt-installed
  packages, since those are installed with just the live CD's
  sources.list (LP: #638073).
* Disable the wireless plugin for now.  It's not ready for release.
* Make use of the new connectivity check page.
* Automatic update of included source packages: apt-setup
  1:0.45ubuntu2, hw-detect 1.73ubuntu5.
[ Mario Limonciello ]
* Restore the functionality of the noninteractive frontend.
* Disable GVFS fuse daemon while in ubiquity-dm
* Remove oem user with userdel rather than deluser (the latter didn't support
  doing it while oem was logged in) (LP: #624888)
* Run oem-config-wrapper as the user oem rather than root.
  - Fixes issues with pulseaudio applet not working
  - Prevents root terminals from ctrl-alt-t (LP: #594233)
* Disable general terminals from ctrl-alt-t unless running in debug mode.
  (LP: #594233)
* Grab focus of the slideshow when it starts, keeping focus off the expander
  in automatic mode.
* Don't allow progressing past the language page unless a valid language is
  picked.
* Fix progressbar reporting messages reporting missing from plugininstall.py
  in ubiquity or oem-config.
[ Colin Watson ]
* GTK frontend: Make user-setup entry boxes activate the Forward button
  when Enter is pressed.
* Revert Debug::identcdrom=true for writable USB media; with changes in
  apt 0.8.3ubuntu3, this is sufficient for stable apt-cdrom identification
  of writable USB media (LP: #628290).
[ Evan Dandrea ]
* Fetch the translations for the release_notes_only and
  update_installer_only strings (LP: #629627).
* Don't use the same name for the error method and GTK label
  (LP: #631046).
* Re-use the valid username check from user-setup in the GTK UI
  (LP: #631046).
* Do not cut off the text of the Try and Install buttons by setting
  their width to just the largest initial width of the two
  (LP: #629437).
* Update the panel to use the new location for the panel background,
  and force a redraw when setting it.
* If the username only contains non-alphanumeric characters, set the
  hostname to ubuntu-{laptop,desktop}.
* Replace RELEASE with the release name in the KDE UI finished dialog
  (LP: #628964).
* Do not look for a full path on non-paths when getting the default
  grub target.
* Fix a crash when there are no disks present on the system
  (LP: #631766).
* Don't let the user continue if there are no disks present, or if
  there isn't enough free space on any of them to install.
* Fix UI bugs in the automatic partitioner page.  Better handle
  determining what the desired partitioning recipe is (LP: #630450).
* Update the KDE partitioning UI to reflect changes to ubi-partman and
  partman-auto.
  - Use the already existent ubiquity variants of the d-i "Guided -" strings
    (LP: #628864).
  - Fix the automatic resize option failing to appear
    (LP: #628897, LP: #628815).
  - Use a combobox to select which disk to use on all options that support
    multiple disks, not just the "use entire disk" option.
* Add notification area support in the panel.
* Drop ia64 and sparc.
* Run nm-applet in the ubiquity GTK session.
[ Colin Watson ]
* Factor out common /proc/mounts handling into a new
  ubiquity.misc.mount_info function.
* Remove lpia architecture support.
* Handle grub-efi when installing on amd64/efi or i386/efi
  subarchitectures (LP: #632642).
[ Mario Limonciello ]
* Adjust the fudge factor for showing languages on oem-config page
  due to the changes to the default window size being much bigger.
* During oem-config's removal of ubiquity, remove other ubiquity
  related items that might have potentially still been on the system
  from a live-helper generated image.
* Refactor mount_info to also report ro/rw, and let plugininstall
  key off that instead.
* Set the panel indicators to show up on the right to match the rest
  of the desktop (LP: #632592)
* Automatic update of included source packages: grub-installer
  1.55ubuntu3.
[ Mario Limonciello ]
* Don't show logout option in only-ubiquity mode(s) (LP: #618744)
* Don't show a minimize option in only-ubiquity mode(s) (LP: #627656)
* Translate the page_title of the language page when languages are
  swapped.
* Restore functionality to set the GTK slideshow size based on a 
  configuration file that was lost in r4123.1.37.
* Parse the slideshow size when the GTK frontend first starts to
  prevent the window resizing later.
* Automatic update of included source packages: grub-installer
  1.55ubuntu1, partman-basicfilesystems 63ubuntu7, partman-efi
  21ubuntu1.
[ Evan Dandrea ]
* Do not generate or show the bootloader options if we're on x86, or
  bootloader installation is explicitly disabled (LP: #628582).
* Add correct URL for the Geonames service.
[ Colin Watson ]
* Remove a number of unused or duplicate imports.
* Clean stray QSocketNotifiers that were missed because their fd was
  reused before they could normally be deleted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import os
5
5
import pwd
 
6
import grp
6
7
import re
7
8
import subprocess
8
9
import syslog
28
29
 
29
30
_dropped_privileges = 0
30
31
 
 
32
def set_groups_for_uid(uid):
 
33
    if uid == os.geteuid() or uid == os.getuid():
 
34
        return
 
35
    user = pwd.getpwuid(uid).pw_name
 
36
    try:
 
37
        os.setgroups([g.gr_gid for g in grp.getgrall() if user in g.gr_mem])
 
38
    except OSError:
 
39
        import traceback
 
40
        for line in traceback.format_exc().split('\n'):
 
41
            syslog.syslog(syslog.LOG_ERR, line)
 
42
 
31
43
def drop_all_privileges():
32
44
    # gconf needs both the UID and effective UID set.
33
45
    global _dropped_privileges
34
 
    if 'SUDO_GID' in os.environ:
35
 
        gid = int(os.environ['SUDO_GID'])
 
46
    uid = os.environ.get('SUDO_UID')
 
47
    gid = os.environ.get('SUDO_GID')
 
48
    if uid is not None:
 
49
        uid = int(uid)
 
50
        set_groups_for_uid(uid)
 
51
    if gid is not None:
 
52
        gid = int(gid)
36
53
        os.setregid(gid, gid)
37
 
    if 'SUDO_UID' in os.environ:
38
 
        uid = int(os.environ['SUDO_UID'])
 
54
    if uid is not None:
 
55
        uid = int(uid)
39
56
        os.setreuid(uid, uid)
40
57
        os.environ['HOME'] = pwd.getpwuid(uid).pw_dir
41
58
    _dropped_privileges = None
44
61
    global _dropped_privileges
45
62
    assert _dropped_privileges is not None
46
63
    if _dropped_privileges == 0:
47
 
        if 'SUDO_GID' in os.environ:
48
 
            gid = int(os.environ['SUDO_GID'])
 
64
        uid = os.environ.get('SUDO_UID')
 
65
        gid = os.environ.get('SUDO_GID')
 
66
        if uid is not None:
 
67
            uid = int(uid)
 
68
            set_groups_for_uid(uid)
 
69
        if gid is not None:
 
70
            gid = int(gid)
49
71
            os.setegid(gid)
50
 
        if 'SUDO_UID' in os.environ:
51
 
            uid = int(os.environ['SUDO_UID'])
 
72
        if uid is not None:
52
73
            os.seteuid(uid)
53
74
    _dropped_privileges += 1
54
75
 
59
80
    if _dropped_privileges == 0:
60
81
        os.seteuid(0)
61
82
        os.setegid(0)
 
83
        os.setgroups([])
62
84
 
63
85
def drop_privileges_save():
64
86
    """Drop the real UID/GID as well, and hide them in saved IDs."""
65
87
    # At the moment, we only know how to handle this when effective
66
88
    # privileges were already dropped.
67
89
    assert _dropped_privileges is not None and _dropped_privileges > 0
68
 
    if 'SUDO_GID' in os.environ:
69
 
        gid = int(os.environ['SUDO_GID'])
 
90
    uid = os.environ.get('SUDO_UID')
 
91
    gid = os.environ.get('SUDO_GID')
 
92
    if uid is not None:
 
93
        uid = int(uid)
 
94
        set_groups_for_uid(uid)
 
95
    if gid is not None:
 
96
        gid = int(gid)
70
97
        osextras.setresgid(gid, gid, 0)
71
 
    if 'SUDO_UID' in os.environ:
72
 
        uid = int(os.environ['SUDO_UID'])
 
98
    if uid is not None:
73
99
        osextras.setresuid(uid, uid, 0)
74
100
 
75
101
def regain_privileges_save():
76
102
    """Recover our real UID/GID after calling drop_privileges_save."""
77
103
    assert _dropped_privileges is not None and _dropped_privileges > 0
78
 
    osextras.setresuid(0, -1, 0)
79
 
    osextras.setresgid(0, -1, 0)
 
104
    osextras.setresuid(0, 0, 0)
 
105
    osextras.setresgid(0, 0, 0)
 
106
    os.setgroups([])
80
107
 
81
108
@contextlib.contextmanager
82
109
def raised_privileges():
140
167
                ostype = ''
141
168
                if part[4] == 'linux-swap':
142
169
                    continue
 
170
                if part[4] == 'free':
 
171
                    continue
143
172
                if os.path.exists(p.part_entry(part[1], 'format')):
 
173
                    # Don't bother looking for an OS type.
144
174
                    pass
145
175
                elif part[5] in oslist.keys():
146
176
                    ostype = oslist[part[5]]
214
244
 
215
245
    return None
216
246
 
 
247
def mount_info(path):
 
248
    """Return the filesystem name, type, and ro/rw used for a given mountpoint."""
 
249
    fsname = ''
 
250
    fstype = ''
 
251
    writable = ''
 
252
    with contextlib.closing(open('/proc/mounts')) as fp:
 
253
        for line in fp:
 
254
            line = line.split()
 
255
            if line[1] == path:
 
256
                fsname = line[0]
 
257
                fstype = line[2]
 
258
                writable = line[3].split(',')[0]
 
259
    return fsname, fstype, writable
 
260
 
217
261
@raise_privileges
218
262
def grub_default():
219
263
    """Return the default GRUB installation target."""
236
280
    if target is None:
237
281
        target = '(hd0)'
238
282
 
239
 
    cdsrc = ''
240
 
    cdfs = ''
241
 
    with contextlib.closing(open('/proc/mounts')) as fp:
242
 
        for line in fp:
243
 
            line = line.split()
244
 
            if line[1] == '/cdrom':
245
 
                cdsrc = line[0]
246
 
                cdfs = line[2]
247
 
                break
 
283
    cdsrc, cdfs, type = mount_info('/cdrom')
248
284
    if (cdsrc == target or target == '(hd0)') and cdfs and cdfs != 'iso9660':
249
285
        # Installing from removable media other than a CD.  Make sure that
250
286
        # we don't accidentally install GRUB to it.
416
452
    else:
417
453
        return text
418
454
 
 
455
@raise_privileges
 
456
def dmimodel():
 
457
    model = ''
 
458
    try:
 
459
        proc = subprocess.Popen(['dmidecode', '--string',
 
460
            'system-manufacturer'], stdout=subprocess.PIPE)
 
461
        manufacturer = proc.communicate()[0]
 
462
        if not manufacturer:
 
463
            return
 
464
        manufacturer = manufacturer.lower()
 
465
        if 'to be filled' in manufacturer:
 
466
            # Don't bother with products in development.
 
467
            return
 
468
        if 'bochs' in manufacturer or 'vmware' in manufacturer:
 
469
            model = 'virtual machine'
 
470
            # VirtualBox sets an appropriate system-product-name.
 
471
        else:
 
472
            if 'lenovo' in manufacturer or 'ibm' in manufacturer:
 
473
                key = 'system-version'
 
474
            else:
 
475
                key = 'system-product-name'
 
476
            proc = subprocess.Popen(['dmidecode', '--string', key],
 
477
                                    stdout=subprocess.PIPE)
 
478
            model = proc.communicate()[0]
 
479
        if 'apple' in manufacturer:
 
480
            # MacBook4,1 - strip the 4,1
 
481
            model = re.sub('[^a-zA-Z\s]', '', model)
 
482
        # Replace each gap of non-alphanumeric characters with a dash.
 
483
        # Ensure the resulting string does not begin or end with a dash.
 
484
        model = re.sub('[^a-zA-Z0-9]+', '-', model).rstrip('-').lstrip('-')
 
485
    except Exception:
 
486
        syslog.syslog(syslog.LOG_ERR, 'Unable to determine the model from DMI')
 
487
    return model
 
488
 
419
489
# vim:ai:et:sts=4:tw=80:sw=4: