mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-18 21:46:19 -04:00
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
37 lines
819 B
Go
37 lines
819 B
Go
//go:build !windows
|
|
|
|
package sysutil
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
"github.com/gookit/goutil/strutil"
|
|
)
|
|
|
|
// ChangeUserByName change work user by new username.
|
|
func ChangeUserByName(newUname string) error {
|
|
u := MustFindUser(newUname)
|
|
// syscall.Setlogin(newUname)
|
|
return ChangeUserUIDGid(strutil.IntOrPanic(u.Uid), strutil.IntOrPanic(u.Gid))
|
|
}
|
|
|
|
// ChangeUserUidGid change work user by new username uid,gid
|
|
//
|
|
// Deprecated: use ChangeUserUIDGid instead
|
|
func ChangeUserUidGid(newUID int, newGid int) error {
|
|
return ChangeUserUIDGid(newUID, newGid)
|
|
}
|
|
|
|
// ChangeUserUIDGid change work user by new username uid,gid
|
|
func ChangeUserUIDGid(newUID int, newGid int) (err error) {
|
|
if newUID > 0 {
|
|
err = syscall.Setuid(newUID)
|
|
|
|
// update group id
|
|
if err == nil && newGid > 0 {
|
|
err = syscall.Setgid(newGid)
|
|
}
|
|
}
|
|
return
|
|
}
|