4 Commits

Author SHA1 Message Date
Lars Scheibling
c1a0f72fa1 Updated path 2024-01-12 09:20:18 +00:00
Lars Scheibling
fabe599f29 Merge branch 'pam-moduler'
Some checks failed
Test / test (1.20.x, ubuntu-latest) (push) Has been cancelled
Test / test (1.21.x, ubuntu-latest) (push) Has been cancelled
Lint / lint (push) Has been cancelled
2024-01-12 09:14:01 +00:00
Marco Trevisan (Treviño)
4851b5d1fc transaction: Add support for Binary conversation
Some checks are pending
Test / test (1.19.x, ubuntu-latest) (push) Waiting to run
Test / test (1.20.x, ubuntu-latest) (push) Waiting to run
PAM Supports binary conversations using private protocols, this
can be handled by C but it's not supported here because we
implicitly convert all the messages to string, and this may lead
to issues when this is not the case (as in binary protocol the
pointer could contain zeros that the GoString conversion would
consider them the end of the message).

So, add another conversation handler implementation that allows
to handle the binary protocol, whose function callback accepts
a pointer to the struct (we can't use bytes as the length is
unknown and may be defined in the header of the pointer itself).

However since the binary prompt is not supported by all the
platform we need to do a compile-time check to disable it in
case is used when not supported.
2023-09-19 21:10:32 +02:00
Marco Trevisan (Treviño)
8fd6202a7b transaction: Use cgo.Handle to pass callback data to PAM
Go provides a nicer way to handle Go structs lifetime when they
are passed to C now, so use this instead of a custom
implementation that requires to store them in a map
2023-09-19 20:04:06 +02:00
19 changed files with 21 additions and 30 deletions

View File

@@ -6,6 +6,11 @@
This is a Go wrapper for the PAM application API. This is a Go wrapper for the PAM application API.
Package path changed for ease of use, and to avoid conflicts with the original
Originally created by [Mike Steinert](https://github.com/msteinert/pam)
Updated and modified by [Marco Trevisan](https://github.com/3v1n0/go-pam/tree/pam-moduler)
## Module support ## Module support
Go PAM can also used to create PAM modules in a simple way, using the go. Go PAM can also used to create PAM modules in a simple way, using the go.

View File

@@ -11,11 +11,11 @@
// //
// For example: // For example:
// //
// //go:generate go run github.com/msteinert/pam/v2/pam-moduler // //go:generate go run git.cloudyne.io/go/msteinert-go-pam/v2/pam-moduler
// //go:generate go generate --skip="pam_module" // //go:generate go generate --skip="pam_module"
// package main // package main
// //
// import "github.com/msteinert/pam/v2" // import "git.cloudyne.io/go/msteinert-go-pam/v2"
// //
// type ExampleHandler struct{} // type ExampleHandler struct{}
// var pamModuleHandler pam.ModuleHandler = &ExampleHandler{} // var pamModuleHandler pam.ModuleHandler = &ExampleHandler{}
@@ -229,7 +229,7 @@ import (
"fmt" "fmt"
"os" "os"
"unsafe" "unsafe"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2"
) )
`) `)

View File

@@ -1,4 +1,4 @@
//go:generate go run github.com/msteinert/pam/v2/cmd/pam-moduler -libname "pam_godebug.so" //go:generate go run git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler -libname "pam_godebug.so"
//go:generate go generate --skip="pam_module.go" //go:generate go generate --skip="pam_module.go"
// This is a similar implementation of pam_debug.so // This is a similar implementation of pam_debug.so
@@ -10,8 +10,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler/tests/internal/utils"
"github.com/msteinert/pam/v2/cmd/pam-moduler/tests/internal/utils"
) )
var pamModuleHandler pam.ModuleHandler = &DebugModule{} var pamModuleHandler pam.ModuleHandler = &DebugModule{}

View File

