Checks the desired permissions with user id and group id against the metadata of an iNode.
The desired permissions can be bitwise combinations of constants.R_OK, constants.W_OK and constants.X_OK.
178588
function checkPermissions(access, uid, gid, stat) {
  return (access & resolveOwnership(uid, gid, stat)) === access;
}
376810
public function check_permissions() {
        $context = context_module::instance($this->cm->id);
        return has_capability('mod/glossary:exportentry', $context)
            || ($this->entry->userid == $this->user->id && has_capability('mod/glossary:exportownentry', $context));
    }
469000
public boolean hasPermission(AccessControlList acl, String[] permission, Identity user)
   {

      String userId = user.getUserId();

      if (userId.equals(IdentityConstants.SYSTEM))
      {
         // SYSTEM has permission everywhere
         return true;
      }
      else if (userId.equals(acl.getOwner()))
      {
         // Current user is owner of node so has all privileges
         return true;
      }
      else if (userId.equals(IdentityConstants.ANONIM))
      {
         List<String> anyPermissions = acl.getPermissions(IdentityConstants.ANY);

         if (anyPermissions.size() < permission.length)
            return false;

         for (int i = 0; i < permission.length; i++)
         {
            if (!anyPermissions.contains(permission[i]))
               return false;
         }

         return true;
      }
      else
      {

         if (acl.getPermissionsSize() > 0 && permission.length > 0)
         {
            // check permission to perform all of the listed actions
            for (int i = 0; i < permission.length; i++)
            {
               // check specific actions
               if (!isPermissionMatch(acl.getPermissionsList(), permission[i], user))
                  return false;
            }
            return true;
         }
         return false;

      }
   }
1034061
def _perform_basic_permission_check(self, forum, user, permission):
        
        checker = self._get_checker(user)

        # The action is granted if...
        #     the user is the superuser
        #     the user has the permission to do so
        check = (user.is_superuser or checker.has_perm(permission, forum))
        return check
54040
def parse_permissions(perms):
    
    if isinstance(perms, six.string_types):
        perms = perms.split(',')
    perms = [perm.strip().lower() for perm in perms]
    if 'all' in perms:
        return ALL_PERMISSIONS
    return validate_permissions(perms)
1166927
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_add_post(obj, user)
874351
async def check_permissions(self, action: str, **kwargs):
        
        for permission in await self.get_permissions(action=action, **kwargs):

            if not await ensure_async(permission.has_permission)(
                    scope=self.scope, consumer=self, action=action, **kwargs):
                raise PermissionDenied()
972943
function checkPermissions (access: number, uid: number, gid: number, stat: Stat): boolean {
  return (access & resolveOwnership(uid, gid, stat)) === access;
}
52680
private CompletableFuture<Collection<Permission>> findPermissions0(String projectName, String repoName,
                                                                       User user) {
        requireNonNull(projectName, "projectName");
        requireNonNull(repoName, "repoName");
        requireNonNull(user, "user");

        return getProject(projectName).thenApply(metadata -> {
            final RepositoryMetadata repositoryMetadata = metadata.repo(repoName);
            final Member member = metadata.memberOrDefault(user.id(), null);

            // If the member is guest.
            if (member == null) {
                return repositoryMetadata.perRolePermissions().guest();
            }
            final Collection<Permission> p = repositoryMetadata.perUserPermissions().get(member.id());
            if (p != null) {
                return p;
            }
            return findPerRolePermissions(repositoryMetadata, member.role());
        });
    }
19535
def check_permissions(self, filename):
        '''
        
        '''
        if salt.utils.platform.is_windows():
            return True

        # After we've ascertained we're not on windows
        groups = salt.utils.user.get_gid_list(self.opts['user'], include_default=False)
        fmode = os.stat(filename)

        if stat.S_IWOTH & fmode.st_mode:
            # don't allow others to write to the file
            return False

        if stat.S_IWGRP & fmode.st_mode:
            # if the group has write access only allow with permissive_pki_access
            if not self.opts.get('permissive_pki_access', False):
                return False
            elif os.getuid() == 0 and fmode.st_gid not in groups:
                # if salt is root it has to be in the group that has write access
                # this gives the group 'permission' to have write access
                return False

        return True
