Skip to content

Commit

Permalink
storage: locale: Validate advanced mounts
Browse files Browse the repository at this point in the history
Ensure that the advanced extra mount points are
absolute paths and correctly formed.

Signed-off-by: Mark D Horn <[email protected]>
  • Loading branch information
mdhorn committed Sep 13, 2019
1 parent 5fc0a05 commit 7529a26
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
4 changes: 4 additions & 0 deletions locale/en_US/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ msgstr "%s must be %s"
msgid "Found multiple %s partition labels"
msgstr "Found multiple %s partition labels"

#, c-format
msgid "Found invalid %s partition label"
msgstr "Found invalid %s partition label"

#, c-format
msgid "Encryption of %s is not supported"
msgstr "Encryption of %s is not supported"
Expand Down
4 changes: 4 additions & 0 deletions locale/es_MX/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ msgstr "MX: %s must be %s"
msgid "Found multiple %s partition labels"
msgstr "MX: Found multiple %s partition labels"

#, c-format
msgid "Found invalid %s partition label"
msgstr "MX: Found invalid %s partition label"

#, c-format
msgid "Encryption of %s is not supported"
msgstr "MX: Encryption of %s is not supported"
Expand Down
4 changes: 4 additions & 0 deletions locale/zh_CN/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ msgstr "CN: %s must be %s"
msgid "Found multiple %s partition labels"
msgstr "CN: Found multiple %s partition labels"

#, c-format
msgid "Found invalid %s partition label"
msgstr "CN: Found invalid %s partition label"

#, c-format
msgid "Encryption of %s is not supported"
msgstr "CN: Encryption of %s is not supported"
Expand Down
58 changes: 42 additions & 16 deletions storage/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,6 @@ func FindAdvancedInstallTargets(medias []*BlockDevice) []*BlockDevice {

for _, ch := range installBlockDevice.Children {
clrFound := false
clrMountFound := false
label := ch.PartitionLabel

if label != "" {
Expand All @@ -1424,19 +1423,6 @@ func FindAdvancedInstallTargets(medias []*BlockDevice) []*BlockDevice {

for _, part := range strings.Split(label, "_") {
lowerPart := strings.ToLower(part)
if clrMountFound {
log.Debug("AdvancedPartitioning: Extra mount %q for %s", part, ch.Name)
ch.MountPoint = part
if ch.FsType == "" {
log.Debug("AdvancedPartitioning: No FsType set for %s, defaulting to %s", ch.Name, defaultFsType)
ch.FsType = defaultFsType
log.Debug("AdvancedPartitioning: Forcing Format partition %s enabled", ch.Name)
ch.FormatPartition = true
}
clrAdded = true
clrMountFound = false
continue
}

if !clrFound {
if lowerPart == "clr" {
Expand Down Expand Up @@ -1481,8 +1467,23 @@ func FindAdvancedInstallTargets(medias []*BlockDevice) []*BlockDevice {
ch.FormatPartition = true
}
case "mnt":
clrMountFound = true
log.Debug("FindAdvancedInstallTargets: Extra mount found %s", ch.Name)
mntParts := strings.Split(label, "MNT_")
if len(mntParts) == 2 {
path := filepath.Clean(mntParts[1])
if filepath.IsAbs(path) {
log.Debug("AdvancedPartitioning: Extra mount %q for %s", path, ch.Name)

ch.MountPoint = path
if ch.FsType == "" {
log.Debug("AdvancedPartitioning: No FsType set for %s, defaulting to %s", ch.Name, defaultFsType)
ch.FsType = defaultFsType
log.Debug("AdvancedPartitioning: Forcing Format partition %s enabled", ch.Name)
ch.FormatPartition = true
}
clrAdded = true
}
}
break
case "e":
if ch.MountPoint == "/boot" {
log.Warning("AdvancedPartitioning: /boot can no be encrypted, skipping")
Expand Down Expand Up @@ -1634,6 +1635,31 @@ func validateAdvancedPartitions(rootSize uint64, medias []*BlockDevice) []string
results = append(results, warning)
log.Warning("validateAdvancedPartitions: %s %+v", warning, ch)
}
case "mnt":
failed := false
warning := utils.Locale.Get("Found invalid %s partition label", label)

mntParts := strings.Split(label, "MNT_")
if len(mntParts) != 2 {
failed = true
log.Warning("validateAdvancedPartitions: %s %+v (%s)", warning, ch, "too many parts")
}

if !strings.HasPrefix(mntParts[1], "/") {
failed = true
log.Warning("validateAdvancedPartitions: %s %+v (%s)", warning, ch, "must start with '/'")
}

path := filepath.Clean(mntParts[1])
if !filepath.IsAbs(path) {
failed = true
log.Warning("validateAdvancedPartitions: %s %+v (%s)", warning, ch, "must be an absolute path")
}

if failed {
results = append(results, warning)
}
break
case "e":
if strings.HasPrefix(strings.ToLower(ch.PartitionLabel), "clr_boot") {
warning := utils.Locale.Get("Encryption of %s is not supported", "CLR_BOOT")
Expand Down

0 comments on commit 7529a26

Please sign in to comment.