This commit is contained in:
2025-04-15 10:34:07 +03:00
parent 35982a0ae7
commit 6df5baa457
10 changed files with 63 additions and 55 deletions

View File

@ -70,9 +70,13 @@ func DropCapsToAlrUser() error {
if err != nil {
return err
}
return EnuseIsAlrUser()
return EnsureIsAlrUser()
}
// ExitIfCantDropCapsToAlrUser attempts to drop capabilities to the already
// running user. Returns a cli.ExitCoder with an error if the operation fails.
// See also [ExitIfCantDropCapsToAlrUserNoPrivs] for a version that also applies
// no-new-privs.
func ExitIfCantDropCapsToAlrUser() cli.ExitCoder {
err := DropCapsToAlrUser()
if err != nil {
@ -81,6 +85,19 @@ func ExitIfCantDropCapsToAlrUser() cli.ExitCoder {
return nil
}
// ExitIfCantDropCapsToAlrUserNoPrivs combines [ExitIfCantDropCapsToAlrUser] with [NoNewPrivs]
func ExitIfCantDropCapsToAlrUserNoPrivs() cli.ExitCoder {
if err := ExitIfCantDropCapsToAlrUser(); err != nil {
return err
}
if err := NoNewPrivs(); err != nil {
return cliutils.FormatCliExit("error no new privs", err)
}
return nil
}
func ExitIfNotRoot() error {
if os.Getuid() != 0 {
return cli.Exit(gotext.Get("You need to be root to perform this action"), 1)
@ -88,7 +105,7 @@ func ExitIfNotRoot() error {
return nil
}
func EnuseIsAlrUser() error {
func EnsureIsAlrUser() error {
uid, gid, err := GetUidGidAlrUser()
if err != nil {
return err