diff options
| author | Joseph Richey <joerichey@google.com> | 2017-07-18 10:59:40 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-18 10:59:40 -0700 |
| commit | 8867856db45abaed8b9e2539ee7c34d99360db56 (patch) | |
| tree | 5895bce36a9dff465057d84819b0d65255e1c702 /pam/pam.go | |
| parent | 3d08d9f6891db3ca94337e9b987ef62cba535fe1 (diff) | |
| parent | 17f7dd867d0fd450377c6862c0782483d39ae408 (diff) | |
Merge pull request #22 from google/fix
Fixing fscrypt build system
Diffstat (limited to 'pam/pam.go')
| -rw-r--r-- | pam/pam.go | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -65,22 +65,32 @@ func (h *Handle) getData(name string) (unsafe.Pointer, error) { return data, h.err() } +// ClearData remotes the PAM data with the specified name. +func (h *Handle) ClearData(name string) error { + return h.setData(name, unsafe.Pointer(C.CString("")), C.CleanupFunc(C.freeData)) +} + +// SetSecret sets a copy of the C string secret into the PAM data with the +// specified name. This copy will be held in locked memory until this PAM data +// is cleared. func (h *Handle) SetSecret(name string, secret unsafe.Pointer) error { return h.setData(name, C.copyIntoSecret(secret), C.CleanupFunc(C.freeSecret)) } +// GetSecret returns a pointer to the C string PAM data with the specified name. +// This a pointer directory to the data, so it shouldn't be modified. It should +// have been previously set with SetSecret(). func (h *Handle) GetSecret(name string) (unsafe.Pointer, error) { return h.getData(name) } -func (h *Handle) ClearSecret(name string) error { - return h.setData(name, unsafe.Pointer(C.CString("")), C.CleanupFunc(C.freeData)) -} - +// SetString sets a string value for the PAM data with the specified name. func (h *Handle) SetString(name string, s string) error { return h.setData(name, unsafe.Pointer(C.CString(s)), C.CleanupFunc(C.freeData)) } +// GetString gets a string value for the PAM data with the specified name. It +// should have been previously set with SetString(). func (h *Handle) GetString(name string) (string, error) { data, err := h.getData(name) if err != nil { @@ -89,6 +99,7 @@ func (h *Handle) GetString(name string) (string, error) { return C.GoString((*C.char)(data)), nil } +// SetSlice sets a []string value for the PAM data with the specified name. func (h *Handle) SetSlice(name string, slice []string) error { sliceLength := uintptr(len(slice)) memorySize := (sliceLength + 1) * unsafe.Sizeof(uintptr(0)) @@ -103,6 +114,8 @@ func (h *Handle) SetSlice(name string, slice []string) error { return h.setData(name, data, C.CleanupFunc(C.freeArray)) } +// GetSlice gets a []string value for the PAM data with the specified name. It +// should have been previously set with SetSlice(). func (h *Handle) GetSlice(name string) ([]string, error) { data, err := h.getData(name) if err != nil { @@ -166,7 +179,11 @@ func Start(service, username string) (*Transaction, error) { handle: nil, status: C.PAM_SUCCESS, } - t.status = C.pam_start(cService, cUsername, &C.conv, &t.handle) + t.status = C.pam_start( + cService, + cUsername, + C.goConv, + &t.handle) return t, (*Handle)(t).err() } |