From 35c5a0b279b99f30430f4a8e5092c7b2f1234316 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Thu, 19 Nov 2015 13:55:58 -0600 Subject: [PATCH 1/3] Protect mountpoint from relative paths and duplicate pathsep Use os.path.realpath() to clean up any path manipulations Signed-off-by: Ryan Harper --- subiquity/models/filesystem.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index 0cac77e1..373f2b74 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -16,6 +16,7 @@ import json import logging import re +from os.path import realpath from .blockdev import Blockdev, Raiddev, Bcachedev, sort_actions import math @@ -470,6 +471,9 @@ class FilesystemModel(ModelPolicy): if not mountpoint.startswith('/'): raise ValueError('Does not start with /') + # remove redundent // and .. + mountpoint = realpath(mountpoint) + # /usr/include/linux/limits.h:PATH_MAX if len(mountpoint) > 4095: raise ValueError('Path exceeds PATH_MAX') From 02f7aade371a44706bd86dd83f29293db6b5b652 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Thu, 19 Nov 2015 16:29:28 -0600 Subject: [PATCH 2/3] Don't let invalid mounts appear in fstable Missing return from error allowed invalid mounts to appear in fs table. Signed-off-by: Ryan Harper --- subiquity/ui/views/filesystem.py | 1 + 1 file changed, 1 insertion(+) diff --git a/subiquity/ui/views/filesystem.py b/subiquity/ui/views/filesystem.py index 898f3e7d..d5fa4c59 100644 --- a/subiquity/ui/views/filesystem.py +++ b/subiquity/ui/views/filesystem.py @@ -345,6 +345,7 @@ class AddPartitionView(ViewPolicy): log.exception('Invalid mount point') self.mountpoint.set_error('Error: {}'.format(str(e))) log.debug("Invalid mountpoint, try again") + return log.debug("Add Partition Result: {}".format(result)) self.signal.emit_signal('filesystem:finish-add-disk-partition', From 9872bdfb941cbdb18b61d1bced8428da2f8b5860 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Thu, 19 Nov 2015 18:31:30 -0600 Subject: [PATCH 3/3] Don't display partition menu options if not allow - Skip add_partition entry for bcache, raid, and lvm devices - Don't display Format entire partition if it's already been formated Signed-off-by: Ryan Harper --- subiquity/models/filesystem.py | 8 ++++++++ subiquity/ui/views/filesystem.py | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index 373f2b74..fcc06c2e 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -122,6 +122,14 @@ class FilesystemModel(ModelPolicy): "10", ] + # th following blocktypes cannot be partitioned + no_partition_blocktypes = [ + "bcache", + "lvm_partition", + "lvm_volgroup", + "raid", + ] + def __init__(self, prober, opts): self.opts = opts self.prober = prober diff --git a/subiquity/ui/views/filesystem.py b/subiquity/ui/views/filesystem.py index d5fa4c59..95e156b1 100644 --- a/subiquity/ui/views/filesystem.py +++ b/subiquity/ui/views/filesystem.py @@ -410,9 +410,12 @@ class DiskPartitionView(ViewPolicy): changes to the button depending on if existing partitions exist or not. """ - return Pile([self.add_partition_w(), - self.create_swap_w(), - self.show_disk_info_w()]) + menus = [ + self.add_partition_w(), + self.create_swap_w(), + self.show_disk_info_w(), + ] + return Pile([m for m in menus if m]) def show_disk_info_w(self): """ Runs hdparm against device and displays its output @@ -431,11 +434,11 @@ class DiskPartitionView(ViewPolicy): """ text = ("Format or create swap on entire " "device (unusual, advanced)") - if len(self.disk_obj.partitions) == 0: + if len(self.disk_obj.partitions) == 0 and \ + self.disk_obj.available: return Color.menu_button(menu_btn(label=text, on_press=self.create_swap), focus_map='menu_button focus') - return Color.info_minor(Text(text)) def add_partition_w(self): """ Handles presenting the add partition widget button @@ -445,9 +448,12 @@ class DiskPartitionView(ViewPolicy): if len(self.disk_obj.partitions) > 0: text = "Add partition (max size {})".format( _humanize_size(self.disk_obj.freespace)) - return Color.menu_button(menu_btn(label=text, - on_press=self.add_partition), - focus_map='menu_button focus') + + if self.disk_obj.available and \ + self.disk_obj.blocktype not in self.model.no_partition_blocktypes: + return Color.menu_button(menu_btn(label=text, + on_press=self.add_partition), + focus_map='menu_button focus') def show_disk_info(self, result): self.signal.emit_signal('menu:filesystem:main:show-disk-information',