Permalink
Browse files

updates for Go 1

  • Loading branch information...
1 parent 36cc8fd commit eb1d96ed198583feeaf82efb10ab9a6d979b324f @bradfitz committed Dec 22, 2011
Showing with 19 additions and 36 deletions.
  1. +1 −1 example.go
  2. +0 −22 runas/Makefile
  3. +18 −13 runas/runas.go
View
2 example.go
@@ -49,6 +49,6 @@ func main() {
continue
}
client.Call("DemoService.WhoAmI", true, &res)
- log.Printf("user %s: %v", user, res)
+ log.Printf("for runas user %s, got: %#v", user, res)
}
}
View
22 runas/Makefile
@@ -1,22 +0,0 @@
-# Copyright 2011 Google Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(GOROOT)/src/Make.inc
-
-TARG=github.com/bradfitz/go-runas/runas
-GOFILES=runas.go
-
-include $(GOROOT)/src/Make.pkg
-
-
View
31 runas/runas.go
@@ -84,17 +84,22 @@ func UidGid(uid, gid int) (*rpc.Client, error) {
panic("runas.MaybeRunChildServer() never called")
}
binary, _ := filepath.Abs(os.Args[0])
- cmd, err := exec.Run(binary,
- []string{os.Args[0]},
- []string{"BECOME_GO_RUNAS_CHILD=1"},
- "/",
- exec.Pipe,
- exec.Pipe,
- exec.DevNull)
+ cmd := exec.Command(binary)
+ cmd.Dir = "/"
+ cmd.Env = []string{"BECOME_GO_RUNAS_CHILD=1"}
+ stdout, err := cmd.StdoutPipe()
+ if err != nil {
+ panic(err)
+ }
+ stdin, err := cmd.StdinPipe()
+ if err != nil {
+ panic(err)
+ }
+ err = cmd.Start()
if err != nil {
panic(err.Error())
}
- c := rpc.NewClient(&splitReadWrite{cmd.Stdout, cmd.Stdin})
+ c := rpc.NewClient(&splitReadWrite{stdout, stdin})
// These are embedded in structs and named with a capital R to make
// reflect & rpc happy. That way we don't have to export them
@@ -119,17 +124,17 @@ type internalDropArg struct {
type internalDropResult struct {
UidDropped, GidDropped bool
- SetuidErrno, SetgidErrno int
+ SetuidErrno, SetgidErrno uintptr
}
func (s *internalService) DropPrivileges(arg *struct{ R internalDropArg }, result *struct{ R internalDropResult }) error {
- if rv := syscall.Setgid(arg.R.Gid); rv != 0 {
- result.R.SetgidErrno = rv
+ if rv := syscall.Setgid(arg.R.Gid); rv != nil {
+ result.R.SetgidErrno = uintptr(rv.(syscall.Errno))
} else {
result.R.GidDropped = true
}
- if rv := syscall.Setuid(arg.R.Uid); rv != 0 {
- result.R.SetuidErrno = rv
+ if rv := syscall.Setuid(arg.R.Uid); rv != nil {
+ result.R.SetuidErrno = uintptr(rv.(syscall.Errno))
} else {
result.R.UidDropped = true
}

0 comments on commit eb1d96e

Please sign in to comment.