1 Star 0 Fork 0

zhangjungang/beats

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
droppriv_unix.go 705 Bytes
Copy Edit Raw Blame History
// +build !windows
package droppriv
import (
"errors"
"fmt"
"syscall"
"github.com/elastic/beats/libbeat/logp"
)
type RunOptions struct {
UID *int
GID *int
}
func DropPrivileges(config RunOptions) error {
var err error
if config.UID == nil {
// not found, no dropping privileges but no err
return nil
}
if config.GID == nil {
return errors.New("GID must be specified for dropping privileges")
}
logp.Info("Switching to user: %d.%d", *config.UID, *config.GID)
if err = syscall.Setgid(*config.GID); err != nil {
return fmt.Errorf("setgid: %s", err.Error())
}
if err = syscall.Setuid(*config.UID); err != nil {
return fmt.Errorf("setuid: %s", err.Error())
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.3.0

Search