-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLE12: revert "apparmor: remove version-conditionals from template"
This reverts the following commits: * 7008a51 ("profiles/apparmor: remove version-conditional constraints (< 2.8.96)") * 2e19a4d ("contrib/apparmor: remove version-conditionals (< 2.9) from template") * d169a57 ("contrib/apparmor: remove remaining version-conditionals (< 2.9) from template") * ecaab08 ("profiles/apparmor: remove use of aaparser.GetVersion()") * e3e7156 ("pkg/aaparser: deprecate GetVersion, as it's no longer used") These version conditionals are still required on SLE 12, where our apparmor_parser version is quite old. Signed-off-by: Aleksa Sarai <[email protected]>
- Loading branch information
Showing
5 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Package aaparser is a convenience package interacting with `apparmor_parser`. | ||
package aaparser // import "github.com/docker/docker/pkg/aaparser" | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
const ( | ||
binary = "apparmor_parser" | ||
) | ||
|
||
// GetVersion returns the major and minor version of apparmor_parser. | ||
func GetVersion() (int, error) { | ||
output, err := cmd("", "--version") | ||
if err != nil { | ||
return -1, err | ||
} | ||
|
||
return parseVersion(output) | ||
} | ||
|
||
// cmd runs `apparmor_parser` with the passed arguments. | ||
func cmd(dir string, arg ...string) (string, error) { | ||
c := exec.Command(binary, arg...) | ||
c.Dir = dir | ||
|
||
output, err := c.CombinedOutput() | ||
if err != nil { | ||
return "", fmt.Errorf("running `%s %s` failed with output: %s\nerror: %v", c.Path, strings.Join(c.Args, " "), output, err) | ||
} | ||
|
||
return string(output), nil | ||
} | ||
|
||
// parseVersion takes the output from `apparmor_parser --version` and returns | ||
// a representation of the {major, minor, patch} version as a single number of | ||
// the form MMmmPPP {major, minor, patch}. | ||
func parseVersion(output string) (int, error) { | ||
// output is in the form of the following: | ||
// AppArmor parser version 2.9.1 | ||
// Copyright (C) 1999-2008 Novell Inc. | ||
// Copyright 2009-2012 Canonical Ltd. | ||
|
||
lines := strings.SplitN(output, "\n", 2) | ||
words := strings.Split(lines[0], " ") | ||
version := words[len(words)-1] | ||
|
||
// trim "-beta1" suffix from version="3.0.0-beta1" if exists | ||
version = strings.SplitN(version, "-", 2)[0] | ||
// also trim "~..." suffix used historically (https://gitlab.com/apparmor/apparmor/-/commit/bca67d3d27d219d11ce8c9cc70612bd637f88c10) | ||
version = strings.SplitN(version, "~", 2)[0] | ||
|
||
// split by major minor version | ||
v := strings.Split(version, ".") | ||
if len(v) == 0 || len(v) > 3 { | ||
return -1, fmt.Errorf("parsing version failed for output: `%s`", output) | ||
} | ||
|
||
// Default the versions to 0. | ||
var majorVersion, minorVersion, patchLevel int | ||
|
||
majorVersion, err := strconv.Atoi(v[0]) | ||
if err != nil { | ||
return -1, err | ||
} | ||
|
||
if len(v) > 1 { | ||
minorVersion, err = strconv.Atoi(v[1]) | ||
if err != nil { | ||
return -1, err | ||
} | ||
} | ||
if len(v) > 2 { | ||
patchLevel, err = strconv.Atoi(v[2]) | ||
if err != nil { | ||
return -1, err | ||
} | ||
} | ||
|
||
// major*10^5 + minor*10^3 + patch*10^0 | ||
numericVersion := majorVersion*1e5 + minorVersion*1e3 + patchLevel | ||
return numericVersion, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters