Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
d41d6fec
Commit
d41d6fec
authored
Mar 29, 2011
by
Albert Strasheim
Committed by
Adam Langley
Mar 29, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
syscall: StartProcess Chroot and Credential.
R=rsc, iant, agl1 CC=golang-dev
https://golang.org/cl/4280065
parent
07931764
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
7 deletions
+47
-7
src/pkg/syscall/exec_unix.go
src/pkg/syscall/exec_unix.go
+47
-7
No files found.
src/pkg/syscall/exec_unix.go
View file @
d41d6fec
...
@@ -96,7 +96,7 @@ func SetNonblock(fd int, nonblocking bool) (errno int) {
...
@@ -96,7 +96,7 @@ func SetNonblock(fd int, nonblocking bool) (errno int) {
// no rescheduling, no malloc calls, and no new stack segments.
// no rescheduling, no malloc calls, and no new stack segments.
// The calls to RawSyscall are okay because they are assembly
// The calls to RawSyscall are okay because they are assembly
// functions that do not grow the stack.
// functions that do not grow the stack.
func
forkAndExecInChild
(
argv0
*
byte
,
argv
,
envv
[]
*
byte
,
dir
*
byte
,
attr
*
ProcAttr
,
pipe
int
)
(
pid
int
,
err
int
)
{
func
forkAndExecInChild
(
argv0
*
byte
,
argv
,
envv
[]
*
byte
,
chroot
,
dir
*
byte
,
attr
*
ProcAttr
,
pipe
int
)
(
pid
int
,
err
int
)
{
// Declare all variables at top in case any
// Declare all variables at top in case any
// declarations require heap allocation (e.g., err1).
// declarations require heap allocation (e.g., err1).
var
r1
,
r2
,
err1
uintptr
var
r1
,
r2
,
err1
uintptr
...
@@ -146,6 +146,35 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, dir *byte, attr *ProcAt
...
@@ -146,6 +146,35 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, dir *byte, attr *ProcAt
}
}
}
}
// Chroot
if
chroot
!=
nil
{
_
,
_
,
err1
=
RawSyscall
(
SYS_CHROOT
,
uintptr
(
unsafe
.
Pointer
(
chroot
)),
0
,
0
)
if
err1
!=
0
{
goto
childerror
}
}
// User and groups
if
attr
.
Credential
!=
nil
{
ngroups
:=
uintptr
(
len
(
attr
.
Credential
.
Groups
))
groups
:=
uintptr
(
0
)
if
ngroups
>
0
{
groups
=
uintptr
(
unsafe
.
Pointer
(
&
attr
.
Credential
.
Groups
[
0
]))
}
_
,
_
,
err1
=
RawSyscall
(
SYS_SETGROUPS
,
ngroups
,
groups
,
0
)
if
err1
!=
0
{
goto
childerror
}
_
,
_
,
err1
=
RawSyscall
(
SYS_SETGID
,
uintptr
(
attr
.
Credential
.
Gid
),
0
,
0
)
if
err1
!=
0
{
goto
childerror
}
_
,
_
,
err1
=
RawSyscall
(
SYS_SETUID
,
uintptr
(
attr
.
Credential
.
Uid
),
0
,
0
)
if
err1
!=
0
{
goto
childerror
}
}
// Chdir
// Chdir
if
dir
!=
nil
{
if
dir
!=
nil
{
_
,
_
,
err1
=
RawSyscall
(
SYS_CHDIR
,
uintptr
(
unsafe
.
Pointer
(
dir
)),
0
,
0
)
_
,
_
,
err1
=
RawSyscall
(
SYS_CHDIR
,
uintptr
(
unsafe
.
Pointer
(
dir
)),
0
,
0
)
...
@@ -231,13 +260,20 @@ childerror:
...
@@ -231,13 +260,20 @@ childerror:
panic
(
"unreached"
)
panic
(
"unreached"
)
}
}
type
Credential
struct
{
Uid
uint32
// User ID.
Gid
uint32
// Group ID.
Groups
[]
uint32
// Supplementary group IDs.
}
type
ProcAttr
struct
{
type
ProcAttr
struct
{
Setsid
bool
// Create session.
Setsid
bool
// Create session.
Ptrace
bool
// Enable tracing.
Ptrace
bool
// Enable tracing.
Dir
string
// Current working directory.
Dir
string
// Current working directory.
Env
[]
string
// Environment.
Env
[]
string
// Environment.
Files
[]
int
// File descriptors.
Files
[]
int
// File descriptors.
Chroot
string
// Chroot.
Credential
*
Credential
// Credential.
}
}
var
zeroAttributes
ProcAttr
var
zeroAttributes
ProcAttr
...
@@ -264,6 +300,10 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
...
@@ -264,6 +300,10 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
argvp
[
0
]
=
argv0p
argvp
[
0
]
=
argv0p
}
}
var
chroot
*
byte
if
attr
.
Chroot
!=
""
{
chroot
=
StringBytePtr
(
attr
.
Chroot
)
}
var
dir
*
byte
var
dir
*
byte
if
attr
.
Dir
!=
""
{
if
attr
.
Dir
!=
""
{
dir
=
StringBytePtr
(
attr
.
Dir
)
dir
=
StringBytePtr
(
attr
.
Dir
)
...
@@ -286,7 +326,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
...
@@ -286,7 +326,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
}
}
// Kick off child.
// Kick off child.
pid
,
err
=
forkAndExecInChild
(
argv0p
,
argvp
,
envvp
,
dir
,
attr
,
p
[
1
])
pid
,
err
=
forkAndExecInChild
(
argv0p
,
argvp
,
envvp
,
chroot
,
dir
,
attr
,
p
[
1
])
if
err
!=
0
{
if
err
!=
0
{
error
:
error
:
if
p
[
0
]
>=
0
{
if
p
[
0
]
>=
0
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment