forked from getsops/sops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exec-file and exec-env subcommands, take two (getsops#532)
* first pass: add --exec flag * fix spacing * subcommand for exec as well as other bits n bobs --placeholder to pass files to child procs (similar to `find(1)`'s -exec flag) --background to background processes if you don't need them to be interactive * break the 2 execs into 2 subcommands * add a non-fifo option for people who like files instead * added a setuid flag just in case * oups, used the wrong functions * Update README.rst * typo * first attempt at separating out windows/unix functionality * add the caveat about windows * windows: make sure --no-fifo is being used and warn when it's not * stray fixes * switch to logrus, break out the command builder, and remove /tmp/ default
- Loading branch information
Showing
4 changed files
with
114 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// +build !windows | ||
|
||
package exec | ||
|
||
import ( | ||
"syscall" | ||
"path/filepath" | ||
"os" | ||
"os/user" | ||
"os/exec" | ||
"strconv" | ||
) | ||
|
||
func BuildCommand(command string) *exec.Cmd { | ||
return exec.Command("/bin/sh", "-c", command) | ||
} | ||
|
||
func WritePipe(pipe string, contents []byte) { | ||
handle, err := os.OpenFile(pipe, os.O_WRONLY, 0600) | ||
|
||
if err != nil { | ||
os.Remove(pipe) | ||
log.Fatal(err) | ||
} | ||
|
||
handle.Write(contents) | ||
handle.Close() | ||
} | ||
|
||
func GetPipe(dir string) string { | ||
tmpfn := filepath.Join(dir, "tmp-file") | ||
err := syscall.Mkfifo(tmpfn, 0600) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return tmpfn | ||
} | ||
|
||
func SwitchUser(username string) { | ||
user, err := user.Lookup(username) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
uid, _ := strconv.Atoi(user.Uid) | ||
|
||
err = syscall.Setgid(uid) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = syscall.Setuid(uid) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = syscall.Setreuid(uid, uid) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = syscall.Setregid(uid, uid) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package exec | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
func BuildCommand(command string) *exec.Cmd { | ||
return exec.Command("cmd.exe", "/C", command) | ||
} | ||
|
||
func WritePipe(pipe string, contents []byte) { | ||
log.Fatal("fifos are not available on windows") | ||
} | ||
|
||
func GetPipe(dir string) string { | ||
log.Fatal("fifos are not available on windows") | ||
return "" | ||
} | ||
|
||
func SwitchUser(username string) { | ||
log.Fatal("user switching not available on windows") | ||
} |