]> Cypherpunks repositories - gostls13.git/commitdiff
os/user: Current support on Plan 9
authorNicolas Owens <mischief@offblast.org>
Sat, 24 Aug 2013 02:05:49 +0000 (21:05 -0500)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 24 Aug 2013 02:05:49 +0000 (21:05 -0500)
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

src/pkg/os/user/lookup_plan9.go [new file with mode: 0644]
src/pkg/os/user/lookup_stubs.go
src/pkg/os/user/user.go
src/pkg/os/user/user_test.go

diff --git a/src/pkg/os/user/lookup_plan9.go b/src/pkg/os/user/lookup_plan9.go
new file mode 100644 (file)
index 0000000..f7ef348
--- /dev/null
@@ -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
+}
index ad06907b5d57760a5deab8a0944bdc911145be8b..86f0e6e645ae64ee61cf6065fac5263a76798f9d 100644 (file)
@@ -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
 
index 841f2263f95f9819fef4c172c98a2d7cbfc63538..e8680fe5465541ab5ab205ac4db9ad57d419c056 100644 (file)
@@ -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
index 444a9aacd47cdc557b2aef1c612903c377ea249c..0421894bac6b75061de9b5d608a48cde86ecb3ff 100644 (file)
@@ -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)