Exemplo n.º 1
0
func lookupFullName(domain, username, domainAndUser string) (string, error) {
	// try domain controller first
	name, e := syscall.TranslateAccountName(domainAndUser,
		syscall.NameSamCompatible, syscall.NameDisplay, 50)
	if e != nil {
		// domain lookup failed, perhaps this pc is not part of domain
		d, e := syscall.UTF16PtrFromString(domain)
		if e != nil {
			return "", e
		}
		u, e := syscall.UTF16PtrFromString(username)
		if e != nil {
			return "", e
		}
		var p *byte
		e = syscall.NetUserGetInfo(d, u, 10, &p)
		if e != nil {
			// path executed when a domain user is disconnected from the domain
			// pretend username is fullname
			return username, nil
		}
		defer syscall.NetApiBufferFree(p)
		i := (*syscall.UserInfo10)(unsafe.Pointer(p))
		if i.FullName == nil {
			return "", nil
		}
		name = syscall.UTF16ToString((*[1024]uint16)(unsafe.Pointer(i.FullName))[:])
	}
	return name, nil
}
Exemplo n.º 2
0
func initScreenWindow() (err error) {
	swc, err := syscall.UTF16PtrFromString(screenWindowClass)
	if err != nil {
		return err
	}
	emptyString, err := syscall.UTF16PtrFromString("")
	if err != nil {
		return err
	}
	wc := _WNDCLASS{
		LpszClassName: swc,
		LpfnWndProc:   syscall.NewCallback(screenWindowWndProc),
		HIcon:         hDefaultIcon,
		HCursor:       hDefaultCursor,
		HInstance:     hThisInstance,
		HbrBackground: syscall.Handle(_COLOR_BTNFACE + 1),
	}
	_, err = _RegisterClass(&wc)
	if err != nil {
		return err
	}
	screenHWND, err = _CreateWindowEx(0,
		swc, emptyString,
		_WS_OVERLAPPEDWINDOW,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		_HWND_MESSAGE, 0, hThisInstance, 0)
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 3
0
func newWindow(opts *screen.NewWindowOptions) (syscall.Handle, error) {
	// TODO(brainman): convert windowClass to *uint16 once (in initWindowClass)
	wcname, err := syscall.UTF16PtrFromString(windowClass)
	if err != nil {
		return 0, err
	}
	title, err := syscall.UTF16PtrFromString("Shiny Window")
	if err != nil {
		return 0, err
	}
	w, h := _CW_USEDEFAULT, _CW_USEDEFAULT
	if opts != nil {
		if opts.Width > 0 {
			w = opts.Width
		}
		if opts.Height > 0 {
			h = opts.Height
		}
	}
	hwnd, err := _CreateWindowEx(0,
		wcname, title,
		_WS_OVERLAPPEDWINDOW,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		int32(w), int32(h),
		0, 0, hThisInstance, 0)
	if err != nil {
		return 0, err
	}
	// TODO(andlabs): use proper nCmdShow
	// TODO(andlabs): call UpdateWindow()

	return hwnd, nil
}
Exemplo n.º 4
0
// Subscribe creates a new subscription to an event log channel.
func Subscribe(
	session EvtHandle,
	event windows.Handle,
	channelPath string,
	query string,
	bookmark EvtHandle,
	flags EvtSubscribeFlag,
) (EvtHandle, error) {
	var err error
	var cp *uint16
	if channelPath != "" {
		cp, err = syscall.UTF16PtrFromString(channelPath)
		if err != nil {
			return 0, err
		}
	}

	var q *uint16
	if query != "" {
		q, err = syscall.UTF16PtrFromString(query)
		if err != nil {
			return 0, err
		}
	}

	eventHandle, err := _EvtSubscribe(session, uintptr(event), cp, q, bookmark,
		0, 0, flags)
	if err != nil {
		return 0, err
	}

	return eventHandle, nil
}
Exemplo n.º 5
0
func openfile(flags uint32, b *FileBuilder) (d filedlg) {
	d.buf = make([]uint16, w32.MAX_PATH)
	d.opf = &w32.OPENFILENAME{
		File:    utf16ptr(d.buf),
		MaxFile: uint32(len(d.buf)),
		Flags:   flags,
	}
	d.opf.StructSize = uint32(unsafe.Sizeof(*d.opf))
	if b.StartDir != "" {
		d.opf.InitialDir, _ = syscall.UTF16PtrFromString(b.StartDir)
	}
	if b.Dlg.Title != "" {
		d.opf.Title, _ = syscall.UTF16PtrFromString(b.Dlg.Title)
	}
	for _, filt := range b.Filters {
		/* build utf16 string of form "Music File\0*.mp3;*.ogg;*.wav;\0" */
		d.filters = append(d.filters, utf16.Encode([]rune(filt.Desc))...)
		d.filters = append(d.filters, 0)
		for _, ext := range filt.Extensions {
			s := fmt.Sprintf("*.%s;", ext)
			d.filters = append(d.filters, utf16.Encode([]rune(s))...)
		}
		d.filters = append(d.filters, 0)
	}
	if d.filters != nil {
		d.filters = append(d.filters, 0, 0) // two extra NUL chars to terminate the list
		d.opf.Filter = utf16ptr(d.filters)
	}
	return d
}
Exemplo n.º 6
0
// changeUserPasswordLocalhost changes the password for username on localhost
func (c *PasswordChanger) ChangeUserPasswordLocalhost(newPassword string) error {
	serverp, err := syscall.UTF16PtrFromString("localhost")
	if err != nil {
		return errors.Trace(err)
	}

	userp, err := syscall.UTF16PtrFromString("jujud")
	if err != nil {
		return errors.Trace(err)
	}

	passp, err := syscall.UTF16PtrFromString(newPassword)
	if err != nil {
		return errors.Trace(err)
	}

	info := netUserSetPassword{passp}

	err = netUserSetInfo(serverp, userp, changePasswordLevel, &info, nil)
	if err != nil {
		return errors.Trace(err)
	}

	return nil
}
Exemplo n.º 7
0
func savePNG(fileName string, newBMP winapi.HBITMAP) error {
	var gdiplusStartupInput winapi.GdiplusStartupInput
	var gdiplusToken winapi.GdiplusStartupOutput

	// GDI+ の初期化
	gdiplusStartupInput.GdiplusVersion = 1
	if winapi.GdiplusStartup(&gdiplusStartupInput, &gdiplusToken) != 0 {
		return fmt.Errorf("failed to initialize GDI+")
	}
	defer winapi.GdiplusShutdown()

	// HBITMAP から Bitmap を作成
	var bmp *winapi.GpBitmap
	if winapi.GdipCreateBitmapFromHBITMAP(newBMP, 0, &bmp) != 0 {
		return fmt.Errorf("failed to create HBITMAP")
	}
	defer winapi.GdipDisposeImage((*winapi.GpImage)(bmp))
	sclsid, err := syscall.UTF16PtrFromString("{557CF406-1A04-11D3-9A73-0000F81EF32E}")
	if err != nil {
		return err
	}
	clsid, err := CLSIDFromString(sclsid)
	if err != nil {
		return err
	}
	fname, err := syscall.UTF16PtrFromString(fileName)
	if err != nil {
		return err
	}
	if GdipSaveImageToFile(bmp, fname, clsid, nil) != 0 {
		return fmt.Errorf("failed to call PNG encoder")
	}
	return nil
}
Exemplo n.º 8
0
// ReplaceFile calls through to the Win32 ReplaceFile API, which can be found at the following
// URL: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365512(v=vs.85).aspx
func ReplaceFile(replaced string, replacement string, backup string, flags Flag) error {
	_, err := os.Stat(replaced)
	if err != nil {
		if os.IsNotExist(err) {
			f, err := os.Create(replaced)
			if err != nil {
				return err
			}
			f.Close()
		}
	}
	replacedPtr, err := syscall.UTF16PtrFromString(replaced)
	if err != nil {
		return err
	}

	replacementPtr, err := syscall.UTF16PtrFromString(replacement)
	if err != nil {
		return err
	}

	backupPtr, err := syscall.UTF16PtrFromString(backup)
	if err != nil {
		return err
	}

	return replaceFileW(replacedPtr, replacementPtr, backupPtr, uint32(flags))
}
Exemplo n.º 9
0
// Call ShellExecute-API: edit,explore,open and so on.
func ShellExecute(action string, path string, param string, directory string) error {
	actionP, actionErr := syscall.UTF16PtrFromString(action)
	if actionErr != nil {
		return actionErr
	}
	pathP, pathErr := syscall.UTF16PtrFromString(path)
	if pathErr != nil {
		return pathErr
	}
	paramP, paramErr := syscall.UTF16PtrFromString(param)
	if paramErr != nil {
		return paramErr
	}
	directoryP, directoryErr := syscall.UTF16PtrFromString(directory)
	if directoryErr != nil {
		return directoryErr
	}
	status, _, _ := shellExecute.Call(
		uintptr(0),
		uintptr(unsafe.Pointer(actionP)),
		uintptr(unsafe.Pointer(pathP)),
		uintptr(unsafe.Pointer(paramP)),
		uintptr(unsafe.Pointer(directoryP)),
		SW_SHOWNORMAL)

	if status <= 32 {
		if err := syscall.GetLastError(); err != nil {
			return err
		} else {
			return fmt.Errorf("Error(%d) in ShellExecuteW()", status)
		}
	}
	return nil
}
Exemplo n.º 10
0
func MyRegisterClass(hInstance winapi.HINSTANCE) winapi.ATOM {
	var wc winapi.WNDCLASSEX

	wc.CbSize = uint32(unsafe.Sizeof(winapi.WNDCLASSEX{}))
	wc.Style = 0
	wc.LpfnWndProc = syscall.NewCallback(WndProc)
	wc.CbClsExtra = 0
	wc.CbWndExtra = 0
	wc.HInstance = hInstance
	wc.HIcon = winapi.LoadIcon(hInstance, winapi.MAKEINTRESOURCE(132))
	wc.HCursor = winapi.LoadCursor(0, winapi.MAKEINTRESOURCE(winapi.IDC_CROSS))
	wc.HbrBackground = 0
	wc.LpszMenuName = nil
	wc.LpszClassName, _ = syscall.UTF16PtrFromString("GYAZOWIN")

	winapi.RegisterClassEx(&wc)

	var lwc winapi.WNDCLASSEX
	lwc.CbSize = uint32(unsafe.Sizeof(winapi.WNDCLASSEX{}))
	lwc.Style = winapi.CS_HREDRAW | winapi.CS_VREDRAW
	lwc.LpfnWndProc = syscall.NewCallback(LayerWndProc)
	lwc.CbClsExtra = 0
	lwc.CbWndExtra = 0
	lwc.HInstance = hInstance
	lwc.HIcon = winapi.LoadIcon(hInstance, winapi.MAKEINTRESOURCE(132))
	lwc.HCursor = winapi.LoadCursor(0, winapi.MAKEINTRESOURCE(winapi.IDC_CROSS))
	lwc.HbrBackground = winapi.HBRUSH(winapi.GetStockObject(winapi.WHITE_BRUSH))
	lwc.LpszMenuName = nil
	lwc.LpszClassName, _ = syscall.UTF16PtrFromString("GYAZOWINL")

	return winapi.RegisterClassEx(&lwc)
}
Exemplo n.º 11
0
func addOrUpdateMenuItem(item *MenuItem) {
	var disabled C.short = 0
	if item.disabled {
		disabled = 1
	}
	var checked C.short = 0
	if item.checked {
		checked = 1
	}

	title, err := syscall.UTF16PtrFromString(item.title)
	if err != nil {
		panic(err)
	}

	tooltip, err := syscall.UTF16PtrFromString(item.tooltip)
	if err != nil {
		panic(err)
	}

	C.add_or_update_menu_item(
		C.int(item.id),
		(*C.wchar_t)(unsafe.Pointer(title)),
		(*C.wchar_t)(unsafe.Pointer(tooltip)),
		disabled,
		checked,
	)
}
Exemplo n.º 12
0
func savePNG(fileName string, newBMP []byte) error {
	var gdiplusStartupInput winapi.GdiplusStartupInput
	var gdiplusToken winapi.GdiplusStartupOutput

	gdiplusStartupInput.GdiplusVersion = 1
	if winapi.GdiplusStartup(&gdiplusStartupInput, &gdiplusToken) != 0 {
		return fmt.Errorf("failed to initialize GDI+")
	}
	defer winapi.GdiplusShutdown()

	var bmp *winapi.GpBitmap
	if r0, _, _ := procGdipCreateBitmapFromGdiDib.Call(
		uintptr(unsafe.Pointer(&newBMP[0])),
		uintptr(unsafe.Pointer(&newBMP[52])),
		uintptr(unsafe.Pointer(&bmp))); r0 != 0 {
		return fmt.Errorf("failed to create bitmap")
	}
	defer winapi.GdipDisposeImage((*winapi.GpImage)(bmp))
	sclsid, err := syscall.UTF16PtrFromString("{557CF406-1A04-11D3-9A73-0000F81EF32E}")
	if err != nil {
		return err
	}
	clsid, err := CLSIDFromString(sclsid)
	if err != nil {
		return err
	}
	fname, err := syscall.UTF16PtrFromString(fileName)
	if err != nil {
		return err
	}
	if GdipSaveImageToFile(bmp, fname, clsid, nil) != 0 {
		return fmt.Errorf("failed to call PNG encoder")
	}
	return nil
}
Exemplo n.º 13
0
func (el *eventLog) Open(recordNumber uint32) error {
	// If uncServerPath is nil the local computer is used.
	var uncServerPath *uint16
	var err error
	if el.uncServerPath != "" {
		uncServerPath, err = syscall.UTF16PtrFromString(el.uncServerPath)
		if err != nil {
			return err
		}
	}

	providerName, err := syscall.UTF16PtrFromString(el.name)
	if err != nil {
		return err
	}

	handle, err := openEventLog(uncServerPath, providerName)
	if err != nil {
		return err
	}

	el.handle = handle
	el.recordNumber = recordNumber
	el.readBuf = make([]byte, maxEventBufferSize)
	// TODO: Start with this buffer smaller and grow it when needed.
	el.formatBuf = make([]byte, maxFormatMessageBufferSize)
	return nil
}
Exemplo n.º 14
0
func (el *eventLog) Open(recordNumber uint32) error {
	// If uncServerPath is nil the local computer is used.
	var uncServerPath *uint16
	var err error
	if el.uncServerPath != "" {
		uncServerPath, err = syscall.UTF16PtrFromString(el.uncServerPath)
		if err != nil {
			return err
		}
	}

	providerName, err := syscall.UTF16PtrFromString(el.name)
	if err != nil {
		return err
	}

	detailf("%s Open(recordNumber=%d) calling openEventLog(uncServerPath=%s, providerName=%s)",
		el.logPrefix, recordNumber, el.uncServerPath, el.name)
	handle, err := openEventLog(uncServerPath, providerName)
	if err != nil {
		return err
	}

	numRecords, err := getNumberOfEventLogRecords(handle)
	if err != nil {
		return err
	}

	var oldestRecord, newestRecord uint32
	if numRecords > 0 {
		el.recordNumber = recordNumber
		el.ignoreFirst = true

		oldestRecord, err = getOldestEventLogRecord(handle)
		if err != nil {
			return err
		}
		newestRecord = oldestRecord + numRecords - 1

		if recordNumber < oldestRecord || recordNumber > newestRecord {
			el.recordNumber = oldestRecord
			el.ignoreFirst = false
		}
	} else {
		el.recordNumber = 0
		el.seek = false
		el.ignoreFirst = false
	}

	logp.Info("%s contains %d records. Record number range [%d, %d]. Starting "+
		"at %d (ignoringFirst=%t)", el.logPrefix, numRecords, oldestRecord,
		newestRecord, el.recordNumber, el.ignoreFirst)

	el.seek = true
	el.handle = handle
	el.readBuf = make([]byte, maxEventBufferSize)
	// TODO: Start with this buffer smaller and grow it when needed.
	el.formatBuf = make([]byte, maxFormatMessageBufferSize)
	return nil
}
Exemplo n.º 15
0
func Rename(src, dst string) error {
	kernel32, err := syscall.LoadLibrary("kernel32.dll")
	if err != nil {
		return err
	}
	defer syscall.FreeLibrary(kernel32)
	moveFileExUnicode, err := syscall.GetProcAddress(kernel32, "MoveFileExW")
	if err != nil {
		return err
	}

	srcString, err := syscall.UTF16PtrFromString(src)
	if err != nil {
		return err
	}

	dstString, err := syscall.UTF16PtrFromString(dst)
	if err != nil {
		return err
	}

	srcPtr := uintptr(unsafe.Pointer(srcString))
	dstPtr := uintptr(unsafe.Pointer(dstString))

	MOVEFILE_REPLACE_EXISTING := 0x1
	flag := uintptr(MOVEFILE_REPLACE_EXISTING)

	_, _, callErr := syscall.Syscall(uintptr(moveFileExUnicode), 3, srcPtr, dstPtr, flag)
	if callErr != 0 {
		return callErr
	}

	return nil
}
Exemplo n.º 16
0
// dial is a helper to initiate a connection to a named pipe that has been started by a server.
// The timeout is only enforced if the pipe server has already created the pipe, otherwise
// this function will return immediately.
func dial(address string, timeout uint32) (*PipeConn, error) {
	name, err := syscall.UTF16PtrFromString(string(address))
	if err != nil {
		return nil, err
	}
	// If at least one instance of the pipe has been created, this function
	// will wait timeout milliseconds for it to become available.
	// It will return immediately regardless of timeout, if no instances
	// of the named pipe have been created yet.
	// If this returns with no error, there is a pipe available.
	if err := waitNamedPipe(name, timeout); err != nil {
		if err == error_bad_pathname {
			// badly formatted pipe name
			return nil, badAddr(address)
		}
		return nil, err
	}
	pathp, err := syscall.UTF16PtrFromString(address)
	if err != nil {
		return nil, err
	}
	handle, err := syscall.CreateFile(pathp, syscall.GENERIC_READ|syscall.GENERIC_WRITE,
		uint32(syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE), nil, syscall.OPEN_EXISTING,
		syscall.FILE_FLAG_OVERLAPPED, 0)
	if err != nil {
		return nil, err
	}
	return &PipeConn{handle: handle, addr: PipeAddr(address)}, nil
}
Exemplo n.º 17
0
func Copy(src string, dst string, isFailIfExists bool) error {
	cSrc, cSrcErr := syscall.UTF16PtrFromString(src)
	if cSrcErr != nil {
		return cSrcErr
	}
	cDst, cDstErr := syscall.UTF16PtrFromString(dst)
	if cDstErr != nil {
		return cDstErr
	}
	var isFailIfExists_ uintptr
	if isFailIfExists {
		isFailIfExists_ = 1
	} else {
		isFailIfExists_ = 0
	}
	rc, _, err := copyFile.Call(
		uintptr(unsafe.Pointer(cSrc)),
		uintptr(unsafe.Pointer(cDst)),
		isFailIfExists_)
	if rc != 0 {
		return nil
	} else {
		return err
	}
}
Exemplo n.º 18
0
// CreateComputeSystem creates a container
func CreateComputeSystem(id string, configuration string) error {

	title := "HCSShim::CreateComputeSystem"
	logrus.Debugln(title+" id=%s, configuration=%s", id, configuration)

	// Load the DLL and get a handle to the procedure we need
	dll, proc, err := loadAndFind(procCreateComputeSystem)
	if dll != nil {
		defer dll.Release()
	}
	if err != nil {
		return err
	}

	/*
		Example configuration JSON below. RootDevicePath MUST use \\ not \ as path
		separator. TODO Windows: Update this JSON sample with final API.

		{
		    "SystemType" : "Container",
			"Name" : "ContainerName",
		    "RootDevicePath" : "C:\\Containers\\test",
			"IsDummy" : true
		}

	*/

	// Convert id to uint16 pointers for calling the procedure
	idp, err := syscall.UTF16PtrFromString(id)
	if err != nil {
		err = fmt.Errorf(title+"- Failed conversion of id %s to pointer %s", id, err)
		logrus.Error(err)
		return err
	}

	// Convert configuration to uint16 pointers for calling the procedure
	configurationp, err := syscall.UTF16PtrFromString(configuration)
	if err != nil {
		err = fmt.Errorf(title+" - Failed conversion of configuration %s to pointer %s", configuration, err)
		logrus.Error(err)
		return err
	}

	// Call the procedure itself.
	r1, _, _ := proc.Call(
		uintptr(unsafe.Pointer(idp)), uintptr(unsafe.Pointer(configurationp)))

	use(unsafe.Pointer(idp))
	use(unsafe.Pointer(configurationp))

	if r1 != 0 {
		err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s id=%s configuration=%s", r1, syscall.Errno(r1), id, configuration)
		logrus.Error(err)
		return err
	}

	logrus.Debugf(title+"- succeeded %s", id)
	return nil
}
Exemplo n.º 19
0
func CreateLayer(info DriverInfo, id, parent string) error {
	title := "hcsshim::CreateLayer "
	logrus.Debugf(title+"Flavour %s ID %s parent %s", info.Flavour, id, parent)

	// Load the DLL and get a handle to the procedure we need
	dll, proc, err := loadAndFind(procCreateLayer)
	if dll != nil {
		defer dll.Release()
	}
	if err != nil {
		return err
	}

	// Convert id to uint16 pointer for calling the procedure
	idp, err := syscall.UTF16PtrFromString(id)
	if err != nil {
		err = fmt.Errorf(title+" - Failed conversion of id %s to pointer %s", id, err)
		logrus.Error(err)
		return err
	}

	// Convert parent to uint16 pointer for calling the procedure
	parentp, err := syscall.UTF16PtrFromString(parent)
	if err != nil {
		err = fmt.Errorf(title+" - Failed conversion of parent %s to pointer %s", parent, err)
		logrus.Error(err)
		return err
	}

	// Convert info to API calling convention
	infop, err := convertDriverInfo(info)
	if err != nil {
		err = fmt.Errorf(title+" - Failed conversion info struct %s", parent, err)
		logrus.Error(err)
		return err
	}

	// Call the procedure itself.
	r1, _, _ := proc.Call(
		uintptr(unsafe.Pointer(&infop)),
		uintptr(unsafe.Pointer(idp)),
		uintptr(unsafe.Pointer(parentp)))

	use(unsafe.Pointer(&infop))
	use(unsafe.Pointer(idp))
	use(unsafe.Pointer(parentp))

	if r1 != 0 {
		err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s id=%s parent=%s flavour=%d",
			r1, syscall.Errno(r1), id, parent, info.Flavour)
		logrus.Error(err)
		return err
	}

	logrus.Debugf(title+" - succeeded id=%s parent=%s flavour=%d", id, parent, info.Flavour)
	return nil
}
Exemplo n.º 20
0
// Returns a list of objects available on the specified computer or in the specified
// log file.
func PdhEnumObjects(DataSource, MachineName string) ([]string, error) {
	var (
		ObjectList   []uint16
		BufferLength = uint32(0)

		source  = uintptr(0)
		machine = uintptr(0)
	)

	if len(DataSource) != 0 {
		ds, _ := syscall.UTF16PtrFromString(DataSource)
		source = uintptr(unsafe.Pointer(ds))
	}

	if len(MachineName) != 0 {
		m, _ := syscall.UTF16PtrFromString(MachineName)
		machine = uintptr(unsafe.Pointer(m))
	}

	r, _, _ := procPdhEnumObjects.Call(
		source,  // real-time source,
		machine, // local machine
		uintptr(0),
		uintptr(unsafe.Pointer(&BufferLength)),
		uintptr(PERF_DETAIL_WIZARD),
		0)

	if r != PDH_MORE_DATA {
		return nil, errors.New(codeText[r])
	}

	ObjectList = make([]uint16, BufferLength)

	r, _, _ = procPdhEnumObjects.Call(
		source,  // real-time source,
		machine, // local machine
		uintptr(unsafe.Pointer(&ObjectList[0])), // NULL to get size
		uintptr(unsafe.Pointer(&BufferLength)),
		uintptr(PERF_DETAIL_WIZARD),
		0)

	if r != 0 {
		return nil, errors.New(codeText[r])
	}

	var ret []string

	start := 0
	for i := 0; i < int(BufferLength); i++ {
		if ObjectList[i] == 0 {
			ret = append(ret, syscall.UTF16ToString(ObjectList[start:i]))
			start = i + 1
		}
	}
	return ret, nil
}
Exemplo n.º 21
0
func Rename(oldpath, newpath string) error {
	from, err := syscall.UTF16PtrFromString(oldpath)
	if err != nil {
		return err
	}
	to, err := syscall.UTF16PtrFromString(newpath)
	if err != nil {
		return err
	}
	return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)
}
Exemplo n.º 22
0
func atomicRename(source, target string) error {
	lpReplacedFileName, err := syscall.UTF16PtrFromString(target)
	if err != nil {
		return err
	}
	lpReplacementFileName, err := syscall.UTF16PtrFromString(source)
	if err != nil {
		return err
	}
	return moveFileEx(lpReplacementFileName, lpReplacedFileName, moveFileReplaceExisting|moveFileWriteThrough)
}
Exemplo n.º 23
0
// The windows implementation of os.Rename(...) doesn't allow renaming files
// across drives (i.e. copy and delete semantics) - this alternative
// implementation is identical to the os.Rename(...) implementation, but
// additionally sets the flag windows.MOVEFILE_COPY_ALLOWED in order to cater
// for oldpath and newpath being on different drives. See:
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
func RenameCrossDevice(oldpath, newpath string) error {
	from, err := syscall.UTF16PtrFromString(oldpath)
	if err != nil {
		return err
	}
	to, err := syscall.UTF16PtrFromString(newpath)
	if err != nil {
		return err
	}
	return windows.MoveFileEx(from, to, windows.MOVEFILE_REPLACE_EXISTING|windows.MOVEFILE_COPY_ALLOWED)
}
Exemplo n.º 24
0
func lookupPrivilegeValue(systemName string, name string, luid *uint64) (err error) {
	var _p0 *uint16
	_p0, err = syscall.UTF16PtrFromString(systemName)
	if err != nil {
		return
	}
	var _p1 *uint16
	_p1, err = syscall.UTF16PtrFromString(name)
	if err != nil {
		return
	}
	return _lookupPrivilegeValue(_p0, _p1, luid)
}
Exemplo n.º 25
0
func DeviceCapabilitiesInt32(device, port string, fwCapability uint16) (int32, error) {
	pDevice, err := syscall.UTF16PtrFromString(device)
	if err != nil {
		return 0, err
	}
	pPort, err := syscall.UTF16PtrFromString(port)
	if err != nil {
		return 0, err
	}

	r1, _, _ := deviceCapabilitiesProc.Call(uintptr(unsafe.Pointer(pDevice)), uintptr(unsafe.Pointer(pPort)), uintptr(fwCapability), 0, 0)
	return int32(r1), nil
}
Exemplo n.º 26
0
func hcsCreateComputeSystem(id string, configuration string, identity syscall.Handle, computeSystem *hcsSystem, result **uint16) (hr error) {
	var _p0 *uint16
	_p0, hr = syscall.UTF16PtrFromString(id)
	if hr != nil {
		return
	}
	var _p1 *uint16
	_p1, hr = syscall.UTF16PtrFromString(configuration)
	if hr != nil {
		return
	}
	return _hcsCreateComputeSystem(_p0, _p1, identity, computeSystem, result)
}
Exemplo n.º 27
0
func createProcessWithStdHandlesInComputeSystem(id string, paramsJson string, pid *uint32, stdin *syscall.Handle, stdout *syscall.Handle, stderr *syscall.Handle) (hr error) {
	var _p0 *uint16
	_p0, hr = syscall.UTF16PtrFromString(id)
	if hr != nil {
		return
	}
	var _p1 *uint16
	_p1, hr = syscall.UTF16PtrFromString(paramsJson)
	if hr != nil {
		return
	}
	return _createProcessWithStdHandlesInComputeSystem(_p0, _p1, pid, stdin, stdout, stderr)
}
Exemplo n.º 28
0
func createComputeSystem(id string, configuration string) (hr error) {
	var _p0 *uint16
	_p0, hr = syscall.UTF16PtrFromString(id)
	if hr != nil {
		return
	}
	var _p1 *uint16
	_p1, hr = syscall.UTF16PtrFromString(configuration)
	if hr != nil {
		return
	}
	return _createComputeSystem(_p0, _p1)
}
Exemplo n.º 29
0
func importLayer(info *driverInfo, id string, path string, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
	var _p0 *uint16
	_p0, hr = syscall.UTF16PtrFromString(id)
	if hr != nil {
		return
	}
	var _p1 *uint16
	_p1, hr = syscall.UTF16PtrFromString(path)
	if hr != nil {
		return
	}
	return _importLayer(info, _p0, _p1, descriptors)
}
Exemplo n.º 30
0
func createSandboxLayer(info *driverInfo, id string, parent string, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
	var _p0 *uint16
	_p0, hr = syscall.UTF16PtrFromString(id)
	if hr != nil {
		return
	}
	var _p1 *uint16
	_p1, hr = syscall.UTF16PtrFromString(parent)
	if hr != nil {
		return
	}
	return _createSandboxLayer(info, _p0, _p1, descriptors)
}