@@ -5,8 +5,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler/tests/internal/utils"
"github.com/msteinert/pam/v2/cmd/pam-moduler/tests/internal/utils"
) )
func Test_DebugModule_ActionStatus(t *testing.T) { func Test_DebugModule_ActionStatus(t *testing.T) {

View File

@@ -16,7 +16,7 @@ import "C"
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2"
"os" "os"
"unsafe" "unsafe"
) )

View File

@@ -6,7 +6,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/msteinert/pam/v2/cmd/pam-moduler/tests/internal/utils" "git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler/tests/internal/utils"
) )
func ensureNoError(t *testing.T, err error) { func ensureNoError(t *testing.T, err error) {

View File

@@ -1,4 +1,4 @@
//go:generate go run github.com/msteinert/pam/v2/cmd/pam-moduler -type integrationTesterModule -parallel-conv //go:generate go run git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler -type integrationTesterModule -parallel-conv
//go:generate go generate --skip="pam_module.go" //go:generate go generate --skip="pam_module.go"
// Package main is the package for the integration tester module PAM shared library. // Package main is the package for the integration tester module PAM shared library.
@@ -10,8 +10,7 @@ import (
"reflect" "reflect"
"strings" "strings"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler/tests/internal/utils"
"github.com/msteinert/pam/v2/cmd/pam-moduler/tests/internal/utils"
) )
type integrationTesterModule struct { type integrationTesterModule struct {

View File

@@ -10,8 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler/tests/internal/utils"
"github.com/msteinert/pam/v2/cmd/pam-moduler/tests/internal/utils"
) )
func (r *Request) check(res *Result, expectedResults []interface{}) error { func (r *Request) check(res *Result, expectedResults []interface{}) error {

View File

@@ -16,7 +16,7 @@ import "C"
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2"
"os" "os"
"unsafe" "unsafe"
) )

View File

@@ -3,8 +3,7 @@ package main
import ( import (
"encoding/gob" "encoding/gob"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler/tests/internal/utils"
"github.com/msteinert/pam/v2/cmd/pam-moduler/tests/internal/utils"
) )
// SerializablePamError represents a [pam.Error] in a // SerializablePamError represents a [pam.Error] in a

View File

@@ -1,7 +1,5 @@
package utils package utils
import "github.com/msteinert/pam/v2"
// BaseModule is the type for a base PAM module. // BaseModule is the type for a base PAM module.
type BaseModule struct{} type BaseModule struct{}

View File

@@ -8,8 +8,6 @@ import (
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
"github.com/msteinert/pam/v2"
) )
// TestSetup is an utility type for having a playground for test PAM modules. // TestSetup is an utility type for having a playground for test PAM modules.

View File

@@ -11,8 +11,6 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"unsafe" "unsafe"
"github.com/msteinert/pam/v2"
) )
// Action represents a PAM action to perform. // Action represents a PAM action to perform.

View File

@@ -2,7 +2,7 @@
// `go generate` once in the module directory. // `go generate` once in the module directory.
// This is not strictly needed // This is not strictly needed
//go:generate go run github.com/msteinert/pam/v2/cmd/pam-moduler //go:generate go run git.cloudyne.io/go/msteinert-go-pam/v2/cmd/pam-moduler
//go:generate go generate --skip="pam_module.go" //go:generate go generate --skip="pam_module.go"
// Package main provides the module shared library. // Package main provides the module shared library.
@@ -10,8 +10,6 @@ package main
import ( import (
"fmt" "fmt"
"github.com/msteinert/pam/v2"
) )
type exampleHandler struct{} type exampleHandler struct{}

View File

@@ -16,7 +16,7 @@ import "C"
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/msteinert/pam/v2" "git.cloudyne.io/go/msteinert-go-pam/v2"
"os" "os"
"unsafe" "unsafe"
) )

View File

@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/msteinert/pam/v2"
"golang.org/x/term" "golang.org/x/term"
) )

2
go.mod
View File

@@ -1,4 +1,4 @@
module github.com/msteinert/pam/v2 module git.cloudyne.io/go/msteinert-go-pam/v2
go 1.20 go 1.20