Example #1
0
def dumpPacket(pkt, filePath, pktType=None):
    """Dump packet into file
		Input: (packet or dict) packet, must contain __str__ method
			(string) path to file
		Output: none
	"""
    # check directory
    dirPath = dirname(filePath)
    if not misc.checkDir(dirPath):
        error('Directory %s not available for logging' % dirPath)
        return

    # dump packet to file
    try:
        debug('Dumping packet to file:\n', filePath)
        file = open(filePath, 'a+')
        if pktType == PACKET_TYPE_ACCT:
            pktStr = misc.acctPacketToStr(pkt)
        elif pktType == PACKET_TYPE_AUTH:
            pktStr = misc.authPacketToStr(pkt)
        else:
            pktStr = misc.packetToStr(pkt)
        file.write(pktStr)
        file.close()
    except:
        error('Can not dump packet to file "%s"' % filePath)
        misc.printExceptionError()
Example #2
0
    def ProcessAuthPacket(self, pkt):
        # decrypt crypted attributes
        pkt.decryptAttributes()
        #debug (pkt)

        received = dict(pkt)  # don't use packet instance any more
        check = {'Auth-Type': [None]}
        reply = {}

        debug(misc.authPacketToStr(received))

        # wait for authorization modules to process the request
        authzModulesResult = modules.execAuthorizationModules(
            received, check, reply)
        if authzModulesResult == modules.MODULE_OK:
            # execute authentication modules
            authcModulesResult = modules.execAuthenticationModules(
                received, check, reply)
            if authcModulesResult == modules.MODULE_OK:
                info('===\n')
                info('Authorization and authentication successful')
                return (True, reply)
            else:
                info('===\n')
                info('Authentication phase failed')
                if authcModulesResult == modules.MODULE_FAILED:
                    dumpPacket.dumpFailedAuthPacket(received)
                return (False, reply)
        else:
            info('===\n')
            info('Authorization phase failed')
            if authzModulesResult == modules.MODULE_FAILED:
                dumpPacket.dumpFailedAuthPacket(received)
            return (False, reply)
	def ProcessAuthPacket(self, pkt):
		# decrypt crypted attributes
		pkt.decryptAttributes()
		#debug (pkt)
		
		received = dict(pkt) # don't use packet instance any more
		check = {'Auth-Type': [None]}
		reply = {}
		
		debug (misc.authPacketToStr(received))
		
		# wait for authorization modules to process the request
		authzModulesResult = modules.execAuthorizationModules(received, check, reply)
		if authzModulesResult == modules.MODULE_OK:
			# execute authentication modules
			authcModulesResult = modules.execAuthenticationModules(received, check, reply)
			if authcModulesResult == modules.MODULE_OK:
				info ('===\n')
				info ('Authorization and authentication successful')
				return (True, reply)
			else:
				info ('===\n')
				info ('Authentication phase failed')
				if authcModulesResult == modules.MODULE_FAILED:
					dumpPacket.dumpFailedAuthPacket(received)
				return (False, reply)
		else:
			info ('===\n')
			info ('Authorization phase failed')
			if authzModulesResult == modules.MODULE_FAILED:
				dumpPacket.dumpFailedAuthPacket(received)
			return (False, reply)
Example #4
0
def dumpPacket(pkt, filePath, pktType = None):
	"""Dump packet into file
		Input: (packet or dict) packet, must contain __str__ method
			(string) path to file
		Output: none
	"""
	# check directory
	dirPath = dirname(filePath)
	if not misc.checkDir(dirPath):
		error('Directory %s not available for logging' % dirPath)
		return
		
	# dump packet to file
	try:
		debug ('Dumping packet to file:\n', filePath)
		file = open(filePath, 'a+')
		if pktType == PACKET_TYPE_ACCT:
			pktStr = misc.acctPacketToStr(pkt)
		elif pktType == PACKET_TYPE_AUTH:
			pktStr = misc.authPacketToStr(pkt)
		else:
			pktStr = misc.packetToStr(pkt)
		file.write(pktStr)
		file.close()
	except:
		error('Can not dump packet to file "%s"' % filePath)
		misc.printExceptionError()
	def ProcessAuthPacket(self, pkt):
		# decrypt crypted attributes
		pkt.decryptAttributes()
		#debug (pkt)
		
		received = dict(pkt) # don't use packet instance any more
		check = {'Auth-Type': [None]}
		reply = {}
		
		debug (misc.authPacketToStr(received))
		
		# wait for authorization modules to process the request
		authzModulesResult = modules.execAuthorizationModules(received, check, reply)
		if authzModulesResult == modules.MODULE_OK:
			# execute authentication modules
			check['forward_reply_items'] = self.server.hosts[pkt.source[0]].forward_reply_items
			authcModulesResult = modules.execAuthenticationModules(received, check, reply)
			if authcModulesResult == modules.MODULE_OK:
				#info ('===\n')
				debug ('Authorization and authentication successful')
				return (True, reply)
			elif authcModulesResult == modules.MODULE_CHALLENGE:
				#info ('===\n')
				debug ('Authorization successful, authentication challenge')
				return (modules.MODULE_CHALLENGE, reply)
			elif authcModulesResult == modules.MODULE_INACTIVE:
				#info ('===\n')
				debug ('Authorization phase failed')
				#dumpPacket.dumpFailedAuthPacket(received)
				return (modules.MODULE_INACTIVE, reply)
			else:
				#info ('===\n')
				debug ('Authentication phase failed')
				if authcModulesResult == modules.MODULE_FAILED:
					dumpPacket.dumpFailedAuthPacket(received)
				return (False, reply)
		else:
			#info ('===\n')
			debug ('Authorization phase failed')
			if authzModulesResult == modules.MODULE_FAILED:
				dumpPacket.dumpFailedAuthPacket(received)
			return (False, reply)
Example #6
0
	def testAuthPacketToStr(self):
		output = misc.authPacketToStr(self.auth_pkt)
		self.failUnless(isinstance(output, types.StringTypes))
		self.failUnless(output != '')
Example #7
0
	def testAuthPacketToStr(self):
		output = misc.authPacketToStr(self.auth_pkt)
		self.failUnless(isinstance(output, types.StringTypes))
		self.failUnless(output != '')