About
The setcred module provides a Go interface for the
setcred(2) system
call on FreeBSD.
Examples
setcred
The setcred(2)
documentation provides a good introduction.
The system call either requires superuser privileges, or a mac policy
similar to mac_do(4)
that enables unprivileged users to execute the setcred(2)
system call successfully.
The following example assumes it is being run with superuser privileges,
and when successful it changes the effective user ID and effective group
ID from 0 (root/wheel) to 1001 (an unprivileged user and group) and keep
in mind that setcred(2) is
capable of changing other credentials as well:
package main
import (
"fmt"
"os"
"github.com/0x1eef/setcred"
)
func main() {
err := setcred.SetCred(
setcred.SetUid(1001),
setcred.SetGid(1001),
)
if err != nil {
panic(err)
} else {
fmt.Printf("euid: %d, egid: %d\n", os.Geteuid(), os.Getegid())
}
}
Install
The install process is more or less straight forward
go get github.com/0x1eef/[email protected]
Sources
License
BSD Zero Clause
See LICENSE