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.
This commit is contained in:
Marco Trevisan (Treviño)
2023-11-20 21:09:43 +01:00
parent 4b39bd8e11
commit 05f676c233
4 changed files with 27 additions and 16 deletions

24
app-transaction.go Normal file
View File

@@ -0,0 +1,24 @@
//go:build !go_pam_module
package pam
/*
#include <security/pam_appl.h>
#include <stdint.h>
*/
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
}

View File

@@ -119,9 +119,9 @@ func main() {
tags = *buildTags tags = *buildTags
} }
var generateTags []string generateTags := []string{"go_pam_module"}
if len(*moduleBuildTags) > 0 { if len(*moduleBuildTags) > 0 {
generateTags = strings.Split(*moduleBuildTags, ",") generateTags = append(generateTags, strings.Split(*moduleBuildTags, ",")...)
} }
var buildFlags []string var buildFlags []string

View File

@@ -1,6 +1,6 @@
// Code generated by "pam-moduler "; DO NOT EDIT. // 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 is the package for the PAM module library.
package main package main

View File

@@ -75,19 +75,6 @@ func (f ConversationFunc) RespondPAM(s Style, msg string) (string, error) {
return f(s, msg) 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. // pamConvHandler is a Go wrapper for the conversation callback function.
func pamConvHandler(style Style, msg *C.char, handler ConversationHandler) (*C.char, C.int) { func pamConvHandler(style Style, msg *C.char, handler ConversationHandler) (*C.char, C.int) {
var r string var r string