Files
opencloud/vendor/github.com/gookit/goutil/sysutil/user_nonwin.go
dependabot[bot] 5ebc596352 Bump github.com/gookit/config/v2 from 2.1.8 to 2.2.2
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.1.8 to 2.2.2.
- [Release notes](https://github.com/gookit/config/releases)
- [Commits](https://github.com/gookit/config/compare/v2.1.8...v2.2.2)

---
updated-dependencies:
- dependency-name: github.com/gookit/config/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-13 10:54:58 +02:00

33 lines
640 B
Go

//go:build !windows
// +build !windows
package sysutil
import (
"syscall"
"github.com/gookit/goutil/strutil"
)
// ChangeUserByName change work user by new username.
func ChangeUserByName(newUname string) (err 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
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
}