984114
def _check_permission(self, request):
        

        if self.access_controller:
            self.access_controller.check_perm(request, self)
410793
def _check_dir_meta(name,
                    user,
                    group,
                    mode,
                    follow_symlinks=False):
    '''
    
    '''
    try:
        stats = __salt__['file.stats'](name, None, follow_symlinks)
    except CommandExecutionError:
        stats = {}

    changes = {}
    if not stats:
        changes['directory'] = 'new'
        return changes
    if (user is not None
            and user != stats['user']
            and user != stats.get('uid')):
        changes['user'] = user
    if (group is not None
            and group != stats['group']
            and group != stats.get('gid')):
        changes['group'] = group
    # Normalize the dir mode
    smode = salt.utils.files.normalize_mode(stats['mode'])
    mode = salt.utils.files.normalize_mode(mode)
    if mode is not None and mode != smode:
        changes['mode'] = mode
    return changes
828909
private INode mkdirsInternal(String src,
                                 PermissionStatus permissions)
    throws IOException {
    src = dir.normalizePath(src);
    
    // tokenize the src into components
    String[] names = INodeDirectory.getPathNames(src);
    
    if (!pathValidator.isValidName(src, names)) {
      numInvalidFilePathOperations++;
      throw new IOException("Invalid directory name: " + src);
    }

    // check validity of the username
    checkUserName(permissions);

    // convert the names into an array of bytes w/o holding lock
    byte[][] components = INodeDirectory.getPathComponents(names);
    INode[] inodes = new INode[components.length];

    writeLock();
    try {
      if (NameNode.stateChangeLog.isDebugEnabled()) {
        NameNode.stateChangeLog.debug("DIR* NameSystem.mkdirs: " + src);
      }
      dir.rootDir.getExistingPathINodes(components, inodes);
      if (isPermissionEnabled
          && isPermissionCheckingEnabled(inodes)) {
        checkTraverse(src, inodes);
      }
      INode lastINode = inodes[inodes.length-1];
      if (lastINode !=null && lastINode.isDirectory()) {
        // all the users of mkdirs() are used to expect 'true' even if
        // a new directory is not created.
        return lastINode;
      }
      if (isInSafeMode()) {
        throw new SafeModeException("Cannot create directory " + src, safeMode);
      }
      if (isPermissionEnabled
          && isPermissionCheckingEnabled(inodes)) {
        checkAncestorAccess(src, inodes, FsAction.WRITE);
      }

      // validate that we have enough inodes. This is, at best, a
      // heuristic because the mkdirs() operation migth need to
      // create multiple inodes.
      checkFsObjectLimit();

      if (!dir.mkdirs(src, names, components, inodes, inodes.length, permissions, false, now())) {
        throw new IOException("Invalid directory name: " + src);
      }
      return inodes[inodes.length-1];
    } finally {
      writeUnlock();
    }
  }
190674
def check_permission_safety(path):
    
    f_stats = os.stat(path)
    return (f_stats.st_mode & (stat.S_IRWXG | stat.S_IRWXO)) == 0 and f_stats.st_uid == os.getuid()
1250289
def get_permissions(self, user, obj=_nothing):
        
        rule = self._get_rule(obj)

        all_permissions = (
            attr[len('can_'):] for attr in dir(rule)
            if attr.startswith('can_')
        )

        return set(
            permission for permission in all_permissions
            if self.allows(user, permission, obj)
        )
283916
def permissions(self, **kwargs):
        
        self._validate_loaded()
        return TailoredAudiencePermission.all(self.account, self.id, **kwargs)
1230246
def filter_permissions(self, search):
        
        user = self.request.user
        if user.is_superuser:
            return search
        if user.is_anonymous:
            user = get_anonymous_user()

        filters = [Q('match', users_with_permissions=user.pk)]
        filters.extend([
            Q('match', groups_with_permissions=group.pk) for group in user.groups.all()
        ])
        filters.append(Q('match', public_permission=True))

        # `minimum_should_match` is set to 1 by default
        return search.query('bool', should=filters)