Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interp: set EUID #958

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [3.6.1] - 2023-??-??

- **interp**
- Set `EUID` just like `UID`

## [3.6.0] - 2022-12-11

This release drops support for Go 1.17 and includes many features and fixes.
Expand Down
7 changes: 7 additions & 0 deletions interp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,13 @@ func (r *Runner) Reset() {
Str: strconv.Itoa(os.Getuid()),
})
}
if !r.writeEnv.Get("EUID").IsSet() {
r.setVar("EUID", nil, expand.Variable{
Kind: expand.String,
ReadOnly: true,
Str: strconv.Itoa(os.Geteuid()),
})
}
if !r.writeEnv.Get("GID").IsSet() {
r.setVar("GID", nil, expand.Variable{
Kind: expand.String,
Expand Down
12 changes: 12 additions & 0 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,18 @@ var runTestsUnix = []runTest{
`unset UID`,
"UID: readonly variable\n #IGNORE",
},
{
`test -n "$EUID" && echo OK`,
"OK\n",
},
{
`set EUID=newvalue; test EUID != newvalue && echo OK || echo EUID=$EUID`,
"OK\n",
},
{
`unset EUID`,
"EUID: readonly variable\n #IGNORE",
},
// GID is not set in bash
{
`unset GID`,
Expand Down