setcred

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2025 License: 0BSD Imports: 3 Imported by: 0

README

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

Documentation

Index

Constants

View Source
const (
	Version = "0.1.0"
)

Variables

This section is empty.

Functions

func SetCred

func SetCred(opts ...Option) error

Types

type Option

type Option func(*setcred, *uint)

func SetGid

func SetGid(gid uint32) Option

func SetMacLabel

func SetMacLabel(label string) Option

func SetRgid

func SetRgid(rgid uint32) Option

func SetRuid

func SetRuid(ruid uint32) Option

func SetSuppGroups

func SetSuppGroups(groups ...uint32) Option

func SetSvGid

func SetSvGid(svgid uint32) Option

func SetSvUid

func SetSvUid(svuid uint32) Option

func SetUid

func SetUid(uid uint32) Option

Directories

Path Synopsis
examples
setcred command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL