Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updates for Go 1

  • Loading branch information...
commit eb1d96ed198583feeaf82efb10ab9a6d979b324f 1 parent 36cc8fd
Brad Fitzpatrick authored

Showing 3 changed files with 19 additions and 36 deletions. Show diff stats Hide diff stats

  1. +1 1  example.go
  2. +0 22 runas/Makefile
  3. +18 13 runas/runas.go
2  example.go
@@ -49,6 +49,6 @@ func main() {
49 49 continue
50 50 }
51 51 client.Call("DemoService.WhoAmI", true, &res)
52   - log.Printf("user %s: %v", user, res)
  52 + log.Printf("for runas user %s, got: %#v", user, res)
53 53 }
54 54 }
22 runas/Makefile
... ... @@ -1,22 +0,0 @@
1   -# Copyright 2011 Google Inc.
2   -#
3   -# Licensed under the Apache License, Version 2.0 (the "License");
4   -# you may not use this file except in compliance with the License.
5   -# You may obtain a copy of the License at
6   -#
7   -# http://www.apache.org/licenses/LICENSE-2.0
8   -#
9   -# Unless required by applicable law or agreed to in writing, software
10   -# distributed under the License is distributed on an "AS IS" BASIS,
11   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   -# See the License for the specific language governing permissions and
13   -# limitations under the License.
14   -
15   -include $(GOROOT)/src/Make.inc
16   -
17   -TARG=github.com/bradfitz/go-runas/runas
18   -GOFILES=runas.go
19   -
20   -include $(GOROOT)/src/Make.pkg
21   -
22   -
31 runas/runas.go
@@ -84,17 +84,22 @@ func UidGid(uid, gid int) (*rpc.Client, error) {
84 84 panic("runas.MaybeRunChildServer() never called")
85 85 }
86 86 binary, _ := filepath.Abs(os.Args[0])
87   - cmd, err := exec.Run(binary,
88   - []string{os.Args[0]},
89   - []string{"BECOME_GO_RUNAS_CHILD=1"},
90   - "/",
91   - exec.Pipe,
92   - exec.Pipe,
93   - exec.DevNull)
  87 + cmd := exec.Command(binary)
  88 + cmd.Dir = "/"
  89 + cmd.Env = []string{"BECOME_GO_RUNAS_CHILD=1"}
  90 + stdout, err := cmd.StdoutPipe()
  91 + if err != nil {
  92 + panic(err)
  93 + }
  94 + stdin, err := cmd.StdinPipe()
  95 + if err != nil {
  96 + panic(err)
  97 + }
  98 + err = cmd.Start()
94 99 if err != nil {
95 100 panic(err.Error())
96 101 }
97   - c := rpc.NewClient(&splitReadWrite{cmd.Stdout, cmd.Stdin})
  102 + c := rpc.NewClient(&splitReadWrite{stdout, stdin})
98 103
99 104 // These are embedded in structs and named with a capital R to make
100 105 // reflect & rpc happy. That way we don't have to export them
@@ -119,17 +124,17 @@ type internalDropArg struct {
119 124
120 125 type internalDropResult struct {
121 126 UidDropped, GidDropped bool
122   - SetuidErrno, SetgidErrno int
  127 + SetuidErrno, SetgidErrno uintptr
123 128 }
124 129
125 130 func (s *internalService) DropPrivileges(arg *struct{ R internalDropArg }, result *struct{ R internalDropResult }) error {
126   - if rv := syscall.Setgid(arg.R.Gid); rv != 0 {
127   - result.R.SetgidErrno = rv
  131 + if rv := syscall.Setgid(arg.R.Gid); rv != nil {
  132 + result.R.SetgidErrno = uintptr(rv.(syscall.Errno))
128 133 } else {
129 134 result.R.GidDropped = true
130 135 }
131   - if rv := syscall.Setuid(arg.R.Uid); rv != 0 {
132   - result.R.SetuidErrno = rv
  136 + if rv := syscall.Setuid(arg.R.Uid); rv != nil {
  137 + result.R.SetuidErrno = uintptr(rv.(syscall.Errno))
133 138 } else {
134 139 result.R.UidDropped = true
135 140 }

0 comments on commit eb1d96e

Please sign in to comment.
Something went wrong with that request. Please try again.