mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-17 19:22:04 -04:00
core: add privesc package for privilege escalation
- Adds support for run0 and doas fixes #998
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/deps"
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/privesc"
|
||||
)
|
||||
|
||||
var GentooGlobalUseFlags = []string{
|
||||
@@ -201,9 +202,9 @@ func (g *GentooDistribution) setGlobalUseFlags(ctx context.Context, sudoPassword
|
||||
|
||||
var cmd *exec.Cmd
|
||||
if hasUse {
|
||||
cmd = ExecSudoCommand(ctx, sudoPassword, fmt.Sprintf("sed -i 's/^USE=\"\\(.*\\)\"/USE=\"\\1 %s\"/' /etc/portage/make.conf", useFlags))
|
||||
cmd = privesc.ExecCommand(ctx, sudoPassword, fmt.Sprintf("sed -i 's/^USE=\"\\(.*\\)\"/USE=\"\\1 %s\"/' /etc/portage/make.conf", useFlags))
|
||||
} else {
|
||||
cmd = ExecSudoCommand(ctx, sudoPassword, fmt.Sprintf("bash -c \"echo 'USE=\\\"%s\\\"' >> /etc/portage/make.conf\"", useFlags))
|
||||
cmd = privesc.ExecCommand(ctx, sudoPassword, fmt.Sprintf("bash -c \"echo 'USE=\\\"%s\\\"' >> /etc/portage/make.conf\"", useFlags))
|
||||
}
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
@@ -281,7 +282,7 @@ func (g *GentooDistribution) InstallPrerequisites(ctx context.Context, sudoPassw
|
||||
LogOutput: "Syncing Portage tree with emerge --sync",
|
||||
}
|
||||
|
||||
syncCmd := ExecSudoCommand(ctx, sudoPassword, "emerge --sync --quiet")
|
||||
syncCmd := privesc.ExecCommand(ctx, sudoPassword, "emerge --sync --quiet")
|
||||
syncOutput, syncErr := syncCmd.CombinedOutput()
|
||||
if syncErr != nil {
|
||||
g.log(fmt.Sprintf("emerge --sync output: %s", string(syncOutput)))
|
||||
@@ -302,7 +303,7 @@ func (g *GentooDistribution) InstallPrerequisites(ctx context.Context, sudoPassw
|
||||
|
||||
args := []string{"emerge", "--ask=n", "--quiet"}
|
||||
args = append(args, missingPkgs...)
|
||||
cmd := ExecSudoCommand(ctx, sudoPassword, strings.Join(args, " "))
|
||||
cmd := privesc.ExecCommand(ctx, sudoPassword, strings.Join(args, " "))
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
g.logError("failed to install prerequisites", err)
|
||||
@@ -503,14 +504,14 @@ func (g *GentooDistribution) installPortagePackages(ctx context.Context, package
|
||||
CommandInfo: fmt.Sprintf("sudo %s", strings.Join(args, " ")),
|
||||
}
|
||||
|
||||
cmd := ExecSudoCommand(ctx, sudoPassword, strings.Join(args, " "))
|
||||
cmd := privesc.ExecCommand(ctx, sudoPassword, strings.Join(args, " "))
|
||||
return g.runWithProgressTimeout(cmd, progressChan, PhaseSystemPackages, 0.40, 0.60, 0)
|
||||
}
|
||||
|
||||
func (g *GentooDistribution) setPackageUseFlags(ctx context.Context, packageName, useFlags, sudoPassword string) error {
|
||||
packageUseDir := "/etc/portage/package.use"
|
||||
|
||||
mkdirCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
mkdirCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
fmt.Sprintf("mkdir -p %s", packageUseDir))
|
||||
if output, err := mkdirCmd.CombinedOutput(); err != nil {
|
||||
g.log(fmt.Sprintf("mkdir output: %s", string(output)))
|
||||
@@ -524,7 +525,7 @@ func (g *GentooDistribution) setPackageUseFlags(ctx context.Context, packageName
|
||||
if checkExistingCmd.Run() == nil {
|
||||
g.log(fmt.Sprintf("Updating USE flags for %s from existing entry", packageName))
|
||||
escapedPkg := strings.ReplaceAll(packageName, "/", "\\/")
|
||||
replaceCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
replaceCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
fmt.Sprintf("sed -i '/^%s /d' %s/danklinux; exit_code=$?; exit $exit_code", escapedPkg, packageUseDir))
|
||||
if output, err := replaceCmd.CombinedOutput(); err != nil {
|
||||
g.log(fmt.Sprintf("sed delete output: %s", string(output)))
|
||||
@@ -532,7 +533,7 @@ func (g *GentooDistribution) setPackageUseFlags(ctx context.Context, packageName
|
||||
}
|
||||
}
|
||||
|
||||
appendCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
appendCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
fmt.Sprintf("bash -c \"echo '%s' >> %s/danklinux\"", useFlagLine, packageUseDir))
|
||||
|
||||
output, err := appendCmd.CombinedOutput()
|
||||
@@ -557,7 +558,7 @@ func (g *GentooDistribution) syncGURURepo(ctx context.Context, sudoPassword stri
|
||||
}
|
||||
|
||||
// Enable GURU repository
|
||||
enableCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
enableCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
"eselect repository enable guru 2>&1; exit_code=$?; exit $exit_code")
|
||||
output, err := enableCmd.CombinedOutput()
|
||||
|
||||
@@ -589,7 +590,7 @@ func (g *GentooDistribution) syncGURURepo(ctx context.Context, sudoPassword stri
|
||||
LogOutput: "Syncing GURU repository",
|
||||
}
|
||||
|
||||
syncCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
syncCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
"emaint sync --repo guru 2>&1; exit_code=$?; exit $exit_code")
|
||||
syncOutput, syncErr := syncCmd.CombinedOutput()
|
||||
|
||||
@@ -622,7 +623,7 @@ func (g *GentooDistribution) setPackageAcceptKeywords(ctx context.Context, packa
|
||||
|
||||
acceptKeywordsDir := "/etc/portage/package.accept_keywords"
|
||||
|
||||
mkdirCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
mkdirCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
fmt.Sprintf("mkdir -p %s", acceptKeywordsDir))
|
||||
if output, err := mkdirCmd.CombinedOutput(); err != nil {
|
||||
g.log(fmt.Sprintf("mkdir output: %s", string(output)))
|
||||
@@ -636,7 +637,7 @@ func (g *GentooDistribution) setPackageAcceptKeywords(ctx context.Context, packa
|
||||
if checkExistingCmd.Run() == nil {
|
||||
g.log(fmt.Sprintf("Updating accept keywords for %s from existing entry", packageName))
|
||||
escapedPkg := strings.ReplaceAll(packageName, "/", "\\/")
|
||||
replaceCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
replaceCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
fmt.Sprintf("sed -i '/^%s /d' %s/danklinux; exit_code=$?; exit $exit_code", escapedPkg, acceptKeywordsDir))
|
||||
if output, err := replaceCmd.CombinedOutput(); err != nil {
|
||||
g.log(fmt.Sprintf("sed delete output: %s", string(output)))
|
||||
@@ -644,7 +645,7 @@ func (g *GentooDistribution) setPackageAcceptKeywords(ctx context.Context, packa
|
||||
}
|
||||
}
|
||||
|
||||
appendCmd := ExecSudoCommand(ctx, sudoPassword,
|
||||
appendCmd := privesc.ExecCommand(ctx, sudoPassword,
|
||||
fmt.Sprintf("bash -c \"echo '%s' >> %s/danklinux\"", keywordLine, acceptKeywordsDir))
|
||||
|
||||
output, err := appendCmd.CombinedOutput()
|
||||
@@ -695,6 +696,6 @@ func (g *GentooDistribution) installGURUPackages(ctx context.Context, packages [
|
||||
CommandInfo: fmt.Sprintf("sudo %s", strings.Join(args, " ")),
|
||||
}
|
||||
|
||||
cmd := ExecSudoCommand(ctx, sudoPassword, strings.Join(args, " "))
|
||||
cmd := privesc.ExecCommand(ctx, sudoPassword, strings.Join(args, " "))
|
||||
return g.runWithProgressTimeout(cmd, progressChan, PhaseAURPackages, 0.70, 0.85, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user