예제 #1
0
    def hasPerms(self, mode, group):
        """Checks that the specified session has the appropriate group 
        memberships"""

        # Import here to avoid circular dependencies
        from crcnetd.modules.ccs_contact import getUserCache, getCustomerCache, getGroupCache
        
        # Check session is of appropriate type
        if mode == SESSION_RW:
            if self.mode != SESSION_RW:
                return SESSION_NONE

        # normal users have AUTH_AUTHENTICATED by default
        if group == AUTH_AUTHENTICATED:
            return mode
        
        # If we have a cached permission record, return that
        if group in self.permCache.keys():
            return self.permCache[group]

        # Check group membership
        users = getUserCache(self.session_id)
        customers = getCustomerCache(self.session_id)
        groups = getGroupCache(self.session_id)
        admin_id = users[self.login_id]["admin_id"]

        if self._isGroupMember(admin_id, groups[group], groups):
            self.permCache[group] = mode
            return mode

        self.permCache[group] = SESSION_NONE
        return SESSION_NONE
예제 #2
0
    def getGroupMemberships(self):
        """Returns a list of all groups this session belongs to"""
        # Import here to avoid circular dependencies
        from crcnetd.modules.ccs_contact import getUserCache, getCustomerCache, getGroupCache

        # Check group membership
        users = getUserCache(self.session_id)
        customers = getCustomerCache(self.session_id)
        groups = getGroupCache(self.session_id)
        if self.login_id in users.keys():
            contact_id = users[self.login_id]["admin_id"]
        else:
            return []
        
        # Cache memberships
        res = []
        for group in groups.keys():
            if self._isGroupMember(contact_id, groups[group], groups):
                res.append(group)
        return res
예제 #3
0
def _validateCustomerPassword(username, password):
    """Helper routine for login. Validates the users password"""
    from crcnetd.modules.ccs_contact import getCustomerCache
    users = getCustomerCache(ADMIN_SESSION_ID)

    if username not in users.keys():
        log_warn("No user %s" % username)
        return FALSE

    # Get password
    passwd = users[username]["passwd"]
    if len(passwd) <= 0:
        log_warn("No password set for %s" % username)
        return FALSE

    # Check password
    if crypt.crypt(password, passwd) != passwd:
        log_info("Password check failed for %s" % username)
        return FALSE
    
    return users[username]['login_id']