From 05f676c2330503598a704d9486d216aec48386b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 20 Nov 2023 21:09:43 +0100 Subject: [PATCH] transaction, moduler: Do not export PAM conv handler function to modules This function is only needed when using go PAM for creating applications so it's not something we expect to have exported to library modules. To prevent this use an `asPamModule` tag to prevent compilation of application-only features. --- app-transaction.go | 24 ++++++++++++++++++++++++ cmd/pam-moduler/moduler.go | 4 ++-- example-module/pam_module.go | 2 +- transaction.go | 13 ------------- 4 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 app-transaction.go diff --git a/app-transaction.go b/app-transaction.go new file mode 100644 index 0000000..2ddfaaa --- /dev/null +++ b/app-transaction.go @@ -0,0 +1,24 @@ +//go:build !go_pam_module + +package pam + +/* +#include +#include +*/ +import "C" + +import "runtime/cgo" + +// _go_pam_conv_handler is a C wrapper for the conversation callback function. +// +//export _go_pam_conv_handler +func _go_pam_conv_handler(msg *C.struct_pam_message, c C.uintptr_t, outMsg **C.char) C.int { + convHandler, ok := cgo.Handle(c).Value().(ConversationHandler) + if !ok || convHandler == nil { + return C.int(ErrConv) + } + replyMsg, r := pamConvHandler(Style(msg.msg_style), msg.msg, convHandler) + *outMsg = replyMsg + return r +} diff --git a/cmd/pam-moduler/moduler.go b/cmd/pam-moduler/moduler.go index b95195d..94298dc 100644 --- a/cmd/pam-moduler/moduler.go +++ b/cmd/pam-moduler/moduler.go @@ -119,9 +119,9 @@ func main() { tags = *buildTags } - var generateTags []string + generateTags := []string{"go_pam_module"} if len(*moduleBuildTags) > 0 { - generateTags = strings.Split(*moduleBuildTags, ",") + generateTags = append(generateTags, strings.Split(*moduleBuildTags, ",")...) } var buildFlags []string diff --git a/example-module/pam_module.go b/example-module/pam_module.go index b3bfb08..b13924e 100644 --- a/example-module/pam_module.go +++ b/example-module/pam_module.go @@ -1,6 +1,6 @@ // Code generated by "pam-moduler "; DO NOT EDIT. -//go:generate go build "-ldflags=-extldflags -Wl,-soname,pam_go.so" -buildmode=c-shared -o pam_go.so +//go:generate go build "-ldflags=-extldflags -Wl,-soname,pam_go.so" -buildmode=c-shared -o pam_go.so -tags go_pam_module // Package main is the package for the PAM module library. package main diff --git a/transaction.go b/transaction.go index 9dba072..600f0cf 100644 --- a/transaction.go +++ b/transaction.go @@ -75,19 +75,6 @@ func (f ConversationFunc) RespondPAM(s Style, msg string) (string, error) { return f(s, msg) } -// _go_pam_conv_handler is a C wrapper for the conversation callback function. -// -//export _go_pam_conv_handler -func _go_pam_conv_handler(msg *C.struct_pam_message, c C.uintptr_t, outMsg **C.char) C.int { - convHandler, ok := cgo.Handle(c).Value().(ConversationHandler) - if !ok || convHandler == nil { - return C.int(ErrConv) - } - replyMsg, r := pamConvHandler(Style(msg.msg_style), msg.msg, convHandler) - *outMsg = replyMsg - return r -} - // pamConvHandler is a Go wrapper for the conversation callback function. func pamConvHandler(style Style, msg *C.char, handler ConversationHandler) (*C.char, C.int) { var r string