Beispiel #1
0
func NewHString(s string) (hstring hstr.HString, err error) {
	u16 := windows.StringToUTF16Ptr(s)
	len := uint32(utf8.RuneCountInString(s))
	err = errors.MaybeError(procWindowsCreateString.Call(
		uintptr(unsafe.Pointer(u16)),
		uintptr(len),
		uintptr(unsafe.Pointer(&hstring))))
	return
}
Beispiel #2
0
// Create an ExplicitAccess instance denying permissions to the provided name.
func DenyName(accessPermissions uint32, name string) api.ExplicitAccess {
	return api.ExplicitAccess{
		AccessPermissions: accessPermissions,
		AccessMode:        api.DENY_ACCESS,
		Inheritance:       api.SUB_CONTAINERS_AND_OBJECTS_INHERIT,
		Trustee: api.Trustee{
			TrusteeForm: api.TRUSTEE_IS_NAME,
			Name:        windows.StringToUTF16Ptr(name),
		},
	}
}
Beispiel #3
0
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379579.aspx
func SetNamedSecurityInfo(objectName string, objectType int32, secInfo uint32, owner, group *windows.SID, dacl, sacl windows.Handle) error {
	ret, _, err := procSetNamedSecurityInfoW.Call(
		uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(objectName))),
		uintptr(objectType),
		uintptr(secInfo),
		uintptr(unsafe.Pointer(owner)),
		uintptr(unsafe.Pointer(group)),
		uintptr(dacl),
		uintptr(sacl),
	)
	if ret != 0 {
		return err
	}
	return nil
}
Beispiel #4
0
func (ds *Directory) FreeSpace(cancel <-chan struct{}) (int64, error) {
	dir, err := filepath.Abs(ds.Dir)
	if err != nil {
		return 0, err
	}

	// TODO: this doesn't look like it's safe under garbage collection
	var avail, total, free int64
	r1, _, err := getDiskFreeSpaceExW.Call(
		uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(dir))),
		uintptr(unsafe.Pointer(&avail)),
		uintptr(unsafe.Pointer(&total)),
		uintptr(unsafe.Pointer(&free)))
	if r1 == 0 {
		return 0, err
	}

	return free, nil
}
Beispiel #5
0
func TestSetEntriesInAcl(t *testing.T) {
	var (
		entries = []ExplicitAccess{
			{
				AccessPermissions: windows.GENERIC_READ,
				AccessMode:        GRANT_ACCESS,
				Inheritance:       NO_INHERITANCE,
				Trustee: Trustee{
					TrusteeForm: TRUSTEE_IS_NAME,
					Name:        windows.StringToUTF16Ptr("CURRENT_USER"),
				},
			},
		}
		acl windows.Handle
	)
	if err := SetEntriesInAcl(
		entries,
		0,
		&acl,
	); err != nil {
		t.Fatal(err)
	}
	defer windows.LocalFree(acl)
}
Beispiel #6
0
func SysAllocString(v string) (ss *int16) {
	pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(v))))
	ss = (*int16)(unsafe.Pointer(pss))
	return
}