Browse Source

vendor: update github.com/msteinert/pam (#4216)

pull/4484/merge
Unknwon 8 years ago
parent
commit
0778d7de80
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 8
      vendor/github.com/msteinert/pam/README.md
  2. 39
      vendor/github.com/msteinert/pam/callback.go
  3. 11
      vendor/github.com/msteinert/pam/transaction.c
  4. 57
      vendor/github.com/msteinert/pam/transaction.go
  5. 6
      vendor/vendor.json

8
vendor/github.com/msteinert/pam/README.md generated vendored

@ -5,13 +5,7 @@
# Go PAM
This is a Go wrapper for the PAM application API. There's not much
else to be said. PAM is a simple API and now it's available for use in Go
applications.
There's an example of a "fake login" program in the examples directory.
Look at the pam module's [godocs][1] for details about the Go API, or refer
to the official [PAM documentation][2].
This is a Go wrapper for the PAM application API.
## Testing

39
vendor/github.com/msteinert/pam/callback.go generated vendored

@ -0,0 +1,39 @@
package pam
import "sync"
var cb struct {
sync.Mutex
m map[int]interface{}
c int
}
func init() {
cb.m = make(map[int]interface{})
}
func cbAdd(v interface{}) int {
cb.Lock()
defer cb.Unlock()
cb.c++
cb.m[cb.c] = v
return cb.c
}
func cbGet(c int) interface{} {
cb.Lock()
defer cb.Unlock()
if v, ok := cb.m[c]; ok {
return v
}
panic("Callback pointer not found")
}
func cbDelete(c int) {
cb.Lock()
defer cb.Unlock()
if _, ok := cb.m[c]; !ok {
panic("Callback pointer not found")
}
delete(cb.m, c)
}

11
vendor/github.com/msteinert/pam/transaction.c generated vendored

@ -19,7 +19,7 @@ int cb_pam_conv(
struct cbPAMConv_return result = cbPAMConv(
msg[i]->msg_style,
(char *)msg[i]->msg,
appdata_ptr);
(long)appdata_ptr);
if (result.r1 != PAM_SUCCESS) {
goto error;
}
@ -39,13 +39,8 @@ error:
return PAM_CONV_ERR;
}
struct pam_conv *make_pam_conv(void *appdata_ptr)
void init_pam_conv(struct pam_conv *conv, long c)
{
struct pam_conv* conv = malloc(sizeof *conv);
if (!conv) {
return NULL;
}
conv->conv = cb_pam_conv;
conv->appdata_ptr = appdata_ptr;
return conv;
conv->appdata_ptr = (void *)c;
}

57
vendor/github.com/msteinert/pam/transaction.go generated vendored

@ -1,10 +1,11 @@
// Package pam provides a wrapper for the PAM application API.
package pam
//#include <security/pam_appl.h>
//#include <stdlib.h>
//#cgo CFLAGS: -Wall -std=c99
//#cgo LDFLAGS: -lpam
//struct pam_conv *make_pam_conv(void *);
//void init_pam_conv(struct pam_conv *conv, long c);
import "C"
import (
@ -50,31 +51,16 @@ func (f ConversationFunc) RespondPAM(s Style, msg string) (string, error) {
return f(s, msg)
}
// Internal conversation structure
type conversation struct {
handler ConversationHandler
conv *C.struct_pam_conv
}
// 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) (*conversation, C.int) {
c := &conversation{}
c.handler = handler
c.conv = C.make_pam_conv(unsafe.Pointer(c))
if c.conv == nil {
return nil, C.PAM_BUF_ERR
}
return 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, appdata unsafe.Pointer) (*C.char, C.int) {
c := (*conversation)(appdata)
r, err := c.handler.RespondPAM(Style(s), C.GoString(msg))
func cbPAMConv(s C.int, msg *C.char, c int) (*C.char, C.int) {
var r string
var err error
v := cbGet(c)
switch cb := v.(type) {
case ConversationHandler:
r, err = cb.RespondPAM(Style(s), C.GoString(msg))
}
if err != nil {
return nil, C.PAM_CONV_ERR
}
@ -84,14 +70,16 @@ func cbPAMConv(s C.int, msg *C.char, appdata unsafe.Pointer) (*C.char, C.int) {
// Transaction is the application's handle for a PAM transaction.
type Transaction struct {
handle *C.pam_handle_t
conv *conversation
conv *C.struct_pam_conv
status C.int
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)
C.free(unsafe.Pointer(t.conv.conv))
cbDelete(t.c)
}
// Start initiates a new PAM transaction. Service is treated identically to
@ -100,11 +88,12 @@ 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.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))
var u *C.char
@ -112,12 +101,10 @@ func Start(service, user string, handler ConversationHandler) (*Transaction, err
u = C.CString(user)
defer C.free(unsafe.Pointer(u))
}
t.status = C.pam_start(s, u, t.conv.conv, &t.handle)
t.status = C.pam_start(s, u, t.conv, &t.handle)
if t.status != C.PAM_SUCCESS {
C.free(unsafe.Pointer(t.conv.conv))
return nil, t
}
runtime.SetFinalizer(t, transactionFinalizer)
return t, nil
}

6
vendor/vendor.json vendored

@ -291,10 +291,10 @@
"revisionTime": "2016-10-12T08:37:05Z"
},
{
"checksumSHA1": "gfDr4rP58HxAyjzDAbHnLdVi+a4=",
"checksumSHA1": "lfOuMiAdiqc/dalUSBTvD5ZMSzA=",
"path": "github.com/msteinert/pam",
"revision": "6534f23b3984c4b8f517feba04a7d65b4da3ca57",
"revisionTime": "2015-09-03T20:12:29Z"
"revision": "02ccfbfaf0cc627aa3aec8ef7ed5cfeec5b43f63",
"revisionTime": "2015-12-04T16:05:44Z"
},
{
"checksumSHA1": "r5eQHkttko6kxroDEENXbmXKrSs=",

Loading…
Cancel
Save