1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30

Updated vendor pkg: github.com/danieljoos/wincred

This includes the following changes:
- Removed need for `C`
- Added some null checks to avoid possible panics
- `List` returns an empty list instead of an error, in case no credentials
  are installed on the system

Signed-off-by: Daniel Joos <daniel@joosweb.de>
This commit is contained in:
Daniel Joos
2016-09-07 09:07:00 +02:00
parent f72c04f1d8
commit a994ca1d54
3 changed files with 40 additions and 10 deletions
+21 -3
View File
@@ -1,7 +1,6 @@
package wincred
import (
"C"
"encoding/binary"
"reflect"
"syscall"
@@ -10,6 +9,8 @@ import (
"unsafe"
)
var nullPointer = unsafe.Pointer(uintptr(0))
// Create a Go string using a pointer to a zero-terminated UTF 16 encoded string.
// See github.com/AllenDang/w32
func utf16PtrToString(wstr *uint16) string {
@@ -36,8 +37,22 @@ func utf16ToByte(wstr []uint16) (result []byte) {
return
}
// Copies the given C byte array to a Go byte array (see `C.GoBytes`)
func goBytes(src unsafe.Pointer, len uint32) []byte {
if src == nullPointer {
return []byte{}
}
slice := (*[1 << 30]byte)(src)[0:len]
rv := make([]byte, len)
copy(rv, slice)
return rv[:]
}
// Convert the given CREDENTIAL struct to a more usable structure
func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) {
if unsafe.Pointer(cred) == nullPointer {
return nil
}
result = new(Credential)
result.Comment = utf16PtrToString(cred.Comment)
result.TargetName = utf16PtrToString(cred.TargetName)
@@ -45,7 +60,7 @@ func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) {
result.UserName = utf16PtrToString(cred.UserName)
result.LastWritten = time.Unix(0, cred.LastWritten.Nanoseconds())
result.Persist = CredentialPersistence(cred.Persist)
result.CredentialBlob = C.GoBytes(unsafe.Pointer(cred.CredentialBlob), C.int(cred.CredentialBlobSize))
result.CredentialBlob = goBytes(unsafe.Pointer(cred.CredentialBlob), cred.CredentialBlobSize)
result.Attributes = make([]CredentialAttribute, cred.AttributeCount)
attrSliceHeader := reflect.SliceHeader{
Data: cred.Attributes,
@@ -56,7 +71,7 @@ func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) {
for i, attr := range attrSlice {
resultAttr := &result.Attributes[i]
resultAttr.Keyword = utf16PtrToString(attr.Keyword)
resultAttr.Value = C.GoBytes(unsafe.Pointer(attr.Value), C.int(attr.ValueSize))
resultAttr.Value = goBytes(unsafe.Pointer(attr.Value), attr.ValueSize)
}
return result
}
@@ -64,6 +79,9 @@ func nativeToCredential(cred *nativeCREDENTIAL) (result *Credential) {
// Convert the given Credential object back to a CREDENTIAL struct, which can be used for calling the
// Windows APIs
func nativeFromCredential(cred *Credential) (result *nativeCREDENTIAL) {
if cred == nil {
return nil
}
result = new(nativeCREDENTIAL)
result.Flags = 0
result.Type = 0