Skip to content

Commit

Permalink
pam/integration-tests/exec: Use a file to pass very long arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
3v1n0 committed Sep 26, 2024
1 parent e7aaa58 commit 1f50dd1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pam/integration-tests/cmd/exec-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"reflect"
"regexp"
"strings"

"github.com/godbus/dbus/v5"
"github.com/msteinert/pam/v2"
Expand All @@ -23,6 +24,7 @@ var (
pamFlags = flag.Int64("flags", 0, "pam flags")
serverAddress = flag.String("server-address", "", "the dbus connection address to use to communicate with module")
logFile = flag.String("client-log", "", "the file where to save logs")
argsFile = flag.String("client-args-file", "", "the file where arguments are saved")
)

func main() {
Expand Down Expand Up @@ -78,6 +80,15 @@ func mainFunc() error {
log.SetOutput(f)
}

if argsFile != nil && *argsFile != "" {
log.Debug(context.TODO(), "Reading arguments from %s", *argsFile)
ca, err := os.ReadFile(*argsFile)
if err != nil {
return err
}
args = append(args, strings.Split(string(ca), "\t")...)
}

actionFlags := pam.Flags(0)
if pamFlags != nil {
actionFlags = pam.Flags(*pamFlags)
Expand Down
11 changes: 11 additions & 0 deletions pam/integration-tests/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,17 @@ func getModuleArgs(t *testing.T, clientPath string, args []string) []string {
if clientPath != "" {
moduleArgs = append(moduleArgs, "--", clientPath)
moduleArgs = append(moduleArgs, "-client-log", logFile)

if len(strings.Join(append(moduleArgs, args...), " ")) > 768 {
// FIXME: If the number of arguments is too big, we may break old PAM.
// This is not required anymore when we can use libpam 1.6.0 in CI:
// https://github.com/linux-pam/linux-pam/pull/658
clientArgsPath := filepath.Join(t.TempDir(), "client-args-file")
require.NoError(t, os.WriteFile(clientArgsPath, []byte(strings.Join(args, "\t")), 0600),
"Setup: Creation of client args file failed")
saveArtifactsForDebugOnCleanup(t, []string{clientArgsPath})
return append(moduleArgs, "-client-args-file", clientArgsPath)
}
}
return append(moduleArgs, args...)
}
Expand Down

0 comments on commit 1f50dd1

Please sign in to comment.