// Change the permissions of the specified file. Only the nine
// least-significant bytes are used, allowing access by the file's owner, the
// file's group, and everyone else to be explicitly controlled.
320559
func Chmod(name string, mode os.FileMode) error {
	// https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems
	creatorOwnerSID, err := windows.StringToSid("S-1-3-0")
	if err != nil {
		return err
	}
	creatorGroupSID, err := windows.StringToSid("S-1-3-1")
	if err != nil {
		return err
	}
	everyoneSID, err := windows.StringToSid("S-1-1-0")
	if err != nil {
		return err
	}

	return Apply(
		name,
		true,
		false,
		GrantSid((uint32(mode)&0700)<<23, creatorOwnerSID),
		GrantSid((uint32(mode)&0070)<<26, creatorGroupSID),
		GrantSid((uint32(mode)&0007)<<29, everyoneSID),
	)
}
1304803
func (s *UserDetail) SetPermissionsBoundary(v *AttachedPermissionsBoundary) *UserDetail {
	s.PermissionsBoundary = v
	return s
}
119522
func (client *Client) ModifySecurityGroupPolicy(args *ModifySecurityGroupPolicyArgs) error {
	response := common.Response{}
	err := client.Invoke("ModifySecurityGroupPolicy", args, &response)
	return err
}
725045
func (g *Group) File(path, file string) {
	g.server.File(g.prefix+path, file)
}
304725
func MemberPermissions(orgID ID) []Permission {
	ps := []Permission{}
	for _, r := range AllResourceTypes {
		if r == OrgsResourceType {
			ps = append(ps, Permission{Action: ReadAction, Resource: Resource{Type: r, ID: &orgID}})
			continue
		}
		ps = append(ps, Permission{Action: ReadAction, Resource: Resource{Type: r, OrgID: &orgID}})
	}

	return ps
}
797443
func (t *TimeSeries) Permissions(ctx context.Context) chronograf.Permissions {
	return t.PermissionsF(ctx)
}
877694
func (l *UpdateableFileLock) Update(contents io.Reader) error {
	lockDir := filepath.Dir(l.path)
	newFile, err := ioutil.TempFile(lockDir, fmt.Sprintf(".%s", filepath.Base(l.path)))
	if err != nil {
		return err
	}
	defer newFile.Close()
	if err := newFile.Chmod(l.perms); err != nil {
		os.Remove(newFile.Name())
		return err
	}

	_, err = io.Copy(newFile, contents)
	if err != nil {
		os.Remove(newFile.Name())
		return err
	}

	newFileLock, err := lock.TryExclusiveLock(newFile.Name(), lock.RegFile)
	if err != nil {
		os.Remove(newFile.Name())
		return fmt.Errorf("could not lock tmpfile: %v", err)
	}

	l.lockLock.Lock()
	defer l.lockLock.Unlock()

	if !l.isLocked {
		os.Remove(newFile.Name())
		return AlreadyUnlockedErr
	}
	// Overwrite the old lock with our new one that has the correct contents
	err = os.Rename(newFile.Name(), l.path)
	if err != nil {
		return err
	}
	// Lock overwritten, update our internal state while we still hold the mutex
	oldLock := l.lock
	l.lock = newFileLock
	oldLock.Unlock()
	return nil
}
454063
func (s *ResourceAccessPolicy) SetPermission(v string) *ResourceAccessPolicy {
	s.Permission = &v
	return s
}
1059246
func (info *FileInfo) Changes(oldInfo *FileInfo) []Change {
	var changes []Change

	info.addChanges(oldInfo, &changes)

	return changes
}
825466
func (w *walker) updateFileInfo(file, curFile protocol.FileInfo) protocol.FileInfo {
	if file.Type == protocol.FileInfoTypeFile && runtime.GOOS == "windows" {
		// If we have an existing index entry, copy the executable bits
		// from there.
		file.Permissions |= (curFile.Permissions & 0111)
	}
	file.Version = curFile.Version.Update(w.ShortID)
	file.ModifiedBy = w.ShortID
	file.LocalFlags = w.LocalFlags
	return file
}
500548
func MePermissions(userID ID) []Permission {
	ps := []Permission{}
	for _, a := range actions {
		ps = append(ps, Permission{Action: a, Resource: Resource{Type: UsersResourceType, ID: &userID}})
	}

	return ps
}
759203
func (c *Checkout) ChangedFiles(ctx context.Context, ref string) ([]string, error) {
	list, err := changed(ctx, c.dir, ref, c.config.Paths)
	if err == nil {
		for i, file := range list {
			list[i] = filepath.Join(c.dir, file)
		}
	}
	return list, err
}
541648
func sslCertificatePermissions(cert, key os.FileInfo) {
	kmode := key.Mode()
	if kmode != kmode&0600 {
		panic(ErrSSLKeyHasWorldPermissions)
	}
}
138999
func (pkz privKeys) Change(i int) privKeys {
	res := make(privKeys, len(pkz))
	copy(res, pkz)
	res[i] = ed25519.GenPrivKey()
	return res
}
1152018
func (o *Options) CheckPermissions() error {
	// get the directory the file exists in
	path, err := o.getPath()
	if err != nil {
		return err
	}

	fileDir := filepath.Dir(path)
	fileName := filepath.Base(path)

	// attempt to open a file in the file's directory
	newPath := filepath.Join(fileDir, fmt.Sprintf(".%s.new", fileName))
	fp, err := openFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, o.TargetMode)
	if err != nil {
		return err
	}
	fp.Close()

	_ = os.Remove(newPath)
	return nil
}
391921
func (s *SharedImagePermissions) SetImagePermissions(v *ImagePermissions) *SharedImagePermissions {
	s.ImagePermissions = v
	return s
}
1285051
func noWritePerms(permissions []string) bool {
	for _, value := range permissions {
		if value == PermWrite {
			return false
		}
	}
	return true
}