diff options
author | Michael Steinert <[email protected]> | 2015-12-04 09:21:38 -0600 |
---|---|---|
committer | Michael Steinert <[email protected]> | 2015-12-04 09:21:38 -0600 |
commit | 7f5fc62ba4a6fc7ea64b3da094269d05d89f60b9 (patch) | |
tree | 4e868741bb5209ccf781e7fa763acd10cda383bd | |
parent | 4314ed7dcc2ce5728603fa8c8385510fa74829fc (diff) |
Remove dead code
-rw-r--r-- | transaction.go | 30 | ||||
-rw-r--r-- | transaction_test.go | 3 |
2 files changed, 10 insertions, 23 deletions
diff --git a/transaction.go b/transaction.go index 458804d..54e285c 100644 --- a/transaction.go +++ b/transaction.go @@ -50,30 +50,15 @@ func (f ConversationFunc) RespondPAM(s Style, msg string) (string, error) { return f(s, msg) } -// Constructs a new conversation object with a given handler and a newly -// allocated pam_conv struct that uses this object as its appdata_ptr. -func newConversation(handler ConversationHandler) (*C.struct_pam_conv, int, C.int) { - c := cbAdd(handler) - conv := &C.struct_pam_conv{} - C.init_pam_conv(conv, C.long(c)) - return conv, c, C.PAM_SUCCESS -} - -// Go-side function for processing a single conversational message. Ultimately -// this calls the associated ConversationHandler's ResponsePAM callback with data -// coming in from a C-side call. +// cbPAMConv is a wrapper for the conversation callback function. //export cbPAMConv func cbPAMConv(s C.int, msg *C.char, c int) (*C.char, C.int) { var r string - var err error + var err error = nil v := cbGet(c) switch cb := v.(type) { - case ConversationFunc: - r, err = cb(Style(s), C.GoString(msg)) case ConversationHandler: r, err = cb.RespondPAM(Style(s), C.GoString(msg)) - default: - return nil, C.PAM_CONV_ERR } if err != nil { return nil, C.PAM_CONV_ERR @@ -89,7 +74,8 @@ type Transaction struct { c int } -// Finalize a PAM transaction. +// transactionFinalizer cleans up the PAM handle and deletes the callback +// function. func transactionFinalizer(t *Transaction) { C.pam_end(t.handle, t.status) cbDelete(t.c) @@ -101,11 +87,11 @@ func transactionFinalizer(t *Transaction) { // All application calls to PAM begin with Start (or StartFunc). The returned // transaction provides an interface to the remainder of the API. func Start(service, user string, handler ConversationHandler) (*Transaction, error) { - t := &Transaction{} - t.conv, t.c, t.status = newConversation(handler) - if t.status != C.PAM_SUCCESS { - return nil, t + t := &Transaction{ + conv: &C.struct_pam_conv{}, + c: cbAdd(handler), } + C.init_pam_conv(t.conv, C.long(t.c)) runtime.SetFinalizer(t, transactionFinalizer) s := C.CString(service) defer C.free(unsafe.Pointer(s)) diff --git a/transaction_test.go b/transaction_test.go index 81714cc..6be678f 100644 --- a/transaction_test.go +++ b/transaction_test.go @@ -12,8 +12,9 @@ func TestPAM_001(t *testing.T) { if u.Uid != "0" { t.Skip("run this test as root") } + p := "secret" tx, err := StartFunc("", "test", func(s Style, msg string) (string, error) { - return "secret", nil + return p, nil }) if err != nil { t.Fatalf("start #error: %v", err) |