mirror of https://github.com/golang/go.git
os/user: Current support on Plan 9
Current for Plan 9 is implemented with /dev/user for Uid/Gid/Username/Name, and $home environment variable for HomeDir. Implementing Lookup/LookupId is not done, which would require parsing /adm/users. It is unclear of how much benefit this would be. R=golang-dev CC=bradfitz, golang-dev, r https://golang.org/cl/13203043
This commit is contained in:
parent
534c67abc4
commit
de8de8912e
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2013 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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// Partial os/user support on Plan 9.
|
||||
// Supports Current(), but not Lookup()/LookupId().
|
||||
// The latter two would require parsing /adm/users.
|
||||
const (
|
||||
userFile = "/dev/user"
|
||||
)
|
||||
|
||||
func current() (*User, error) {
|
||||
ubytes, err := ioutil.ReadFile(userFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("user: %s", err)
|
||||
}
|
||||
|
||||
uname := string(ubytes)
|
||||
|
||||
u := &User{
|
||||
Uid: uname,
|
||||
Gid: uname,
|
||||
Username: uname,
|
||||
Name: uname,
|
||||
HomeDir: os.Getenv("home"),
|
||||
}
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func lookup(username string) (*User, error) {
|
||||
return nil, syscall.EPLAN9
|
||||
}
|
||||
|
||||
func lookupId(uid string) (*User, error) {
|
||||
return nil, syscall.EPLAN9
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !cgo,!windows
|
||||
// +build !cgo,!windows,!plan9
|
||||
|
||||
package user
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ var implemented = true // set to false by lookup_stubs.go's init
|
|||
// On posix systems Uid and Gid contain a decimal number
|
||||
// representing uid and gid. On windows Uid and Gid
|
||||
// contain security identifier (SID) in a string format.
|
||||
// On Plan 9, Uid, Gid, Username, and Name will be the
|
||||
// contents of /dev/user.
|
||||
type User struct {
|
||||
Uid string // user id
|
||||
Gid string // primary group id
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func check(t *testing.T) {
|
|||
t.Skip("user: not implemented; skipping tests")
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "linux", "freebsd", "darwin", "windows":
|
||||
case "linux", "freebsd", "darwin", "windows", "plan9":
|
||||
// test supported
|
||||
default:
|
||||
t.Skipf("user: Lookup not implemented on %q; skipping test", runtime.GOOS)
|
||||
|
|
@ -61,6 +61,10 @@ func compare(t *testing.T, want, got *User) {
|
|||
func TestLookup(t *testing.T) {
|
||||
check(t)
|
||||
|
||||
if runtime.GOOS == "plan9" {
|
||||
t.Skipf("Lookup not implemented on %q", runtime.GOOS)
|
||||
}
|
||||
|
||||
want, err := Current()
|
||||
if err != nil {
|
||||
t.Fatalf("Current: %v", err)
|
||||
|
|
@ -75,6 +79,10 @@ func TestLookup(t *testing.T) {
|
|||
func TestLookupId(t *testing.T) {
|
||||
check(t)
|
||||
|
||||
if runtime.GOOS == "plan9" {
|
||||
t.Skipf("LookupId not implemented on %q", runtime.GOOS)
|
||||
}
|
||||
|
||||
want, err := Current()
|
||||
if err != nil {
|
||||
t.Fatalf("Current: %v", err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue