From 178c8578d5794aee6b111c6831e9a04e8a9d51ae Mon Sep 17 00:00:00 2001 From: Anthony Martin Date: Mon, 26 Nov 2012 16:02:08 -0800 Subject: [PATCH] os/user: update stub documentation R=golang-dev, minux.ma, bradfitz CC=golang-dev https://golang.org/cl/6844088 --- src/pkg/os/user/lookup.go | 22 ++++++++++++++++++++++ src/pkg/os/user/lookup_stubs.go | 6 +++--- src/pkg/os/user/lookup_unix.go | 19 +++++++------------ src/pkg/os/user/lookup_windows.go | 9 +++------ 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 src/pkg/os/user/lookup.go diff --git a/src/pkg/os/user/lookup.go b/src/pkg/os/user/lookup.go new file mode 100644 index 0000000000..09f00c7bdb --- /dev/null +++ b/src/pkg/os/user/lookup.go @@ -0,0 +1,22 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package user + +// Current returns the current user. +func Current() (*User, error) { + return current() +} + +// Lookup looks up a user by username. If the user cannot be found, the +// returned error is of type UnknownUserError. +func Lookup(username string) (*User, error) { + return lookup(username) +} + +// LookupId looks up a user by userid. If the user cannot be found, the +// returned error is of type UnknownUserIdError. +func LookupId(uid string) (*User, error) { + return lookupId(uid) +} diff --git a/src/pkg/os/user/lookup_stubs.go b/src/pkg/os/user/lookup_stubs.go index 415f869f22..ad06907b5d 100644 --- a/src/pkg/os/user/lookup_stubs.go +++ b/src/pkg/os/user/lookup_stubs.go @@ -15,14 +15,14 @@ func init() { implemented = false } -func Current() (*User, error) { +func current() (*User, error) { return nil, fmt.Errorf("user: Current not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) } -func Lookup(username string) (*User, error) { +func lookup(username string) (*User, error) { return nil, fmt.Errorf("user: Lookup not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) } -func LookupId(string) (*User, error) { +func lookupId(uid string) (*User, error) { return nil, fmt.Errorf("user: LookupId not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) } diff --git a/src/pkg/os/user/lookup_unix.go b/src/pkg/os/user/lookup_unix.go index 1102e5bb1b..05c34b66e6 100644 --- a/src/pkg/os/user/lookup_unix.go +++ b/src/pkg/os/user/lookup_unix.go @@ -29,28 +29,23 @@ static int mygetpwuid_r(int uid, struct passwd *pwd, */ import "C" -// Current returns the current user. -func Current() (*User, error) { - return lookup(syscall.Getuid(), "", false) +func current() (*User, error) { + return lookupUnix(syscall.Getuid(), "", false) } -// Lookup looks up a user by username. If the user cannot be found, -// the returned error is of type UnknownUserError. -func Lookup(username string) (*User, error) { - return lookup(-1, username, true) +func lookup(username string) (*User, error) { + return lookupUnix(-1, username, true) } -// LookupId looks up a user by userid. If the user cannot be found, -// the returned error is of type UnknownUserIdError. -func LookupId(uid string) (*User, error) { +func lookupId(uid string) (*User, error) { i, e := strconv.Atoi(uid) if e != nil { return nil, e } - return lookup(i, "", false) + return lookupUnix(i, "", false) } -func lookup(uid int, username string, lookupByName bool) (*User, error) { +func lookupUnix(uid int, username string, lookupByName bool) (*User, error) { var pwd C.struct_passwd var result *C.struct_passwd diff --git a/src/pkg/os/user/lookup_windows.go b/src/pkg/os/user/lookup_windows.go index 3626a4e9f0..a0a8a4ec10 100644 --- a/src/pkg/os/user/lookup_windows.go +++ b/src/pkg/os/user/lookup_windows.go @@ -68,8 +68,7 @@ func newUser(usid *syscall.SID, gid, dir string) (*User, error) { return u, nil } -// Current returns the current user. -func Current() (*User, error) { +func current() (*User, error) { t, e := syscall.OpenCurrentProcessToken() if e != nil { return nil, e @@ -103,8 +102,7 @@ func newUserFromSid(usid *syscall.SID) (*User, error) { return newUser(usid, gid, dir) } -// Lookup looks up a user by username. -func Lookup(username string) (*User, error) { +func lookup(username string) (*User, error) { sid, _, t, e := syscall.LookupSID("", username) if e != nil { return nil, e @@ -115,8 +113,7 @@ func Lookup(username string) (*User, error) { return newUserFromSid(sid) } -// LookupId looks up a user by userid. -func LookupId(uid string) (*User, error) { +func lookupId(uid string) (*User, error) { sid, e := syscall.StringToSid(uid) if e != nil { return nil, e -- 2.48.1