From a8f1e11ed24329ab0c30da71e37d00b75cc60fe6 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 21 Jul 2015 12:46:42 -0700 Subject: [PATCH] Adding methods for calling into hcsshim to do string to guid hashing. Signed-off-by: Stefan J. Wernli --- hcsshim.go | 1 + nametoguid.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 nametoguid.go diff --git a/hcsshim.go b/hcsshim.go index c17c96b3a7..6ef12489bb 100644 --- a/hcsshim.go +++ b/hcsshim.go @@ -39,6 +39,7 @@ const ( procExportLayer = "ExportLayer" procImportLayer = "ImportLayer" procGetSharedBaseImages = "GetBaseImages" + procNameToGuid = "NameToGuid" // Name of the standard OLE dll oleDLLName = "Ole32.dll" diff --git a/nametoguid.go b/nametoguid.go new file mode 100644 index 0000000000..a371e49ca0 --- /dev/null +++ b/nametoguid.go @@ -0,0 +1,46 @@ +package hcsshim + +import ( + "fmt" + "syscall" + "unsafe" + + "github.com/Sirupsen/logrus" +) + +func NameToGuid(name string) (id GUID, err error) { + title := "hcsshim::NameToGuid " + logrus.Debugf(title+"Name %s", name) + + // Load the DLL and get a handle to the procedure we need + dll, proc, err := loadAndFind(procNameToGuid) + if dll != nil { + defer dll.Release() + } + if err != nil { + return + } + + // Convert name to uint16 pointer for calling the procedure + namep, err := syscall.UTF16PtrFromString(name) + if err != nil { + err = fmt.Errorf(title+" - Failed conversion of name %s to pointer %s", name, err) + logrus.Error(err) + return + } + + // Call the procedure itself. + logrus.Debugf("Calling proc (1)") + r1, _, _ := proc.Call( + uintptr(unsafe.Pointer(namep)), + uintptr(unsafe.Pointer(&id))) + + if r1 != 0 { + err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s name=%s", + r1, syscall.Errno(r1), name) + logrus.Error(err) + return + } + + return +}