// Returns the User struct for a particular login name. func FindUser(name string) ([]User, error) { pwent, err := C.getpwnam(C.CString(name)) if pwent == nil { return []User{}, err } return []User{pwentToUser(pwent)}, nil }
// Getpwnam searches the user database for an entry with a matching name. func Getpwnam(name string) *Passwd { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) cpw := C.getpwnam(cname) if cpw == nil { return nil } return cpasswd2go(cpw) }
func Getpwnam(name string) *Passwd { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) cpw := C.getpwnam(cname) return &Passwd{ Uid: uint32(cpw.pw_uid), Gid: uint32(cpw.pw_gid), Dir: C.GoString(cpw.pw_dir), Shell: C.GoString(cpw.pw_shell), } }
func DropPrivileges(name string) { cname := C.CString(name) home := C.CString("HOME") slash := C.CString("/") defer C.cfree(unsafe.Pointer(home)) defer C.cfree(unsafe.Pointer(cname)) defer C.cfree(unsafe.Pointer(slash)) cpw := C.getpwnam(cname) C.setgid(cpw.pw_gid) C.setuid(cpw.pw_uid) C.setenv(home, cpw.pw_dir, 1) C.setsid() C.chdir(slash) C.umask(022) }